From b6e05f205d184299dc67d6039a8e80a75512e322 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 10 Jun 2020 09:52:52 +0300 Subject: [PATCH 1/6] SKALE-2693 add logs and improve error handling --- libethereum/SkaleHost.cpp | 5 +++++ libskale/SnapshotHashAgent.cpp | 15 +++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 627866613..8922dfd25 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -395,6 +395,11 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro if ( this->m_client.chainParams().sChain.snapshotIntervalMs > 0 ) { // this is need for testing. should add better handling + LOG( m_traceLogger ) + << cc::debug( "STATE ROOT FOR BLOCK: " ) << cc::debug( std::to_string( _blockID ) ) + << cc::debug( this->m_client.blockInfo( this->m_client.hashFromNumber( _blockID ) ) + .stateRoot() + .hex() ); assert( dev::h256::Arith( this->m_client.blockInfo( this->m_client.hashFromNumber( _blockID ) ) .stateRoot() ) == _stateRoot ); diff --git a/libskale/SnapshotHashAgent.cpp b/libskale/SnapshotHashAgent.cpp index bc1f82839..3af1c717f 100644 --- a/libskale/SnapshotHashAgent.cpp +++ b/libskale/SnapshotHashAgent.cpp @@ -60,11 +60,15 @@ bool SnapshotHashAgent::voteForHash( std::pair< dev::h256, libff::alt_bn128_G1 > bool verified = false; try { this->verifyAllData( verified ); - } catch ( std::exception& ex ) { - std::throw_with_nested( std::runtime_error( + } catch ( IsNotVerified& ex ) { + IsNotVerified( cc::fatal( "FATAL:" ) + " " + cc::error( "Exception while verifying signatures from other skaleds: " ) + " " + - cc::warn( ex.what() ) ) ); + cc::warn( ex.what() ) ); + } catch ( std::exception& ex ) { + std::throw_with_nested( cc::fatal( "FATAL:" ) + " " + + cc::error( "Exception while verifying signatures from other skaleds: " ) + " " + + cc::warn( ex.what() ) ); } if ( !verified ) { @@ -200,7 +204,10 @@ std::vector< std::string > SnapshotHashAgent::getNodesToDownloadSnapshotFrom( bool result = false; try { result = this->voteForHash( this->voted_hash_ ); - } catch ( NotEnoughVotesException& ex ) { + } catch ( SnapshotHashAgentException& ex ) { + std::cerr << cc::error( "Exception while voting for snapshot hash from other skaleds: " ) + << cc::warn( ex.what() ) << std::endl; + } catch ( std::exception& ex ) { std::cerr << cc::error( "Exception while voting for snapshot hash from other skaleds: " ) << cc::warn( ex.what() ) << std::endl; } From 05990770d5a6ba0a58ef141efaf68225450ce009 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 10 Jun 2020 09:58:42 +0300 Subject: [PATCH 2/6] SKALE-2693 format --- libskale/SnapshotHashAgent.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libskale/SnapshotHashAgent.cpp b/libskale/SnapshotHashAgent.cpp index 3af1c717f..a7d712cf0 100644 --- a/libskale/SnapshotHashAgent.cpp +++ b/libskale/SnapshotHashAgent.cpp @@ -61,14 +61,14 @@ bool SnapshotHashAgent::voteForHash( std::pair< dev::h256, libff::alt_bn128_G1 > try { this->verifyAllData( verified ); } catch ( IsNotVerified& ex ) { - IsNotVerified( + IsNotVerified( cc::fatal( "FATAL:" ) + " " + + cc::error( "Exception while verifying signatures from other skaleds: " ) + + " " + cc::warn( ex.what() ) ); + } catch ( std::exception& ex ) { + std::throw_with_nested( cc::fatal( "FATAL:" ) + " " + cc::error( "Exception while verifying signatures from other skaleds: " ) + " " + cc::warn( ex.what() ) ); - } catch ( std::exception& ex ) { - std::throw_with_nested( cc::fatal( "FATAL:" ) + " " + - cc::error( "Exception while verifying signatures from other skaleds: " ) + " " + - cc::warn( ex.what() ) ); } if ( !verified ) { From 8bbcacd2e4ce7c6843b4a44fcb5f3c1568ff13cc Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 10 Jun 2020 12:48:51 +0300 Subject: [PATCH 3/6] SKALE-2693 improve error handling --- libskale/SnapshotHashAgent.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libskale/SnapshotHashAgent.cpp b/libskale/SnapshotHashAgent.cpp index a7d712cf0..79481ee79 100644 --- a/libskale/SnapshotHashAgent.cpp +++ b/libskale/SnapshotHashAgent.cpp @@ -229,8 +229,14 @@ std::vector< std::string > SnapshotHashAgent::getNodesToDownloadSnapshotFrom( } std::pair< dev::h256, libff::alt_bn128_G1 > SnapshotHashAgent::getVotedHash() const { - assert( this->voted_hash_.first != dev::h256() && - this->voted_hash_.second != libff::alt_bn128_G1::zero() && - this->voted_hash_.second.is_well_formed() ); + if ( this->voted_hash_.first == dev::h256() ) { + throw std::invalid_argument( "Hash is empty" ); + } + + if ( this->voted_hash_.second == libff::alt_bn128_G1::zero() || + !this->voted_hash_.second.is_well_formed() ) { + throw std::invalid_argument( "Signature is not well formed" ); + } + return this->voted_hash_; } From 6e01d7fc1deeca5e273bbfb263c189e42809a7f4 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 11 Jun 2020 14:55:33 +0300 Subject: [PATCH 4/6] SKALE-2693 edit release name --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e2105eb54..9cf9499b2 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -181,7 +181,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token with: tag_name: ${{ env.VERSION }} - release_name: Release ${{ env.VERSION }} + release_name: ${{ env.VERSION }} draft: false prerelease: true From 90139ed995886a46b08a3b1f3223e9b60545532d Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 11 Jun 2020 17:37:12 +0300 Subject: [PATCH 5/6] SKLAE-2693 remove redundant code --- libethereum/Client.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 8a9c320b3..5e556f2ab 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -988,14 +988,10 @@ void Client::updateHashes( unsigned block_number ) { if ( this->last_snapshoted_block == -1 ) { this->last_snapshot_hashes.first = this->m_snapshotManager->getSnapshotHash( block_number ); } else { - if ( this->last_snapshot_hashes.second == this->empty_str_hash ) { - this->last_snapshot_hashes.second = - this->m_snapshotManager->getSnapshotHash( block_number ); - } else { + if ( this->last_snapshot_hashes.second != this->empty_str_hash ) { std::swap( this->last_snapshot_hashes.first, this->last_snapshot_hashes.second ); - this->last_snapshot_hashes.second = - this->m_snapshotManager->getSnapshotHash( block_number ); } + this->last_snapshot_hashes.second = this->m_snapshotManager->getSnapshotHash( block_number ); } this->last_snapshoted_block = block_number; } From 775555fae0baaf1dc1088f593f3f93cbddc5b326 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 11 Jun 2020 18:28:29 +0300 Subject: [PATCH 6/6] SKALE-2693 format --- libethereum/Client.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 5e556f2ab..401607f0c 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -991,7 +991,8 @@ void Client::updateHashes( unsigned block_number ) { if ( this->last_snapshot_hashes.second != this->empty_str_hash ) { std::swap( this->last_snapshot_hashes.first, this->last_snapshot_hashes.second ); } - this->last_snapshot_hashes.second = this->m_snapshotManager->getSnapshotHash( block_number ); + this->last_snapshot_hashes.second = + this->m_snapshotManager->getSnapshotHash( block_number ); } this->last_snapshoted_block = block_number; }