From a820829e0ec63eb3b5223d8bce749c2c90f97860 Mon Sep 17 00:00:00 2001 From: "John L. Jegutanis" Date: Tue, 14 Mar 2017 02:27:32 +0200 Subject: [PATCH] Dynamic header support Block headers can have a dynamic size that is being indexed on a new meta file "headers_offsets". The offsets are 64 bits in order to accommodate coins with big headers that will accumulate GBs of header data after some years. Closes #128 --- docs/AUTHORS | 3 ++- server/db.py | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/docs/AUTHORS b/docs/AUTHORS index 722c701..09871ce 100644 --- a/docs/AUTHORS +++ b/docs/AUTHORS @@ -1,2 +1,3 @@ Neil Booth: creator and maintainer -Johann Bauer: backend DB abstraction \ No newline at end of file +Johann Bauer: backend DB abstraction +John Jegutanis: alt-chain integrations \ No newline at end of file diff --git a/server/db.py b/server/db.py index 2d65ea2..cd42d66 100644 --- a/server/db.py +++ b/server/db.py @@ -50,7 +50,8 @@ class DB(util.LoggedClass): self.header_offset = self.coin.static_header_offset self.header_len = self.coin.static_header_len else: - raise Exception("Non static headers are not supported") + self.header_offset = self.dynamic_header_offset + self.header_len = self.dynamic_header_len self.logger.info('switching current directory to {}' .format(env.db_dir)) @@ -69,6 +70,12 @@ class DB(util.LoggedClass): self.headers_file = util.LogicalFile('meta/headers', 2, 16000000) self.tx_counts_file = util.LogicalFile('meta/txcounts', 2, 2000000) self.hashes_file = util.LogicalFile('meta/hashes', 4, 16000000) + if not self.coin.STATIC_BLOCK_HEADERS: + self.headers_offsets_file = util.LogicalFile( + 'meta/headers_offsets', 2, 16000000) + # Write the offset of the genesis block + if self.headers_offsets_file.read(0, 8) != b'\x00' * 8: + self.headers_offsets_file.write(0, b'\x00' * 8) # tx_counts[N] has the cumulative number of txs at the end of # height N. So tx_counts[0] is 1 - the genesis coinbase @@ -192,6 +199,28 @@ class DB(util.LoggedClass): self.clear_excess_history(self.utxo_flush_count) self.clear_excess_undo_info() + def fs_update_header_offsets(self, offset_start, height_start, headers): + if self.coin.STATIC_BLOCK_HEADERS: + return + offset = offset_start + offsets = [] + for h in headers: + offset += len(h) + offsets.append(pack("