未验证 提交 a339b5d6 编写于 作者: W wanderingbort 提交者: GitHub

Merge pull request #2714 from wanderingbort/feature/explicitly-remove-implicit-calls

explicitly remove implicit calls
...@@ -710,8 +710,8 @@ struct controller_impl { ...@@ -710,8 +710,8 @@ struct controller_impl {
void push_block( const signed_block_ptr& b ) { void push_block( const signed_block_ptr& b ) {
FC_ASSERT(!pending, "it is not valid to push a block when there is a pending block");
try { try {
if( pending ) abort_block();
FC_ASSERT( b ); FC_ASSERT( b );
auto new_header_state = fork_db.add( b ); auto new_header_state = fork_db.add( b );
emit( self.accepted_block_header, new_header_state ); emit( self.accepted_block_header, new_header_state );
...@@ -720,6 +720,7 @@ struct controller_impl { ...@@ -720,6 +720,7 @@ struct controller_impl {
} }
void push_confirmation( const header_confirmation& c ) { void push_confirmation( const header_confirmation& c ) {
FC_ASSERT(!pending, "it is not valid to push a confirmation when there is a pending block");
fork_db.add( c ); fork_db.add( c );
emit( self.accepted_confirmation, c ); emit( self.accepted_confirmation, c );
maybe_switch_forks(); maybe_switch_forks();
...@@ -730,7 +731,6 @@ struct controller_impl { ...@@ -730,7 +731,6 @@ struct controller_impl {
if( new_head->header.previous == head->id ) { if( new_head->header.previous == head->id ) {
try { try {
abort_block();
apply_block( new_head->block ); apply_block( new_head->block );
fork_db.mark_in_current_chain( new_head, true ); fork_db.mark_in_current_chain( new_head, true );
fork_db.set_validity( new_head, true ); fork_db.set_validity( new_head, true );
...@@ -822,8 +822,10 @@ struct controller_impl { ...@@ -822,8 +822,10 @@ struct controller_impl {
void finalize_block() void finalize_block()
{ try { {
if( !pending ) self.start_block(); FC_ASSERT(pending, "it is not valid to finalize when there is no pending block");
try {
/* /*
ilog( "finalize block ${n} (${id}) at ${t} by ${p} (${signing_key}); schedule_version: ${v} lib: ${lib} #dtrxs: ${ndtrxs} ${np}", ilog( "finalize block ${n} (${id}) at ${t} by ${p} (${signing_key}); schedule_version: ${v} lib: ${lib} #dtrxs: ${ndtrxs} ${np}",
......
...@@ -83,6 +83,7 @@ namespace eosio { namespace testing { ...@@ -83,6 +83,7 @@ namespace eosio { namespace testing {
} }
signed_block_ptr base_tester::push_block(signed_block_ptr b) { signed_block_ptr base_tester::push_block(signed_block_ptr b) {
control->abort_block();
control->push_block(b); control->push_block(b);
return b; return b;
} }
...@@ -650,6 +651,7 @@ namespace eosio { namespace testing { ...@@ -650,6 +651,7 @@ namespace eosio { namespace testing {
for( int i = 1; i <= a.control->head_block_num(); ++i ) { for( int i = 1; i <= a.control->head_block_num(); ++i ) {
auto block = a.control->fetch_block_by_number(i); auto block = a.control->fetch_block_by_number(i);
if( block ) { //&& !b.control->is_known_block(block->id()) ) { if( block ) { //&& !b.control->is_known_block(block->id()) ) {
b.control->abort_block();
b.control->push_block(block); //, eosio::chain::validation_steps::created_block); b.control->push_block(block); //, eosio::chain::validation_steps::created_block);
} }
} }
......
...@@ -82,6 +82,7 @@ BOOST_AUTO_TEST_CASE( forking ) try { ...@@ -82,6 +82,7 @@ BOOST_AUTO_TEST_CASE( forking ) try {
wlog( "push c1 blocks to c2" ); wlog( "push c1 blocks to c2" );
while( c2.control->head_block_num() < c.control->head_block_num() ) { while( c2.control->head_block_num() < c.control->head_block_num() ) {
auto fb = c.control->fetch_block_by_number( c2.control->head_block_num()+1 ); auto fb = c.control->fetch_block_by_number( c2.control->head_block_num()+1 );
c2.control->abort_block();
c2.control->push_block( fb ); c2.control->push_block( fb );
} }
wlog( "end push c1 blocks to c2" ); wlog( "end push c1 blocks to c2" );
...@@ -107,6 +108,7 @@ BOOST_AUTO_TEST_CASE( forking ) try { ...@@ -107,6 +108,7 @@ BOOST_AUTO_TEST_CASE( forking ) try {
wlog( "push c1 blocks to c2" ); wlog( "push c1 blocks to c2" );
while( c2.control->head_block_num() < c.control->head_block_num() ) { while( c2.control->head_block_num() < c.control->head_block_num() ) {
auto fb = c.control->fetch_block_by_number( c2.control->head_block_num()+1 ); auto fb = c.control->fetch_block_by_number( c2.control->head_block_num()+1 );
c2.control->abort_block();
c2.control->push_block( fb ); c2.control->push_block( fb );
} }
wlog( "end push c1 blocks to c2" ); wlog( "end push c1 blocks to c2" );
...@@ -134,6 +136,7 @@ BOOST_AUTO_TEST_CASE( forking ) try { ...@@ -134,6 +136,7 @@ BOOST_AUTO_TEST_CASE( forking ) try {
wlog( "push c2 blocks to c1" ); wlog( "push c2 blocks to c1" );
for( uint32_t start = fork_block_num + 1, end = c2.control->head_block_num(); start <= end; ++start ) { for( uint32_t start = fork_block_num + 1, end = c2.control->head_block_num(); start <= end; ++start ) {
auto fb = c2.control->fetch_block_by_number( start ); auto fb = c2.control->fetch_block_by_number( start );
c.control->abort_block();
c.control->push_block( fb ); c.control->push_block( fb );
} }
wlog( "end push c2 blocks to c1" ); wlog( "end push c2 blocks to c1" );
...@@ -153,6 +156,7 @@ BOOST_AUTO_TEST_CASE( forking ) try { ...@@ -153,6 +156,7 @@ BOOST_AUTO_TEST_CASE( forking ) try {
wlog( "push c1 blocks to c2" ); wlog( "push c1 blocks to c2" );
while( c2.control->head_block_num() < c.control->head_block_num() ) { while( c2.control->head_block_num() < c.control->head_block_num() ) {
auto fb = c.control->fetch_block_by_number( c2.control->head_block_num()+1 ); auto fb = c.control->fetch_block_by_number( c2.control->head_block_num()+1 );
c2.control->abort_block();
c2.control->push_block( fb ); c2.control->push_block( fb );
} }
wlog( "end push c1 blocks to c2" ); wlog( "end push c1 blocks to c2" );
...@@ -180,12 +184,14 @@ BOOST_AUTO_TEST_CASE( forking ) try { ...@@ -180,12 +184,14 @@ BOOST_AUTO_TEST_CASE( forking ) try {
wlog( "push c2 blocks (except for the last block by dan) to c1" ); wlog( "push c2 blocks (except for the last block by dan) to c1" );
for( uint32_t start = fork_block_num + 1, end = c2.control->head_block_num() - 1; start <= end; ++start ) { for( uint32_t start = fork_block_num + 1, end = c2.control->head_block_num() - 1; start <= end; ++start ) {
auto fb = c2.control->fetch_block_by_number( start ); auto fb = c2.control->fetch_block_by_number( start );
c.control->abort_block();
c.control->push_block( fb ); c.control->push_block( fb );
} }
wlog( "end push c2 blocks to c1" ); wlog( "end push c2 blocks to c1" );
wlog( "now push dan's block to c1 but first corrupt it so it is a bad block" ); wlog( "now push dan's block to c1 but first corrupt it so it is a bad block" );
auto bad_block = *b; auto bad_block = *b;
bad_block.transaction_mroot = bad_block.previous; bad_block.transaction_mroot = bad_block.previous;
c.control->abort_block();
BOOST_REQUIRE_EXCEPTION(c.control->push_block( std::make_shared<signed_block>(bad_block) ), fc::exception, BOOST_REQUIRE_EXCEPTION(c.control->push_block( std::make_shared<signed_block>(bad_block) ), fc::exception,
[] (const fc::exception &ex)->bool { [] (const fc::exception &ex)->bool {
return ex.to_detail_string().find("block not signed by expected key") != std::string::npos; return ex.to_detail_string().find("block not signed by expected key") != std::string::npos;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册