| 164 | } |
| 165 | |
| 166 | size_t BlockFilterIndex::WriteFilterToDisk(FlatFilePos& pos, const BlockFilter& filter) |
| 167 | { |
| 168 | assert(filter.GetFilterType() == GetFilterType()); |
| 169 | |
| 170 | size_t data_size = |
| 171 | GetSerializeSize(filter.GetBlockHash(), CLIENT_VERSION) + |
| 172 | GetSerializeSize(filter.GetEncodedFilter(), CLIENT_VERSION); |
| 173 | |
| 174 | // If writing the filter would overflow the file, flush and move to the next one. |
| 175 | if (pos.nPos + data_size > MAX_FLTR_FILE_SIZE) { |
| 176 | CAutoFile last_file(m_filter_fileseq->Open(pos), SER_DISK, CLIENT_VERSION); |
| 177 | if (last_file.IsNull()) { |
| 178 | LogPrintf("%s: Failed to open filter file %d\n", __func__, pos.nFile); |
| 179 | return 0; |
| 180 | } |
| 181 | if (!TruncateFile(last_file.Get(), pos.nPos)) { |
| 182 | LogPrintf("%s: Failed to truncate filter file %d\n", __func__, pos.nFile); |
| 183 | return 0; |
| 184 | } |
| 185 | if (!FileCommit(last_file.Get())) { |
| 186 | LogPrintf("%s: Failed to commit filter file %d\n", __func__, pos.nFile); |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | pos.nFile++; |
| 191 | pos.nPos = 0; |
| 192 | } |
| 193 | |
| 194 | // Pre-allocate sufficient space for filter data. |
| 195 | bool out_of_space; |
| 196 | m_filter_fileseq->Allocate(pos, data_size, out_of_space); |
| 197 | if (out_of_space) { |
| 198 | LogPrintf("%s: out of disk space\n", __func__); |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | CAutoFile fileout(m_filter_fileseq->Open(pos), SER_DISK, CLIENT_VERSION); |
| 203 | if (fileout.IsNull()) { |
| 204 | LogPrintf("%s: Failed to open filter file %d\n", __func__, pos.nFile); |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | fileout << filter.GetBlockHash() << filter.GetEncodedFilter(); |
| 209 | return data_size; |
| 210 | } |
| 211 | |
| 212 | bool BlockFilterIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex) |
| 213 | { |
nothing calls this directly
no test coverage detected