Skip to content

Commit

Permalink
Merge pull request #2094 from skalenetwork/enhancement/2004-patch-tim…
Browse files Browse the repository at this point in the history
…estamp-debug-api

Feature/2004 Add debug api for patchTimestamps
  • Loading branch information
olehnikolaiev authored Feb 11, 2025
2 parents 3ff7836 + fcfccdb commit 281a8a2
Show file tree
Hide file tree
Showing 11 changed files with 112 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
- name: checkout
uses: actions/checkout@v2
- name: Cache apt packages
uses: actions/cache@v2
uses: actions/cache@v4.2.0
with:
path: |
/var/cache/apt/archives
Expand Down
45 changes: 36 additions & 9 deletions docs/json-rpc-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This doc does NOT describe all possible erroneous situations.

Parameters marked as `OPTIONAL` are optional, otherwise they are required!

---

## `web3_*` Methods

### `web3_clientVersion`
Expand Down Expand Up @@ -38,6 +40,9 @@ Get `sha3` (`keccak256`) hash of input data
#### Return format
Output data represented as a "0x"-prefixed hex `String` (32 bytes)


---

## `net_*` Methods

### `net_version`
Expand Down Expand Up @@ -79,6 +84,8 @@ None
#### Return format
`String` value "0x0"

---

## `eth_*` Methods

### `eth_protocolVersion`
Expand Down Expand Up @@ -1007,36 +1014,56 @@ WS(S): unsubscribe from events/transactions/blocks/stats (see `eth_subscribe`)
#### Return format
None


---

## `personal_*` Methods
Not supported

---

## `db_*` Methods
Not supported

---

## `shh_*` Methods
Not supported

---

## `debug_*` Methods
### debug_accountRangeAt
### `debug_accountRangeAt`
#### Description
Not supported, always throws exception

### debug_traceTransaction
### debug_storageRangeAt
### `debug_traceTransaction`
### `debug_storageRangeAt`
#### Description
Not supported, always throws exception

### debug_preimage
### `debug_preimage`
#### Description
Not supported, always throws exception

### debug_traceBlockByNumber
### debug_traceBlockByHash
### debug_traceCall
### `debug_traceBlockByNumber`
### `debug_traceBlockByHash`
### `debug_traceCall`

### `debug_getPatchTimestamps`

#### Description
Gets timestamps for all patches defined.

#### Parameters
None

#### Return format
Returns the timestamp of each defined patch. Returns `0` for any undefined patch timestamp.


## Non-standard Methods
### oracle_submitRequest
### oracle_checkResult
### `oracle_submitRequest`
### `oracle_checkResult`


2 changes: 0 additions & 2 deletions libethereum/SchainPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ std::string getPatchNameForEnum( SchainPatchEnum _enumValue ) {
return "StorageDestructionPatch";
case SchainPatchEnum::SkipInvalidTransactionsPatch:
return "SkipInvalidTransactionsPatch";
case SchainPatchEnum::SelfdestructStorageLimitPatch:
return "SelfdestructStorageLimitPatch";
case SchainPatchEnum::VerifyDaSigsPatch:
return "VerifyDaSigsPatch";
case SchainPatchEnum::FastConsensusPatch:
Expand Down
5 changes: 0 additions & 5 deletions libethereum/SchainPatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ DEFINE_AMNESIC_PATCH( ContractStoragePatch )
*/
DEFINE_AMNESIC_PATCH( StorageDestructionPatch );

/*
* Enable restriction on contract storage size, when it's doing selfdestruct
*/
DEFINE_SIMPLE_PATCH( SelfdestructStorageLimitPatch );

/*
* Enable restriction on contract storage size, when it's doing selfdestruct
*/
Expand Down
1 change: 0 additions & 1 deletion libethereum/SchainPatchEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ enum class SchainPatchEnum {
ContractStoragePatch,
StorageDestructionPatch,
SkipInvalidTransactionsPatch,
SelfdestructStorageLimitPatch,
VerifyDaSigsPatch,
FastConsensusPatch,
EIP1559TransactionsPatch,
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
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 @@ -2991,6 +2991,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< size_t > 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 );
size_t 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;
}

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] );
size_t returnedTimestamp = static_cast< size_t > (returnedPatchTimestamps[patchName].asInt());

BOOST_REQUIRE_EQUAL( returnedTimestamp, patchTimestamps[patchIdx]);
}
}

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

Expand Down

0 comments on commit 281a8a2

Please sign in to comment.