Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6856 from EOSIO/6851-completed-block-construction…
Browse files Browse the repository at this point in the history
…-bug

fix bug in apply_block that constructed and committed blocks with missing signatures in the protocol-feature-foundations branch
  • Loading branch information
arhag committed Mar 4, 2019
2 parents afd982e + 8974cf7 commit 5560c0d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libraries/chain/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ struct controller_impl {

auto bsp = std::make_shared<block_state>(
std::move( ab._pending_block_header_state ),
std::move( ab._unsigned_block ),
b,
std::move( ab._trx_metas ),
true // signature should have already been verified (assuming untrusted) prior to apply_block
);
Expand Down
6 changes: 3 additions & 3 deletions libraries/chain/include/eosio/chain/block_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ namespace eosio { namespace chain {
);

block_state( pending_block_header_state&& cur,
signed_block_ptr&& b, // unsigned block
vector<transaction_metadata_ptr>&& trx_metas,
const std::function<signature_type(const digest_type&)>& signer
signed_block_ptr&& b, // unsigned block
vector<transaction_metadata_ptr>&& trx_metas,
const std::function<signature_type(const digest_type&)>& signer
);

block_state( pending_block_header_state&& cur,
Expand Down
39 changes: 39 additions & 0 deletions unittests/forked_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,45 @@ BOOST_AUTO_TEST_CASE( prune_remove_branch ) try {
} FC_LOG_AND_RETHROW()


/**
* Tests that a validating node does not accept a block which is considered invalid by another node.
*/
BOOST_AUTO_TEST_CASE( validator_accepts_valid_blocks ) try {

tester n1;
tester n2;
tester n3;

n1.produce_block();

auto id = n1.control->head_block_id();

block_state_ptr first_block;

auto c = n2.control->accepted_block.connect( [&]( const block_state_ptr& bsp) {
if( bsp->block_num == 2 ) {
first_block = bsp;
}
} );

push_blocks( n1, n2 );

BOOST_CHECK_EQUAL( n2.control->head_block_id(), id );

BOOST_REQUIRE( first_block );
first_block->verify_signee( first_block->signee() );
BOOST_CHECK_EQUAL( first_block->header.id(), first_block->block->id() );
BOOST_CHECK( first_block->header.producer_signature == first_block->block->producer_signature );

c.disconnect();

n3.push_block( first_block->block );

BOOST_CHECK_EQUAL( n3.control->head_block_id(), id );


} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_CASE( read_modes ) try {
tester c;
c.produce_block();
Expand Down

0 comments on commit 5560c0d

Please sign in to comment.