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

Enhancement/2004 add patch timestamp debug api #2077

Open
wants to merge 10 commits into
base: v4.0.0
Choose a base branch
from
2 changes: 2 additions & 0 deletions libethereum/SchainPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ SchainPatchEnum getEnumForPatchName( const std::string& _patchName ) {
return SchainPatchEnum::StorageDestructionPatch;
else if ( _patchName == "SkipInvalidTransactionsPatch" )
return SchainPatchEnum::SkipInvalidTransactionsPatch;
else if ( _patchName == "SelfdestructStorageLimitPatch" )
return SchainPatchEnum::SelfdestructStorageLimitPatch;
Comment on lines +29 to +30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this patch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was missing in the original code. We had the SchainPatchEnum::SelfdestructStorageLimitPatch enum variant defined, but not the convertion from its string value to the enum variant in this function (which converts a string to the corresponding SchainPatchEnum variant. So I added the missing conversion.

else if ( _patchName == "VerifyDaSigsPatch" )
return SchainPatchEnum::VerifyDaSigsPatch;
else if ( _patchName == "FastConsensusPatch" )
Expand Down
15 changes: 15 additions & 0 deletions libweb3jsonrpc/Debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,18 @@ Json::Value Debug::debug_getFutureTransactions() {
t.removeMember( "data" );
return res;
}

Json::Value Debug::debug_getPatchTimestamps() {
Json::Value jsonResponse;
ChainParams chainParams = m_eth.chainParams();

size_t numberOfPatches = static_cast< size_t >( SchainPatchEnum::PatchesCount );
for ( size_t patch = 0; patch < numberOfPatches; patch++ ) {
SchainPatchEnum patchEnum = static_cast< SchainPatchEnum >( patch );
std::string patchName = getPatchNameForEnum( patchEnum ) + "Timestamp";
patchName[0] = tolower( patchName[0] );
jsonResponse[patchName] = chainParams.getPatchTimestamp( patchEnum );
}

return jsonResponse;
}
2 changes: 2 additions & 0 deletions libweb3jsonrpc/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Debug : public DebugFace {

virtual Json::Value debug_getFutureTransactions() override;

virtual Json::Value debug_getPatchTimestamps() override;

private:
eth::Client& m_eth;
SkaleDebugInterface* m_debugInterface = nullptr;
Expand Down
10 changes: 10 additions & 0 deletions libweb3jsonrpc/DebugFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ class DebugFace : public ServerInterface< DebugFace > {
this->bindAndAddMethod( jsonrpc::Procedure( "debug_getFutureTransactions",
jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, NULL ),
&dev::rpc::DebugFace::debug_getFutureTransactionsI );

this->bindAndAddMethod( jsonrpc::Procedure( "debug_getPatchTimestamps",
jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, NULL ),
&dev::rpc::DebugFace::debug_getPatchTimestampsI );
}
inline virtual void debug_accountRangeAtI( const Json::Value& request, Json::Value& response ) {
response = this->debug_accountRangeAt( request[0u].asString(), request[1u].asInt(),
Expand Down Expand Up @@ -159,6 +163,10 @@ class DebugFace : public ServerInterface< DebugFace > {
response = this->debug_getFutureTransactions();
}

inline virtual void debug_getPatchTimestampsI( const Json::Value&, Json::Value& response ) {
response = this->debug_getPatchTimestamps();
}

virtual Json::Value debug_accountRangeAt(
const std::string& param1, int param2, const std::string& param3, int param4 ) = 0;
virtual Json::Value debug_storageRangeAt( const std::string& param1, int param2,
Expand All @@ -181,6 +189,8 @@ class DebugFace : public ServerInterface< DebugFace > {
virtual uint64_t debug_doBlocksDbCompaction() = 0;

virtual Json::Value debug_getFutureTransactions() = 0;

virtual Json::Value debug_getPatchTimestamps() = 0;
};

} // namespace rpc
Expand Down
1 change: 1 addition & 0 deletions libweb3jsonrpc/SkaleFace.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class SkaleFace : public ServerInterface< SkaleFace > {
this->bindAndAddMethod( jsonrpc::Procedure( "skale_getLatestBlockNumber",
jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_INTEGER, NULL ),
&dev::rpc::SkaleFace::skale_getLatestBlockNumberI );

this->bindAndAddMethod( jsonrpc::Procedure( "skale_getDBUsage", jsonrpc::PARAMS_BY_POSITION,
jsonrpc::JSON_INTEGER, NULL ),
&dev::rpc::SkaleFace::skale_getDBUsageI );
Expand Down
10 changes: 10 additions & 0 deletions test/unittests/libweb3jsonrpc/WebThreeStubClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1402,3 +1402,13 @@ Json::Value WebThreeStubClient::debug_getFutureTransactions() {
throw jsonrpc::JsonRpcException(
jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString() );
}

Json::Value WebThreeStubClient::debug_getPatchTimestamps() {
Json::Value p;
Json::Value result = this->CallMethod( "debug_getPatchTimestamps", p );
if ( result.isObject() )
return result;
else
throw jsonrpc::JsonRpcException(
jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString() );
}
1 change: 1 addition & 0 deletions test/unittests/libweb3jsonrpc/WebThreeStubClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ class WebThreeStubClient : public jsonrpc::Client {
Json::Value debug_doStateDbCompaction() noexcept( false );
Json::Value debug_doBlocksDbCompaction() noexcept( false );
Json::Value debug_getFutureTransactions() noexcept( false );
Json::Value debug_getPatchTimestamps() noexcept( false );
};

#endif // JSONRPC_CPP_STUB_WEBTHREESTUBCLIENT_H_
37 changes: 37 additions & 0 deletions test/unittests/libweb3jsonrpc/jsonrpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2790,6 +2790,43 @@ BOOST_AUTO_TEST_CASE( doDbCompactionDebugCall ) {
fixture.rpcClient->debug_doBlocksDbCompaction();
}

BOOST_AUTO_TEST_CASE( debugGetPatchTimestamps ) {
Json::Value configJson;
Json::Reader().parse(c_genesisConfigString, configJson);

// indexed by enum int value
std::vector< int > patchTimestamps;

// Set custom config file & create timestamps for each patch
size_t numPatches = static_cast< size_t >( SchainPatchEnum::PatchesCount );
for (size_t patch = 0; patch < numPatches ; patch++ ) {
SchainPatchEnum patchEnum = static_cast< SchainPatchEnum >( patch );
int ts = patch + 1000; // just to offset from the default values (0, 1)
patchTimestamps.push_back(ts);

std::string patchName = getPatchNameForEnum(patchEnum) + "Timestamp";
patchName[0] = tolower( patchName[0] );
configJson["skaleConfig"]["sChain"][patchName] = ts;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use time_t type instead of int, as patchTimestamps are time_t


Json::FastWriter fastWriter;
std::string customConfigFile = fastWriter.write( configJson );

JsonRpcFixture fixture(customConfigFile, false, false, false, false);
Json::Value returnedPatchTimestamps = fixture.rpcClient->debug_getPatchTimestamps();

// compare returned timestamps to actual timestamps
for( size_t patchIdx = 0; patchIdx < numPatches; patchIdx++ ) {
SchainPatchEnum patchEnum = static_cast< SchainPatchEnum >( patchIdx );

std::string patchName = getPatchNameForEnum(patchEnum) + "Timestamp";
patchName[0] = tolower( patchName[0] );

BOOST_REQUIRE_EQUAL(returnedPatchTimestamps[patchName],
patchTimestamps[patchIdx]);
}
}

BOOST_AUTO_TEST_CASE( powTxnGasLimit ) {
JsonRpcFixture fixture(c_genesisConfigString, false, false, true, false);

Expand Down
Loading