From 4c0fbb84d65a866c70e9aff8589efb57e411bd58 Mon Sep 17 00:00:00 2001 From: Lex Berezhny Date: Fri, 14 Feb 2020 12:19:55 -0500 Subject: [PATCH] reproduce issue with lbrycrd -reindex --- .gitignore | 3 +- lbry/blockchain/__init__.py | 2 + lbry/blockchain/block.py | 47 +++++ lbry/blockchain/db.py | 124 ++++++++++++++ lbry/blockchain/lbrycrd.py | 208 +++++++++++++++++++++++ lbry/blockchain/sync.py | 109 ++++++++++++ scripts/generate_blockchain_test_data.py | 24 +++ 7 files changed, 516 insertions(+), 1 deletion(-) create mode 100644 lbry/blockchain/__init__.py create mode 100644 lbry/blockchain/block.py create mode 100644 lbry/blockchain/db.py create mode 100644 lbry/blockchain/lbrycrd.py create mode 100644 lbry/blockchain/sync.py create mode 100644 scripts/generate_blockchain_test_data.py diff --git a/.gitignore b/.gitignore index 36cb694de..ab1320464 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ _trial_temp/ /tests/integration/blockchain/files /tests/.coverage.* -/lbry/wallet/bin \ No newline at end of file +/lbry/blockchain/bin +/lbry/wallet/bin diff --git a/lbry/blockchain/__init__.py b/lbry/blockchain/__init__.py new file mode 100644 index 000000000..6c1cc0ec5 --- /dev/null +++ b/lbry/blockchain/__init__.py @@ -0,0 +1,2 @@ +from .sync import BlockSync +from .lbrycrd import Lbrycrd \ No newline at end of file diff --git a/lbry/blockchain/block.py b/lbry/blockchain/block.py new file mode 100644 index 000000000..150cb6e14 --- /dev/null +++ b/lbry/blockchain/block.py @@ -0,0 +1,47 @@ +import struct +from lbry.crypto.hash import double_sha256 +from lbry.wallet.transaction import Transaction +from lbry.wallet.bcd_data_stream import BCDataStream + + +ZERO_BLOCK = bytes((0,)*32) + + +class Block: + + __slots__ = ( + 'version', 'block_hash', 'prev_block_hash', + 'merkle_root', 'claim_trie_root', 'timestamp', + 'bits', 'nonce', 'txs' + ) + + def __init__(self, stream): + stream.read_uint32() # block size + header = stream.data.read(112) + version, = struct.unpack('