From 3b79b353311924273f44a5458904302b341f5816 Mon Sep 17 00:00:00 2001 From: Guilherme Salgado Date: Fri, 6 Nov 2020 10:11:54 +0000 Subject: [PATCH] Demo issues 1961 and 1962 --- eth/vm/base.py | 2 +- .../test_build_block_incrementally.py | 3 ++- tests/core/consensus/test_clique_consensus.py | 25 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/eth/vm/base.py b/eth/vm/base.py index ebcb2bbdc7..b0c6d4433b 100644 --- a/eth/vm/base.py +++ b/eth/vm/base.py @@ -392,7 +392,7 @@ def finalize_block(self, block: BlockAPI) -> BlockAndMetaWitness: final_block = block.copy(header=block.header.copy(state_root=self.state.state_root)) - self.logger.debug( + self.logger.info( "%s reads %d unique node hashes, %d addresses, %d bytecodes, and %d storage slots", final_block, len(meta_witness.hashes), diff --git a/tests/core/chain-object/test_build_block_incrementally.py b/tests/core/chain-object/test_build_block_incrementally.py index d1a96d086a..d7bfd556f3 100644 --- a/tests/core/chain-object/test_build_block_incrementally.py +++ b/tests/core/chain-object/test_build_block_incrementally.py @@ -35,7 +35,8 @@ def test_building_block_incrementally_with_single_transaction( # test that the *latest* block hasn't changed assert chain.get_canonical_head().hash == head_hash - mined_block = chain.mine_block() + mined_block, meta_witness = chain.mine_block_extended() + assert len(meta_witness.hashes) == 2 assert len(mined_block.transactions) == 1 actual_tx = mined_block.transactions[0] diff --git a/tests/core/consensus/test_clique_consensus.py b/tests/core/consensus/test_clique_consensus.py index a5ea22fc19..750075ac47 100644 --- a/tests/core/consensus/test_clique_consensus.py +++ b/tests/core/consensus/test_clique_consensus.py @@ -235,6 +235,31 @@ def test_validate_chain_works_across_forks(paragon_chain): paragon_chain.validate_chain_extension((PARAGON_GENESIS_HEADER,) + voting_chain) +def test_building_block_incrementally(paragon_chain): + extra_data_len = VANITY_LENGTH + SIGNATURE_LENGTH + header = paragon_chain.header.copy(extra_data=extra_data_len * b'0') + # XXX: Comment out the two lines below and the test will fail. + # This is a quick hack to demonstrate what needs to be done in order to incrementally build + # clique blocks; what we probably need is an API to set the signer before we start building + paragon_chain.header = sign_block_header(header, ALICE_PK) + assert get_block_signer(paragon_chain.header) == ALICE + + tx = new_transaction(paragon_chain.get_vm(), ALICE, BOB, 10, ALICE_PK) + _, _, computation = paragon_chain.apply_transaction(tx) + computation.raise_if_error() + signed_header = sign_block_header( + paragon_chain.header.copy(extra_data=extra_data_len * b'0', difficulty=2, nonce=NONCE_DROP), + ALICE_PK) + mined_block, meta_witness = paragon_chain.mine_block_extended( + extra_data=signed_header.extra_data, difficulty=2, nonce=NONCE_DROP) + state_root = b'\x99\xaa\xf5CF^\x95_\xce~\xe4)\x00\xb1zr\x1dr\xd6\x00N^\xa6\xdc\xc41\x90~\xb7te\x00' # noqa: E501 + assert mined_block.header.state_root == state_root + + # XXX: This should not be empty, just like it is not when using PoW chains + # (tests/core/chain-object/test_build_block_incrementally.py) + assert len(meta_witness.hashes) == 0 + + def test_import_block(paragon_chain): vm = paragon_chain.get_vm()