Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IS-902 check block number to download snapshot #1784

Merged
merged 7 commits into from
Jan 17, 2024
9 changes: 9 additions & 0 deletions libweb3jsonrpc/Skale.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ nlohmann::json Skale::impl_skale_getSnapshot( const nlohmann::json& joRequest, C

// TODO check
unsigned blockNumber = joRequest["blockNumber"].get< unsigned >();
if ( blockNumber != m_client.getLatestSnapshotBlockNumer() ) {
joResponse["error"] = "Invalid snapshot block number requested - it might be deleted.";
return joResponse;
}

// exit if too early
if ( currentSnapshotBlockNumber >= 0 ) {
Expand Down Expand Up @@ -366,6 +370,11 @@ Json::Value Skale::skale_getSnapshotSignature( unsigned blockNumber ) {
if ( chainParams.nodeInfo.keyShareName.empty() || chainParams.nodeInfo.sgxServerUrl.empty() )
throw jsonrpc::JsonRpcException( "Snapshot signing is not enabled" );

if ( blockNumber != this->m_client.getLatestSnapshotBlockNumer() ) {
throw jsonrpc::JsonRpcException(
"Invalid snapshot block number requested - it might be deleted." );
}

try {
dev::h256 snapshot_hash = this->m_client.getSnapshotHash( blockNumber );
if ( !snapshot_hash )
Expand Down
Loading