Skip to content

Commit

Permalink
Merge pull request #288 from skalenetwork/bug/SKALE-2693-stateRoot
Browse files Browse the repository at this point in the history
Bug/skale 2693 state root
  • Loading branch information
olehnikolaiev authored Jun 12, 2020
2 parents 9e22aca + 3deec88 commit 02e9cc0
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 3 additions & 6 deletions libethereum/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,14 +988,11 @@ 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;
}
Expand Down
5 changes: 5 additions & 0 deletions libethereum/SkaleHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
25 changes: 19 additions & 6 deletions libskale/SnapshotHashAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ bool SnapshotHashAgent::voteForHash( std::pair< dev::h256, libff::alt_bn128_G1 >
bool verified = false;
try {
this->verifyAllData( verified );
} catch ( IsNotVerified& ex ) {
IsNotVerified( cc::fatal( "FATAL:" ) + " " +

This comment has been minimized.

Copy link
@dimalit

dimalit Jun 12, 2020

Collaborator

looks like here should be "throw"?

cc::error( "Exception while verifying signatures from other skaleds: " ) +
" " + cc::warn( ex.what() ) );
} catch ( std::exception& ex ) {
std::throw_with_nested( std::runtime_error(
std::throw_with_nested(
cc::fatal( "FATAL:" ) + " " +
cc::error( "Exception while verifying signatures from other skaleds: " ) + " " +
cc::warn( ex.what() ) ) );
cc::warn( ex.what() ) );
}

if ( !verified ) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -222,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_;
}

0 comments on commit 02e9cc0

Please sign in to comment.