MCPcopy Create free account
hub / github.com/ElementsProject/elements / WriteFilterToDisk

Method WriteFilterToDisk

src/index/blockfilterindex.cpp:166–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164}
165
166size_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
212bool BlockFilterIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
213{

Callers

nothing calls this directly

Calls 9

GetSerializeSizeFunction · 0.85
TruncateFileFunction · 0.85
FileCommitFunction · 0.85
GetFilterTypeMethod · 0.45
GetBlockHashMethod · 0.45
OpenMethod · 0.45
IsNullMethod · 0.45
GetMethod · 0.45
AllocateMethod · 0.45

Tested by

no test coverage detected