From 5293237ba301cd36ce3309cd7dba1de23524bd3c Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 4 Jun 2024 21:43:11 +0300 Subject: [PATCH 01/61] Some work on json-rpc-interface.md --- docs/json-rpc-interface.md | 147 +++++++++++++++++++++++++++++-------- 1 file changed, 117 insertions(+), 30 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index d59e9e52c..49d063257 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -2,22 +2,114 @@ # JSON-RPC Interface Compatibility -| Method | Status | Comments | -|:--------------------------------------- |:-------------------:|:----------------------------------------------------------------------------- | -| web3_clientVersion | Supported | | -| web3_sha3 | Supported | | -| net_version | Supported | Returns ChainID from config.json. | -| net_listening | Supported | | -| net_peerCount | Partially supported | Always returns 0 | -| eth_protocolVersion | Supported | | -| eth_syncing | Supported | | -| eth_coinbase | Supported | Returns sChainOwner address from config.json (it is used as coinbase address) | -| eth_mining | Partially supported | There is no mining for SKALE s-chains, always returns false | -| eth_hashrate | Partially supported | There is no hashrate for SKALE s-chains, always returns 0 | -| eth_gasPrice | Supported | Gas price is dynamically adjusted from 1000 wei and above as load grows | -| eth_accounts | Supported | | -| eth_blockNumber | Supported | | -| eth_getBalance | Partially supported | Second parameter is ignored and always set to "latest" | +## `web3_*` Methods + +### `web3_clientVersion` +Returns detailed `skaled` version +### Parameters +None +### Returns +`String` representing exact build of `skaled` + +Example: "skaled/3.19.0+commit.859d742c/linux/gnu9.5.0/debug" + +### `web3_sha3` +Returns `sha3` (`keccak256`) hash of input data +### Parameters +1. Input data represented as a "0x"-prefixed hex `String` +### Returns +Output data represented as a "0x"-prefixed hex `String` (32 bytes) + +## `net_*` Methods + +### `net_version` +Returns chainID from config.json +### Parameters +None +### Returns +Decimal number as `String` + +### `net_listening` +Returns `true` +### Parameters +None +### Returns +Boolean literal `true` + +### `net_peerCount` +Returns 0 +### Parameters +None +### Returns +`String` value "0x0" + +## `eth_*` Methods + +### `eth_protocolVersion` +Returns `0x3f` +### Parameters +None +### Returns +`String` value "0x3f" + +### `eth_syncing` +Returns `false` +### Parameters +None +### Returns +Boolean literal `false` + +### `eth_coinbase` +Returns sChainOwner address from config.json (it is used as coinbase address) +### Parameters +None +### Returns +"0x"-prefixed hex `String` (20 bytes) + +### `eth_mining` +Returns `false` +### Parameters +None +### Returns +Boolean literal `false` + +### `eth_hashrate` +There is no hashrate for SKALE s-chains, always returns 0 +### Parameters +None +### Returns +Boolean `String` literal "0x0" + +### `eth_gasPrice` +Returns current minimum gas price needed for transaction to be accepted into the Transaction Queue. Gas price is dynamically adjusted from 100k wei and above as load grows +### Parameters +None +### Returns +"0x"-prefixed hex `String` representing current gas price + +### `eth_accounts` +Get list of accounts with locally-stored private keys +### Parameters +None +### Returns +`Array` of "0x"-prefixed hex `String`s, 20 bytes each + +### `eth_blockNumber` +Returns the number of most recent block +### Parameters +None +### Returns +"0x"-prefixed hex `String` representing block number + +### `eth_getBalance` +Returns the balance of the account of given address. +### Parameters +1. Address: "0x"-prefixed hex `String`, 20 bytes +2. Block number: `String` that is either +### Returns +"0x"-prefixed hex `String` representing block number + +| | Partially supported | Second parameter is ignored and always set to "latest" | | eth_getStorageAt | Partially supported | Third parameter is ignored and always set to "latest" | | eth_getTransactionCount | Partially supported | Second parameter is ignored and always set to "latest" | | eth_getBlockTransactionCountByHash | Supported | | @@ -53,17 +145,12 @@ | eth_submitWork | Not supported | | | eth_submitHashrate | Supported | | | eth_getProof | Not supported | | -| db_putString | Not supported | | -| db_getString | Not supported | | -| db_putHex | Not supported | | -| db_getHex | Not supported | | -| shh_version | Not supported | | -| shh_post | Not supported | | -| shh_newIdentity | Not supported | | -| shh_hasIdentity | Not supported | | -| shh_newGroup | Not supported | | -| shh_addToGroup | Not supported | | -| shh_newFilter | Not supported | | -| shh_uninstallFilter | Not supported | | -| shh_getFilterChanges | Not supported | | -| shh_getMessages | Not supported | | + +## `personal_*` Methods +Not supported + +## `db_*` Methods +Not supported + +## `shh_*` Methods +Not supported From 621ea96c20d908acc0fcb3a34623558bb420a062 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 5 Jun 2024 17:50:21 +0300 Subject: [PATCH 02/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 49d063257..c99f025c4 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -102,15 +102,32 @@ None "0x"-prefixed hex `String` representing block number ### `eth_getBalance` -Returns the balance of the account of given address. +Returns the balance of the account of given address ### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes -2. Block number: `String` that is either +2. Block number: `String` that is interprered differently for normal and historic builds: +Noramal build: parameter ignored, latest balance is always returted. +Historic build: + - "latest" or "pending" - latest balance is returted; + - "earliest" - balance before block 1 is returned; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. ### Returns -"0x"-prefixed hex `String` representing block number +"0x"-prefixed hex `String` representing balance in wei + +## `eth_getStorageAt` +Returns the value from a storage position at a given account +### Parameters +1. Address: "0x"-prefixed hex `String`, 20 bytes; +2. Position: `String` representation of an integer storage position, either decimal or "0x"-prefixed hexadecimal; +3. Block number: `String` that is interprered differently for normal and historic builds: +Noramal build: parameter ignored, latest value is always returted. +Historic build: + - "latest" or "pending" - latest value is returted; + - "earliest" - value before block 1 is returned; + - `String` representation of and integer block number, either decimal or "0x"-prefixed hexadecimal. +### Returns +"0x"-prefixed hex `String` (32 bytes) -| | Partially supported | Second parameter is ignored and always set to "latest" | -| eth_getStorageAt | Partially supported | Third parameter is ignored and always set to "latest" | | eth_getTransactionCount | Partially supported | Second parameter is ignored and always set to "latest" | | eth_getBlockTransactionCountByHash | Supported | | | eth_getBlockTransactionCountByNumber | Supported | | From 7c2a18c9553d88c24f514b50bdd01fa73b8ea6b4 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 5 Jun 2024 20:18:10 +0300 Subject: [PATCH 03/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 56 ++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index c99f025c4..dd218bc14 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -78,7 +78,7 @@ There is no hashrate for SKALE s-chains, always returns 0 ### Parameters None ### Returns -Boolean `String` literal "0x0" +`String` literal "0x0" ### `eth_gasPrice` Returns current minimum gas price needed for transaction to be accepted into the Transaction Queue. Gas price is dynamically adjusted from 100k wei and above as load grows @@ -105,10 +105,10 @@ None Returns the balance of the account of given address ### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes -2. Block number: `String` that is interprered differently for normal and historic builds: -Noramal build: parameter ignored, latest balance is always returted. +2. Block number: `String` that is interpreted differently for normal and historic builds: +Normal build: parameter ignored, latest balance is always returned. Historic build: - - "latest" or "pending" - latest balance is returted; + - "latest" or "pending" - latest balance is returned; - "earliest" - balance before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. ### Returns @@ -119,21 +119,49 @@ Returns the value from a storage position at a given account ### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; 2. Position: `String` representation of an integer storage position, either decimal or "0x"-prefixed hexadecimal; -3. Block number: `String` that is interprered differently for normal and historic builds: -Noramal build: parameter ignored, latest value is always returted. +3. Block number: `String` that is interpreted differently for normal and historic builds: +Normal build: parameter ignored, latest value is always returned. Historic build: - - "latest" or "pending" - latest value is returted; + - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; - - `String` representation of and integer block number, either decimal or "0x"-prefixed hexadecimal. + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. ### Returns "0x"-prefixed hex `String` (32 bytes) -| eth_getTransactionCount | Partially supported | Second parameter is ignored and always set to "latest" | -| eth_getBlockTransactionCountByHash | Supported | | -| eth_getBlockTransactionCountByNumber | Supported | | -| eth_getUncleCountByBlockHash | Supported | There are no uncles in SKALE s-chains | -| eth_getUncleCountByBlockNumber | Supported | There are no uncles in SKALE s-chains | -| eth_getCode | Partially supported | Second parameter is ignored and always set to "latest" | +## `eth_getTransactionCount` +Returns the number of transactions sent from an address. +### Parameters +1. Address: "0x"-prefixed hex `String`, 20 bytes; +2. Block number: `String` that is interpreted differently for normal and historic builds: +Normal build: parameter ignored, latest value is always returned. +Historic build: + - "latest" or "pending" - latest value is returned; + - "earliest" - value before block 1 is returned; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. +### Returns +"0x"-prefixed hex `String` representing transaction count + +eth_getBlockTransactionCountByHash +eth_getBlockTransactionCountByNumber + +eth_getUncleCountByBlockHash +eth_getUncleCountByBlockNumber +### Returns +`String` literal "0x0" + +## `eth_getCode` +Returns code at a given address +### Parameters +1. Address: "0x"-prefixed hex `String`, 20 bytes; +2. Block number: `String` that is interpreted differently for normal and historic builds: +Normal build: parameter ignored, latest value is always returned. +Historic build: + - "latest" or "pending" - latest value is returned; + - "earliest" - value before block 1 is returned; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. +### Returns +"0x"-prefixed hex `String` + | eth_sign | Not supported | | | eth_sendTransaction | Supported | | | eth_sendRawTransaction | Supported | | From f2ba90ebed485e30ec516e07b6df37777966e947 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 5 Jun 2024 21:11:11 +0300 Subject: [PATCH 04/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index dd218bc14..90004f42b 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -162,8 +162,23 @@ Historic build: ### Returns "0x"-prefixed hex `String` -| eth_sign | Not supported | | -| eth_sendTransaction | Supported | | +## `eth_sign` +Not supported + +## `eth_sendTransaction` +Creates new transaction from the provided fields, signs it with specified `from` address and submits it to the Transaction Queue +### Parameters + - "from" + - "to" + - "value" + - "gas" + - "gasPrice" + - "maxFeePerGas" + - "code" + - "data" + - "input" + - "nonce" + | eth_sendRawTransaction | Supported | | | eth_call | Partially supported | Second parameter is ignored and always set to "latest" | | eth_estimateGas | Supported | But does not use binary search | From a654ed1e75a197a3e205f8d26873ed515c42a0bf Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 6 Jun 2024 21:06:39 +0300 Subject: [PATCH 05/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 90004f42b..8a28c8799 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -166,18 +166,19 @@ Historic build: Not supported ## `eth_sendTransaction` -Creates new transaction from the provided fields, signs it with specified `from` address and submits it to the Transaction Queue -### Parameters - - "from" - - "to" - - "value" - - "gas" - - "gasPrice" - - "maxFeePerGas" - - "code" - - "data" - - "input" - - "nonce" +Creates new transaction from the provided fields, signs it with the specified `from` address and submits it to the Transaction Queue +### Parameters +1. JSON object with the following fields: + - "from": OPTIONAL "0x"-prefixed hex `String`, 20 bytes OR null; if omitted or null, personal account with the largest balance is used; + - "to": OPTIONAL "0x"-prefixed hex `String`, 20 bytes OR "0x" OR null; omitted/null/""/"0x" means contract creation; + - "value": OPTIONAL decimal `String` OR "0x"-prefixed hexadecimal `String` OR integer literal OR "" OR "0x" OR null; defaults to 0; + - "gas": OPTIONAL decimal `String` OR "0x"-prefixed hexadecimal `String` OR integer literal OR null; defaults to 90000 if omitted or null; + - "gasPrice": OPTIONAL decimal `String` OR "0x"-prefixed hexadecimal `String` OR integer literal OR null; defaults to eth_gasPrice() if omitted or null; + - "maxFeePerGas": OPTOPNAL same as "gasPrice", used if "gasPrice" is absent or null; + - "code": OPTIONAL same as "data"; + - "data": OPTIONAL "0x"-prefixed hex `String` OR "0x" OR "" OR null; defaults to empty; + - "input": OPTIONAL same as "data"; + - "nonce": OPTIONAL decimal `String` OR "0x"-prefixed hexadecimal `String` OR integer literal OR null; defaults to current nonce of the sender OR maximum nonce of the sender's transactions in the Transaction Queue (if omitted or null). | eth_sendRawTransaction | Supported | | | eth_call | Partially supported | Second parameter is ignored and always set to "latest" | From ae80f16d2ac8b3d2cc523063d5408b09b3d89022 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 6 Jun 2024 21:37:06 +0300 Subject: [PATCH 06/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 8a28c8799..d9d4cc4e4 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -178,10 +178,33 @@ Creates new transaction from the provided fields, signs it with the specified `f - "code": OPTIONAL same as "data"; - "data": OPTIONAL "0x"-prefixed hex `String` OR "0x" OR "" OR null; defaults to empty; - "input": OPTIONAL same as "data"; - - "nonce": OPTIONAL decimal `String` OR "0x"-prefixed hexadecimal `String` OR integer literal OR null; defaults to current nonce of the sender OR maximum nonce of the sender's transactions in the Transaction Queue (if omitted or null). + - "nonce": OPTIONAL decimal `String` OR "0x"-prefixed hexadecimal `String` OR integer literal OR null; defaults to current nonce of the sender OR maximum nonce of the sender's transactions in the Transaction Queue if it is larger (default is applied if omitted or null). +### Returns + "0x"-prefixed hex `String`, 32 bytes - hash of the transaction. + If transaction was attributed to a proxy account, empty hash is returned. + + TODO What the heck is proxy account? + +## `eth_sendRawTransaction` +Submit pre-signed transaction into the Transaction Queue +### Parameters +1. "0x"-prefixed hex `String` - transaction bytes. +### Returns +"0x"-prefixed hex `String`, 32 bytes - hash of the transaction. + +## `eth_call` +Execute read-only contract call +### Parameters +1. Same object as in `eth_sendTransaction`. TODO Find out if decimal literals are allowed in ETH +2. Block number: `String` that is interpreted differently for normal and historic builds: +Normal build: parameter ignored, latest value is always returned. +Historic build: + - "latest" or "pending" - latest value is returned; + - "earliest" - value before block 1 is returned; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal: the `State` after executing of the specified block is used to execute call. +### Returns +"0x"-prefixed hex `String` or "0x", call result -| eth_sendRawTransaction | Supported | | -| eth_call | Partially supported | Second parameter is ignored and always set to "latest" | | eth_estimateGas | Supported | But does not use binary search | | eth_getBlockByHash | Supported | Old blocks are "rotated out" | | eth_getBlockByNumber | Supported | Raises "block not found" error if block is "rotated out" | From 207ea71ffea7abfadba4bfd2dcbfbb8ed9237c03 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Fri, 7 Jun 2024 19:14:19 +0300 Subject: [PATCH 07/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 106 +++++++++++++++++++++++++++++++++---- 1 file changed, 97 insertions(+), 9 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index d9d4cc4e4..f8a3c5851 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -205,19 +205,107 @@ Historic build: ### Returns "0x"-prefixed hex `String` or "0x", call result -| eth_estimateGas | Supported | But does not use binary search | -| eth_getBlockByHash | Supported | Old blocks are "rotated out" | -| eth_getBlockByNumber | Supported | Raises "block not found" error if block is "rotated out" | -| eth_getTransactionByHash | Supported | | -| eth_getTransactionByBlockHashAndIndex | Supported | | +## `eth_estimateGas` +Execute transaction on a temporary state without committing to DB and return gas usage +### Parameters +1. Same object as in `eth_sendTransaction`. +2. OPTIONAL Ignored +### Returns +"0x"-prefixed hex `String`, gas estimate + +## `eth_getBlockByHash` +Return details about block +### Parameters +1. Block hash: "0x"-prefixed hex `String`, 32 bytes +2. Include transactions: boolean literal - true/false +### Returns +`null` if block is absent or rotated out. +Otherwise - object with the following fields: +TODO add descriptions + - "hash" + - "parentHash" + - "sha3Uncles" + - "author" + - "stateRoot" + - "transactionsRoot" + - "receiptsRoot" + - "number" + - "gasUsed" + - "gasLimit" + - "extraData" + - "logsBloom" + - "timestamp" + - "miner" + - "nonce" + - "seedHash" + - "mixHash" + - "boundary" + - "difficulty" + - "totalDifficulty" + - "size" + - "uncles" + - "baseFeePerGas" + - "transactions" TODO document skipping of invalid + +## `eth_getBlockByNumber` +Return details about block +### Parameters +1. Block number: + - "latest" or "pending" - latest value is returned; + - "earliest" - value before block 1 is returned; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. +2. Include transactions: boolean literal - true/false +### Returns +Same as `eth_getBlockByHash` +### Exceptions +TODO Check that it Raises "block not found" error if block is "rotated out" + +## `eth_getTransactionByHash` +Return details about transaction +### Parameters +1. Transaction hash: "0x"-prefixed hex `String`, 32 bytes +### Returns +`null` if transaction not found. +Otherwise, object with the following fields: +TODO describe + - "blockHash" + - "blockNumber" + - "from" + - "gas" + - "gasPrice" + - "hash" + - "input" + - "nonce" + - "to" + - "transactionIndex" + - "value" + - "v" + - "r" + - "s" + - "type" + - "yParity" + - "accessList" + - "maxPriorityFeePerGas" + - "maxFeePerGas" + +## `eth_getTransactionByBlockHashAndIndex` +Return details about transaction +### Parameters +1. Block hash: "0x"-prefixed hex `String`, 32 bytes +2. Transaction index: either decimal or "0x"-prefixed hexadecimal `String` +### Returns +Same as `eth_getTransactionByHash` + | eth_getTransactionByBlockNumberAndIndex | Supported | | + | eth_getTransactionReceipt | Supported | | + | eth_getUncleByBlockHashAndIndex | Supported | There are no uncles in SKALE s-chains | | eth_getUncleByBlockNumberAndIndex | Supported | There are no uncles in SKALE s-chains | -| eth_getCompilers | Not supported | | -| eth_compileSolidity | Not supported | | -| eth_compileLLL | Not supported | | -| eth_compileSerpent | Not supported | | + +## `eth_compile*` and `eth_getCompilers` +Not supported + | eth_newFilter | Partially supported | Ignores logs that originated from blocks that were "rotated out" | | eth_newBlockFilter | Supported | | | eth_newPendingTransactionFilter | Supported | | From 723b87557f316f226a2332e899d101e8f20d13e0 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 10 Jun 2024 15:55:19 +0300 Subject: [PATCH 08/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 73 ++++++++++++++++++++++++++++++++++---- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index f8a3c5851..068ecebea 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -1,6 +1,10 @@ -# JSON-RPC Interface Compatibility +# JSON-RPC Interface Specification + +This doc describes all supported JSON-RPC methods, their parameters and return values. + +This doc does NOT describe all possible erroneous situations. ## `web3_*` Methods @@ -296,23 +300,80 @@ Return details about transaction ### Returns Same as `eth_getTransactionByHash` -| eth_getTransactionByBlockNumberAndIndex | Supported | | +## `eth_getTransactionByBlockNumberAndIndex` +Return details about transaction +### Parameters +1. Block number: + - "latest" or "pending" - latest block is used; + - "earliest" - block 0; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; +3. Transaction index: either decimal or "0x"-prefixed hexadecimal `String` +### Returns +Same as `eth_getTransactionByHash` -| eth_getTransactionReceipt | Supported | | +## `eth_getTransactionReceipt` +Get transaction receipt +### Parameters +1. Transaction hash: "0x"-prefixed hex `String`, 32 bytes +### Returns +`null` if transaction not mined. +Otherwise - object with the following fields: +TODO descrition + - "from" + - "to" + - "transactionHash" + - "transactionIndex" + - "blockHash" + - "blockNumber" + - "cumulativeGasUsed" + - "gasUsed" + - "contractAddress" + - "logs" + - "logsBloom" + - "status" + - "revertReason" OPTIONAL + - "type" + - "effectiveGasPrice" + +## `eth_getUncleByBlockHashAndIndex` +Return `null` +### Parameters +1. Block hash: "0x"-prefixed hex `String`, 32 bytes +2. Uncle index: either decimal or "0x"-prefixed hexadecimal `String` +### Returns +`null` -| eth_getUncleByBlockHashAndIndex | Supported | There are no uncles in SKALE s-chains | -| eth_getUncleByBlockNumberAndIndex | Supported | There are no uncles in SKALE s-chains | +## `eth_getUncleByBlockNumberAndIndex` +Return `null` +### Parameters +1. Block number: + - "latest" or "pending" - latest block; + - "earliest" - block 0; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; +3. Uncle index: either decimal or "0x"-prefixed hexadecimal `String` +### Returns +`null` ## `eth_compile*` and `eth_getCompilers` Not supported -| eth_newFilter | Partially supported | Ignores logs that originated from blocks that were "rotated out" | +## `eth_newFilter` +Creates new logs (events) filter and returns it's ID +Ignores logs that originated from blocks that were "rotated out" +### Parameters +1. Object: + - "fromBlock" + - "toBlock" + - "address" + - "topics" + | eth_newBlockFilter | Supported | | | eth_newPendingTransactionFilter | Supported | | | eth_uninstallFilter | Supported | | | eth_getFilterChanges | Supported | | | eth_getFilterLogs | Supported | | | eth_getLogs | Partially supported | Ignores logs that originated from blocks that were "rotated out" | + | eth_getWork | Supported | | | eth_submitWork | Not supported | | | eth_submitHashrate | Supported | | From da534435fe5a1037b76b8cc5f15007fcab1a3ee1 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 10 Jun 2024 21:05:57 +0300 Subject: [PATCH 09/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 263 ++++++++++++++++++++++++------------- 1 file changed, 175 insertions(+), 88 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 068ecebea..14d3f4be4 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -10,104 +10,104 @@ This doc does NOT describe all possible erroneous situations. ### `web3_clientVersion` Returns detailed `skaled` version -### Parameters +#### Parameters None -### Returns +#### Returns `String` representing exact build of `skaled` Example: "skaled/3.19.0+commit.859d742c/linux/gnu9.5.0/debug" ### `web3_sha3` Returns `sha3` (`keccak256`) hash of input data -### Parameters +#### Parameters 1. Input data represented as a "0x"-prefixed hex `String` -### Returns +#### Returns Output data represented as a "0x"-prefixed hex `String` (32 bytes) ## `net_*` Methods ### `net_version` Returns chainID from config.json -### Parameters +#### Parameters None -### Returns +#### Returns Decimal number as `String` ### `net_listening` Returns `true` -### Parameters +#### Parameters None -### Returns +#### Returns Boolean literal `true` ### `net_peerCount` Returns 0 -### Parameters +#### Parameters None -### Returns +#### Returns `String` value "0x0" ## `eth_*` Methods ### `eth_protocolVersion` Returns `0x3f` -### Parameters +#### Parameters None -### Returns +#### Returns `String` value "0x3f" ### `eth_syncing` Returns `false` -### Parameters +#### Parameters None -### Returns +#### Returns Boolean literal `false` ### `eth_coinbase` Returns sChainOwner address from config.json (it is used as coinbase address) -### Parameters +#### Parameters None -### Returns +#### Returns "0x"-prefixed hex `String` (20 bytes) ### `eth_mining` Returns `false` -### Parameters +#### Parameters None -### Returns +#### Returns Boolean literal `false` ### `eth_hashrate` There is no hashrate for SKALE s-chains, always returns 0 -### Parameters +#### Parameters None -### Returns +#### Returns `String` literal "0x0" ### `eth_gasPrice` Returns current minimum gas price needed for transaction to be accepted into the Transaction Queue. Gas price is dynamically adjusted from 100k wei and above as load grows -### Parameters +#### Parameters None -### Returns +#### Returns "0x"-prefixed hex `String` representing current gas price ### `eth_accounts` Get list of accounts with locally-stored private keys -### Parameters +#### Parameters None -### Returns +#### Returns `Array` of "0x"-prefixed hex `String`s, 20 bytes each ### `eth_blockNumber` Returns the number of most recent block -### Parameters +#### Parameters None -### Returns +#### Returns "0x"-prefixed hex `String` representing block number ### `eth_getBalance` Returns the balance of the account of given address -### Parameters +#### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes 2. Block number: `String` that is interpreted differently for normal and historic builds: Normal build: parameter ignored, latest balance is always returned. @@ -115,12 +115,12 @@ Historic build: - "latest" or "pending" - latest balance is returned; - "earliest" - balance before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. -### Returns +#### Returns "0x"-prefixed hex `String` representing balance in wei -## `eth_getStorageAt` +### `eth_getStorageAt` Returns the value from a storage position at a given account -### Parameters +#### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; 2. Position: `String` representation of an integer storage position, either decimal or "0x"-prefixed hexadecimal; 3. Block number: `String` that is interpreted differently for normal and historic builds: @@ -129,12 +129,12 @@ Historic build: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. -### Returns +#### Returns "0x"-prefixed hex `String` (32 bytes) -## `eth_getTransactionCount` +### `eth_getTransactionCount` Returns the number of transactions sent from an address. -### Parameters +#### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; 2. Block number: `String` that is interpreted differently for normal and historic builds: Normal build: parameter ignored, latest value is always returned. @@ -142,7 +142,7 @@ Historic build: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. -### Returns +#### Returns "0x"-prefixed hex `String` representing transaction count eth_getBlockTransactionCountByHash @@ -150,12 +150,12 @@ eth_getBlockTransactionCountByNumber eth_getUncleCountByBlockHash eth_getUncleCountByBlockNumber -### Returns +#### Returns `String` literal "0x0" -## `eth_getCode` +### `eth_getCode` Returns code at a given address -### Parameters +#### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; 2. Block number: `String` that is interpreted differently for normal and historic builds: Normal build: parameter ignored, latest value is always returned. @@ -163,15 +163,15 @@ Historic build: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. -### Returns +#### Returns "0x"-prefixed hex `String` -## `eth_sign` +### `eth_sign` Not supported -## `eth_sendTransaction` +### `eth_sendTransaction` Creates new transaction from the provided fields, signs it with the specified `from` address and submits it to the Transaction Queue -### Parameters +#### Parameters 1. JSON object with the following fields: - "from": OPTIONAL "0x"-prefixed hex `String`, 20 bytes OR null; if omitted or null, personal account with the largest balance is used; - "to": OPTIONAL "0x"-prefixed hex `String`, 20 bytes OR "0x" OR null; omitted/null/""/"0x" means contract creation; @@ -183,22 +183,22 @@ Creates new transaction from the provided fields, signs it with the specified `f - "data": OPTIONAL "0x"-prefixed hex `String` OR "0x" OR "" OR null; defaults to empty; - "input": OPTIONAL same as "data"; - "nonce": OPTIONAL decimal `String` OR "0x"-prefixed hexadecimal `String` OR integer literal OR null; defaults to current nonce of the sender OR maximum nonce of the sender's transactions in the Transaction Queue if it is larger (default is applied if omitted or null). -### Returns +#### Returns "0x"-prefixed hex `String`, 32 bytes - hash of the transaction. If transaction was attributed to a proxy account, empty hash is returned. TODO What the heck is proxy account? -## `eth_sendRawTransaction` +### `eth_sendRawTransaction` Submit pre-signed transaction into the Transaction Queue -### Parameters +#### Parameters 1. "0x"-prefixed hex `String` - transaction bytes. -### Returns +#### Returns "0x"-prefixed hex `String`, 32 bytes - hash of the transaction. -## `eth_call` +### `eth_call` Execute read-only contract call -### Parameters +#### Parameters 1. Same object as in `eth_sendTransaction`. TODO Find out if decimal literals are allowed in ETH 2. Block number: `String` that is interpreted differently for normal and historic builds: Normal build: parameter ignored, latest value is always returned. @@ -206,23 +206,23 @@ Historic build: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal: the `State` after executing of the specified block is used to execute call. -### Returns +#### Returns "0x"-prefixed hex `String` or "0x", call result -## `eth_estimateGas` +### `eth_estimateGas` Execute transaction on a temporary state without committing to DB and return gas usage -### Parameters +#### Parameters 1. Same object as in `eth_sendTransaction`. 2. OPTIONAL Ignored -### Returns +#### Returns "0x"-prefixed hex `String`, gas estimate -## `eth_getBlockByHash` +### `eth_getBlockByHash` Return details about block -### Parameters +#### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes 2. Include transactions: boolean literal - true/false -### Returns +#### Returns `null` if block is absent or rotated out. Otherwise - object with the following fields: TODO add descriptions @@ -251,24 +251,24 @@ TODO add descriptions - "baseFeePerGas" - "transactions" TODO document skipping of invalid -## `eth_getBlockByNumber` +### `eth_getBlockByNumber` Return details about block -### Parameters +#### Parameters 1. Block number: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. 2. Include transactions: boolean literal - true/false -### Returns +#### Returns Same as `eth_getBlockByHash` -### Exceptions +#### Exceptions TODO Check that it Raises "block not found" error if block is "rotated out" -## `eth_getTransactionByHash` +### `eth_getTransactionByHash` Return details about transaction -### Parameters +#### Parameters 1. Transaction hash: "0x"-prefixed hex `String`, 32 bytes -### Returns +#### Returns `null` if transaction not found. Otherwise, object with the following fields: TODO describe @@ -292,30 +292,30 @@ TODO describe - "maxPriorityFeePerGas" - "maxFeePerGas" -## `eth_getTransactionByBlockHashAndIndex` +### `eth_getTransactionByBlockHashAndIndex` Return details about transaction -### Parameters +#### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes 2. Transaction index: either decimal or "0x"-prefixed hexadecimal `String` -### Returns +#### Returns Same as `eth_getTransactionByHash` -## `eth_getTransactionByBlockNumberAndIndex` +### `eth_getTransactionByBlockNumberAndIndex` Return details about transaction -### Parameters +#### Parameters 1. Block number: - "latest" or "pending" - latest block is used; - "earliest" - block 0; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; 3. Transaction index: either decimal or "0x"-prefixed hexadecimal `String` -### Returns +#### Returns Same as `eth_getTransactionByHash` -## `eth_getTransactionReceipt` +### `eth_getTransactionReceipt` Get transaction receipt -### Parameters +#### Parameters 1. Transaction hash: "0x"-prefixed hex `String`, 32 bytes -### Returns +#### Returns `null` if transaction not mined. Otherwise - object with the following fields: TODO descrition @@ -335,44 +335,131 @@ TODO descrition - "type" - "effectiveGasPrice" -## `eth_getUncleByBlockHashAndIndex` +### `eth_getUncleByBlockHashAndIndex` Return `null` -### Parameters +#### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes 2. Uncle index: either decimal or "0x"-prefixed hexadecimal `String` -### Returns +#### Returns `null` -## `eth_getUncleByBlockNumberAndIndex` +### `eth_getUncleByBlockNumberAndIndex` Return `null` -### Parameters +#### Parameters 1. Block number: - "latest" or "pending" - latest block; - "earliest" - block 0; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; 3. Uncle index: either decimal or "0x"-prefixed hexadecimal `String` -### Returns +#### Returns `null` -## `eth_compile*` and `eth_getCompilers` +### `eth_compile*` and `eth_getCompilers` Not supported -## `eth_newFilter` +### `eth_newFilter` Creates new logs (events) filter and returns it's ID -Ignores logs that originated from blocks that were "rotated out" -### Parameters + +| Variability | | +|-----|-----------| +| ETH | Same | +| Historic | Same | + +#### Parameters 1. Object: - - "fromBlock" - - "toBlock" + - "fromBlock" OPTIONAL defaults to "earliest" with values: + - "earliest", "latest" or "pending"; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; + - "toBlock" OPTIONAL defaults to "pending" with values: + - "earliest", "latest" or "pending"; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; + - "address" OPTIONAL: "0x"-prefixed hex `String`, 20 bytes; + - "topics" OPTIONAL: `Array`, see https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newfilter +#### Returns +"0x"-prefixed hex `String` - ID of the filter +#### Notes +Any non-WS filter is deleted if it's not being polled for 20 seconds + +### `eth_newBlockFilter` +Create filter for monitoring new blocks and returns it's ID +#### Parameters +None +#### Returns +"0x"-prefixed hex `String` - ID of the filter + +### `eth_newPendingTransactionFilter` +Create filter for monitoring new transactins and returns it's ID +#### Parameters +None +#### Returns +"0x"-prefixed hex `String` - ID of the filter + +### `eth_uninstallFilter` +Remove previously created filter +#### Parameters +1. Decimal or "0x"-prefixed hex `String` - ID of the filter +#### Returns +`true` if filter was successfully found and uninstalled, `false` if it's not found + +### `eth_getFilterChanges` +Get changes in filter results since previous call (or filter creation) +Ignores logs that originated from blocks that were "rotated out" +#### Parameters +1. Decimal or "0x"-prefixed hex `String` - ID of the filter +#### Returns +`Array` of changes (can be empty). + +For a block filter, array items are block hashes. + +For a transaction filter, array items are transaction hashes. + +For an event filter, array items are objects with the following fields: +TODO description + - "data" - "address" - "topics" + - "polarity" + - "type": "mined" or "pending" + - "blockNumber" + - "blockHash" + - "logIndex" + - "transactionHash" + - "transactionIndex" + +#### Exceptions +Throws `INVALID_PARAMS` if filter cannot be found -| eth_newBlockFilter | Supported | | -| eth_newPendingTransactionFilter | Supported | | -| eth_uninstallFilter | Supported | | -| eth_getFilterChanges | Supported | | -| eth_getFilterLogs | Supported | | -| eth_getLogs | Partially supported | Ignores logs that originated from blocks that were "rotated out" | +#### Notes +If a block is removed from the DB due to block rotation, it doesn't affect this call results + +### `eth_getFilterLogs` +Get all events matching a filter +#### Parameters +1. Decimal or "0x"-prefixed hex `String` - ID of the filter +#### Returns +Same as `eth_getFilterChanges` +TODO Compare +#### Exceptions +Throws `INVALID_PARAMS` if filter cannot be found or if response size is exceeded + +### `eth_getLogs` +Same as `eth_getFilterLogs`, but doesn't require filter creation +#### Parameters + +1. Object: + - "fromBlock" OPTIONAL defaults to "earliest" with values: + - "earliest", "latest" or "pending"; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; + - "toBlock" OPTIONAL defaults to "pending" with values: + - "earliest", "latest" or "pending"; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; + - "address" OPTIONAL: "0x"-prefixed hex `String`, 20 bytes; + - "topics" OPTIONAL: `Array`, see https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newfilter + - "blockHash" OPTIONAL: "0x"-prefixed hex `String`, 32 bytes; if this field is present, then `fromBlock` and `toBlock` are not allowed. +#### Returns +Same as `eth_getFilterChanges` +#### Exceptions +Throws `INVALID_PARAMS` if block does not exist, if response size is exceeded, or `fromBlock` or `toBlock` are present together with `blockHash` | eth_getWork | Supported | | | eth_submitWork | Not supported | | From 5d449dda79d294ebe3f67e576d9865bb935a9cc1 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 10 Jun 2024 21:25:43 +0300 Subject: [PATCH 10/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 14d3f4be4..9a0538303 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -461,10 +461,32 @@ Same as `eth_getFilterChanges` #### Exceptions Throws `INVALID_PARAMS` if block does not exist, if response size is exceeded, or `fromBlock` or `toBlock` are present together with `blockHash` -| eth_getWork | Supported | | -| eth_submitWork | Not supported | | -| eth_submitHashrate | Supported | | -| eth_getProof | Not supported | | +### `eth_getWork` +Returns three magic hashes +#### Parameters +None +#### Returns +`Array` of three "0x"-prefixed hex `String`s, 32 bytes each + +### `eth_submitWork` +Weird legacy method +#### Parameters +1. nonce: decimal or "0x"-prefixed hexadecimal number, 8 bytes; +2. powHash: decimal or "0x"-prefixed hexadecimal number, 32 bytes; +3. mixDigest: decimal or "0x"-prefixed hexadecimal number, 32 bytes. +#### Returns +`true` + +### `eth_submitHashrate` +Weird legacy method +#### Parameters +1. hashrate: decimal or "0x"-prefixed hexadecimal number, 32 bytes; +2. miner id: decimal or "0x"-prefixed hexadecimal number, 32 bytes. +#### Returns +`true` + +### `eth_getProof` +Not supported ## `personal_*` Methods Not supported From 97dcbcdf29ba4ae497cf47e309536bfdfe2620eb Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 10 Jun 2024 21:42:30 +0300 Subject: [PATCH 11/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 9a0538303..dfa240691 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -148,8 +148,17 @@ Historic build: eth_getBlockTransactionCountByHash eth_getBlockTransactionCountByNumber -eth_getUncleCountByBlockHash -eth_getUncleCountByBlockNumber +### `eth_getUncleCountByBlockHash` +#### Parameters +1. Block hash: "0x"-prefixed hex `String`, 32 bytes +#### Returns +`String` literal "0x0" + +### `eth_getUncleCountByBlockNumber` +#### Parameters +1. Block number: + - "earliest", "latest", or "pending"; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. #### Returns `String` literal "0x0" @@ -488,6 +497,25 @@ Weird legacy method ### `eth_getProof` Not supported +### `eth_unregister` +### `eth_unsubscribe` +### `eth_chainId` +### `eth_feeHistory` +### `eth_fetchQueuedTransactions` +### `eth_flush` +### `eth_createAccessList` +### `eth_getBlockTransactionCountByHash` +### `eth_getBlockTransactionCountByNumber` +### `eth_getFilterChangesEx` +### `eth_getStorageRoot` +### `eth_inspectTransaction` +### `eth_maxPriorityFeePerGas` +### `eth_notePassword` +### `eth_pendingTransactions` +### `eth_register` +### `eth_signTransaction` +### `eth_subscribe` + ## `personal_*` Methods Not supported From 3b2a9eb9d6c64ae3ea9e096a0c73dbd1d848cb8a Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 11 Jun 2024 15:32:14 +0300 Subject: [PATCH 12/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 57 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index dfa240691..37f547d82 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -316,7 +316,7 @@ Return details about transaction - "latest" or "pending" - latest block is used; - "earliest" - block 0; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; -3. Transaction index: either decimal or "0x"-prefixed hexadecimal `String` +2. Transaction index: either decimal or "0x"-prefixed hexadecimal `String` #### Returns Same as `eth_getTransactionByHash` @@ -497,22 +497,75 @@ Weird legacy method ### `eth_getProof` Not supported +### `eth_register` +Add proxy account, whatever that can mean +#### Parameters +1. Address: "0x"-prefixed hex `String`, 20 bytes +#### Returns +"0x"-prefixed hex `String` - id of added account + ### `eth_unregister` +Remove proxy account +#### Parameters +1. id: decimal or "0x"-prefixed hexadecimal number, previously obtained through `eth_register` +#### Returns +`true` if account was found and removed, `false` otherwise + ### `eth_unsubscribe` +Not supported + ### `eth_chainId` +Returns chainID from config.json as hex string +#### Parameters +None +#### Returns +"0x"-prefixed hex `String` + ### `eth_feeHistory` ### `eth_fetchQueuedTransactions` + ### `eth_flush` +Weird mystery method. Probably it will mine a block with PoW +#### Parameters +None +#### Returns +`true` + ### `eth_createAccessList` +Returns empy access list +#### Parameters +1. Transaction object same as in `eth_sendTransaction`; +2. `String` block hash or number (ignored). +#### Returns +Object: + - "accessList" - empty list; + - "gasUsed" - "0x" prefixed hex `String` - result of `eth_estimateGas`. + ### `eth_getBlockTransactionCountByHash` +Get number of transactions in a block +#### Parameters +1. Block hash: "0x"-prefixed hex `String`, 32 bytes +#### Returns +"0x"-prefixed hex `String` + ### `eth_getBlockTransactionCountByNumber` +Get number of transactions in a block +#### Parameters +1. Block number: + - "latest" or "pending" - latest block is used; + - "earliest" - block 0; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; +#### Returns +"0x"-prefixed hex `String` + ### `eth_getFilterChangesEx` +Same as `eth_getFilterChanges` + ### `eth_getStorageRoot` ### `eth_inspectTransaction` ### `eth_maxPriorityFeePerGas` ### `eth_notePassword` ### `eth_pendingTransactions` -### `eth_register` ### `eth_signTransaction` ### `eth_subscribe` From 0ad23285558a023b2e3fb87669c614955a583aea Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 11 Jun 2024 17:58:29 +0300 Subject: [PATCH 13/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 37f547d82..a36bae028 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -562,8 +562,24 @@ Get number of transactions in a block Same as `eth_getFilterChanges` ### `eth_getStorageRoot` +Get account's `storageRoot` (according to Yellow Paper) +#### Parameters +1. Address: "0x"-prefixed hex `String`, 20 bytes; +2. Block number: + - "latest" or "pending" - latest value is returned; + - "earliest" - value before block 1 is returned; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal - value after execution of specified block is returned. +#### Returns +"0x"-prefixed hex `String` (32 bytes). If account cannot be found - `sha3( rlp( "" ) )` is returned + ### `eth_inspectTransaction` + ### `eth_maxPriorityFeePerGas` +#### Parameters +None +#### Returns +"0x0" + ### `eth_notePassword` ### `eth_pendingTransactions` ### `eth_signTransaction` From 769d0a3bcac1f1566e5f6093a725c33198a1f392 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 11 Jun 2024 20:01:03 +0300 Subject: [PATCH 14/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 88 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 4 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index a36bae028..927d2ce16 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -367,13 +367,14 @@ Return `null` Not supported ### `eth_newFilter` -Creates new logs (events) filter and returns it's ID | Variability | | |-----|-----------| | ETH | Same | | Historic | Same | +Creates new logs (events) filter and returns it's ID + #### Parameters 1. Object: - "fromBlock" OPTIONAL defaults to "earliest" with values: @@ -511,9 +512,6 @@ Remove proxy account #### Returns `true` if account was found and removed, `false` otherwise -### `eth_unsubscribe` -Not supported - ### `eth_chainId` Returns chainID from config.json as hex string #### Parameters @@ -562,7 +560,15 @@ Get number of transactions in a block Same as `eth_getFilterChanges` ### `eth_getStorageRoot` + +| Variability | | +|-----|-----------| +| ETH | Unsupported both in Ethereum and in SKALE | +| Historic | Supported | + Get account's `storageRoot` (according to Yellow Paper) +Noramal node - call always throws exception. +Historic node - see below. #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; 2. Block number: @@ -573,6 +579,28 @@ Get account's `storageRoot` (according to Yellow Paper) "0x"-prefixed hex `String` (32 bytes). If account cannot be found - `sha3( rlp( "" ) )` is returned ### `eth_inspectTransaction` +| Variability | | +|-----|-----------| +| ETH | Unsupported | +| Historic | Same | +Parse binary transaction into fields +#### Parameters +1. Raw transaction: "0x"-prefixed hex `String` +#### Returns +Object: + - "data" + - "from" + - "gas" + - "gasPrice" + - "hash" + - "nonce" + - "r" + - "s" + - "sighash" + - "to" + - "type" + - "v" + - "value" ### `eth_maxPriorityFeePerGas` #### Parameters @@ -581,9 +609,61 @@ None "0x0" ### `eth_notePassword` +Weird legacy method +#### Parameters +1. `String` - ignored +#### Returns +`false` + ### `eth_pendingTransactions` +Get transaction queue +#### Parameters +None +#### Returns + - "to" + - "from" + - "gas" + - "gasPrice" + - "value" + - "data" + ### `eth_signTransaction` +Sign transaction using stored private key and make raw transaction +#### Parameters +1. Object same as `eth_sendTransaction` +#### Returns +Object: + - "raw": "0x"-prefixed hex `String`; + - "tx": object: + - "to" + - "from" + - "gas" + - "gasPrice" + - "value" + - "data" + - "nonce" + - "r" + - "s" + - "v" + - "type" + - "yParity" + - "accessList" + - "maxPriorityFeePerGas" + - "maxFeePerGas" + ### `eth_subscribe` +Works in WS, unsupported through HTTP(S) +#### Parameters +1. Object +#### Exceptions +Always throws exception + +### `eth_unsubscribe` +Works in WS, unsupported through HTTP(S) +#### Parameters +1. Object +#### Exceptions +Always throws exception ## `personal_*` Methods Not supported From 01535353d18929ab929adaad58bdb89e79bed3e7 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 11 Jun 2024 21:56:57 +0300 Subject: [PATCH 15/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 56 ++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 927d2ce16..507ff15e4 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -588,19 +588,21 @@ Parse binary transaction into fields 1. Raw transaction: "0x"-prefixed hex `String` #### Returns Object: - - "data" + - "to" - "from" - "gas" - "gasPrice" - - "hash" + - "value" + - "data" - "nonce" - "r" - "s" - - "sighash" - - "to" - - "type" - "v" - - "value" + - "type" + - "yParity" + - "accessList" + - "maxPriorityFeePerGas" + - "maxFeePerGas" ### `eth_maxPriorityFeePerGas` #### Parameters @@ -634,36 +636,30 @@ Sign transaction using stored private key and make raw transaction #### Returns Object: - "raw": "0x"-prefixed hex `String`; - - "tx": object: - - "to" - - "from" - - "gas" - - "gasPrice" - - "value" - - "data" - - "nonce" - - "r" - - "s" - - "v" - - "type" - - "yParity" - - "accessList" - - "maxPriorityFeePerGas" - - "maxFeePerGas" + - "tx": same as in `eth_inspectTransaction` ### `eth_subscribe` -Works in WS, unsupported through HTTP(S) +HTTP(S): unsupported, always throws exception + +WS(S): subscribe for new events/transactions/blocks/stats #### Parameters -1. Object -#### Exceptions -Always throws exception +1. `String` subscription type: + - "logs"; + - "newPendingTransactions"; + - "newHeads"; + - "skaleStats". +2. Used only when type="logs": object, format is the same as in `eth_newFilter` +#### Returns +"0x"-prefixed hex `String` - subscription id ### `eth_unsubscribe` -Works in WS, unsupported through HTTP(S) +HTTP(S): unsupported, always throws exception + +WS(S): unsubscribe from events/transactions/blocks/stats (see `eth_subscribe`) #### Parameters -1. Object -#### Exceptions -Always throws exception +1. id: decimal or "0x"-prefixed hexadecimal number `String` OR number literal - previously obtained through `eth_subscribe` +#### Returns +None ## `personal_*` Methods Not supported From 27c77344de4431c2350d50b2e221b258d4c9d039 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 12 Jun 2024 15:57:22 +0300 Subject: [PATCH 16/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 507ff15e4..c224a8cea 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -652,6 +652,52 @@ WS(S): subscribe for new events/transactions/blocks/stats #### Returns "0x"-prefixed hex `String` - subscription id +#### Events format +Depending on the type of subscription, different data is pushed back to the client when requested event happens. +1. type="logs": +``` +{ +"jsonrpc":"2.0", +"method":"eth_subscription", +"params":{ + "result":{ + "address":"0x"-prefixed hex `String`, 20 bytes, + "blockHash":"0x"-prefixed hex `String`, 32 bytes, + "blockNumber":"0x"-prefixed hex `String`, + "data":"0x"-prefixed hex `String`, + "logIndex": integer literal, + "topics": array of "0x"-prefixed hex `String`s, 32 bytes each, + "transactionHash":"0x"-prefixed hex `String`, 32 bytes, + "transactionIndex": integer literal + }, + "subscription": "0x"-prefixed hex `String`, subscription id + } +} +``` +2. type="newHeads" +``` +{ +"jsonrpc":"2.0", +"method":"eth_subscription", +"params":{ + "result": see `eth_getBlockByHash`, includeTransactions=false, + "subscription": "0x"-prefixed hex `String`, subscription id + } +} +``` + +3. type="newPendingTransactions" +``` +{ +"jsonrpc":"2.0", +"method":"eth_subscription", +"params":{ + "result": "0x"-prefixed hex `String`, 32 bytes - transaction hash, + "subscription": "0x"-prefixed hex `String`, subscription id + } +} +``` + ### `eth_unsubscribe` HTTP(S): unsupported, always throws exception From c56a1415b95bae324a973a6a6970670cd53d6ee8 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 12 Jun 2024 17:40:57 +0300 Subject: [PATCH 17/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index c224a8cea..8c36ace3e 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -715,3 +715,40 @@ Not supported ## `shh_*` Methods Not supported + +## Internal Methods +### setSchainExitTime +### skale_protocolVersion +### skale_receiveTransaction +### skale_shutdownInstance +### skale_getSnapshot +### skale_downloadSnapshotFragment +### skale_getSnapshotSignature +### skale_getLatestSnapshotBlockNumber +### skale_getLatestBlockNumber +### skale_getDBUsage +### oracle_submitRequest +### oracle_checkResult +### debug_accountRangeAt +### debug_traceTransaction +### debug_storageRangeAt +### debug_preimage +### debug_traceBlockByNumber +### debug_traceBlockByHash +### debug_traceCall +### debug_getFutureTransactions + +## Private Methods +### debug_pauseConsensus +### debug_pauseBroadcast +### debug_forceBlock +### debug_forceBroadcast +### debug_interfaceCall +### debug_getVersion +### debug_getArguments +### debug_getConfig +### debug_getSchainName +### debug_getSnapshotCalculationTime +### debug_getSnapshotHashCalculationTime +### debug_doStateDbCompaction +### debug_doBlocksDbCompaction From 0b35c8701c453e19d99e26da002bfb1a000a5b15 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 12 Jun 2024 21:40:46 +0300 Subject: [PATCH 18/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 368 +++++++++++++++++++++++++++++++++---- 1 file changed, 336 insertions(+), 32 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 8c36ace3e..5a0611fea 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -9,6 +9,11 @@ This doc does NOT describe all possible erroneous situations. ## `web3_*` Methods ### `web3_clientVersion` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Mostly same | +| Historic vs ETH | Mostly same | + Returns detailed `skaled` version #### Parameters None @@ -18,6 +23,11 @@ None Example: "skaled/3.19.0+commit.859d742c/linux/gnu9.5.0/debug" ### `web3_sha3` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Returns `sha3` (`keccak256`) hash of input data #### Parameters 1. Input data represented as a "0x"-prefixed hex `String` @@ -27,6 +37,11 @@ Output data represented as a "0x"-prefixed hex `String` (32 bytes) ## `net_*` Methods ### `net_version` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Returns chainID from config.json #### Parameters None @@ -34,6 +49,11 @@ None Decimal number as `String` ### `net_listening` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Returns `true` #### Parameters None @@ -41,6 +61,11 @@ None Boolean literal `true` ### `net_peerCount` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Compatible, but makes no sense in SKALE | +| Historic vs ETH | Compatible, but makes no sense in SKALE | + Returns 0 #### Parameters None @@ -50,6 +75,11 @@ None ## `eth_*` Methods ### `eth_protocolVersion` +| Compatibility | | +|-----|-----------| +| Core vs ETH | SKALE uses hex, ETH uses dec | +| Historic vs ETH | SKALE uses hex, ETH uses dec | + Returns `0x3f` #### Parameters None @@ -57,6 +87,11 @@ None `String` value "0x3f" ### `eth_syncing` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Compatible, but not implemented in SKALE | +| Historic vs ETH | Compatible, but not implemented in SKALE | + Returns `false` #### Parameters None @@ -64,13 +99,35 @@ None Boolean literal `false` ### `eth_coinbase` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Returns sChainOwner address from config.json (it is used as coinbase address) #### Parameters None #### Returns "0x"-prefixed hex `String` (20 bytes) +### `eth_chainId` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + +Returns chainID from config.json as hex string +#### Parameters +None +#### Returns +"0x"-prefixed hex `String` + ### `eth_mining` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Compatible, but makes no sense in SKALE | +| Historic vs ETH | Compatible, but makes no sense in SKALE | + Returns `false` #### Parameters None @@ -78,6 +135,11 @@ None Boolean literal `false` ### `eth_hashrate` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Compatible, but makes no sense in SKALE | +| Historic vs ETH | Compatible, but makes no sense in SKALE | + There is no hashrate for SKALE s-chains, always returns 0 #### Parameters None @@ -85,6 +147,11 @@ None `String` literal "0x0" ### `eth_gasPrice` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Returns current minimum gas price needed for transaction to be accepted into the Transaction Queue. Gas price is dynamically adjusted from 100k wei and above as load grows #### Parameters None @@ -92,6 +159,11 @@ None "0x"-prefixed hex `String` representing current gas price ### `eth_accounts` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Get list of accounts with locally-stored private keys #### Parameters None @@ -99,6 +171,11 @@ None `Array` of "0x"-prefixed hex `String`s, 20 bytes each ### `eth_blockNumber` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Returns the number of most recent block #### Parameters None @@ -106,6 +183,11 @@ None "0x"-prefixed hex `String` representing block number ### `eth_getBalance` +| Compatibility | | +|-----|-----------| +| Core vs ETH | SKALE ignores block number | +| Historic vs ETH | Same | + Returns the balance of the account of given address #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes @@ -119,6 +201,11 @@ Historic build: "0x"-prefixed hex `String` representing balance in wei ### `eth_getStorageAt` +| Compatibility | | +|-----|-----------| +| Core vs ETH | SKALE ignores block number | +| Historic vs ETH | Same | + Returns the value from a storage position at a given account #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; @@ -133,6 +220,11 @@ Historic build: "0x"-prefixed hex `String` (32 bytes) ### `eth_getTransactionCount` +| Compatibility | | +|-----|-----------| +| Core vs ETH | SKALE ignores block number | +| Historic vs ETH | Same | + Returns the number of transactions sent from an address. #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; @@ -145,16 +237,48 @@ Historic build: #### Returns "0x"-prefixed hex `String` representing transaction count -eth_getBlockTransactionCountByHash -eth_getBlockTransactionCountByNumber + +### `eth_getBlockTransactionCountByHash` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + +#### Parameters +1. Block hash: "0x"-prefixed hex `String`, 32 bytes +#### Returns +"0x"-prefixed hex `String` representing transaction count + +### `eth_getBlockTransactionCountByNumber` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + +#### Parameters +1. Block number: + - "earliest", "latest", or "pending"; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. +#### Returns +"0x"-prefixed hex `String` representing transaction count ### `eth_getUncleCountByBlockHash` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Compatible, but makes no sense in SKALE | +| Historic vs ETH | Compatible, but makes no sense in SKALE | + #### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes #### Returns `String` literal "0x0" ### `eth_getUncleCountByBlockNumber` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Compatible, but makes no sense in SKALE | +| Historic vs ETH | Compatible, but makes no sense in SKALE | + #### Parameters 1. Block number: - "earliest", "latest", or "pending"; @@ -163,6 +287,11 @@ eth_getBlockTransactionCountByNumber `String` literal "0x0" ### `eth_getCode` +| Compatibility | | +|-----|-----------| +| Core vs ETH | SKALE ignores block number | +| Historic vs ETH | Same | + Returns code at a given address #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; @@ -176,9 +305,33 @@ Historic build: "0x"-prefixed hex `String` ### `eth_sign` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Not supported | +| Historic vs ETH | Not supported | + Not supported +### `eth_signTransaction` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + +Sign transaction using stored private key and make raw transaction +#### Parameters +1. Object same as `eth_sendTransaction` +#### Returns +Object: + - "raw": "0x"-prefixed hex `String`; + - "tx": same as in `eth_inspectTransaction` + ### `eth_sendTransaction` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Creates new transaction from the provided fields, signs it with the specified `from` address and submits it to the Transaction Queue #### Parameters 1. JSON object with the following fields: @@ -199,6 +352,11 @@ Creates new transaction from the provided fields, signs it with the specified `f TODO What the heck is proxy account? ### `eth_sendRawTransaction` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Submit pre-signed transaction into the Transaction Queue #### Parameters 1. "0x"-prefixed hex `String` - transaction bytes. @@ -206,6 +364,11 @@ Submit pre-signed transaction into the Transaction Queue "0x"-prefixed hex `String`, 32 bytes - hash of the transaction. ### `eth_call` +| Compatibility | | +|-----|-----------| +| Core vs ETH | SKALE ignores block number | +| Historic vs ETH | Same | + Execute read-only contract call #### Parameters 1. Same object as in `eth_sendTransaction`. TODO Find out if decimal literals are allowed in ETH @@ -219,6 +382,11 @@ Historic build: "0x"-prefixed hex `String` or "0x", call result ### `eth_estimateGas` +| Compatibility | | +|-----|-----------| +| Core vs ETH | SKALE ignores block number | +| Historic vs ETH | SKALE ignores block number | + Execute transaction on a temporary state without committing to DB and return gas usage #### Parameters 1. Same object as in `eth_sendTransaction`. @@ -227,6 +395,11 @@ Execute transaction on a temporary state without committing to DB and return gas "0x"-prefixed hex `String`, gas estimate ### `eth_getBlockByHash` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Return details about block #### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes @@ -261,6 +434,11 @@ TODO add descriptions - "transactions" TODO document skipping of invalid ### `eth_getBlockByNumber` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Return details about block #### Parameters 1. Block number: @@ -274,6 +452,11 @@ Same as `eth_getBlockByHash` TODO Check that it Raises "block not found" error if block is "rotated out" ### `eth_getTransactionByHash` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Return details about transaction #### Parameters 1. Transaction hash: "0x"-prefixed hex `String`, 32 bytes @@ -302,6 +485,11 @@ TODO describe - "maxFeePerGas" ### `eth_getTransactionByBlockHashAndIndex` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Return details about transaction #### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes @@ -310,6 +498,11 @@ Return details about transaction Same as `eth_getTransactionByHash` ### `eth_getTransactionByBlockNumberAndIndex` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Return details about transaction #### Parameters 1. Block number: @@ -321,6 +514,11 @@ Return details about transaction Same as `eth_getTransactionByHash` ### `eth_getTransactionReceipt` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Get transaction receipt #### Parameters 1. Transaction hash: "0x"-prefixed hex `String`, 32 bytes @@ -345,6 +543,11 @@ TODO descrition - "effectiveGasPrice" ### `eth_getUncleByBlockHashAndIndex` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Compatible, but makes no sense in SKALE | +| Historic vs ETH | Compatible, but makes no sense in SKALE | + Return `null` #### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes @@ -353,6 +556,11 @@ Return `null` `null` ### `eth_getUncleByBlockNumberAndIndex` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Compatible, but makes no sense in SKALE | +| Historic vs ETH | Compatible, but makes no sense in SKALE | + Return `null` #### Parameters 1. Block number: @@ -363,15 +571,12 @@ Return `null` #### Returns `null` -### `eth_compile*` and `eth_getCompilers` -Not supported - ### `eth_newFilter` -| Variability | | +| Compatibility | | |-----|-----------| -| ETH | Same | -| Historic | Same | +| Core vs ETH | Same | +| Historic vs ETH | Same | Creates new logs (events) filter and returns it's ID @@ -391,6 +596,11 @@ Creates new logs (events) filter and returns it's ID Any non-WS filter is deleted if it's not being polled for 20 seconds ### `eth_newBlockFilter` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Create filter for monitoring new blocks and returns it's ID #### Parameters None @@ -398,6 +608,11 @@ None "0x"-prefixed hex `String` - ID of the filter ### `eth_newPendingTransactionFilter` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Create filter for monitoring new transactins and returns it's ID #### Parameters None @@ -405,6 +620,11 @@ None "0x"-prefixed hex `String` - ID of the filter ### `eth_uninstallFilter` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Remove previously created filter #### Parameters 1. Decimal or "0x"-prefixed hex `String` - ID of the filter @@ -412,6 +632,11 @@ Remove previously created filter `true` if filter was successfully found and uninstalled, `false` if it's not found ### `eth_getFilterChanges` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Get changes in filter results since previous call (or filter creation) Ignores logs that originated from blocks that were "rotated out" #### Parameters @@ -443,6 +668,11 @@ Throws `INVALID_PARAMS` if filter cannot be found If a block is removed from the DB due to block rotation, it doesn't affect this call results ### `eth_getFilterLogs` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Get all events matching a filter #### Parameters 1. Decimal or "0x"-prefixed hex `String` - ID of the filter @@ -453,6 +683,11 @@ TODO Compare Throws `INVALID_PARAMS` if filter cannot be found or if response size is exceeded ### `eth_getLogs` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Same | +| Historic vs ETH | Same | + Same as `eth_getFilterLogs`, but doesn't require filter creation #### Parameters @@ -471,7 +706,15 @@ Same as `eth_getFilterChanges` #### Exceptions Throws `INVALID_PARAMS` if block does not exist, if response size is exceeded, or `fromBlock` or `toBlock` are present together with `blockHash` +### `eth_compile*` and `eth_getCompilers` +Not supported + ### `eth_getWork` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Unknown | +| Historic vs ETH | Unknown | + Returns three magic hashes #### Parameters None @@ -479,6 +722,11 @@ None `Array` of three "0x"-prefixed hex `String`s, 32 bytes each ### `eth_submitWork` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Unknown | +| Historic vs ETH | Unknown | + Weird legacy method #### Parameters 1. nonce: decimal or "0x"-prefixed hexadecimal number, 8 bytes; @@ -488,6 +736,11 @@ Weird legacy method `true` ### `eth_submitHashrate` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Unknown | +| Historic vs ETH | Unknown | + Weird legacy method #### Parameters 1. hashrate: decimal or "0x"-prefixed hexadecimal number, 32 bytes; @@ -499,6 +752,11 @@ Weird legacy method Not supported ### `eth_register` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Unknown | +| Historic vs ETH | Unknown | + Add proxy account, whatever that can mean #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes @@ -506,23 +764,26 @@ Add proxy account, whatever that can mean "0x"-prefixed hex `String` - id of added account ### `eth_unregister` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Unknown | +| Historic vs ETH | Unknown | + Remove proxy account #### Parameters 1. id: decimal or "0x"-prefixed hexadecimal number, previously obtained through `eth_register` #### Returns `true` if account was found and removed, `false` otherwise -### `eth_chainId` -Returns chainID from config.json as hex string -#### Parameters -None -#### Returns -"0x"-prefixed hex `String` - ### `eth_feeHistory` ### `eth_fetchQueuedTransactions` ### `eth_flush` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Unknown | +| Historic vs ETH | Unknown | + Weird mystery method. Probably it will mine a block with PoW #### Parameters None @@ -540,6 +801,11 @@ Object: - "gasUsed" - "0x" prefixed hex `String` - result of `eth_estimateGas`. ### `eth_getBlockTransactionCountByHash` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Unknown | +| Historic vs ETH | Unknown | + Get number of transactions in a block #### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes @@ -547,6 +813,11 @@ Get number of transactions in a block "0x"-prefixed hex `String` ### `eth_getBlockTransactionCountByNumber` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Unknown | +| Historic vs ETH | Unknown | + Get number of transactions in a block #### Parameters 1. Block number: @@ -557,14 +828,19 @@ Get number of transactions in a block "0x"-prefixed hex `String` ### `eth_getFilterChangesEx` +| Compatibility | | +|-----|-----------| +| Core vs ETH | Unknown | +| Historic vs ETH | Unknown | + Same as `eth_getFilterChanges` ### `eth_getStorageRoot` -| Variability | | +| Compatibility | | |-----|-----------| -| ETH | Unsupported both in Ethereum and in SKALE | -| Historic | Supported | +| Core vs ETH | Unsupported in both | +| Historic vs ETH | Supported in Historic, unsupported in ETH | Get account's `storageRoot` (according to Yellow Paper) Noramal node - call always throws exception. @@ -579,10 +855,12 @@ Historic node - see below. "0x"-prefixed hex `String` (32 bytes). If account cannot be found - `sha3( rlp( "" ) )` is returned ### `eth_inspectTransaction` -| Variability | | + +| Compatibility | | |-----|-----------| -| ETH | Unsupported | -| Historic | Same | +| Core vs ETH | Unsupported in ETH | +| Historic vs ETH | Unsupported in ETH | + Parse binary transaction into fields #### Parameters 1. Raw transaction: "0x"-prefixed hex `String` @@ -628,15 +906,17 @@ None - "gasPrice" - "value" - "data" - -### `eth_signTransaction` -Sign transaction using stored private key and make raw transaction -#### Parameters -1. Object same as `eth_sendTransaction` -#### Returns -Object: - - "raw": "0x"-prefixed hex `String`; - - "tx": same as in `eth_inspectTransaction` + - "nonce" + - "r" + - "s" + - "v" + - "type" + - "yParity" + - "accessList" + - "maxPriorityFeePerGas" + - "maxFeePerGas" + - "hash" + - "sighash" ### `eth_subscribe` HTTP(S): unsupported, always throws exception @@ -716,7 +996,7 @@ Not supported ## `shh_*` Methods Not supported -## Internal Methods +## Non-standard Methods ### setSchainExitTime ### skale_protocolVersion ### skale_receiveTransaction @@ -736,9 +1016,33 @@ Not supported ### debug_traceBlockByNumber ### debug_traceBlockByHash ### debug_traceCall + ### debug_getFutureTransactions +Get future transaction queue +#### Parameters +None +#### Returns + - "to" + - "from" + - "gas" + - "gasPrice" + - "value" + - "data" + - "nonce" + - "r" + - "s" + - "v" + - "type" + - "yParity" + - "accessList" + - "maxPriorityFeePerGas" + - "maxFeePerGas" + - "hash" + - "sighash" + +## Debug Methods +Enabled by special flag only -## Private Methods ### debug_pauseConsensus ### debug_pauseBroadcast ### debug_forceBlock From c65c910e839ead1a7228fed3c1316ec865d57a5e Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Wed, 12 Jun 2024 22:04:39 +0300 Subject: [PATCH 19/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 47 +++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 5a0611fea..21131174f 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -89,10 +89,16 @@ None ### `eth_syncing` | Compatibility | | |-----|-----------| -| Core vs ETH | Compatible, but not implemented in SKALE | -| Historic vs ETH | Compatible, but not implemented in SKALE | +| Core vs ETH | SKALE uses dec, ETH uses hex | +| Historic vs ETH | SKALE uses dec, ETH uses hex | + +If node has all up-to-date blocks - returns `false`. + +If it's behind others and is catching up - retuns object: + - "startingBlock": decimal literal; + - "highestBlock": decimal literal; + - "currentBlock": decimal literal. -Returns `false` #### Parameters None #### Returns @@ -999,20 +1005,39 @@ Not supported ## Non-standard Methods ### setSchainExitTime ### skale_protocolVersion +Returns "0.2" + ### skale_receiveTransaction +Can be used for receiving broadcasted transactions from other nodes, but currenlty substituted by ZMQ + ### skale_shutdownInstance ### skale_getSnapshot +Triggers snapshot serialization on local hard drive + ### skale_downloadSnapshotFragment +Can be used after `skale_getSnapshot` + ### skale_getSnapshotSignature ### skale_getLatestSnapshotBlockNumber +Returns block number of latest snapshot which can be downloaded. Usually it is the snapshot that was created at 00:00 yesterday. + ### skale_getLatestBlockNumber +Same as `eth_blockNumber` but returns decimal literal. + ### skale_getDBUsage ### oracle_submitRequest ### oracle_checkResult + ### debug_accountRangeAt +Not supported, always throws + ### debug_traceTransaction ### debug_storageRangeAt +Not supported, always throws + ### debug_preimage +Not supported, always throws + ### debug_traceBlockByNumber ### debug_traceBlockByHash ### debug_traceCall @@ -1044,14 +1069,30 @@ None Enabled by special flag only ### debug_pauseConsensus +Receives parameter `true` or `false` to pause or unpause block processing after consensus. + ### debug_pauseBroadcast +Receives parameter `true` or `false` to pause or unpause broadcast. + ### debug_forceBlock +Temporary sets consensus' empty block interval to 50 ms, waits until block from consensus, then sets empty block interval back. + ### debug_forceBroadcast ### debug_interfaceCall +Allows to pause and resume skaled in some key points of operation + ### debug_getVersion +Returns string similar to "3.19.0+commit.859d742c" + ### debug_getArguments +Probably returns command-line as string + ### debug_getConfig +Returns full config.json + ### debug_getSchainName +Returns `chainParams.sChain.name` + ### debug_getSnapshotCalculationTime ### debug_getSnapshotHashCalculationTime ### debug_doStateDbCompaction From fa0618903fb45f5815339ea485f43e4da0eaf9cb Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 13 Jun 2024 14:20:05 +0300 Subject: [PATCH 20/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 21131174f..ed5a1f88b 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -198,7 +198,9 @@ Returns the balance of the account of given address #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes 2. Block number: `String` that is interpreted differently for normal and historic builds: + Normal build: parameter ignored, latest balance is always returned. + Historic build: - "latest" or "pending" - latest balance is returned; - "earliest" - balance before block 1 is returned; @@ -235,7 +237,9 @@ Returns the number of transactions sent from an address. #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; 2. Block number: `String` that is interpreted differently for normal and historic builds: + Normal build: parameter ignored, latest value is always returned. + Historic build: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; @@ -313,8 +317,8 @@ Historic build: ### `eth_sign` | Compatibility | | |-----|-----------| -| Core vs ETH | Not supported | -| Historic vs ETH | Not supported | +| Core vs ETH | Not supported in SKALE| +| Historic vs ETH | Not supported in SKALE | Not supported @@ -589,11 +593,11 @@ Creates new logs (events) filter and returns it's ID #### Parameters 1. Object: - "fromBlock" OPTIONAL defaults to "earliest" with values: - - "earliest", "latest" or "pending"; - - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; + - "earliest", "latest" or "pending"; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; - "toBlock" OPTIONAL defaults to "pending" with values: - - "earliest", "latest" or "pending"; - - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; + - "earliest", "latest" or "pending"; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; - "address" OPTIONAL: "0x"-prefixed hex `String`, 20 bytes; - "topics" OPTIONAL: `Array`, see https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newfilter #### Returns @@ -699,11 +703,11 @@ Same as `eth_getFilterLogs`, but doesn't require filter creation 1. Object: - "fromBlock" OPTIONAL defaults to "earliest" with values: - - "earliest", "latest" or "pending"; - - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; + - "earliest", "latest" or "pending"; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; - "toBlock" OPTIONAL defaults to "pending" with values: - - "earliest", "latest" or "pending"; - - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; + - "earliest", "latest" or "pending"; + - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; - "address" OPTIONAL: "0x"-prefixed hex `String`, 20 bytes; - "topics" OPTIONAL: `Array`, see https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newfilter - "blockHash" OPTIONAL: "0x"-prefixed hex `String`, 32 bytes; if this field is present, then `fromBlock` and `toBlock` are not allowed. From 7e0a94d0ced6df7ae3b4ab5891eccf5fd58f34fa Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 13 Jun 2024 22:40:08 +0300 Subject: [PATCH 21/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 183 +++++++++++++++---------------------- 1 file changed, 72 insertions(+), 111 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index ed5a1f88b..f7c36efa8 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -219,7 +219,9 @@ Returns the value from a storage position at a given account 1. Address: "0x"-prefixed hex `String`, 20 bytes; 2. Position: `String` representation of an integer storage position, either decimal or "0x"-prefixed hexadecimal; 3. Block number: `String` that is interpreted differently for normal and historic builds: + Normal build: parameter ignored, latest value is always returned. + Historic build: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; @@ -306,7 +308,9 @@ Returns code at a given address #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; 2. Block number: `String` that is interpreted differently for normal and historic builds: + Normal build: parameter ignored, latest value is always returned. + Historic build: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; @@ -383,7 +387,9 @@ Execute read-only contract call #### Parameters 1. Same object as in `eth_sendTransaction`. TODO Find out if decimal literals are allowed in ETH 2. Block number: `String` that is interpreted differently for normal and historic builds: + Normal build: parameter ignored, latest value is always returned. + Historic build: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; @@ -416,32 +422,34 @@ Return details about block 2. Include transactions: boolean literal - true/false #### Returns `null` if block is absent or rotated out. + Otherwise - object with the following fields: -TODO add descriptions - - "hash" - - "parentHash" - - "sha3Uncles" - - "author" - - "stateRoot" - - "transactionsRoot" - - "receiptsRoot" - - "number" - - "gasUsed" - - "gasLimit" - - "extraData" - - "logsBloom" - - "timestamp" - - "miner" - - "nonce" - - "seedHash" - - "mixHash" - - "boundary" - - "difficulty" - - "totalDifficulty" - - "size" - - "uncles" - - "baseFeePerGas" - - "transactions" TODO document skipping of invalid + - "hash": "0x"-prefixed hex `String`, 32 bytes; + - "parentHash": "0x"-prefixed hex `String`, 32 bytes; + - "sha3Uncles": "0x"-prefixed hex `String`, 32 bytes; + - "author": "0x"-prefixed hex `String`, 20 bytes - address of schainOwner; + - "stateRoot": "0x"-prefixed hex `String`, 32 bytes; + - "transactionsRoot": "0x"-prefixed hex `String`, 32 bytes; + - "receiptsRoot": "0x"-prefixed hex `String`, 32 bytes; + - "number": decimal literal; + - "gasUsed": decimal literal; + - "gasLimit": decimal literal; + - "extraData": `String` "0x736b616c65" ("skale" in ASCII); + - "logsBloom": "0x"-prefixed hex `String`, 256 bytes; + - "timestamp": decimal literal; + - "miner": same as `author`; + - "nonce": `String` "0x0000000000000000"; + - "seedHash": `String` "0x0000000000000000000000000000000000000000000000000000000000000000", 32 bytes; + - "mixHash": `String` "0x0000000000000000000000000000000000000000000000000000000000000000", 32 bytes; + - "boundary": `String` "0x0000000000000000000000000000000000000000000000000000000000000000", 32 bytes; + - "difficulty": decimal literal 0; + - "totalDifficulty": decimal literal 0; + - "size": decimal literal; + - "uncles": empty arra; + - "baseFeePerGas": "0x"-prefixed hex `String`, gas price in block, field is present only if EIP-1559 is enabled; for rotated out old blocks this field is set to latest gasPrice; + - "transactions": array of transaction hashes ("0x"-prefixed hex `String`s, 32 bytes) OR detaled transactions info (same as in `eth_getTransactionByHash`) if 2nd argument was `true`; + +TODO document skipping of invalid ### `eth_getBlockByNumber` | Compatibility | | @@ -472,27 +480,27 @@ Return details about transaction 1. Transaction hash: "0x"-prefixed hex `String`, 32 bytes #### Returns `null` if transaction not found. + Otherwise, object with the following fields: -TODO describe - - "blockHash" - - "blockNumber" - - "from" - - "gas" - - "gasPrice" - - "hash" - - "input" - - "nonce" - - "to" - - "transactionIndex" - - "value" - - "v" - - "r" - - "s" - - "type" - - "yParity" - - "accessList" - - "maxPriorityFeePerGas" - - "maxFeePerGas" + - "blockHash": "0x"-prefixed hex `String`, 32 bytes; + - "blockNumber": decimal literal; + - "from": "0x"-prefixed hex `String`, 20 bytes; + - "gas": decimal literal; + - "gasPrice": decimal literal; + - "hash": "0x"-prefixed hex `String`, 32 bytes; + - "input": "0x"-prefixed hex `String` OR "0x" if there is no input; + - "nonce": decimal literal; + - "to": "0x"-prefixed hex `String`, 20 bytes OR `null` if contract creation; + - "transactionIndex": decimal literal; + - "value": decimal literal; + - "v": "0x"-prefixed hex `String`; + - "r": "0x"-prefixed hex `String`, 32 bytes; + - "s": "0x"-prefixed hex `String`, 32 bytes; + - "type": "0x"-prefixed hex `String`: "0x0", "0x1", or "0x2"; + - "yParity": "0x"-prefixed hex `String` (present in `type 1` and `type 2`); + - "accessList": present in `type 1` and `type 2`; + - "maxPriorityFeePerGas": "0x"-prefixed hex `String` (present in `type 2` only); + - "maxFeePerGas": "0x"-prefixed hex `String` (present in `type 2` only); ### `eth_getTransactionByBlockHashAndIndex` | Compatibility | | @@ -534,23 +542,23 @@ Get transaction receipt 1. Transaction hash: "0x"-prefixed hex `String`, 32 bytes #### Returns `null` if transaction not mined. + Otherwise - object with the following fields: -TODO descrition - - "from" - - "to" - - "transactionHash" - - "transactionIndex" - - "blockHash" - - "blockNumber" - - "cumulativeGasUsed" - - "gasUsed" - - "contractAddress" - - "logs" - - "logsBloom" - - "status" - - "revertReason" OPTIONAL - - "type" - - "effectiveGasPrice" + - "from": "0x"-prefixed hex `String`, 20 bytes; + - "to": "0x"-prefixed hex `String`, 32 bytes (contains all 0s if contract deployment); + - "transactionHash": "0x"-prefixed hex `String`, 32 bytes; + - "transactionIndex": decimal literal; + - "blockHash": "0x"-prefixed hex `String`, 32 bytes; + - "blockNumber": decimal literal; + - "cumulativeGasUsed": decimal literal; + - "gasUsed": decimal literal; + - "contractAddress": "0x"-prefixed hex `String`, 20 bytes if deployment OR `null` if not; + - "logs": `Array`; + - "logsBloom": "0x"-prefixed hex `String`, 256 bytes; + - "status": `String` "0x0" or "0x1"; + - "revertReason" OPTIONAL: `String`; + - "type": "0x"-prefixed hex `String`: "0x0", "0x1", or "0x2"; + - "effectiveGasPrice": "0x"-prefixed hex `String`. ### `eth_getUncleByBlockHashAndIndex` | Compatibility | | @@ -875,22 +883,7 @@ Parse binary transaction into fields #### Parameters 1. Raw transaction: "0x"-prefixed hex `String` #### Returns -Object: - - "to" - - "from" - - "gas" - - "gasPrice" - - "value" - - "data" - - "nonce" - - "r" - - "s" - - "v" - - "type" - - "yParity" - - "accessList" - - "maxPriorityFeePerGas" - - "maxFeePerGas" +Object, see `eth_getTransactionByHash` ### `eth_maxPriorityFeePerGas` #### Parameters @@ -910,23 +903,7 @@ Get transaction queue #### Parameters None #### Returns - - "to" - - "from" - - "gas" - - "gasPrice" - - "value" - - "data" - - "nonce" - - "r" - - "s" - - "v" - - "type" - - "yParity" - - "accessList" - - "maxPriorityFeePerGas" - - "maxFeePerGas" - - "hash" - - "sighash" +`Array` of `Object`s, see `eth_getTransactionByHash`. `sighash` equals to `hash` ### `eth_subscribe` HTTP(S): unsupported, always throws exception @@ -1051,23 +1028,7 @@ Get future transaction queue #### Parameters None #### Returns - - "to" - - "from" - - "gas" - - "gasPrice" - - "value" - - "data" - - "nonce" - - "r" - - "s" - - "v" - - "type" - - "yParity" - - "accessList" - - "maxPriorityFeePerGas" - - "maxFeePerGas" - - "hash" - - "sighash" +See `eth_pendingTransactions` ## Debug Methods Enabled by special flag only From 61a09946dcc500bac85f25ef007daf2fb599c775 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Thu, 13 Jun 2024 22:41:34 +0300 Subject: [PATCH 22/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index f7c36efa8..43067cb1b 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -6,6 +6,8 @@ This doc describes all supported JSON-RPC methods, their parameters and return v This doc does NOT describe all possible erroneous situations. +Parameters marked as `OPTIONAL` are optional, otherwise they are required! + ## `web3_*` Methods ### `web3_clientVersion` From 29e752b2d8ba34f270846708b128acbfbcf9ea1b Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 18 Jun 2024 15:17:20 +0300 Subject: [PATCH 23/61] Fix doc style --- docs/json-rpc-interface.md | 66 +++----------------------------------- 1 file changed, 4 insertions(+), 62 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 43067cb1b..66bbaa952 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -2,7 +2,7 @@ # JSON-RPC Interface Specification -This doc describes all supported JSON-RPC methods, their parameters and return values. +This doc describes all supported JSON-RPC methods, except `skale_*` and debug methods. Doc describes methods' parameters and return values. This doc does NOT describe all possible erroneous situations. @@ -365,8 +365,6 @@ Creates new transaction from the provided fields, signs it with the specified `f "0x"-prefixed hex `String`, 32 bytes - hash of the transaction. If transaction was attributed to a proxy account, empty hash is returned. - TODO What the heck is proxy account? - ### `eth_sendRawTransaction` | Compatibility | | |-----|-----------| @@ -469,7 +467,7 @@ Return details about block #### Returns Same as `eth_getBlockByHash` #### Exceptions -TODO Check that it Raises "block not found" error if block is "rotated out" +Raises "block not found" error if block is "rotated out" ### `eth_getTransactionByHash` | Compatibility | | @@ -747,7 +745,6 @@ None | Core vs ETH | Unknown | | Historic vs ETH | Unknown | -Weird legacy method #### Parameters 1. nonce: decimal or "0x"-prefixed hexadecimal number, 8 bytes; 2. powHash: decimal or "0x"-prefixed hexadecimal number, 32 bytes; @@ -761,7 +758,6 @@ Weird legacy method | Core vs ETH | Unknown | | Historic vs ETH | Unknown | -Weird legacy method #### Parameters 1. hashrate: decimal or "0x"-prefixed hexadecimal number, 32 bytes; 2. miner id: decimal or "0x"-prefixed hexadecimal number, 32 bytes. @@ -804,14 +800,14 @@ Remove proxy account | Core vs ETH | Unknown | | Historic vs ETH | Unknown | -Weird mystery method. Probably it will mine a block with PoW +Probably it will mine a block with PoW #### Parameters None #### Returns `true` ### `eth_createAccessList` -Returns empy access list +Returns empty access list #### Parameters 1. Transaction object same as in `eth_sendTransaction`; 2. `String` block hash or number (ignored). @@ -894,7 +890,6 @@ None "0x0" ### `eth_notePassword` -Weird legacy method #### Parameters 1. `String` - ignored #### Returns @@ -987,27 +982,6 @@ Not supported ## Non-standard Methods ### setSchainExitTime -### skale_protocolVersion -Returns "0.2" - -### skale_receiveTransaction -Can be used for receiving broadcasted transactions from other nodes, but currenlty substituted by ZMQ - -### skale_shutdownInstance -### skale_getSnapshot -Triggers snapshot serialization on local hard drive - -### skale_downloadSnapshotFragment -Can be used after `skale_getSnapshot` - -### skale_getSnapshotSignature -### skale_getLatestSnapshotBlockNumber -Returns block number of latest snapshot which can be downloaded. Usually it is the snapshot that was created at 00:00 yesterday. - -### skale_getLatestBlockNumber -Same as `eth_blockNumber` but returns decimal literal. - -### skale_getDBUsage ### oracle_submitRequest ### oracle_checkResult @@ -1032,35 +1006,3 @@ None #### Returns See `eth_pendingTransactions` -## Debug Methods -Enabled by special flag only - -### debug_pauseConsensus -Receives parameter `true` or `false` to pause or unpause block processing after consensus. - -### debug_pauseBroadcast -Receives parameter `true` or `false` to pause or unpause broadcast. - -### debug_forceBlock -Temporary sets consensus' empty block interval to 50 ms, waits until block from consensus, then sets empty block interval back. - -### debug_forceBroadcast -### debug_interfaceCall -Allows to pause and resume skaled in some key points of operation - -### debug_getVersion -Returns string similar to "3.19.0+commit.859d742c" - -### debug_getArguments -Probably returns command-line as string - -### debug_getConfig -Returns full config.json - -### debug_getSchainName -Returns `chainParams.sChain.name` - -### debug_getSnapshotCalculationTime -### debug_getSnapshotHashCalculationTime -### debug_doStateDbCompaction -### debug_doBlocksDbCompaction From 9d9f18c401113b91f970bc49c4a08f87ca50c7b5 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 18 Jun 2024 15:19:25 +0300 Subject: [PATCH 24/61] Create private-api.md --- docs/private-api.md | 55 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 docs/private-api.md diff --git a/docs/private-api.md b/docs/private-api.md new file mode 100644 index 000000000..b6528b8bf --- /dev/null +++ b/docs/private-api.md @@ -0,0 +1,55 @@ +## `skale_*` Methods +### skale_protocolVersion +Returns "0.2" + +### skale_receiveTransaction +Can be used for receiving broadcasted transactions from other nodes, but currenlty substituted by ZMQ + +### skale_shutdownInstance +### skale_getSnapshot +Triggers snapshot serialization on local hard drive + +### skale_downloadSnapshotFragment +Can be used after `skale_getSnapshot` + +### skale_getSnapshotSignature +### skale_getLatestSnapshotBlockNumber +Returns block number of latest snapshot which can be downloaded. Usually it is the snapshot that was created at 00:00 yesterday. + +### skale_getLatestBlockNumber +Same as `eth_blockNumber` but returns decimal literal. + +### skale_getDBUsage + +## Debug Methods +Enabled by special flag only + +### debug_pauseConsensus +Receives parameter `true` or `false` to pause or unpause block processing after consensus. + +### debug_pauseBroadcast +Receives parameter `true` or `false` to pause or unpause broadcast. + +### debug_forceBlock +Temporary sets consensus' empty block interval to 50 ms, waits until block from consensus, then sets empty block interval back. + +### debug_forceBroadcast +### debug_interfaceCall +Allows to pause and resume skaled in some key points of operation + +### debug_getVersion +Returns string similar to "3.19.0+commit.859d742c" + +### debug_getArguments +Probably returns command-line as string + +### debug_getConfig +Returns full config.json + +### debug_getSchainName +Returns `chainParams.sChain.name` + +### debug_getSnapshotCalculationTime +### debug_getSnapshotHashCalculationTime +### debug_doStateDbCompaction +### debug_doBlocksDbCompaction From 3ca749a2626e3a6bd6f901d1bc5ab1625135a2c3 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 18 Jun 2024 15:21:22 +0300 Subject: [PATCH 25/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 66bbaa952..170e8db31 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -773,7 +773,7 @@ Not supported | Core vs ETH | Unknown | | Historic vs ETH | Unknown | -Add proxy account, whatever that can mean +Add proxy account #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes #### Returns From f643e93540fd4d02c4d23a959598b91b9321fba3 Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Tue, 18 Jun 2024 13:34:36 +0100 Subject: [PATCH 26/61] Rename private-api.md to internal-api.md --- docs/{private-api.md => internal-api.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/{private-api.md => internal-api.md} (100%) diff --git a/docs/private-api.md b/docs/internal-api.md similarity index 100% rename from docs/private-api.md rename to docs/internal-api.md From 5daddade4434b6888337d4c18cf5461deb70cf7a Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 1 Jul 2024 18:09:39 +0300 Subject: [PATCH 27/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 232 ++++++++++++++++++++++++------------- 1 file changed, 152 insertions(+), 80 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 170e8db31..04d484653 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -16,10 +16,11 @@ Parameters marked as `OPTIONAL` are optional, otherwise they are required! | Core vs ETH | Mostly same | | Historic vs ETH | Mostly same | -Returns detailed `skaled` version +#### Description +Get detailed `skaled` version #### Parameters None -#### Returns +#### Return format `String` representing exact build of `skaled` Example: "skaled/3.19.0+commit.859d742c/linux/gnu9.5.0/debug" @@ -30,10 +31,11 @@ Example: "skaled/3.19.0+commit.859d742c/linux/gnu9.5.0/debug" | Core vs ETH | Same | | Historic vs ETH | Same | -Returns `sha3` (`keccak256`) hash of input data +#### Description +Get `sha3` (`keccak256`) hash of input data #### Parameters 1. Input data represented as a "0x"-prefixed hex `String` -#### Returns +#### Return format Output data represented as a "0x"-prefixed hex `String` (32 bytes) ## `net_*` Methods @@ -44,10 +46,11 @@ Output data represented as a "0x"-prefixed hex `String` (32 bytes) | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Returns chainID from config.json #### Parameters None -#### Returns +#### Return format Decimal number as `String` ### `net_listening` @@ -56,10 +59,11 @@ Decimal number as `String` | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Returns `true` #### Parameters None -#### Returns +#### Return format Boolean literal `true` ### `net_peerCount` @@ -68,10 +72,11 @@ Boolean literal `true` | Core vs ETH | Compatible, but makes no sense in SKALE | | Historic vs ETH | Compatible, but makes no sense in SKALE | +#### Description Returns 0 #### Parameters None -#### Returns +#### Return format `String` value "0x0" ## `eth_*` Methods @@ -82,10 +87,11 @@ None | Core vs ETH | SKALE uses hex, ETH uses dec | | Historic vs ETH | SKALE uses hex, ETH uses dec | +#### Description Returns `0x3f` #### Parameters None -#### Returns +#### Return format `String` value "0x3f" ### `eth_syncing` @@ -94,6 +100,9 @@ None | Core vs ETH | SKALE uses dec, ETH uses hex | | Historic vs ETH | SKALE uses dec, ETH uses hex | +#### Description +Get node's sync status. + If node has all up-to-date blocks - returns `false`. If it's behind others and is catching up - retuns object: @@ -103,7 +112,7 @@ If it's behind others and is catching up - retuns object: #### Parameters None -#### Returns +#### Return format Boolean literal `false` ### `eth_coinbase` @@ -112,10 +121,11 @@ Boolean literal `false` | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Returns sChainOwner address from config.json (it is used as coinbase address) #### Parameters None -#### Returns +#### Return format "0x"-prefixed hex `String` (20 bytes) ### `eth_chainId` @@ -124,10 +134,11 @@ None | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Returns chainID from config.json as hex string #### Parameters None -#### Returns +#### Return format "0x"-prefixed hex `String` ### `eth_mining` @@ -136,10 +147,11 @@ None | Core vs ETH | Compatible, but makes no sense in SKALE | | Historic vs ETH | Compatible, but makes no sense in SKALE | +#### Description Returns `false` #### Parameters None -#### Returns +#### Return format Boolean literal `false` ### `eth_hashrate` @@ -148,10 +160,11 @@ Boolean literal `false` | Core vs ETH | Compatible, but makes no sense in SKALE | | Historic vs ETH | Compatible, but makes no sense in SKALE | +#### Description There is no hashrate for SKALE s-chains, always returns 0 #### Parameters None -#### Returns +#### Return format `String` literal "0x0" ### `eth_gasPrice` @@ -160,10 +173,11 @@ None | Core vs ETH | Same | | Historic vs ETH | Same | -Returns current minimum gas price needed for transaction to be accepted into the Transaction Queue. Gas price is dynamically adjusted from 100k wei and above as load grows +#### Description +Get current minimum gas price needed for transaction to be accepted into the Transaction Queue. Gas price is dynamically adjusted from 100k wei and above as load grows #### Parameters None -#### Returns +#### Return format "0x"-prefixed hex `String` representing current gas price ### `eth_accounts` @@ -172,10 +186,11 @@ None | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Get list of accounts with locally-stored private keys #### Parameters None -#### Returns +#### Return format `Array` of "0x"-prefixed hex `String`s, 20 bytes each ### `eth_blockNumber` @@ -184,10 +199,11 @@ None | Core vs ETH | Same | | Historic vs ETH | Same | -Returns the number of most recent block +#### Description +Get the number of most recent block #### Parameters None -#### Returns +#### Return format "0x"-prefixed hex `String` representing block number ### `eth_getBalance` @@ -196,7 +212,8 @@ None | Core vs ETH | SKALE ignores block number | | Historic vs ETH | Same | -Returns the balance of the account of given address +#### Description +Get the balance of the account of given address #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes 2. Block number: `String` that is interpreted differently for normal and historic builds: @@ -207,7 +224,7 @@ Historic build: - "latest" or "pending" - latest balance is returned; - "earliest" - balance before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. -#### Returns +#### Return format "0x"-prefixed hex `String` representing balance in wei ### `eth_getStorageAt` @@ -216,7 +233,8 @@ Historic build: | Core vs ETH | SKALE ignores block number | | Historic vs ETH | Same | -Returns the value from a storage position at a given account +#### Description +Get the value from a storage position at a given account #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; 2. Position: `String` representation of an integer storage position, either decimal or "0x"-prefixed hexadecimal; @@ -228,7 +246,7 @@ Historic build: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. -#### Returns +#### Return format "0x"-prefixed hex `String` (32 bytes) ### `eth_getTransactionCount` @@ -237,7 +255,8 @@ Historic build: | Core vs ETH | SKALE ignores block number | | Historic vs ETH | Same | -Returns the number of transactions sent from an address. +#### Description +Get the number of transactions sent from an address. #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; 2. Block number: `String` that is interpreted differently for normal and historic builds: @@ -248,7 +267,7 @@ Historic build: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. -#### Returns +#### Return format "0x"-prefixed hex `String` representing transaction count @@ -258,9 +277,11 @@ Historic build: | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description +Get number of transactions in a block #### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes -#### Returns +#### Return format "0x"-prefixed hex `String` representing transaction count ### `eth_getBlockTransactionCountByNumber` @@ -269,11 +290,13 @@ Historic build: | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description +Get number of transactions in a block #### Parameters 1. Block number: - "earliest", "latest", or "pending"; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. -#### Returns +#### Return format "0x"-prefixed hex `String` representing transaction count ### `eth_getUncleCountByBlockHash` @@ -282,9 +305,12 @@ Historic build: | Core vs ETH | Compatible, but makes no sense in SKALE | | Historic vs ETH | Compatible, but makes no sense in SKALE | +#### Description +Always returns 0. + #### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes -#### Returns +#### Return format `String` literal "0x0" ### `eth_getUncleCountByBlockNumber` @@ -293,11 +319,14 @@ Historic build: | Core vs ETH | Compatible, but makes no sense in SKALE | | Historic vs ETH | Compatible, but makes no sense in SKALE | +#### Description +Always returns 0. + #### Parameters 1. Block number: - "earliest", "latest", or "pending"; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. -#### Returns +#### Return format `String` literal "0x0" ### `eth_getCode` @@ -306,7 +335,8 @@ Historic build: | Core vs ETH | SKALE ignores block number | | Historic vs ETH | Same | -Returns code at a given address +#### Description +Get code at a given address #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; 2. Block number: `String` that is interpreted differently for normal and historic builds: @@ -317,7 +347,7 @@ Historic build: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. -#### Returns +#### Return format "0x"-prefixed hex `String` ### `eth_sign` @@ -326,6 +356,7 @@ Historic build: | Core vs ETH | Not supported in SKALE| | Historic vs ETH | Not supported in SKALE | +#### Description Not supported ### `eth_signTransaction` @@ -334,10 +365,11 @@ Not supported | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Sign transaction using stored private key and make raw transaction #### Parameters 1. Object same as `eth_sendTransaction` -#### Returns +#### Return format Object: - "raw": "0x"-prefixed hex `String`; - "tx": same as in `eth_inspectTransaction` @@ -348,7 +380,8 @@ Object: | Core vs ETH | Same | | Historic vs ETH | Same | -Creates new transaction from the provided fields, signs it with the specified `from` address and submits it to the Transaction Queue +#### Description +Create new transaction from the provided fields, sign it with the specified `from` address and submit it to the Transaction Queue #### Parameters 1. JSON object with the following fields: - "from": OPTIONAL "0x"-prefixed hex `String`, 20 bytes OR null; if omitted or null, personal account with the largest balance is used; @@ -361,7 +394,7 @@ Creates new transaction from the provided fields, signs it with the specified `f - "data": OPTIONAL "0x"-prefixed hex `String` OR "0x" OR "" OR null; defaults to empty; - "input": OPTIONAL same as "data"; - "nonce": OPTIONAL decimal `String` OR "0x"-prefixed hexadecimal `String` OR integer literal OR null; defaults to current nonce of the sender OR maximum nonce of the sender's transactions in the Transaction Queue if it is larger (default is applied if omitted or null). -#### Returns +#### Return format "0x"-prefixed hex `String`, 32 bytes - hash of the transaction. If transaction was attributed to a proxy account, empty hash is returned. @@ -371,10 +404,11 @@ Creates new transaction from the provided fields, signs it with the specified `f | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Submit pre-signed transaction into the Transaction Queue #### Parameters 1. "0x"-prefixed hex `String` - transaction bytes. -#### Returns +#### Return format "0x"-prefixed hex `String`, 32 bytes - hash of the transaction. ### `eth_call` @@ -383,6 +417,7 @@ Submit pre-signed transaction into the Transaction Queue | Core vs ETH | SKALE ignores block number | | Historic vs ETH | Same | +#### Description Execute read-only contract call #### Parameters 1. Same object as in `eth_sendTransaction`. TODO Find out if decimal literals are allowed in ETH @@ -394,7 +429,7 @@ Historic build: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal: the `State` after executing of the specified block is used to execute call. -#### Returns +#### Return format "0x"-prefixed hex `String` or "0x", call result ### `eth_estimateGas` @@ -403,11 +438,12 @@ Historic build: | Core vs ETH | SKALE ignores block number | | Historic vs ETH | SKALE ignores block number | +#### Description Execute transaction on a temporary state without committing to DB and return gas usage #### Parameters 1. Same object as in `eth_sendTransaction`. 2. OPTIONAL Ignored -#### Returns +#### Return format "0x"-prefixed hex `String`, gas estimate ### `eth_getBlockByHash` @@ -416,11 +452,12 @@ Execute transaction on a temporary state without committing to DB and return gas | Core vs ETH | Same | | Historic vs ETH | Same | -Return details about block +#### Description +Get details about block #### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes 2. Include transactions: boolean literal - true/false -#### Returns +#### Return format `null` if block is absent or rotated out. Otherwise - object with the following fields: @@ -457,14 +494,15 @@ TODO document skipping of invalid | Core vs ETH | Same | | Historic vs ETH | Same | -Return details about block +#### Description +Get details about block #### Parameters 1. Block number: - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal. 2. Include transactions: boolean literal - true/false -#### Returns +#### Return format Same as `eth_getBlockByHash` #### Exceptions Raises "block not found" error if block is "rotated out" @@ -475,10 +513,11 @@ Raises "block not found" error if block is "rotated out" | Core vs ETH | Same | | Historic vs ETH | Same | -Return details about transaction +#### Description +Get details about transaction #### Parameters 1. Transaction hash: "0x"-prefixed hex `String`, 32 bytes -#### Returns +#### Return format `null` if transaction not found. Otherwise, object with the following fields: @@ -508,11 +547,12 @@ Otherwise, object with the following fields: | Core vs ETH | Same | | Historic vs ETH | Same | -Return details about transaction +#### Description +Get details about transaction #### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes 2. Transaction index: either decimal or "0x"-prefixed hexadecimal `String` -#### Returns +#### Return format Same as `eth_getTransactionByHash` ### `eth_getTransactionByBlockNumberAndIndex` @@ -521,14 +561,15 @@ Same as `eth_getTransactionByHash` | Core vs ETH | Same | | Historic vs ETH | Same | -Return details about transaction +#### Description +Get details about transaction #### Parameters 1. Block number: - "latest" or "pending" - latest block is used; - "earliest" - block 0; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; 2. Transaction index: either decimal or "0x"-prefixed hexadecimal `String` -#### Returns +#### Return format Same as `eth_getTransactionByHash` ### `eth_getTransactionReceipt` @@ -537,10 +578,11 @@ Same as `eth_getTransactionByHash` | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Get transaction receipt #### Parameters 1. Transaction hash: "0x"-prefixed hex `String`, 32 bytes -#### Returns +#### Return format `null` if transaction not mined. Otherwise - object with the following fields: @@ -566,11 +608,12 @@ Otherwise - object with the following fields: | Core vs ETH | Compatible, but makes no sense in SKALE | | Historic vs ETH | Compatible, but makes no sense in SKALE | +#### Description Return `null` #### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes 2. Uncle index: either decimal or "0x"-prefixed hexadecimal `String` -#### Returns +#### Return format `null` ### `eth_getUncleByBlockNumberAndIndex` @@ -579,6 +622,7 @@ Return `null` | Core vs ETH | Compatible, but makes no sense in SKALE | | Historic vs ETH | Compatible, but makes no sense in SKALE | +#### Description Return `null` #### Parameters 1. Block number: @@ -586,7 +630,7 @@ Return `null` - "earliest" - block 0; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; 3. Uncle index: either decimal or "0x"-prefixed hexadecimal `String` -#### Returns +#### Return format `null` ### `eth_newFilter` @@ -596,7 +640,8 @@ Return `null` | Core vs ETH | Same | | Historic vs ETH | Same | -Creates new logs (events) filter and returns it's ID +#### Description +Create new logs (events) filter and return it's ID #### Parameters 1. Object: @@ -608,7 +653,7 @@ Creates new logs (events) filter and returns it's ID - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; - "address" OPTIONAL: "0x"-prefixed hex `String`, 20 bytes; - "topics" OPTIONAL: `Array`, see https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newfilter -#### Returns +#### Return format "0x"-prefixed hex `String` - ID of the filter #### Notes Any non-WS filter is deleted if it's not being polled for 20 seconds @@ -619,10 +664,11 @@ Any non-WS filter is deleted if it's not being polled for 20 seconds | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Create filter for monitoring new blocks and returns it's ID #### Parameters None -#### Returns +#### Return format "0x"-prefixed hex `String` - ID of the filter ### `eth_newPendingTransactionFilter` @@ -631,10 +677,11 @@ None | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Create filter for monitoring new transactins and returns it's ID #### Parameters None -#### Returns +#### Return format "0x"-prefixed hex `String` - ID of the filter ### `eth_uninstallFilter` @@ -643,10 +690,11 @@ None | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Remove previously created filter #### Parameters 1. Decimal or "0x"-prefixed hex `String` - ID of the filter -#### Returns +#### Return format `true` if filter was successfully found and uninstalled, `false` if it's not found ### `eth_getFilterChanges` @@ -655,11 +703,13 @@ Remove previously created filter | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Get changes in filter results since previous call (or filter creation) + Ignores logs that originated from blocks that were "rotated out" #### Parameters 1. Decimal or "0x"-prefixed hex `String` - ID of the filter -#### Returns +#### Return format `Array` of changes (can be empty). For a block filter, array items are block hashes. @@ -691,10 +741,11 @@ If a block is removed from the DB due to block rotation, it doesn't affect this | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Get all events matching a filter #### Parameters 1. Decimal or "0x"-prefixed hex `String` - ID of the filter -#### Returns +#### Return format Same as `eth_getFilterChanges` TODO Compare #### Exceptions @@ -706,6 +757,7 @@ Throws `INVALID_PARAMS` if filter cannot be found or if response size is exceede | Core vs ETH | Same | | Historic vs ETH | Same | +#### Description Same as `eth_getFilterLogs`, but doesn't require filter creation #### Parameters @@ -719,7 +771,7 @@ Same as `eth_getFilterLogs`, but doesn't require filter creation - "address" OPTIONAL: "0x"-prefixed hex `String`, 20 bytes; - "topics" OPTIONAL: `Array`, see https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_newfilter - "blockHash" OPTIONAL: "0x"-prefixed hex `String`, 32 bytes; if this field is present, then `fromBlock` and `toBlock` are not allowed. -#### Returns +#### Return format Same as `eth_getFilterChanges` #### Exceptions Throws `INVALID_PARAMS` if block does not exist, if response size is exceeded, or `fromBlock` or `toBlock` are present together with `blockHash` @@ -733,10 +785,11 @@ Not supported | Core vs ETH | Unknown | | Historic vs ETH | Unknown | +#### Description Returns three magic hashes #### Parameters None -#### Returns +#### Return format `Array` of three "0x"-prefixed hex `String`s, 32 bytes each ### `eth_submitWork` @@ -749,7 +802,7 @@ None 1. nonce: decimal or "0x"-prefixed hexadecimal number, 8 bytes; 2. powHash: decimal or "0x"-prefixed hexadecimal number, 32 bytes; 3. mixDigest: decimal or "0x"-prefixed hexadecimal number, 32 bytes. -#### Returns +#### Return format `true` ### `eth_submitHashrate` @@ -761,10 +814,11 @@ None #### Parameters 1. hashrate: decimal or "0x"-prefixed hexadecimal number, 32 bytes; 2. miner id: decimal or "0x"-prefixed hexadecimal number, 32 bytes. -#### Returns +#### Return format `true` ### `eth_getProof` +#### Description Not supported ### `eth_register` @@ -773,10 +827,11 @@ Not supported | Core vs ETH | Unknown | | Historic vs ETH | Unknown | +#### Description Add proxy account #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes -#### Returns +#### Return format "0x"-prefixed hex `String` - id of added account ### `eth_unregister` @@ -785,10 +840,11 @@ Add proxy account | Core vs ETH | Unknown | | Historic vs ETH | Unknown | +#### Description Remove proxy account #### Parameters 1. id: decimal or "0x"-prefixed hexadecimal number, previously obtained through `eth_register` -#### Returns +#### Return format `true` if account was found and removed, `false` otherwise ### `eth_feeHistory` @@ -800,10 +856,11 @@ Remove proxy account | Core vs ETH | Unknown | | Historic vs ETH | Unknown | +#### Description Probably it will mine a block with PoW #### Parameters None -#### Returns +#### Return format `true` ### `eth_createAccessList` @@ -811,7 +868,7 @@ Returns empty access list #### Parameters 1. Transaction object same as in `eth_sendTransaction`; 2. `String` block hash or number (ignored). -#### Returns +#### Return format Object: - "accessList" - empty list; - "gasUsed" - "0x" prefixed hex `String` - result of `eth_estimateGas`. @@ -822,10 +879,11 @@ Object: | Core vs ETH | Unknown | | Historic vs ETH | Unknown | +#### Description Get number of transactions in a block #### Parameters 1. Block hash: "0x"-prefixed hex `String`, 32 bytes -#### Returns +#### Return format "0x"-prefixed hex `String` ### `eth_getBlockTransactionCountByNumber` @@ -834,13 +892,14 @@ Get number of transactions in a block | Core vs ETH | Unknown | | Historic vs ETH | Unknown | +#### Description Get number of transactions in a block #### Parameters 1. Block number: - "latest" or "pending" - latest block is used; - "earliest" - block 0; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal; -#### Returns +#### Return format "0x"-prefixed hex `String` ### `eth_getFilterChangesEx` @@ -849,6 +908,7 @@ Get number of transactions in a block | Core vs ETH | Unknown | | Historic vs ETH | Unknown | +#### Description Same as `eth_getFilterChanges` ### `eth_getStorageRoot` @@ -858,8 +918,11 @@ Same as `eth_getFilterChanges` | Core vs ETH | Unsupported in both | | Historic vs ETH | Supported in Historic, unsupported in ETH | +#### Description Get account's `storageRoot` (according to Yellow Paper) + Noramal node - call always throws exception. + Historic node - see below. #### Parameters 1. Address: "0x"-prefixed hex `String`, 20 bytes; @@ -867,7 +930,7 @@ Historic node - see below. - "latest" or "pending" - latest value is returned; - "earliest" - value before block 1 is returned; - `String` representation of an integer block number, either decimal or "0x"-prefixed hexadecimal - value after execution of specified block is returned. -#### Returns +#### Return format "0x"-prefixed hex `String` (32 bytes). If account cannot be found - `sha3( rlp( "" ) )` is returned ### `eth_inspectTransaction` @@ -877,32 +940,35 @@ Historic node - see below. | Core vs ETH | Unsupported in ETH | | Historic vs ETH | Unsupported in ETH | +#### Description Parse binary transaction into fields #### Parameters 1. Raw transaction: "0x"-prefixed hex `String` -#### Returns +#### Return format Object, see `eth_getTransactionByHash` ### `eth_maxPriorityFeePerGas` #### Parameters None -#### Returns +#### Return format "0x0" ### `eth_notePassword` #### Parameters 1. `String` - ignored -#### Returns +#### Return format `false` ### `eth_pendingTransactions` +#### Description Get transaction queue #### Parameters None -#### Returns +#### Return format `Array` of `Object`s, see `eth_getTransactionByHash`. `sighash` equals to `hash` ### `eth_subscribe` +#### Description HTTP(S): unsupported, always throws exception WS(S): subscribe for new events/transactions/blocks/stats @@ -913,7 +979,7 @@ WS(S): subscribe for new events/transactions/blocks/stats - "newHeads"; - "skaleStats". 2. Used only when type="logs": object, format is the same as in `eth_newFilter` -#### Returns +#### Return format "0x"-prefixed hex `String` - subscription id #### Events format @@ -963,12 +1029,13 @@ Depending on the type of subscription, different data is pushed back to the clie ``` ### `eth_unsubscribe` +#### Description HTTP(S): unsupported, always throws exception WS(S): unsubscribe from events/transactions/blocks/stats (see `eth_subscribe`) #### Parameters 1. id: decimal or "0x"-prefixed hexadecimal number `String` OR number literal - previously obtained through `eth_subscribe` -#### Returns +#### Return format None ## `personal_*` Methods @@ -980,29 +1047,34 @@ Not supported ## `shh_*` Methods Not supported -## Non-standard Methods -### setSchainExitTime -### oracle_submitRequest -### oracle_checkResult - +## Debug Methods ### debug_accountRangeAt +#### Description Not supported, always throws ### debug_traceTransaction ### debug_storageRangeAt +#### Description Not supported, always throws ### debug_preimage +#### Description Not supported, always throws ### debug_traceBlockByNumber ### debug_traceBlockByHash ### debug_traceCall -### debug_getFutureTransactions + +## Non-standard Methods +### oracle_submitRequest +### oracle_checkResult + +#### Description Get future transaction queue #### Parameters None -#### Returns +#### Return format +#### Description See `eth_pendingTransactions` From f00b82349a0d1ba6df6f0e689b9ff3c153350bff Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 1 Jul 2024 18:11:03 +0300 Subject: [PATCH 28/61] Update internal-api.md --- docs/internal-api.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/internal-api.md b/docs/internal-api.md index b6528b8bf..4c6e64fa1 100644 --- a/docs/internal-api.md +++ b/docs/internal-api.md @@ -1,4 +1,5 @@ ## `skale_*` Methods + ### skale_protocolVersion Returns "0.2" @@ -53,3 +54,7 @@ Returns `chainParams.sChain.name` ### debug_getSnapshotHashCalculationTime ### debug_doStateDbCompaction ### debug_doBlocksDbCompaction + +## Other Methods +### setSchainExitTime +### debug_getFutureTransactions From 42a633169cbdffbb1a9b9deac05771b0b62cd7fd Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 1 Jul 2024 18:12:59 +0300 Subject: [PATCH 29/61] Delete docs/internal-api.md --- docs/internal-api.md | 60 -------------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 docs/internal-api.md diff --git a/docs/internal-api.md b/docs/internal-api.md deleted file mode 100644 index 4c6e64fa1..000000000 --- a/docs/internal-api.md +++ /dev/null @@ -1,60 +0,0 @@ -## `skale_*` Methods - -### skale_protocolVersion -Returns "0.2" - -### skale_receiveTransaction -Can be used for receiving broadcasted transactions from other nodes, but currenlty substituted by ZMQ - -### skale_shutdownInstance -### skale_getSnapshot -Triggers snapshot serialization on local hard drive - -### skale_downloadSnapshotFragment -Can be used after `skale_getSnapshot` - -### skale_getSnapshotSignature -### skale_getLatestSnapshotBlockNumber -Returns block number of latest snapshot which can be downloaded. Usually it is the snapshot that was created at 00:00 yesterday. - -### skale_getLatestBlockNumber -Same as `eth_blockNumber` but returns decimal literal. - -### skale_getDBUsage - -## Debug Methods -Enabled by special flag only - -### debug_pauseConsensus -Receives parameter `true` or `false` to pause or unpause block processing after consensus. - -### debug_pauseBroadcast -Receives parameter `true` or `false` to pause or unpause broadcast. - -### debug_forceBlock -Temporary sets consensus' empty block interval to 50 ms, waits until block from consensus, then sets empty block interval back. - -### debug_forceBroadcast -### debug_interfaceCall -Allows to pause and resume skaled in some key points of operation - -### debug_getVersion -Returns string similar to "3.19.0+commit.859d742c" - -### debug_getArguments -Probably returns command-line as string - -### debug_getConfig -Returns full config.json - -### debug_getSchainName -Returns `chainParams.sChain.name` - -### debug_getSnapshotCalculationTime -### debug_getSnapshotHashCalculationTime -### debug_doStateDbCompaction -### debug_doBlocksDbCompaction - -## Other Methods -### setSchainExitTime -### debug_getFutureTransactions From 53a2ace4bc1f43449e163e5f0f1394ee7b01943a Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Mon, 22 Jul 2024 21:16:16 +0300 Subject: [PATCH 30/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 04d484653..5feb96b36 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -420,7 +420,7 @@ Submit pre-signed transaction into the Transaction Queue #### Description Execute read-only contract call #### Parameters -1. Same object as in `eth_sendTransaction`. TODO Find out if decimal literals are allowed in ETH +1. Same object as in `eth_sendTransaction`. 2. Block number: `String` that is interpreted differently for normal and historic builds: Normal build: parameter ignored, latest value is always returned. @@ -485,8 +485,6 @@ Otherwise - object with the following fields: - "uncles": empty arra; - "baseFeePerGas": "0x"-prefixed hex `String`, gas price in block, field is present only if EIP-1559 is enabled; for rotated out old blocks this field is set to latest gasPrice; - "transactions": array of transaction hashes ("0x"-prefixed hex `String`s, 32 bytes) OR detaled transactions info (same as in `eth_getTransactionByHash`) if 2nd argument was `true`; - -TODO document skipping of invalid ### `eth_getBlockByNumber` | Compatibility | | @@ -717,7 +715,6 @@ For a block filter, array items are block hashes. For a transaction filter, array items are transaction hashes. For an event filter, array items are objects with the following fields: -TODO description - "data" - "address" - "topics" @@ -747,7 +744,6 @@ Get all events matching a filter 1. Decimal or "0x"-prefixed hex `String` - ID of the filter #### Return format Same as `eth_getFilterChanges` -TODO Compare #### Exceptions Throws `INVALID_PARAMS` if filter cannot be found or if response size is exceeded @@ -921,7 +917,7 @@ Same as `eth_getFilterChanges` #### Description Get account's `storageRoot` (according to Yellow Paper) -Noramal node - call always throws exception. +Normal node - call always throws exception. Historic node - see below. #### Parameters @@ -1070,11 +1066,4 @@ Not supported, always throws ### oracle_submitRequest ### oracle_checkResult -#### Description -Get future transaction queue -#### Parameters -None -#### Return format -#### Description -See `eth_pendingTransactions` From e548a9150483d3274bb66830c8bd0e617baee035 Mon Sep 17 00:00:00 2001 From: Dima Litvinov Date: Tue, 23 Jul 2024 21:38:30 +0300 Subject: [PATCH 31/61] Update json-rpc-interface.md --- docs/json-rpc-interface.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/json-rpc-interface.md b/docs/json-rpc-interface.md index 5feb96b36..c05827aa2 100644 --- a/docs/json-rpc-interface.md +++ b/docs/json-rpc-interface.md @@ -1043,19 +1043,19 @@ Not supported ## `shh_*` Methods Not supported -## Debug Methods +## `debug_*` Methods ### debug_accountRangeAt #### Description -Not supported, always throws +Not supported, always throws exception ### debug_traceTransaction ### debug_storageRangeAt #### Description -Not supported, always throws +Not supported, always throws exception ### debug_preimage #### Description -Not supported, always throws +Not supported, always throws exception ### debug_traceBlockByNumber ### debug_traceBlockByHash From 1bbfaa4b12d328df706c9d1e509181f99ed64ad4 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Fri, 9 Aug 2024 20:41:26 +0000 Subject: [PATCH 32/61] #1931 Handle data field for reverts --- libweb3jsonrpc/Eth.cpp | 9 +++------ libweb3jsonrpc/rapidjson_handlers.cpp | 3 +-- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 6fe5af509..b088b8822 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -486,12 +486,9 @@ string Eth::eth_call( TransactionSkeleton& t, string const& strRevertReason = skutils::eth::call_error_message_2_str( er.output ); if ( strRevertReason.empty() ) strRevertReason = "EVM revert instruction without description message"; - std::string strTx = t.toString(); - std::string strOut = "Error message from eth_call(): " + strRevertReason + - ", with call arguments: " + strTx + - ", and using blockNumber=" + blockNumber; - cerror << strOut; - throw std::logic_error( strRevertReason ); + + Json::Value output = toJS( er.output ); + BOOST_THROW_EXCEPTION( JsonRpcException( -32004, strRevertReason, output ) ); } diff --git a/libweb3jsonrpc/rapidjson_handlers.cpp b/libweb3jsonrpc/rapidjson_handlers.cpp index 9a80587ea..8b57c2286 100644 --- a/libweb3jsonrpc/rapidjson_handlers.cpp +++ b/libweb3jsonrpc/rapidjson_handlers.cpp @@ -22,8 +22,7 @@ void wrapJsonRpcException( const rapidjson::Document& /*joRequest*/, Json::Value joData = exception.GetData(); if ( joData != Json::nullValue ) { joError.AddMember( "data", rapidjson::Value(), joResponse.GetAllocator() ); - Json::FastWriter fastWriter; - std::string data = fastWriter.write( joData ); + std::string data = joData.asString(); joError["data"].SetString( data.c_str(), data.size(), joResponse.GetAllocator() ); } From 29d2dc4d51640d27240d5d138e0bf3f92c5453b2 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Tue, 13 Aug 2024 17:51:09 +0000 Subject: [PATCH 33/61] #1931 Handle data field in estimateGas --- libweb3jsonrpc/Eth.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index b088b8822..7d624edbd 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -512,11 +512,15 @@ string Eth::eth_estimateGas( Json::Value const& _json ) { strRevertReason = skutils::eth::call_error_message_2_str( result.second.output ); if ( strRevertReason.empty() ) strRevertReason = "EVM revert instruction without description message"; - throw std::logic_error( strRevertReason ); + + Json::Value output = toJS( result.second.output ); + BOOST_THROW_EXCEPTION( JsonRpcException( -32004, strRevertReason, output ) ); } return toJS( result.first ); } catch ( std::logic_error& error ) { throw error; + } catch ( jsonrpc::JsonRpcException& error ) { + throw error; } catch ( ... ) { BOOST_THROW_EXCEPTION( JsonRpcException( Errors::ERROR_RPC_INVALID_PARAMS ) ); } From 64d1557e6f630163c6c920e8709769b37fe05516 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Tue, 13 Aug 2024 23:04:18 +0000 Subject: [PATCH 34/61] #1931 Fix linter --- libweb3jsonrpc/Eth.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 7d624edbd..8eab9b861 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -49,6 +49,7 @@ using namespace dev::rpc; const uint64_t MAX_CALL_CACHE_ENTRIES = 1024; const uint64_t MAX_RECEIPT_CACHE_ENTRIES = 1024; const u256 MAX_BLOCK_RANGE = 1024; +const int REVERT_INSTRUCTION_ERROR_CODE = -32000; #ifdef HISTORIC_STATE @@ -488,7 +489,8 @@ string Eth::eth_call( TransactionSkeleton& t, string const& strRevertReason = "EVM revert instruction without description message"; Json::Value output = toJS( er.output ); - BOOST_THROW_EXCEPTION( JsonRpcException( -32004, strRevertReason, output ) ); + BOOST_THROW_EXCEPTION( + JsonRpcException( REVERT_INSTRUCTION_ERROR_CODE, strRevertReason, output ) ); } @@ -512,9 +514,10 @@ string Eth::eth_estimateGas( Json::Value const& _json ) { strRevertReason = skutils::eth::call_error_message_2_str( result.second.output ); if ( strRevertReason.empty() ) strRevertReason = "EVM revert instruction without description message"; - + Json::Value output = toJS( result.second.output ); - BOOST_THROW_EXCEPTION( JsonRpcException( -32004, strRevertReason, output ) ); + BOOST_THROW_EXCEPTION( + JsonRpcException( REVERT_INSTRUCTION_ERROR_CODE, strRevertReason, output ) ); } return toJS( result.first ); } catch ( std::logic_error& error ) { From e41bcaeca975f334317f67aeaf06c91928a5781b Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Wed, 14 Aug 2024 00:01:44 +0000 Subject: [PATCH 35/61] #1931 Add eth_call_error test --- libweb3jsonrpc/Eth.cpp | 2 +- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 50 +++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 8eab9b861..4d74562dd 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -49,7 +49,7 @@ using namespace dev::rpc; const uint64_t MAX_CALL_CACHE_ENTRIES = 1024; const uint64_t MAX_RECEIPT_CACHE_ENTRIES = 1024; const u256 MAX_BLOCK_RANGE = 1024; -const int REVERT_INSTRUCTION_ERROR_CODE = -32000; +const int REVERT_INSTRUCTION_ERROR_CODE = -32004; #ifdef HISTORIC_STATE diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index c955130e6..14aebd755 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -1770,6 +1770,56 @@ BOOST_AUTO_TEST_CASE( call_from_parameter ) { responseString, "0x000000000000000000000000112233445566778899aabbccddeeff0011223344" ); } + +BOOST_AUTO_TEST_CASE( call_with_error ) { + JsonRpcFixture fixture; + dev::eth::simulateMining( *( fixture.client ), 1 ); + + // pragma solidity ^0.8.0; + + // contract BasicCustomErrorContract { + + // // Define custom errors + // error InsufficientBalance(); + // error Unauthorized(); + // address public owner; + + + // // Function only callable by the owner + // function ownerOnlyFunction() external { + // revert Unauthorized(); + // } + // } + + + string compiled = + "608060405234801561001057600080fd5b50610168806100206000396000f3fe608060405234801561001057600080fd5b5060043610610053576000357c0100000000000000000000000000000000000000000000000000000000900480638da5cb5b14610058578063e021c20614610076575b600080fd5b610060610080565b60405161006d9190610117565b60405180910390f35b61007e6100a4565b005b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610101826100d6565b9050919050565b610111816100f6565b82525050565b600060208201905061012c6000830184610108565b9291505056fea2646970667358221220132ca0f4158a0540a7e67f304c94305f81bbe52de2314e2b9cee92a2c74e103a64736f6c63430008120033"; + + auto senderAddress = fixture.coinbase.address(); + + Json::Value create; + create["from"] = toJS( senderAddress ); + create["code"] = compiled; + create["gas"] = "180000"; + string txHash = fixture.rpcClient->eth_sendTransaction( create ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + string contractAddress = receipt["contractAddress"].asString(); + + Json::Value transactionCallObject; + transactionCallObject["to"] = contractAddress; + transactionCallObject["data"] = "0xe021c206"; + + try { + fixture.rpcClient->eth_call( transactionCallObject, "latest" ); + } catch ( jsonrpc::JsonRpcException& ex) { + BOOST_CHECK_EQUAL(ex.GetCode(), -32004); + BOOST_CHECK_EQUAL(ex.GetData().asString(), "0x82b42900"); + BOOST_CHECK_EQUAL(ex.GetMessage(), "EVM revert instruction without description message"); + } +} + BOOST_AUTO_TEST_CASE( simplePoWTransaction ) { // 1s empty block interval JsonRpcFixture fixture( "", true, true, false, false, false, 1000 ); From b826f95f72eca4a439995a9abbdfef4e05f6e841 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Wed, 14 Aug 2024 00:08:35 +0000 Subject: [PATCH 36/61] #1931 Add estimate_gas_error test --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 73 +++++++++++++++++++++-- 1 file changed, 67 insertions(+), 6 deletions(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 14aebd755..a9faa9e4b 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -1776,24 +1776,30 @@ BOOST_AUTO_TEST_CASE( call_with_error ) { dev::eth::simulateMining( *( fixture.client ), 1 ); // pragma solidity ^0.8.0; - // contract BasicCustomErrorContract { - // // Define custom errors // error InsufficientBalance(); // error Unauthorized(); // address public owner; - - // // Function only callable by the owner // function ownerOnlyFunction() external { // revert Unauthorized(); // } // } - string compiled = - "608060405234801561001057600080fd5b50610168806100206000396000f3fe608060405234801561001057600080fd5b5060043610610053576000357c0100000000000000000000000000000000000000000000000000000000900480638da5cb5b14610058578063e021c20614610076575b600080fd5b610060610080565b60405161006d9190610117565b60405180910390f35b61007e6100a4565b005b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6040517f82b4290000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610101826100d6565b9050919050565b610111816100f6565b82525050565b600060208201905061012c6000830184610108565b9291505056fea2646970667358221220132ca0f4158a0540a7e67f304c94305f81bbe52de2314e2b9cee92a2c74e103a64736f6c63430008120033"; + "608060405234801561001057600080fd5b50610168806100206000396000f3fe608060" + "405234801561001057600080fd5b5060043610610053576000357c0100000000000000" + "000000000000000000000000000000000000000000900480638da5cb5b146100585780" + "63e021c20614610076575b600080fd5b610060610080565b60405161006d9190610117" + "565b60405180910390f35b61007e6100a4565b005b60008054906101000a900473ffff" + "ffffffffffffffffffffffffffffffffffff1681565b6040517f82b429000000000000" + "0000000000000000000000000000000000000000000000815260040160405180910390" + "fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60" + "00610101826100d6565b9050919050565b610111816100f6565b82525050565b600060" + "208201905061012c6000830184610108565b9291505056fea264697066735822122013" + "2ca0f4158a0540a7e67f304c94305f81bbe52de2314e2b9cee92a2c74e103a64736f6c" + "63430008120033"; auto senderAddress = fixture.coinbase.address(); @@ -1820,6 +1826,61 @@ BOOST_AUTO_TEST_CASE( call_with_error ) { } } +BOOST_AUTO_TEST_CASE( estimate_gas_with_error ) { + JsonRpcFixture fixture; + dev::eth::simulateMining( *( fixture.client ), 1 ); + + // pragma solidity ^0.8.0; + // contract BasicCustomErrorContract { + // // Define custom errors + // error InsufficientBalance(); + // error Unauthorized(); + // address public owner; + // // Function only callable by the owner + // function ownerOnlyFunction() external { + // revert Unauthorized(); + // } + // } + + string compiled = + "608060405234801561001057600080fd5b50610168806100206000396000f3fe608060" + "405234801561001057600080fd5b5060043610610053576000357c0100000000000000" + "000000000000000000000000000000000000000000900480638da5cb5b146100585780" + "63e021c20614610076575b600080fd5b610060610080565b60405161006d9190610117" + "565b60405180910390f35b61007e6100a4565b005b60008054906101000a900473ffff" + "ffffffffffffffffffffffffffffffffffff1681565b6040517f82b429000000000000" + "0000000000000000000000000000000000000000000000815260040160405180910390" + "fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60" + "00610101826100d6565b9050919050565b610111816100f6565b82525050565b600060" + "208201905061012c6000830184610108565b9291505056fea264697066735822122013" + "2ca0f4158a0540a7e67f304c94305f81bbe52de2314e2b9cee92a2c74e103a64736f6c" + "63430008120033"; + + auto senderAddress = fixture.coinbase.address(); + + Json::Value create; + create["from"] = toJS( senderAddress ); + create["code"] = compiled; + create["gas"] = "180000"; + string txHash = fixture.rpcClient->eth_sendTransaction( create ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + string contractAddress = receipt["contractAddress"].asString(); + + Json::Value transactionCallObject; + transactionCallObject["to"] = contractAddress; + transactionCallObject["data"] = "0xe021c206"; + + try { + fixture.rpcClient->eth_estimateGas( transactionCallObject, "latest" ); + } catch ( jsonrpc::JsonRpcException& ex) { + BOOST_CHECK_EQUAL(ex.GetCode(), -32004); + BOOST_CHECK_EQUAL(ex.GetData().asString(), "0x82b42900"); + BOOST_CHECK_EQUAL(ex.GetMessage(), "EVM revert instruction without description message"); + } +} + BOOST_AUTO_TEST_CASE( simplePoWTransaction ) { // 1s empty block interval JsonRpcFixture fixture( "", true, true, false, false, false, 1000 ); From 9c9a85eab3866d15a0cb796cdb7492383d3e45f4 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Fri, 16 Aug 2024 13:23:09 +0100 Subject: [PATCH 37/61] 1959 add chainId field to txn json rpc representation --- libweb3jsonrpc/JsonHelper.cpp | 3 +++ test/unittests/libweb3jsonrpc/jsonrpc.cpp | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libweb3jsonrpc/JsonHelper.cpp b/libweb3jsonrpc/JsonHelper.cpp index 5ee633768..c459e246f 100644 --- a/libweb3jsonrpc/JsonHelper.cpp +++ b/libweb3jsonrpc/JsonHelper.cpp @@ -107,6 +107,7 @@ Json::Value toJson( dev::eth::Transaction const& _t, std::pair< h256, unsigned > res["s"] = toJS( _t.signature().s ); res["type"] = toJS( int( _t.txType() ) ); if ( _t.txType() != dev::eth::TransactionType::Legacy ) { + res["chainId"] = toJS( _t.chainId() ); res["yParity"] = toJS( _t.signature().v ); res["accessList"] = Json::Value( Json::arrayValue ); for ( const auto& d : _t.accessList() ) { @@ -352,6 +353,7 @@ Json::Value toJson( dev::eth::Transaction const& _t ) { res["v"] = toJS( _t.signature().v ); res["type"] = toJS( int( _t.txType() ) ); if ( _t.txType() != dev::eth::TransactionType::Legacy ) { + res["chainId"] = toJS( _t.chainId() ); res["yParity"] = toJS( _t.signature().v ); res["accessList"] = Json::Value( Json::arrayValue ); for ( const auto& d : _t.accessList() ) { @@ -404,6 +406,7 @@ Json::Value toJson( dev::eth::LocalisedTransaction const& _t ) { res["s"] = toJS( _t.signature().s.hex() ); res["type"] = toJS( int( _t.txType() ) ); if ( _t.txType() != dev::eth::TransactionType::Legacy ) { + res["chainId"] = toJS( _t.chainId() ); res["yParity"] = toJS( _t.signature().v ); res["accessList"] = Json::Value( Json::arrayValue ); for ( const auto& d : _t.accessList() ) { diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index c955130e6..1a28c27f9 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -2881,7 +2881,8 @@ BOOST_AUTO_TEST_CASE( eip2930Transactions ) { Json::Reader().parse( _config, ret ); // Set chainID = 151 - ret["params"]["chainID"] = "0x97"; + std::string chainID = "0x97"; + ret["params"]["chainID"] = chainID; time_t eip1559PatchActivationTimestamp = time(nullptr) + 10; ret["skaleConfig"]["sChain"]["EIP1559TransactionsPatchTimestamp"] = eip1559PatchActivationTimestamp; @@ -2955,6 +2956,8 @@ BOOST_AUTO_TEST_CASE( eip2930Transactions ) { BOOST_REQUIRE( toJS( jsToInt( block["transactions"][0]["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == block["transactions"][0]["v"].asString() ); BOOST_REQUIRE( block["transactions"][0]["accessList"].isArray() ); BOOST_REQUIRE( block["transactions"][0]["accessList"].size() == 0 ); + BOOST_REQUIRE( block["transactions"][0].isMember( "chainId" ) ); + BOOST_REQUIRE( block["transactions"][0]["chainId"].asString() == chainID ); std::string blockHash = block["hash"].asString(); BOOST_REQUIRE( fixture.client->transactionHashes( dev::h256( blockHash ) )[0] == dev::h256( "0xc843560015a655b8f81f65a458be9019bdb5cd8e416b6329ca18f36de0b8244d") ); @@ -3103,6 +3106,8 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) { BOOST_REQUIRE( block["transactions"][0]["type"] == "0x2" ); BOOST_REQUIRE( toJS( jsToInt( block["transactions"][0]["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == block["transactions"][0]["v"].asString() ); BOOST_REQUIRE( block["transactions"][0]["accessList"].isArray() ); + BOOST_REQUIRE( block["transactions"][0].isMember( "chainId" ) ); + BOOST_REQUIRE( block["transactions"][0]["chainId"].asString() == chainID ); std::string blockHash = block["hash"].asString(); From 046981b1ea1cc252a2493f7194dec0a4e096f003 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Fri, 16 Aug 2024 13:37:27 +0100 Subject: [PATCH 38/61] #1959 fix tests --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 1a28c27f9..3010a9016 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -3030,7 +3030,8 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) { Json::Reader().parse( _config, ret ); // Set chainID = 151 - ret["params"]["chainID"] = "0x97"; + std::string chainID = "0x97"; + ret["params"]["chainID"] = chainID; time_t eip1559PatchActivationTimestamp = time(nullptr) + 10; ret["skaleConfig"]["sChain"]["EIP1559TransactionsPatchTimestamp"] = eip1559PatchActivationTimestamp; From d34368d3d70fe58e2c1a8cd7ae523a5e0fb565f9 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Wed, 21 Aug 2024 21:25:33 +0000 Subject: [PATCH 39/61] #1931 Add geth compatible error code --- libweb3jsonrpc/Eth.cpp | 24 ++++++++++++++++------- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 4 ++-- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/libweb3jsonrpc/Eth.cpp b/libweb3jsonrpc/Eth.cpp index 4d74562dd..6a39183fd 100644 --- a/libweb3jsonrpc/Eth.cpp +++ b/libweb3jsonrpc/Eth.cpp @@ -49,7 +49,9 @@ using namespace dev::rpc; const uint64_t MAX_CALL_CACHE_ENTRIES = 1024; const uint64_t MAX_RECEIPT_CACHE_ENTRIES = 1024; const u256 MAX_BLOCK_RANGE = 1024; -const int REVERT_INSTRUCTION_ERROR_CODE = -32004; + +// Geth compatible error code for a revert +const uint64_t REVERT_RPC_ERROR_CODE = 3; #ifdef HISTORIC_STATE @@ -488,9 +490,13 @@ string Eth::eth_call( TransactionSkeleton& t, string const& if ( strRevertReason.empty() ) strRevertReason = "EVM revert instruction without description message"; - Json::Value output = toJS( er.output ); - BOOST_THROW_EXCEPTION( - JsonRpcException( REVERT_INSTRUCTION_ERROR_CODE, strRevertReason, output ) ); + if ( !er.output.empty() ) { + Json::Value output = toJS( er.output ); + BOOST_THROW_EXCEPTION( + JsonRpcException( REVERT_RPC_ERROR_CODE, strRevertReason, output ) ); + } + + throw std::logic_error( strRevertReason ); } @@ -515,9 +521,13 @@ string Eth::eth_estimateGas( Json::Value const& _json ) { if ( strRevertReason.empty() ) strRevertReason = "EVM revert instruction without description message"; - Json::Value output = toJS( result.second.output ); - BOOST_THROW_EXCEPTION( - JsonRpcException( REVERT_INSTRUCTION_ERROR_CODE, strRevertReason, output ) ); + if ( !result.second.output.empty() ) { + Json::Value output = toJS( result.second.output ); + BOOST_THROW_EXCEPTION( + JsonRpcException( REVERT_RPC_ERROR_CODE, strRevertReason, output ) ); + } + + throw std::logic_error( strRevertReason ); } return toJS( result.first ); } catch ( std::logic_error& error ) { diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index a9faa9e4b..ad2b1a23f 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -1820,7 +1820,7 @@ BOOST_AUTO_TEST_CASE( call_with_error ) { try { fixture.rpcClient->eth_call( transactionCallObject, "latest" ); } catch ( jsonrpc::JsonRpcException& ex) { - BOOST_CHECK_EQUAL(ex.GetCode(), -32004); + BOOST_CHECK_EQUAL(ex.GetCode(), 3); BOOST_CHECK_EQUAL(ex.GetData().asString(), "0x82b42900"); BOOST_CHECK_EQUAL(ex.GetMessage(), "EVM revert instruction without description message"); } @@ -1875,7 +1875,7 @@ BOOST_AUTO_TEST_CASE( estimate_gas_with_error ) { try { fixture.rpcClient->eth_estimateGas( transactionCallObject, "latest" ); } catch ( jsonrpc::JsonRpcException& ex) { - BOOST_CHECK_EQUAL(ex.GetCode(), -32004); + BOOST_CHECK_EQUAL(ex.GetCode(), 3); BOOST_CHECK_EQUAL(ex.GetData().asString(), "0x82b42900"); BOOST_CHECK_EQUAL(ex.GetMessage(), "EVM revert instruction without description message"); } From 5bfa5d510f33eb53c051fe28109dad332017f81c Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Tue, 27 Aug 2024 16:54:46 +0100 Subject: [PATCH 40/61] Update VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 419f30096..4f6817bc5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.19.0 +3.19.1 From 86ea5fda919f2d2212e3e82ed424940c3b4f7e2d Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 10 Sep 2024 11:41:28 +0100 Subject: [PATCH 41/61] #1980 fix mismatched v --- libweb3jsonrpc/JsonHelper.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libweb3jsonrpc/JsonHelper.cpp b/libweb3jsonrpc/JsonHelper.cpp index c459e246f..8f3b78ac6 100644 --- a/libweb3jsonrpc/JsonHelper.cpp +++ b/libweb3jsonrpc/JsonHelper.cpp @@ -101,8 +101,8 @@ Json::Value toJson( dev::eth::Transaction const& _t, std::pair< h256, unsigned > res["blockHash"] = toJS( _location.first ); res["transactionIndex"] = toJS( _location.second ); res["blockNumber"] = toJS( _blockNumber ); - res["v"] = _t.isReplayProtected() ? toJS( 2 * _t.chainId() + 35 + _t.signature().v ) : - toJS( 27 + _t.signature().v ); + res["v"] = _t.txType() != dev::eth::TransactionType::Legacy ? toJS( _t.signature().v ) : + toJS( 37 + _t.signature().v ); res["r"] = toJS( _t.signature().r ); res["s"] = toJS( _t.signature().s ); res["type"] = toJS( int( _t.txType() ) ); @@ -400,8 +400,8 @@ Json::Value toJson( dev::eth::LocalisedTransaction const& _t ) { res["to"] = _t.isCreation() ? Json::Value() : toJS( _t.receiveAddress() ); res["transactionIndex"] = toJS( _t.transactionIndex() ); res["value"] = toJS( _t.value() ); - res["v"] = _t.isReplayProtected() ? toJS( 2 * _t.chainId() + 35 + _t.signature().v ) : - toJS( 27 + _t.signature().v ); + res["v"] = _t.txType() != dev::eth::TransactionType::Legacy ? toJS( _t.signature().v ) : + toJS( 37 + _t.signature().v ); res["r"] = toJS( _t.signature().r.hex() ); res["s"] = toJS( _t.signature().s.hex() ); res["type"] = toJS( int( _t.txType() ) ); From 9513c4a1eb65d3b72d7df1e7d2e3d44066725f49 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 10 Sep 2024 11:55:08 +0100 Subject: [PATCH 42/61] #1980 fix unittests --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index ac047af96..496c97165 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -3064,7 +3064,7 @@ BOOST_AUTO_TEST_CASE( eip2930Transactions ) { BOOST_REQUIRE( block["transactions"].size() == 1 ); BOOST_REQUIRE( block["transactions"][0]["hash"].asString() == txHash ); BOOST_REQUIRE( block["transactions"][0]["type"] == "0x1" ); - BOOST_REQUIRE( toJS( jsToInt( block["transactions"][0]["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == block["transactions"][0]["v"].asString() ); + BOOST_REQUIRE( block["transactions"][0]["yParity"].asString() == block["transactions"][0]["v"].asString() ); BOOST_REQUIRE( block["transactions"][0]["accessList"].isArray() ); BOOST_REQUIRE( block["transactions"][0]["accessList"].size() == 0 ); BOOST_REQUIRE( block["transactions"][0].isMember( "chainId" ) ); @@ -3081,20 +3081,20 @@ BOOST_AUTO_TEST_CASE( eip2930Transactions ) { result = fixture.rpcClient->eth_getTransactionByHash( txHash ); BOOST_REQUIRE( result["hash"].asString() == txHash ); BOOST_REQUIRE( result["type"] == "0x1" ); - BOOST_REQUIRE( toJS( jsToInt( result["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == result["v"].asString() ); + BOOST_REQUIRE( result["yParity"].asString() == result["v"].asString() ); BOOST_REQUIRE( result["accessList"].isArray() ); BOOST_REQUIRE( result["accessList"].size() == 0 ); result = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex( blockHash, "0x0" ); BOOST_REQUIRE( result["hash"].asString() == txHash ); BOOST_REQUIRE( result["type"] == "0x1" ); - BOOST_REQUIRE( toJS( jsToInt( result["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == result["v"].asString() ); + BOOST_REQUIRE( result["yParity"].asString() == result["v"].asString() ); BOOST_REQUIRE( result["accessList"].isArray() ); result = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex( "0x4", "0x0" ); BOOST_REQUIRE( result["hash"].asString() == txHash ); BOOST_REQUIRE( result["type"] == "0x1" ); - BOOST_REQUIRE( toJS( jsToInt( result["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == result["v"].asString() ); + BOOST_REQUIRE( result["yParity"].asString() == result["v"].asString() ); BOOST_REQUIRE( result["accessList"].isArray() ); BOOST_REQUIRE( result["accessList"].size() == 0 ); @@ -3202,7 +3202,6 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) { // compare with txn hash from geth BOOST_REQUIRE( txHash == "0x7bd586e93e3012577de4ba33e3b887baf520cbb92c5dd10996b262f9c5c8f747" ); - std::cout << dev::toHexPrefixed( fixture.client->transactions( 4 )[0].toBytes() ) << '\n'; BOOST_REQUIRE( dev::toHexPrefixed( fixture.client->transactions( 4 )[0].toBytes() ) == "0x02f8c98197808504a817c8008504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b0180f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000780a0f1a407dfc1a9f782001d89f617e9b3a2f295378533784fb39960dea60beea2d0a05ac3da2946554ba3d5721850f4f89ee7a0c38e4acab7130908e7904d13174388" ); BOOST_REQUIRE( fixture.rpcClient->eth_getBalance( "0x7D36aF85A184E220A656525fcBb9A63B9ab3C12b", "latest" ) == "0x1" ); @@ -3216,7 +3215,7 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) { BOOST_REQUIRE( block["transactions"].size() == 1 ); BOOST_REQUIRE( block["transactions"][0]["hash"].asString() == txHash ); BOOST_REQUIRE( block["transactions"][0]["type"] == "0x2" ); - BOOST_REQUIRE( toJS( jsToInt( block["transactions"][0]["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == block["transactions"][0]["v"].asString() ); + BOOST_REQUIRE( block["transactions"][0]["yParity"].asString() == block["transactions"][0]["v"].asString() ); BOOST_REQUIRE( block["transactions"][0]["accessList"].isArray() ); BOOST_REQUIRE( block["transactions"][0].isMember( "chainId" ) ); BOOST_REQUIRE( block["transactions"][0]["chainId"].asString() == chainID ); @@ -3231,7 +3230,7 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) { result = fixture.rpcClient->eth_getTransactionByHash( txHash ); BOOST_REQUIRE( result["hash"].asString() == txHash ); BOOST_REQUIRE( result["type"] == "0x2" ); - BOOST_REQUIRE( toJS( jsToInt( result["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == result["v"].asString() ); + BOOST_REQUIRE( result["yParity"].asString() == result["v"].asString() ); BOOST_REQUIRE( result["accessList"].isArray() ); BOOST_REQUIRE( result.isMember( "maxPriorityFeePerGas" ) && result["maxPriorityFeePerGas"].isString() ); BOOST_REQUIRE( result.isMember( "maxFeePerGas" ) && result["maxFeePerGas"].isString() ); @@ -3239,7 +3238,7 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) { result = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex( blockHash, "0x0" ); BOOST_REQUIRE( result["hash"].asString() == txHash ); BOOST_REQUIRE( result["type"] == "0x2" ); - BOOST_REQUIRE( toJS( jsToInt( result["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == result["v"].asString() ); + BOOST_REQUIRE( result["yParity"].asString() == result["v"].asString() ); BOOST_REQUIRE( result["accessList"].isArray() ); BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c800" ); BOOST_REQUIRE( result["maxFeePerGas"] == "0x4a817c800" ); @@ -3247,7 +3246,7 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) { result = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex( "0x4", "0x0" ); BOOST_REQUIRE( result["hash"].asString() == txHash ); BOOST_REQUIRE( result["type"] == "0x2" ); - BOOST_REQUIRE( toJS( jsToInt( result["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == result["v"].asString() ); + BOOST_REQUIRE( result["yParity"].asString() == result["v"].asString() ); BOOST_REQUIRE( result["accessList"].isArray() ); BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c800" ); BOOST_REQUIRE( result["maxFeePerGas"] == "0x4a817c800" ); From 7332faf21b26c849aa6040abb688a3e907da29af Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Tue, 10 Sep 2024 11:12:50 +0000 Subject: [PATCH 43/61] #1976 Add chainId in envInfo --- libethereum/ClientBase.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libethereum/ClientBase.cpp b/libethereum/ClientBase.cpp index 04b4302a8..200fb295f 100644 --- a/libethereum/ClientBase.cpp +++ b/libethereum/ClientBase.cpp @@ -92,8 +92,8 @@ std::pair< bool, ExecutionResult > ClientBase::estimateGasStep( int64_t _gas, Bl t.forceChainId( chainId() ); t.ignoreExternalGas(); EnvInfo const env( _pendingBlock.info(), bc().lastBlockHashes(), - _pendingBlock.previousInfo().timestamp(), 0, _gas ); - // Make a copy of state!! It will be deleted after step! + _pendingBlock.previousInfo().timestamp(), 0, _gas, bc().chainParams().chainID ); + // Make a copy of the state, it will be deleted after this step State tempState = _latestBlock.mutableState(); tempState.addBalance( _from, ( u256 )( t.gas() * t.gasPrice() + t.value() ) ); ExecutionResult executionResult = From 1263fb2614726f770289aad134ecbdabf2971414 Mon Sep 17 00:00:00 2001 From: DmytroNazarenko Date: Tue, 10 Sep 2024 14:31:29 +0000 Subject: [PATCH 44/61] #1976 Add unit test --- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index ac047af96..da770c5ce 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -1483,6 +1483,40 @@ BOOST_AUTO_TEST_CASE( eth_estimateGas ) { BOOST_CHECK_EQUAL( response3, "0x1db20" ); } +BOOST_AUTO_TEST_CASE( eth_estimateGas_chainId ) { + std::string _config = c_genesisConfigString; + Json::Value ret; + Json::Reader().parse( _config, ret ); + + // Set chainID = 65535 + ret["params"]["chainID"] = "0xffff"; + + Json::FastWriter fastWriter; + std::string config = fastWriter.write( ret ); + JsonRpcFixture fixture( config ); + + // pragma solidity ^0.8.13; + + // contract Counter { + // error BlockNumber(uint256 blockNumber); + + // constructor() { + // revert BlockNumber(block.chainid); + // } + // } + + Json::Value testRevert; + testRevert["data"] = "0x6080604052348015600f57600080fd5b50604051633013bad360e21b815246600482015260240160405180910390fdfe"; + + try { + fixture.rpcClient->eth_estimateGas( testRevert, "latest" ); + } catch ( jsonrpc::JsonRpcException& ex) { + BOOST_CHECK_EQUAL(ex.GetCode(), 3); + BOOST_CHECK_EQUAL(ex.GetData().asString(), "0xc04eeb4c000000000000000000000000000000000000000000000000000000000000ffff"); + BOOST_CHECK_EQUAL(ex.GetMessage(), "EVM revert instruction without description message"); + } +} + BOOST_AUTO_TEST_CASE( eth_sendRawTransaction_gasLimitExceeded ) { JsonRpcFixture fixture; auto senderAddress = fixture.coinbase.address(); From 48055a72bab7270e4fbb76e2131e578e4b913bcb Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 10 Sep 2024 16:24:55 +0100 Subject: [PATCH 45/61] #1963 fix max fee per gas in json rpc representation --- libweb3jsonrpc/JsonHelper.cpp | 6 +++--- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libweb3jsonrpc/JsonHelper.cpp b/libweb3jsonrpc/JsonHelper.cpp index c459e246f..c81193ab8 100644 --- a/libweb3jsonrpc/JsonHelper.cpp +++ b/libweb3jsonrpc/JsonHelper.cpp @@ -120,7 +120,7 @@ Json::Value toJson( dev::eth::Transaction const& _t, std::pair< h256, unsigned > } res["accessList"].append( accessList ); } - if ( _t.txType() != dev::eth::TransactionType::Type1 ) { + if ( _t.txType() == dev::eth::TransactionType::Type2 ) { res["maxPriorityFeePerGas"] = toJS( _t.maxPriorityFeePerGas() ); res["maxFeePerGas"] = toJS( _t.maxFeePerGas() ); } @@ -366,7 +366,7 @@ Json::Value toJson( dev::eth::Transaction const& _t ) { } res["accessList"].append( accessList ); } - if ( _t.txType() != dev::eth::TransactionType::Type1 ) { + if ( _t.txType() == dev::eth::TransactionType::Type2 ) { res["maxPriorityFeePerGas"] = toJS( _t.maxPriorityFeePerGas() ); res["maxFeePerGas"] = toJS( _t.maxFeePerGas() ); } @@ -421,7 +421,7 @@ Json::Value toJson( dev::eth::LocalisedTransaction const& _t ) { } if ( _t.txType() != dev::eth::TransactionType::Type1 ) { res["maxPriorityFeePerGas"] = toJS( _t.maxPriorityFeePerGas() ); - res["maxFeePerGas"] = toJS( _t.maxPriorityFeePerGas() ); + res["maxFeePerGas"] = toJS( _t.maxFeePerGas() ); } } } diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index ac047af96..d872b02b8 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -3192,7 +3192,7 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) { // send 1 WEI from 0x5EdF1e852fdD1B0Bc47C0307EF755C76f4B9c251 to 0x7D36aF85A184E220A656525fcBb9A63B9ab3C12b // encoded type 2 txn - txHash = fixture.rpcClient->eth_sendRawTransaction( "0x02f8c98197808504a817c8008504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b0180f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000780a0f1a407dfc1a9f782001d89f617e9b3a2f295378533784fb39960dea60beea2d0a05ac3da2946554ba3d5721850f4f89ee7a0c38e4acab7130908e7904d13174388" ); + txHash = fixture.rpcClient->eth_sendRawTransaction( "0x02f8c98197808504a817c8018504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b0180f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000701a005bd1eedc509a8e94cfcfc84d0b5fd53a0888a475274cbeee321047da5d139f8a00e7f0dd8b5277766d447ea51b7d8f571dc8bb57ff95c068c58f5b6fe9089dde8" ); auto pendingTransactions = fixture.rpcClient->eth_pendingTransactions(); BOOST_REQUIRE( pendingTransactions.isArray() && pendingTransactions.size() == 1); BOOST_REQUIRE( pendingTransactions[0]["type"] == "0x2" ); @@ -3201,9 +3201,8 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) { dev::eth::mineTransaction( *( fixture.client ), 1 ); // compare with txn hash from geth - BOOST_REQUIRE( txHash == "0x7bd586e93e3012577de4ba33e3b887baf520cbb92c5dd10996b262f9c5c8f747" ); - std::cout << dev::toHexPrefixed( fixture.client->transactions( 4 )[0].toBytes() ) << '\n'; - BOOST_REQUIRE( dev::toHexPrefixed( fixture.client->transactions( 4 )[0].toBytes() ) == "0x02f8c98197808504a817c8008504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b0180f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000780a0f1a407dfc1a9f782001d89f617e9b3a2f295378533784fb39960dea60beea2d0a05ac3da2946554ba3d5721850f4f89ee7a0c38e4acab7130908e7904d13174388" ); + BOOST_REQUIRE( txHash == "0xde30b1c26b89e20f6426a87b9427381f9e79e2bb80f992a6f2e1b4dccfa345de" ); + BOOST_REQUIRE( dev::toHexPrefixed( fixture.client->transactions( 4 )[0].toBytes() ) == "0x02f8c98197808504a817c8018504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b0180f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000701a005bd1eedc509a8e94cfcfc84d0b5fd53a0888a475274cbeee321047da5d139f8a00e7f0dd8b5277766d447ea51b7d8f571dc8bb57ff95c068c58f5b6fe9089dde8" ); BOOST_REQUIRE( fixture.rpcClient->eth_getBalance( "0x7D36aF85A184E220A656525fcBb9A63B9ab3C12b", "latest" ) == "0x1" ); @@ -3235,13 +3234,15 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) { BOOST_REQUIRE( result["accessList"].isArray() ); BOOST_REQUIRE( result.isMember( "maxPriorityFeePerGas" ) && result["maxPriorityFeePerGas"].isString() ); BOOST_REQUIRE( result.isMember( "maxFeePerGas" ) && result["maxFeePerGas"].isString() ); + BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c801" ); + BOOST_REQUIRE( result["maxFeePerGas"] == "0x4a817c800" ); result = fixture.rpcClient->eth_getTransactionByBlockHashAndIndex( blockHash, "0x0" ); BOOST_REQUIRE( result["hash"].asString() == txHash ); BOOST_REQUIRE( result["type"] == "0x2" ); BOOST_REQUIRE( toJS( jsToInt( result["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == result["v"].asString() ); BOOST_REQUIRE( result["accessList"].isArray() ); - BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c800" ); + BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c801" ); BOOST_REQUIRE( result["maxFeePerGas"] == "0x4a817c800" ); result = fixture.rpcClient->eth_getTransactionByBlockNumberAndIndex( "0x4", "0x0" ); @@ -3249,7 +3250,7 @@ BOOST_AUTO_TEST_CASE( eip1559Transactions ) { BOOST_REQUIRE( result["type"] == "0x2" ); BOOST_REQUIRE( toJS( jsToInt( result["yParity"].asString() ) + 35 + 2 * fixture.client->chainParams().chainID ) == result["v"].asString() ); BOOST_REQUIRE( result["accessList"].isArray() ); - BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c800" ); + BOOST_REQUIRE( result["maxPriorityFeePerGas"] == "0x4a817c801" ); BOOST_REQUIRE( result["maxFeePerGas"] == "0x4a817c800" ); BOOST_REQUIRE_NO_THROW( fixture.rpcClient->eth_getBlockByNumber( "0x0", false ) ); From 86af74d1d020810da7aef512658a70487c2cb662 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 10 Sep 2024 16:36:08 +0100 Subject: [PATCH 46/61] #1980 format --- libweb3jsonrpc/JsonHelper.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libweb3jsonrpc/JsonHelper.cpp b/libweb3jsonrpc/JsonHelper.cpp index 8f3b78ac6..6fe5af66d 100644 --- a/libweb3jsonrpc/JsonHelper.cpp +++ b/libweb3jsonrpc/JsonHelper.cpp @@ -101,8 +101,9 @@ Json::Value toJson( dev::eth::Transaction const& _t, std::pair< h256, unsigned > res["blockHash"] = toJS( _location.first ); res["transactionIndex"] = toJS( _location.second ); res["blockNumber"] = toJS( _blockNumber ); - res["v"] = _t.txType() != dev::eth::TransactionType::Legacy ? toJS( _t.signature().v ) : - toJS( 37 + _t.signature().v ); + res["v"] = _t.txType() == dev::eth::TransactionType::Legacy ? + toJS( 37 + _t.signature().v ) : + toJS( _t.signature().v ); res["r"] = toJS( _t.signature().r ); res["s"] = toJS( _t.signature().s ); res["type"] = toJS( int( _t.txType() ) ); @@ -350,7 +351,9 @@ Json::Value toJson( dev::eth::Transaction const& _t ) { res["nonce"] = toJS( _t.nonce() ); res["r"] = toJS( _t.signature().r ); res["s"] = toJS( _t.signature().s ); - res["v"] = toJS( _t.signature().v ); + res["v"] = _t.txType() == dev::eth::TransactionType::Legacy ? + toJS( 37 + _t.signature().v ) : + toJS( _t.signature().v ); res["type"] = toJS( int( _t.txType() ) ); if ( _t.txType() != dev::eth::TransactionType::Legacy ) { res["chainId"] = toJS( _t.chainId() ); @@ -400,8 +403,9 @@ Json::Value toJson( dev::eth::LocalisedTransaction const& _t ) { res["to"] = _t.isCreation() ? Json::Value() : toJS( _t.receiveAddress() ); res["transactionIndex"] = toJS( _t.transactionIndex() ); res["value"] = toJS( _t.value() ); - res["v"] = _t.txType() != dev::eth::TransactionType::Legacy ? toJS( _t.signature().v ) : - toJS( 37 + _t.signature().v ); + res["v"] = _t.txType() == dev::eth::TransactionType::Legacy ? + toJS( 37 + _t.signature().v ) : + toJS( _t.signature().v ); res["r"] = toJS( _t.signature().r.hex() ); res["s"] = toJS( _t.signature().s.hex() ); res["type"] = toJS( int( _t.txType() ) ); From c71bff7705f6da91bf32326d71e8b1c22c380b64 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 11 Sep 2024 11:32:49 +0100 Subject: [PATCH 47/61] #1980 add tests --- libweb3jsonrpc/JsonHelper.cpp | 9 ++-- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 59 +++++++++++++++++++++++ 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/libweb3jsonrpc/JsonHelper.cpp b/libweb3jsonrpc/JsonHelper.cpp index 6fe5af66d..b46bf6f08 100644 --- a/libweb3jsonrpc/JsonHelper.cpp +++ b/libweb3jsonrpc/JsonHelper.cpp @@ -102,7 +102,8 @@ Json::Value toJson( dev::eth::Transaction const& _t, std::pair< h256, unsigned > res["transactionIndex"] = toJS( _location.second ); res["blockNumber"] = toJS( _blockNumber ); res["v"] = _t.txType() == dev::eth::TransactionType::Legacy ? - toJS( 37 + _t.signature().v ) : + ( _t.isReplayProtected() ? toJS( 2 * _t.chainId() + 35 + _t.signature().v ) : + toJS( 27 + _t.signature().v ) ) : toJS( _t.signature().v ); res["r"] = toJS( _t.signature().r ); res["s"] = toJS( _t.signature().s ); @@ -352,7 +353,8 @@ Json::Value toJson( dev::eth::Transaction const& _t ) { res["r"] = toJS( _t.signature().r ); res["s"] = toJS( _t.signature().s ); res["v"] = _t.txType() == dev::eth::TransactionType::Legacy ? - toJS( 37 + _t.signature().v ) : + ( _t.isReplayProtected() ? toJS( 2 * _t.chainId() + 35 + _t.signature().v ) : + toJS( 27 + _t.signature().v ) ) : toJS( _t.signature().v ); res["type"] = toJS( int( _t.txType() ) ); if ( _t.txType() != dev::eth::TransactionType::Legacy ) { @@ -404,7 +406,8 @@ Json::Value toJson( dev::eth::LocalisedTransaction const& _t ) { res["transactionIndex"] = toJS( _t.transactionIndex() ); res["value"] = toJS( _t.value() ); res["v"] = _t.txType() == dev::eth::TransactionType::Legacy ? - toJS( 37 + _t.signature().v ) : + ( _t.isReplayProtected() ? toJS( 2 * _t.chainId() + 35 + _t.signature().v ) : + toJS( 27 + _t.signature().v ) ) : toJS( _t.signature().v ); res["r"] = toJS( _t.signature().r.hex() ); res["s"] = toJS( _t.signature().s.hex() ); diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 496c97165..d7a9d0d62 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -3349,6 +3349,65 @@ BOOST_AUTO_TEST_CASE( eip1559RpcMethods ) { BOOST_REQUIRE_NO_THROW( fixture.rpcClient->eth_feeHistory( blockCnt, "latest", percentiles ) ); } +BOOST_AUTO_TEST_CASE( vInTxnSignature ) { + std::string _config = c_genesisConfigString; + Json::Value ret; + Json::Reader().parse( _config, ret ); + + // Set chainID = 151 + ret["params"]["chainID"] = "0x97"; + time_t eip1559PatchActivationTimestamp = time(nullptr); + ret["skaleConfig"]["sChain"]["EIP1559TransactionsPatchTimestamp"] = eip1559PatchActivationTimestamp; + + Json::FastWriter fastWriter; + std::string config = fastWriter.write( ret ); + JsonRpcFixture fixture( config ); + + dev::eth::simulateMining( *( fixture.client ), 20 ); + string senderAddress = toJS(fixture.coinbase.address()); + + Json::Value txRefill; + txRefill["to"] = "0x5EdF1e852fdD1B0Bc47C0307EF755C76f4B9c251"; + txRefill["from"] = senderAddress; + txRefill["gas"] = "100000"; + txRefill["gasPrice"] = fixture.rpcClient->eth_gasPrice(); + txRefill["value"] = 100000000000000000; + string txHash = fixture.rpcClient->eth_sendTransaction( txRefill ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + // send non replay protected txn + txHash = fixture.rpcClient->eth_sendRawTransaction( "0xf864808504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b01801ba0171c7f31feaa0fd7825a5a28d7b535d0b0ee200b27792f66eb7796e7a6a555d7a0081790244f21cefa563b55a7a68ee78f8466738b5827be19faaeff0586fd71be" ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + Json::Value txn = fixture.rpcClient->eth_getTransactionByHash( txHash ); + dev::u256 v = dev::jsToU256( txn["v"].asString() ); + BOOST_REQUIRE( v < 29 && v > 26 ); + + // send replay protected legacy txn + txHash = fixture.rpcClient->eth_sendRawTransaction( "0xf866018504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b0180820151a018b400fc56bc3568e4f23f6f93d538745a5b18054252d6030791c294c9aea9d4a00930492125784fad0a8b38b915e8621f54c53f0878a77f21920c751ec5fd220a" ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + txn = fixture.rpcClient->eth_getTransactionByHash( txHash ); + v = dev::jsToU256( txn["v"].asString() ); + BOOST_REQUIRE( v < 339 && v > 336 ); // 2 * 151 + 35 + + // send type1 txn + txHash = fixture.rpcClient->eth_sendRawTransaction( "0x01f8c38197028504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b0180f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000701a0ee608b7c5df843b4a1988a3e9c24d53019fa674e06a6b2ae0c347a00601c1a84a06ed451f9cc0f4334a180458605ecaa212e58f8436e1a4318e75ae417c72eba2b" ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + txn = fixture.rpcClient->eth_getTransactionByHash( txHash ); + v = dev::jsToU256( txn["v"].asString() ); + BOOST_REQUIRE( v < 2 && v >= 0 ); + + // send type2 txn + txHash = fixture.rpcClient->eth_sendRawTransaction( "0x02f8c98197038504a817c8018504a817c800827530947d36af85a184e220a656525fcbb9a63b9ab3c12b0180f85bf85994de0b295669a9fd93d5f28d9ec85e40f4cb697baef842a00000000000000000000000000000000000000000000000000000000000000003a0000000000000000000000000000000000000000000000000000000000000000701a0c16ec291a6f4e91476f39e624baf42730b21a805e570fe52334df13d69b63d3fa01c7e9662635512a3bc47d479b17af2df59491e6663823ca13789a86da6dff1a5" ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + txn = fixture.rpcClient->eth_getTransactionByHash( txHash ); + v = dev::jsToU256( txn["v"].asString() ); + BOOST_REQUIRE( v < 2 && v >= 0 ); +} + BOOST_AUTO_TEST_CASE( etherbase_generation2 ) { JsonRpcFixture fixture(c_genesisGeneration2ConfigString, false, false, true); string etherbase = fixture.rpcClient->eth_coinbase(); From 8ec6d48d1b689be4f28873dc477556dd3f9989db Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 11 Sep 2024 18:25:04 +0100 Subject: [PATCH 48/61] #1980 format --- libweb3jsonrpc/JsonHelper.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/libweb3jsonrpc/JsonHelper.cpp b/libweb3jsonrpc/JsonHelper.cpp index b46bf6f08..12fe1ef55 100644 --- a/libweb3jsonrpc/JsonHelper.cpp +++ b/libweb3jsonrpc/JsonHelper.cpp @@ -101,10 +101,13 @@ Json::Value toJson( dev::eth::Transaction const& _t, std::pair< h256, unsigned > res["blockHash"] = toJS( _location.first ); res["transactionIndex"] = toJS( _location.second ); res["blockNumber"] = toJS( _blockNumber ); - res["v"] = _t.txType() == dev::eth::TransactionType::Legacy ? - ( _t.isReplayProtected() ? toJS( 2 * _t.chainId() + 35 + _t.signature().v ) : - toJS( 27 + _t.signature().v ) ) : - toJS( _t.signature().v ); + if ( _t.txType() == dev::eth::TransactionType::Legacy ) + if ( _t.isReplayProtected() ) + res["v"] = toJS( 2 * _t.chainId() + 35 + _t.signature().v ); + else + res["v"] = toJS( 27 + _t.signature().v ); + else + res["v"] = toJS( _t.signature().v ); res["r"] = toJS( _t.signature().r ); res["s"] = toJS( _t.signature().s ); res["type"] = toJS( int( _t.txType() ) ); @@ -352,10 +355,13 @@ Json::Value toJson( dev::eth::Transaction const& _t ) { res["nonce"] = toJS( _t.nonce() ); res["r"] = toJS( _t.signature().r ); res["s"] = toJS( _t.signature().s ); - res["v"] = _t.txType() == dev::eth::TransactionType::Legacy ? - ( _t.isReplayProtected() ? toJS( 2 * _t.chainId() + 35 + _t.signature().v ) : - toJS( 27 + _t.signature().v ) ) : - toJS( _t.signature().v ); + if ( _t.txType() == dev::eth::TransactionType::Legacy ) + if ( _t.isReplayProtected() ) + res["v"] = toJS( 2 * _t.chainId() + 35 + _t.signature().v ); + else + res["v"] = toJS( 27 + _t.signature().v ); + else + res["v"] = toJS( _t.signature().v ); res["type"] = toJS( int( _t.txType() ) ); if ( _t.txType() != dev::eth::TransactionType::Legacy ) { res["chainId"] = toJS( _t.chainId() ); @@ -405,10 +411,13 @@ Json::Value toJson( dev::eth::LocalisedTransaction const& _t ) { res["to"] = _t.isCreation() ? Json::Value() : toJS( _t.receiveAddress() ); res["transactionIndex"] = toJS( _t.transactionIndex() ); res["value"] = toJS( _t.value() ); - res["v"] = _t.txType() == dev::eth::TransactionType::Legacy ? - ( _t.isReplayProtected() ? toJS( 2 * _t.chainId() + 35 + _t.signature().v ) : - toJS( 27 + _t.signature().v ) ) : - toJS( _t.signature().v ); + if ( _t.txType() == dev::eth::TransactionType::Legacy ) + if ( _t.isReplayProtected() ) + res["v"] = toJS( 2 * _t.chainId() + 35 + _t.signature().v ); + else + res["v"] = toJS( 27 + _t.signature().v ); + else + res["v"] = toJS( _t.signature().v ); res["r"] = toJS( _t.signature().r.hex() ); res["s"] = toJS( _t.signature().s.hex() ); res["type"] = toJS( int( _t.txType() ) ); From 219192df9980103c029e85a7193d21784ae53e24 Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Thu, 12 Sep 2024 12:35:39 +0100 Subject: [PATCH 49/61] Update functional-tests.yml --- .github/workflows/functional-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/functional-tests.yml b/.github/workflows/functional-tests.yml index f7356fc36..027486dec 100644 --- a/.github/workflows/functional-tests.yml +++ b/.github/workflows/functional-tests.yml @@ -83,7 +83,7 @@ for C in $(docker ps -aq); do docker logs $C>$C.log; done || true if: ${{ always() }} - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v4 if: ${{ always() }} continue-on-error: true with: From 603c15ab8677d212bef9512aa3e5c0c7736c71e4 Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Thu, 12 Sep 2024 17:58:58 +0100 Subject: [PATCH 50/61] Update setup-build-publish.yml --- .github/workflows/setup-build-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/setup-build-publish.yml b/.github/workflows/setup-build-publish.yml index d1b15117f..0b3bf1b0a 100644 --- a/.github/workflows/setup-build-publish.yml +++ b/.github/workflows/setup-build-publish.yml @@ -161,7 +161,7 @@ jobs: bash ./scripts/build_and_publish.sh - name: Upload skaled binary as artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 if: ${{ always() }} with: name: skaled-${{ inputs.node_type }} From 481504391ce62d921329ccb027c58549cc3ee324 Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Fri, 13 Sep 2024 19:28:37 +0100 Subject: [PATCH 51/61] Update VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 4f6817bc5..a8346d5d1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.19.1 +3.19.2 From 44dafae8ca06f461d0e8d614cebf15054ddc1fd1 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Thu, 19 Sep 2024 16:42:57 +0100 Subject: [PATCH 52/61] IS 1074 fix externalGas calculation --- libethereum/Transaction.cpp | 9 ++++++- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 31 ++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index d2c7f9962..f91b39707 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -200,7 +200,14 @@ void Transaction::checkOutExternalGas( const ChainParams& _cp, time_t _committed u256 const& difficulty = _cp.externalGasDifficulty; assert( difficulty > 0 ); if ( ( _force || !m_externalGasIsChecked ) && !isInvalid() ) { - h256 hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( gasPrice() ); + // reset externalGas value + // we may face patch activation after txn was added to the queue but before it was executed + // therefore we need to recalculate externalGas + if ( m_externalGasIsChecked && hasExternalGas() ) + m_externalGas = 0; + + h256 hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ + dev::sha3( TransactionBase::gasPrice() ); if ( !hash ) { hash = h256( 1 ); } diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 09e05dced..570e31393 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -1987,6 +1987,35 @@ BOOST_AUTO_TEST_CASE( simplePoWTransaction ) { BOOST_REQUIRE_EQUAL(receipt["status"], "0x1"); } +BOOST_AUTO_TEST_CASE( recalculateExternalGas ) { + std::string _config = c_genesisConfigString; + Json::Value ret; + Json::Reader().parse( _config, ret ); + + // Set chainID = 2192608523748315 + std::string chainID = "0x7ca2a743083db"; + ret["params"]["chainID"] = chainID; + time_t eip1559PatchActivationTimestamp = time(nullptr); + ret["skaleConfig"]["sChain"]["EIP1559TransactionsPatchTimestamp"] = eip1559PatchActivationTimestamp; + + Json::FastWriter fastWriter; + std::string config = fastWriter.write( ret ); + JsonRpcFixture fixture( config ); + dev::eth::simulateMining( *( fixture.client ), 20 ); + + fixture.rpcClient->eth_sendRawTransaction( "0x02f8ae8707ca2a743083db8080a0d7d2692231d351eab7d73269effb12393260eb38d11e81085a995dbfffeb4d4b830103ae9403f7c171a32e275c712fe6f32612ad21b485728180a40c11dedd000000000000000000000000229a61f480631a331ffde0dff312d06c087f818dc001a084bb73dbd78dbb45040982a5425c110ff217acb6b04d2e5366c0b75fbdadd450a001fef7f8c83e7472e51fae99dda30e7d0318d5a78487121a69642ca77763c02d" ); + + auto pendingTransactions = fixture.rpcClient->eth_pendingTransactions(); + BOOST_REQUIRE( pendingTransactions.size() == 1 ); + + auto t = fixture.client->pending().front(); + + BOOST_REQUIRE( t.hasExternalGas() ); + BOOST_REQUIRE( t.getExternalGas() == 92966 ); + t.checkOutExternalGas( fixture.chainParams, 1, 0, true ); + BOOST_REQUIRE( t.getExternalGas() == 92966 ); +} + BOOST_AUTO_TEST_CASE( transactionWithoutFunds ) { JsonRpcFixture fixture; dev::eth::simulateMining( *( fixture.client ), 1 ); @@ -2924,7 +2953,7 @@ BOOST_AUTO_TEST_CASE( powTxnGasLimit ) { txPOW2["gasPrice"] = "0xc5002ab03e1e7e196b3d0ffa9801e783fcd48d4c6d972f1389ab63f4e2d0bef0"; // gas 1m txPOW2["value"] = 100; BOOST_REQUIRE_THROW( fixture.rpcClient->eth_sendTransaction( txPOW2 ), jsonrpc::JsonRpcException ); // block gas limit reached - } +} BOOST_AUTO_TEST_CASE( EIP1898Calls ) { JsonRpcFixture fixture; From b28639aba2a08ff487f7c07c106605f72eb96da3 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 23 Sep 2024 17:56:58 +0100 Subject: [PATCH 53/61] IS 1074 add patch] --- libethereum/SchainPatch.cpp | 4 + libethereum/SchainPatch.h | 5 + libethereum/SchainPatchEnum.h | 1 + libethereum/Transaction.cpp | 20 ++-- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 126 +++++++++++++++++++--- 5 files changed, 135 insertions(+), 21 deletions(-) diff --git a/libethereum/SchainPatch.cpp b/libethereum/SchainPatch.cpp index f3a5f8daa..fde678f6c 100644 --- a/libethereum/SchainPatch.cpp +++ b/libethereum/SchainPatch.cpp @@ -36,6 +36,8 @@ SchainPatchEnum getEnumForPatchName( const std::string& _patchName ) { return SchainPatchEnum::VerifyBlsSyncPatch; else if ( _patchName == "FlexibleDeploymentPatch" ) return SchainPatchEnum::FlexibleDeploymentPatch; + else if ( _patchName == "ExternalGasPatch" ) + return SchainPatchEnum::ExternalGasPatch; else throw std::out_of_range( _patchName ); } @@ -72,6 +74,8 @@ std::string getPatchNameForEnum( SchainPatchEnum _enumValue ) { return "VerifyBlsSyncPatch"; case SchainPatchEnum::FlexibleDeploymentPatch: return "FlexibleDeploymentPatch"; + case SchainPatchEnum::ExternalGasPatch: + return "ExternalGasPatch"; default: throw std::out_of_range( "UnknownPatch #" + std::to_string( static_cast< size_t >( _enumValue ) ) ); diff --git a/libethereum/SchainPatch.h b/libethereum/SchainPatch.h index 9af149fb9..75f2c878f 100644 --- a/libethereum/SchainPatch.h +++ b/libethereum/SchainPatch.h @@ -146,4 +146,9 @@ DEFINE_AMNESIC_PATCH( VerifyBlsSyncPatch ); */ DEFINE_SIMPLE_PATCH( FlexibleDeploymentPatch ); +/* + * Context: fix externalGas calculation + */ +DEFINE_SIMPLE_PATCH( ExternalGasPatch ); + #endif // SCHAINPATCH_H diff --git a/libethereum/SchainPatchEnum.h b/libethereum/SchainPatchEnum.h index ac0b1c19a..69f023143 100644 --- a/libethereum/SchainPatchEnum.h +++ b/libethereum/SchainPatchEnum.h @@ -20,6 +20,7 @@ enum class SchainPatchEnum { EIP1559TransactionsPatch, VerifyBlsSyncPatch, FlexibleDeploymentPatch, + ExternalGasPatch, PatchesCount }; diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index f91b39707..6bb925e64 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -200,14 +200,18 @@ void Transaction::checkOutExternalGas( const ChainParams& _cp, time_t _committed u256 const& difficulty = _cp.externalGasDifficulty; assert( difficulty > 0 ); if ( ( _force || !m_externalGasIsChecked ) && !isInvalid() ) { - // reset externalGas value - // we may face patch activation after txn was added to the queue but before it was executed - // therefore we need to recalculate externalGas - if ( m_externalGasIsChecked && hasExternalGas() ) - m_externalGas = 0; - - h256 hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ - dev::sha3( TransactionBase::gasPrice() ); + h256 hash; + if ( !ExternalGasPatch::isEnabledWhen( _committedBlockTimestamp ) ) { + hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( gasPrice() ); + } else { + // reset externalGas value + // we may face patch activation after txn was added to the queue but before it was + // executed therefore we need to recalculate externalGas + if ( m_externalGasIsChecked && hasExternalGas() ) + m_externalGas.reset(); + hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ + dev::sha3( TransactionBase::gasPrice() ); + } if ( !hash ) { hash = h256( 1 ); } diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 570e31393..1a15b3405 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -1992,28 +1992,128 @@ BOOST_AUTO_TEST_CASE( recalculateExternalGas ) { Json::Value ret; Json::Reader().parse( _config, ret ); - // Set chainID = 2192608523748315 - std::string chainID = "0x7ca2a743083db"; + // Set chainID = 21 + std::string chainID = "0x15"; ret["params"]["chainID"] = chainID; - time_t eip1559PatchActivationTimestamp = time(nullptr); - ret["skaleConfig"]["sChain"]["EIP1559TransactionsPatchTimestamp"] = eip1559PatchActivationTimestamp; + + // remove deployment control + auto accounts = ret["accounts"]; + accounts.removeMember( "0xD2002000000000000000000000000000000000D2" ); + ret["accounts"] = accounts; + + // setup patch + time_t externalGasPatchActivationTimestamp = time(nullptr) + 10; + ret["skaleConfig"]["sChain"]["ExternalGasPatchTimestamp"] = externalGasPatchActivationTimestamp; Json::FastWriter fastWriter; std::string config = fastWriter.write( ret ); - JsonRpcFixture fixture( config ); + JsonRpcFixture fixture( config, true, false ); dev::eth::simulateMining( *( fixture.client ), 20 ); - fixture.rpcClient->eth_sendRawTransaction( "0x02f8ae8707ca2a743083db8080a0d7d2692231d351eab7d73269effb12393260eb38d11e81085a995dbfffeb4d4b830103ae9403f7c171a32e275c712fe6f32612ad21b485728180a40c11dedd000000000000000000000000229a61f480631a331ffde0dff312d06c087f818dc001a084bb73dbd78dbb45040982a5425c110ff217acb6b04d2e5366c0b75fbdadd450a001fef7f8c83e7472e51fae99dda30e7d0318d5a78487121a69642ca77763c02d" ); + auto senderAddress = fixture.coinbase.address().hex(); - auto pendingTransactions = fixture.rpcClient->eth_pendingTransactions(); - BOOST_REQUIRE( pendingTransactions.size() == 1 ); +// // SPDX-License-Identifier: GPL-3.0 + +// pragma solidity >=0.8.2 <0.9.0; + +// /** +// * @title Storage +// * @dev Store & retrieve value in a variable +// * @custom:dev-run-script ./scripts/deploy_with_ethers.ts +// */ +// contract Storage { + +// uint256 number; +// uint256 number1; +// uint256 number2; + +// /** +// * @dev Store value in variable +// * @param num value to store +// */ +// function store(uint256 num) public { +// number = num; +// number1 = num; +// number2 = num; +// } + +// /** +// * @dev Return value +// * @return value of 'number' +// */ +// function retrieve() public view returns (uint256){ +// return number; +// } +// } + std::string bytecode = "608060405234801561001057600080fd5b5061015e806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80632e64cec11461003b5780636057361d14610059575b600080fd5b610043610075565b60405161005091906100e7565b60405180910390f35b610073600480360381019061006e91906100ab565b61007e565b005b60008054905090565b80600081905550806001819055508060028190555050565b6000813590506100a581610111565b92915050565b6000602082840312156100c1576100c061010c565b5b60006100cf84828501610096565b91505092915050565b6100e181610102565b82525050565b60006020820190506100fc60008301846100d8565b92915050565b6000819050919050565b600080fd5b61011a81610102565b811461012557600080fd5b5056fea2646970667358221220780703bb6ac2eec922a510d57edcae39b852b578e7f63a263ddb936758dc9c4264736f6c63430008070033"; + + // deploy contact + Json::Value create; + create["from"] = senderAddress; + create["code"] = bytecode; + create["gasPrice"] = fixture.rpcClient->eth_gasPrice(); + create["gas"] = 140000; + create["nonce"] = 0; + + std::string txHash = fixture.rpcClient->eth_sendTransaction( create ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + BOOST_REQUIRE( receipt["status"].asString() == "0x1" ); + std::string contractAddress = receipt["contractAddress"].asString(); + + // send txn to a contract from the suspicious account + // store( 4 ) + Json::Value txn; + txn["from"] = "0x40797bb29d12FC0dFD04277D16a3Dd4FAc3a6e5B"; + txn["data"] = "0x6057361d0000000000000000000000000000000000000000000000000000000000000004"; + txn["gasPrice"] = "0xdffe55527a88d3775c23ecd3ae38ff1e90caf12b5beb4f7ea3ad998a990a895c"; + txn["gas"] = 140000; + txn["chainId"] = "0x15"; + txn["nonce"] = 0; + txn["to"] = contractAddress; + + auto ts = toTransactionSkeleton( txn ); + auto t = dev::eth::Transaction( ts, dev::Secret( "7be24de049f2d0d4ecaeaa81564aecf647fa7a4c86264243d77e01da25d859a0" ) ); + + txHash = fixture.rpcClient->eth_sendRawTransaction( dev::toHex( t.toBytes() ) ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + + BOOST_REQUIRE( receipt["status"].asString() == "0x0" ); + BOOST_REQUIRE( receipt["gasUsed"].asString() == "0x61cb" ); + + sleep(10); + + // push new block to update timestamp + Json::Value refill; + refill["from"] = senderAddress; + refill["to"] = dev::Address::random().hex(); + refill["gasPrice"] = fixture.rpcClient->eth_gasPrice(); + refill["value"] = 100; + refill["nonce"] = 1; + + txHash = fixture.rpcClient->eth_sendTransaction( refill ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + // send txn to a contract from another suspicious account + // store( 4 ) + txn["from"] = "0x5cdb7527ec85022991D4e27F254C438E8337ad7E"; + txn["data"] = "0x6057361d0000000000000000000000000000000000000000000000000000000000000004"; + txn["gasPrice"] = "0x974749a06d5cd0dba6a4e1f3d14d5f480db716dcbc9a34ec5496b8d86e99f898"; + txn["gas"] = 140000; + txn["chainId"] = "0x15"; + txn["nonce"] = 0; + txn["to"] = contractAddress; + + ts = toTransactionSkeleton( txn ); + t = dev::eth::Transaction( ts, dev::Secret( "8df08814fcfc169aad0015654114be06c28b27bdcdef286cf4dbd5e2950a3ffc" ) ); - auto t = fixture.client->pending().front(); + txHash = fixture.rpcClient->eth_sendRawTransaction( dev::toHex( t.toBytes() ) ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); - BOOST_REQUIRE( t.hasExternalGas() ); - BOOST_REQUIRE( t.getExternalGas() == 92966 ); - t.checkOutExternalGas( fixture.chainParams, 1, 0, true ); - BOOST_REQUIRE( t.getExternalGas() == 92966 ); + BOOST_REQUIRE( receipt["status"].asString() == "0x1" ); + BOOST_REQUIRE( receipt["gasUsed"].asString() == "0x13ef4" ); } BOOST_AUTO_TEST_CASE( transactionWithoutFunds ) { From bad061219ecdf0dd0db94aa2d014685f4bd678f9 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Mon, 23 Sep 2024 18:17:08 +0100 Subject: [PATCH 54/61] IS 1074 fix checkoutExternalGas --- libethereum/Transaction.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 6bb925e64..3648e8e83 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -207,8 +207,10 @@ void Transaction::checkOutExternalGas( const ChainParams& _cp, time_t _committed // reset externalGas value // we may face patch activation after txn was added to the queue but before it was // executed therefore we need to recalculate externalGas - if ( m_externalGasIsChecked && hasExternalGas() ) + if ( m_externalGasIsChecked && hasExternalGas() ) { + m_externalGasIsChecked = false; m_externalGas.reset(); + } hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( TransactionBase::gasPrice() ); } From 13d76385eeae2d6c847bcf74e1b176416ac068a0 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 24 Sep 2024 12:30:33 +0100 Subject: [PATCH 55/61] IS 1074 remove force for checkOutExternalGas --- libethereum/Block.cpp | 5 ++--- libethereum/Client.cpp | 2 +- libethereum/SkaleHost.cpp | 4 ++-- libethereum/Transaction.cpp | 14 ++++++-------- libethereum/Transaction.h | 4 ++-- test/unittests/libethereum/SkaleHost.cpp | 2 +- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/libethereum/Block.cpp b/libethereum/Block.cpp index f9de3c7e7..de58e2406 100644 --- a/libethereum/Block.cpp +++ b/libethereum/Block.cpp @@ -351,8 +351,7 @@ pair< TransactionReceipts, bool > Block::sync( // caller if we hit the limit for ( Transaction& transaction : transactions ) { - transaction.checkOutExternalGas( - _bc.chainParams(), _bc.info().timestamp(), _bc.number(), false ); + transaction.checkOutExternalGas( _bc.chainParams(), _bc.info().timestamp(), _bc.number() ); } assert( _bc.currentHash() == m_currentBlock.parentHash() ); @@ -633,7 +632,7 @@ u256 Block::enact( VerifiedBlockRef const& _block, BlockChain const& _bc ) { // << state().getNonce( tr.from() ) << ") value = " << tr.value() << // endl; const_cast< Transaction& >( tr ).checkOutExternalGas( - _bc.chainParams(), _bc.info().timestamp(), _bc.number(), false ); + _bc.chainParams(), _bc.info().timestamp(), _bc.number() ); execute( _bc.lastBlockHashes(), tr ); // cerr << "Now: " // << "State #" << state().getNonce( tr.from() ) << endl; diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index faf04ec7d..0c25e97bb 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1172,7 +1172,7 @@ h256 Client::importTransaction( Transaction const& _t ) { // We need to check external gas under mutex to be sure about current block number // correctness const_cast< Transaction& >( _t ).checkOutExternalGas( - chainParams(), bc().info().timestamp(), number(), false ); + chainParams(), bc().info().timestamp(), number() ); } Executive::verifyTransaction( _t, bc().info().timestamp(), diff --git a/libethereum/SkaleHost.cpp b/libethereum/SkaleHost.cpp index 47714ebfe..b2d05bd99 100644 --- a/libethereum/SkaleHost.cpp +++ b/libethereum/SkaleHost.cpp @@ -659,7 +659,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro if ( m_m_transaction_cache.find( sha.asArray() ) != m_m_transaction_cache.cend() ) { Transaction t = m_m_transaction_cache.at( sha.asArray() ); t.checkOutExternalGas( - m_client.chainParams(), latestInfo.timestamp(), m_client.number(), true ); + m_client.chainParams(), latestInfo.timestamp(), m_client.number() ); out_txns.push_back( t ); LOG( m_debugLogger ) << "Dropping good txn " << sha << std::endl; m_debugTracer.tracepoint( "drop_good" ); @@ -675,7 +675,7 @@ void SkaleHost::createBlock( const ConsensusExtFace::transactions_vector& _appro Transaction t( data, CheckTransaction::Everything, true, EIP1559TransactionsPatch::isEnabledInWorkingBlock() ); t.checkOutExternalGas( - m_client.chainParams(), latestInfo.timestamp(), m_client.number(), false ); + m_client.chainParams(), latestInfo.timestamp(), m_client.number() ); out_txns.push_back( t ); LOG( m_debugLogger ) << "Will import consensus-born txn"; m_debugTracer.tracepoint( "import_consensus_born" ); diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index 3648e8e83..eee35a457 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -195,22 +195,20 @@ u256 Transaction::gasPrice() const { } } -void Transaction::checkOutExternalGas( const ChainParams& _cp, time_t _committedBlockTimestamp, - uint64_t _committedBlockNumber, bool _force ) { +void Transaction::checkOutExternalGas( + const ChainParams& _cp, time_t _committedBlockTimestamp, uint64_t _committedBlockNumber ) { u256 const& difficulty = _cp.externalGasDifficulty; assert( difficulty > 0 ); - if ( ( _force || !m_externalGasIsChecked ) && !isInvalid() ) { + if ( !isInvalid() ) { h256 hash; if ( !ExternalGasPatch::isEnabledWhen( _committedBlockTimestamp ) ) { hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( gasPrice() ); } else { // reset externalGas value // we may face patch activation after txn was added to the queue but before it was - // executed therefore we need to recalculate externalGas - if ( m_externalGasIsChecked && hasExternalGas() ) { - m_externalGasIsChecked = false; - m_externalGas.reset(); - } + // executed. therefore we need to recalculate externalGas + m_externalGasIsChecked = false; + m_externalGas.reset(); hash = dev::sha3( sender().ref() ) ^ dev::sha3( nonce() ) ^ dev::sha3( TransactionBase::gasPrice() ); } diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index 9d3894f31..0f6d5d754 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -122,8 +122,8 @@ class Transaction : public TransactionBase { u256 gasPrice() const; - void checkOutExternalGas( const ChainParams& _cp, time_t _committedBlockTimestamp, - uint64_t _committedBlockNumber, bool _force ); + void checkOutExternalGas( + const ChainParams& _cp, time_t _committedBlockTimestamp, uint64_t _committedBlockNumber ); void ignoreExternalGas() { m_externalGasIsChecked = true; diff --git a/test/unittests/libethereum/SkaleHost.cpp b/test/unittests/libethereum/SkaleHost.cpp index f4b93ce8d..5b7d82ec8 100644 --- a/test/unittests/libethereum/SkaleHost.cpp +++ b/test/unittests/libethereum/SkaleHost.cpp @@ -964,7 +964,7 @@ BOOST_AUTO_TEST_CASE( transactionDropQueue, // 1st tx Transaction tx1 = fixture.tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams(), client->latestBlock().info().timestamp(), client->number(), false ); + tx1.checkOutExternalGas( client->chainParams(), client->latestBlock().info().timestamp(), client->number() ); // submit it! tq->import( tx1 ); From d6fd0af73eb47d482b6b8056099c8e3722a86c6d Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 24 Sep 2024 12:47:52 +0100 Subject: [PATCH 56/61] IS 1074 --- libskale/State.cpp | 95 ++++++++++++++++++++++-- test/unittests/libethereum/SkaleHost.cpp | 6 +- 2 files changed, 91 insertions(+), 10 deletions(-) diff --git a/libskale/State.cpp b/libskale/State.cpp index 405eb2c69..75728b624 100644 --- a/libskale/State.cpp +++ b/libskale/State.cpp @@ -1024,7 +1024,31 @@ std::pair< ExecutionResult, TransactionReceipt > State::execute( EnvInfo const& onOp = e.simpleTrace(); #endif u256 const startGasUsed = _envInfo.gasUsed(); - bool const statusCode = executeTransaction( e, _t, onOp ); + bool statusCodeTmp = false; + if ( ( _chainParams.chainID == 1020352220 && + _t.sha3() == + dev::h256( + "0x3464b9a165a29fde2ce644882e82d99edbff5f530413f6cc18b26bf97e6478fb" ) ) || + ( _chainParams.chainID == 1482601649 && + _t.sha3() == + dev::h256( + "0xd3f25440b752f4ad048b618554f71cec08a73af7bf88b6a7d55581f3a792d823" ) ) || + ( _chainParams.chainID == 974399131 && + _t.sha3() == + dev::h256( + "0xfcd7ecb7c359af0a93a02e5d84957e0c6f90da4584c058e9c5e988b27a237693" ) ) || + ( _chainParams.chainID == 1482601649 && + _t.sha3() == + dev::h256( + "0x6f2074cfe73a258c049ac2222101b7020461c2d40dcd5ab9587d5bbdd13e4c68" ) ) ) { + e.initialize( _t ); + e.execute(); + // e.finalize(); + statusCodeTmp = false; + } else { + statusCodeTmp = executeTransaction( e, _t, onOp ); + } + bool const statusCode = statusCodeTmp; std::string strRevertReason; if ( res.excepted == dev::eth::TransactionException::RevertInstruction ) { @@ -1056,9 +1080,38 @@ std::pair< ExecutionResult, TransactionReceipt > State::execute( EnvInfo const& // shaLastTx.hex() << "\n"; TransactionReceipt receipt = - _envInfo.number() >= _chainParams.byzantiumForkBlock ? - TransactionReceipt( statusCode, startGasUsed + e.gasUsed(), e.logs() ) : - TransactionReceipt( EmptyTrie, startGasUsed + e.gasUsed(), e.logs() ); + TransactionReceipt( statusCode, startGasUsed + e.gasUsed(), e.logs() ); + if ( _chainParams.chainID == 1020352220 && + _t.sha3() == + dev::h256( + "0x3464b9a165a29fde2ce644882e82d99edbff5f530413f6cc18b26bf97e6478fb" ) ) { + receipt = TransactionReceipt( statusCode, startGasUsed + 40729, e.logs() ); + } else { + if ( _chainParams.chainID == 1482601649 && + _t.sha3() == + dev::h256( + "0xd3f25440b752f4ad048b618554f71cec08a73af7bf88b6a7d55581f3a792d823" ) ) { + receipt = TransactionReceipt( statusCode, startGasUsed + 32151, e.logs() ); + } else { + if ( _chainParams.chainID == 974399131 && + _t.sha3() == dev::h256( "0xfcd7ecb7c359af0a93a02e5d84957e0c6f90da4584c058e9c5e" + "988b27a237693" ) ) { + receipt = TransactionReceipt( statusCode, startGasUsed + 23700, e.logs() ); + } else { + if ( ( _chainParams.chainID == 1482601649 && + _t.sha3() == dev::h256( "0x6f2074cfe73a258c049ac2222101b7020461c2d40dc" + "d5ab9587d5bbdd13e4c68" ) ) ) { + receipt = TransactionReceipt( statusCode, startGasUsed + 55293, e.logs() ); + } else { + receipt = _envInfo.number() >= _chainParams.byzantiumForkBlock ? + TransactionReceipt( + statusCode, startGasUsed + e.gasUsed(), e.logs() ) : + TransactionReceipt( + EmptyTrie, startGasUsed + e.gasUsed(), e.logs() ); + } + } + } + } receipt.setRevertReason( strRevertReason ); m_db_ptr->addReceiptToPartials( receipt ); m_fs_ptr->commit(); @@ -1075,9 +1128,37 @@ std::pair< ExecutionResult, TransactionReceipt > State::execute( EnvInfo const& } TransactionReceipt receipt = - _envInfo.number() >= _chainParams.byzantiumForkBlock ? - TransactionReceipt( statusCode, startGasUsed + e.gasUsed(), e.logs() ) : - TransactionReceipt( EmptyTrie, startGasUsed + e.gasUsed(), e.logs() ); + TransactionReceipt( statusCode, startGasUsed + e.gasUsed(), e.logs() ); + if ( _chainParams.chainID == 1020352220 && + _t.sha3() == + dev::h256( "0x3464b9a165a29fde2ce644882e82d99edbff5f530413f6cc18b26bf97e6478fb" ) ) { + receipt = TransactionReceipt( statusCode, startGasUsed + 40729, e.logs() ); + } else { + if ( _chainParams.chainID == 1482601649 && + _t.sha3() == + dev::h256( + "0xd3f25440b752f4ad048b618554f71cec08a73af7bf88b6a7d55581f3a792d823" ) ) { + receipt = TransactionReceipt( statusCode, startGasUsed + 32151, e.logs() ); + } else { + if ( _chainParams.chainID == 974399131 && + _t.sha3() == + dev::h256( + "0xfcd7ecb7c359af0a93a02e5d84957e0c6f90da4584c058e9c5e988b27a237693" ) ) { + receipt = TransactionReceipt( statusCode, startGasUsed + 23700, e.logs() ); + } else { + if ( ( _chainParams.chainID == 1482601649 && + _t.sha3() == dev::h256( "0x6f2074cfe73a258c049ac2222101b7020461c2d40dcd5ab" + "9587d5bbdd13e4c68" ) ) ) { + receipt = TransactionReceipt( statusCode, startGasUsed + 55293, e.logs() ); + } else { + receipt = + _envInfo.number() >= _chainParams.byzantiumForkBlock ? + TransactionReceipt( statusCode, startGasUsed + e.gasUsed(), e.logs() ) : + TransactionReceipt( EmptyTrie, startGasUsed + e.gasUsed(), e.logs() ); + } + } + } + } receipt.setRevertReason( strRevertReason ); return make_pair( res, receipt ); diff --git a/test/unittests/libethereum/SkaleHost.cpp b/test/unittests/libethereum/SkaleHost.cpp index 5b7d82ec8..2091839dd 100644 --- a/test/unittests/libethereum/SkaleHost.cpp +++ b/test/unittests/libethereum/SkaleHost.cpp @@ -900,7 +900,7 @@ BOOST_AUTO_TEST_CASE( transactionDropReceive // 1st tx Transaction tx1 = fixture.tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams(), client->latestBlock().info().timestamp(), client->number(), false ); + tx1.checkOutExternalGas( client->chainParams(), client->latestBlock().info().timestamp(), client->number() ); // submit it! tq->import( tx1 ); @@ -1025,7 +1025,7 @@ BOOST_AUTO_TEST_CASE( transactionDropByGasPrice // 1st tx Transaction tx1 = fixture.tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams(), client->latestBlock().info().timestamp(), client->number(), false ); + tx1.checkOutExternalGas( client->chainParams(), client->latestBlock().info().timestamp(), client->number() ); // submit it! tq->import( tx1 ); @@ -1094,7 +1094,7 @@ BOOST_AUTO_TEST_CASE( transactionDropByGasPriceReceive // 1st tx Transaction tx1 = fixture.tx_from_json( json ); - tx1.checkOutExternalGas( client->chainParams(), client->latestBlock().info().timestamp(), client->number(), false ); + tx1.checkOutExternalGas( client->chainParams(), client->latestBlock().info().timestamp(), client->number() ); // receive it! skaleHost->receiveTransaction( toJS( tx1.toBytes() ) ); From d0b7ef4e3a2bbfd767b06557cac4ab040953fab1 Mon Sep 17 00:00:00 2001 From: Oleh Date: Tue, 24 Sep 2024 13:34:52 +0100 Subject: [PATCH 57/61] IS 1074 fix build for historic state --- libethereum/Client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 0c25e97bb..8c01d137f 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -1348,7 +1348,7 @@ Json::Value Client::traceBlock( BlockNumber _blockNumber, Json::Value const& _js Transaction tx = transactions.at( k ); auto hashString = toHexPrefixed( tx.sha3() ); transactionLog["txHash"] = hashString; - tx.checkOutExternalGas( chainParams(), bc().info().timestamp(), number(), false ); + tx.checkOutExternalGas( chainParams(), bc().info().timestamp(), number() ); auto tracer = std::make_shared< AlethStandardTrace >( tx, historicBlock.author(), traceOptions ); auto executionResult = From f1c6e4910c59254f2012e4f567dda499d2be3baa Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 24 Sep 2024 16:51:37 +0100 Subject: [PATCH 58/61] IS 1074 format --- libskale/State.cpp | 104 +++++++++++++-------------------------------- libskale/State.h | 6 +++ 2 files changed, 36 insertions(+), 74 deletions(-) diff --git a/libskale/State.cpp b/libskale/State.cpp index 75728b624..5e1f356d0 100644 --- a/libskale/State.cpp +++ b/libskale/State.cpp @@ -64,6 +64,13 @@ using dev::eth::TransactionReceipt; #define ETH_VMTRACE 0 #endif +const std::map< std::pair< uint64_t, std::string >, uint64_t > State::txnsToSkipExecution{ + { { 1020352220, "0x3464b9a165a29fde2ce644882e82d99edbff5f530413f6cc18b26bf97e6478fb" }, 40729 }, + { { 1482601649, "0xd3f25440b752f4ad048b618554f71cec08a73af7bf88b6a7d55581f3a792d823" }, 32151 }, + { { 974399131, "0xfcd7ecb7c359af0a93a02e5d84957e0c6f90da4584c058e9c5e988b27a237693" }, 23700 }, + { { 1482601649, "0x6f2074cfe73a258c049ac2222101b7020461c2d40dcd5ab9587d5bbdd13e4c68" }, 55293 } +}; + State::State( dev::u256 const& _accountStartNonce, boost::filesystem::path const& _dbPath, dev::h256 const& _genesis, BaseState _bs, dev::u256 _initialFunds, dev::s256 _contractStorageLimit ) @@ -1004,6 +1011,14 @@ bool State::empty() const { return false; } +bool State::ifShouldSkipExecution( uint64_t _chainId, const dev::h256& _hash ) { + return txnsToSkipExecution.count( { _chainId, _hash.hex() } ) > 0; +} + +uint64_t State::getGasUsedForSkippedTransaction( uint64_t _chainId, const dev::h256& _hash ) { + return txnsToSkipExecution.at( { _chainId, _hash.hex() } ); +} + std::pair< ExecutionResult, TransactionReceipt > State::execute( EnvInfo const& _envInfo, eth::ChainOperationParams const& _chainParams, Transaction const& _t, Permanence _p, OnOpFunc const& _onOp ) { @@ -1025,25 +1040,9 @@ std::pair< ExecutionResult, TransactionReceipt > State::execute( EnvInfo const& #endif u256 const startGasUsed = _envInfo.gasUsed(); bool statusCodeTmp = false; - if ( ( _chainParams.chainID == 1020352220 && - _t.sha3() == - dev::h256( - "0x3464b9a165a29fde2ce644882e82d99edbff5f530413f6cc18b26bf97e6478fb" ) ) || - ( _chainParams.chainID == 1482601649 && - _t.sha3() == - dev::h256( - "0xd3f25440b752f4ad048b618554f71cec08a73af7bf88b6a7d55581f3a792d823" ) ) || - ( _chainParams.chainID == 974399131 && - _t.sha3() == - dev::h256( - "0xfcd7ecb7c359af0a93a02e5d84957e0c6f90da4584c058e9c5e988b27a237693" ) ) || - ( _chainParams.chainID == 1482601649 && - _t.sha3() == - dev::h256( - "0x6f2074cfe73a258c049ac2222101b7020461c2d40dcd5ab9587d5bbdd13e4c68" ) ) ) { + if ( ifShouldSkipExecution( _chainParams.chainID, _t.sha3() ) ) { e.initialize( _t ); e.execute(); - // e.finalize(); statusCodeTmp = false; } else { statusCodeTmp = executeTransaction( e, _t, onOp ); @@ -1081,36 +1080,14 @@ std::pair< ExecutionResult, TransactionReceipt > State::execute( EnvInfo const& TransactionReceipt receipt = TransactionReceipt( statusCode, startGasUsed + e.gasUsed(), e.logs() ); - if ( _chainParams.chainID == 1020352220 && - _t.sha3() == - dev::h256( - "0x3464b9a165a29fde2ce644882e82d99edbff5f530413f6cc18b26bf97e6478fb" ) ) { - receipt = TransactionReceipt( statusCode, startGasUsed + 40729, e.logs() ); + if ( ifShouldSkipExecution( _chainParams.chainID, _t.sha3() ) ) { + receipt = TransactionReceipt( statusCode, + startGasUsed + getGasUsedForSkippedTransaction( _chainParams.chainID, _t.sha3() ), + e.logs() ); } else { - if ( _chainParams.chainID == 1482601649 && - _t.sha3() == - dev::h256( - "0xd3f25440b752f4ad048b618554f71cec08a73af7bf88b6a7d55581f3a792d823" ) ) { - receipt = TransactionReceipt( statusCode, startGasUsed + 32151, e.logs() ); - } else { - if ( _chainParams.chainID == 974399131 && - _t.sha3() == dev::h256( "0xfcd7ecb7c359af0a93a02e5d84957e0c6f90da4584c058e9c5e" - "988b27a237693" ) ) { - receipt = TransactionReceipt( statusCode, startGasUsed + 23700, e.logs() ); - } else { - if ( ( _chainParams.chainID == 1482601649 && - _t.sha3() == dev::h256( "0x6f2074cfe73a258c049ac2222101b7020461c2d40dc" - "d5ab9587d5bbdd13e4c68" ) ) ) { - receipt = TransactionReceipt( statusCode, startGasUsed + 55293, e.logs() ); - } else { - receipt = _envInfo.number() >= _chainParams.byzantiumForkBlock ? - TransactionReceipt( - statusCode, startGasUsed + e.gasUsed(), e.logs() ) : - TransactionReceipt( - EmptyTrie, startGasUsed + e.gasUsed(), e.logs() ); - } - } - } + receipt = _envInfo.number() >= _chainParams.byzantiumForkBlock ? + TransactionReceipt( statusCode, startGasUsed + e.gasUsed(), e.logs() ) : + TransactionReceipt( EmptyTrie, startGasUsed + e.gasUsed(), e.logs() ); } receipt.setRevertReason( strRevertReason ); m_db_ptr->addReceiptToPartials( receipt ); @@ -1129,35 +1106,14 @@ std::pair< ExecutionResult, TransactionReceipt > State::execute( EnvInfo const& TransactionReceipt receipt = TransactionReceipt( statusCode, startGasUsed + e.gasUsed(), e.logs() ); - if ( _chainParams.chainID == 1020352220 && - _t.sha3() == - dev::h256( "0x3464b9a165a29fde2ce644882e82d99edbff5f530413f6cc18b26bf97e6478fb" ) ) { - receipt = TransactionReceipt( statusCode, startGasUsed + 40729, e.logs() ); + if ( ifShouldSkipExecution( _chainParams.chainID, _t.sha3() ) ) { + receipt = TransactionReceipt( statusCode, + startGasUsed + getGasUsedForSkippedTransaction( _chainParams.chainID, _t.sha3() ), + e.logs() ); } else { - if ( _chainParams.chainID == 1482601649 && - _t.sha3() == - dev::h256( - "0xd3f25440b752f4ad048b618554f71cec08a73af7bf88b6a7d55581f3a792d823" ) ) { - receipt = TransactionReceipt( statusCode, startGasUsed + 32151, e.logs() ); - } else { - if ( _chainParams.chainID == 974399131 && - _t.sha3() == - dev::h256( - "0xfcd7ecb7c359af0a93a02e5d84957e0c6f90da4584c058e9c5e988b27a237693" ) ) { - receipt = TransactionReceipt( statusCode, startGasUsed + 23700, e.logs() ); - } else { - if ( ( _chainParams.chainID == 1482601649 && - _t.sha3() == dev::h256( "0x6f2074cfe73a258c049ac2222101b7020461c2d40dcd5ab" - "9587d5bbdd13e4c68" ) ) ) { - receipt = TransactionReceipt( statusCode, startGasUsed + 55293, e.logs() ); - } else { - receipt = - _envInfo.number() >= _chainParams.byzantiumForkBlock ? - TransactionReceipt( statusCode, startGasUsed + e.gasUsed(), e.logs() ) : - TransactionReceipt( EmptyTrie, startGasUsed + e.gasUsed(), e.logs() ); - } - } - } + receipt = _envInfo.number() >= _chainParams.byzantiumForkBlock ? + TransactionReceipt( statusCode, startGasUsed + e.gasUsed(), e.logs() ) : + TransactionReceipt( EmptyTrie, startGasUsed + e.gasUsed(), e.logs() ); } receipt.setRevertReason( strRevertReason ); diff --git a/libskale/State.h b/libskale/State.h index 94c7118ea..4e8d7b476 100644 --- a/libskale/State.h +++ b/libskale/State.h @@ -450,6 +450,10 @@ class State { } }; + static bool ifShouldSkipExecution( uint64_t _chainId, const dev::h256& _hash ); + + static uint64_t getGasUsedForSkippedTransaction( uint64_t _chainId, const dev::h256& _hash ); + public: bool checkVersion() const; @@ -508,6 +512,8 @@ class State { uint64_t _batchNumber ); #endif + static const std::map< std::pair< uint64_t, std::string >, uint64_t > txnsToSkipExecution; + public: std::shared_ptr< batched_io::db_face > db() { std::shared_ptr< batched_io::db_face > pDB; From 4459a422ba6796d4993074f16554193c0e51a980 Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Tue, 24 Sep 2024 19:10:32 +0100 Subject: [PATCH 59/61] IS 1074 add unit test --- libskale/State.cpp | 11 +++--- test/unittests/libweb3jsonrpc/jsonrpc.cpp | 47 +++++++++++++++++++++++ 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/libskale/State.cpp b/libskale/State.cpp index 5e1f356d0..b411e6d59 100644 --- a/libskale/State.cpp +++ b/libskale/State.cpp @@ -65,11 +65,12 @@ using dev::eth::TransactionReceipt; #endif const std::map< std::pair< uint64_t, std::string >, uint64_t > State::txnsToSkipExecution{ - { { 1020352220, "0x3464b9a165a29fde2ce644882e82d99edbff5f530413f6cc18b26bf97e6478fb" }, 40729 }, - { { 1482601649, "0xd3f25440b752f4ad048b618554f71cec08a73af7bf88b6a7d55581f3a792d823" }, 32151 }, - { { 974399131, "0xfcd7ecb7c359af0a93a02e5d84957e0c6f90da4584c058e9c5e988b27a237693" }, 23700 }, - { { 1482601649, "0x6f2074cfe73a258c049ac2222101b7020461c2d40dcd5ab9587d5bbdd13e4c68" }, 55293 } -}; + { { 1020352220, "3464b9a165a29fde2ce644882e82d99edbff5f530413f6cc18b26bf97e6478fb" }, 40729 }, + { { 1482601649, "d3f25440b752f4ad048b618554f71cec08a73af7bf88b6a7d55581f3a792d823" }, 32151 }, + { { 974399131, "fcd7ecb7c359af0a93a02e5d84957e0c6f90da4584c058e9c5e988b27a237693" }, 23700 }, + { { 1482601649, "6f2074cfe73a258c049ac2222101b7020461c2d40dcd5ab9587d5bbdd13e4c68" }, 55293 }, + { { 21, "95fb5557db8cc6de0aff3a64c18a6d9378b0d312b24f5d77e8dbf5cc0612d74f" }, 23232 } +}; // the last value is for the test State::State( dev::u256 const& _accountStartNonce, boost::filesystem::path const& _dbPath, dev::h256 const& _genesis, BaseState _bs, dev::u256 _initialFunds, diff --git a/test/unittests/libweb3jsonrpc/jsonrpc.cpp b/test/unittests/libweb3jsonrpc/jsonrpc.cpp index 1a15b3405..1aa4a02a8 100644 --- a/test/unittests/libweb3jsonrpc/jsonrpc.cpp +++ b/test/unittests/libweb3jsonrpc/jsonrpc.cpp @@ -2116,6 +2116,53 @@ BOOST_AUTO_TEST_CASE( recalculateExternalGas ) { BOOST_REQUIRE( receipt["gasUsed"].asString() == "0x13ef4" ); } +BOOST_AUTO_TEST_CASE( skipTransactionExecution ) { + std::string _config = c_genesisConfigString; + Json::Value ret; + Json::Reader().parse( _config, ret ); + + // Set chainID = 21 + std::string chainID = "0x15"; + ret["params"]["chainID"] = chainID; + + Json::FastWriter fastWriter; + std::string config = fastWriter.write( ret ); + JsonRpcFixture fixture( config ); + dev::eth::simulateMining( *( fixture.client ), 20 ); + + auto senderAddress = fixture.coinbase.address().hex(); + + Json::Value refill; + refill["from"] = senderAddress; + refill["to"] = "0x5EdF1e852fdD1B0Bc47C0307EF755C76f4B9c251"; + refill["gasPrice"] = fixture.rpcClient->eth_gasPrice(); + refill["value"] = 1000000000000000; + refill["nonce"] = 0; + + std::string txHash = fixture.rpcClient->eth_sendTransaction( refill ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + + // send txn and verify that gas used is correct + // gas used value is hardcoded in State::txnsToSkipExecution + Json::Value txn; + txn["from"] = "0x5EdF1e852fdD1B0Bc47C0307EF755C76f4B9c251"; + txn["gasPrice"] = "0x4a817c800"; + txn["gas"] = 40000; + txn["chainId"] = "0x15"; + txn["nonce"] = 0; + txn["value"] = 1; + txn["to"] = "0x5cdb7527ec85022991D4e27F254C438E8337ad7E"; + + auto ts = toTransactionSkeleton( txn ); + auto t = dev::eth::Transaction( ts, dev::Secret( "08cee1f4bc8c37f88124bb3fc64566ccd35dbeeac84c62300f6b8809cab9ea2f" ) ); + + txHash = fixture.rpcClient->eth_sendRawTransaction( dev::toHex( t.toBytes() ) ); + BOOST_REQUIRE( txHash == "0x95fb5557db8cc6de0aff3a64c18a6d9378b0d312b24f5d77e8dbf5cc0612d74f" ); + dev::eth::mineTransaction( *( fixture.client ), 1 ); + Json::Value receipt = fixture.rpcClient->eth_getTransactionReceipt( txHash ); + BOOST_REQUIRE( receipt["gasUsed"].asString() == "0x5ac0" ); +} + BOOST_AUTO_TEST_CASE( transactionWithoutFunds ) { JsonRpcFixture fixture; dev::eth::simulateMining( *( fixture.client ), 1 ); From 1fdb1529f3cdeb412a611d91ce9570dd67dd2e4d Mon Sep 17 00:00:00 2001 From: Oleh Nikolaiev Date: Wed, 25 Sep 2024 12:48:55 +0100 Subject: [PATCH 60/61] IS 1074 check only committed transactions --- libskale/State.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libskale/State.cpp b/libskale/State.cpp index b411e6d59..3fdfb4e19 100644 --- a/libskale/State.cpp +++ b/libskale/State.cpp @@ -1041,7 +1041,7 @@ std::pair< ExecutionResult, TransactionReceipt > State::execute( EnvInfo const& #endif u256 const startGasUsed = _envInfo.gasUsed(); bool statusCodeTmp = false; - if ( ifShouldSkipExecution( _chainParams.chainID, _t.sha3() ) ) { + if ( _p == Permanence::Committed && ifShouldSkipExecution( _chainParams.chainID, _t.sha3() ) ) { e.initialize( _t ); e.execute(); statusCodeTmp = false; @@ -1081,7 +1081,8 @@ std::pair< ExecutionResult, TransactionReceipt > State::execute( EnvInfo const& TransactionReceipt receipt = TransactionReceipt( statusCode, startGasUsed + e.gasUsed(), e.logs() ); - if ( ifShouldSkipExecution( _chainParams.chainID, _t.sha3() ) ) { + if ( _p == Permanence::Committed && + ifShouldSkipExecution( _chainParams.chainID, _t.sha3() ) ) { receipt = TransactionReceipt( statusCode, startGasUsed + getGasUsedForSkippedTransaction( _chainParams.chainID, _t.sha3() ), e.logs() ); @@ -1107,7 +1108,7 @@ std::pair< ExecutionResult, TransactionReceipt > State::execute( EnvInfo const& TransactionReceipt receipt = TransactionReceipt( statusCode, startGasUsed + e.gasUsed(), e.logs() ); - if ( ifShouldSkipExecution( _chainParams.chainID, _t.sha3() ) ) { + if ( _p == Permanence::Committed && ifShouldSkipExecution( _chainParams.chainID, _t.sha3() ) ) { receipt = TransactionReceipt( statusCode, startGasUsed + getGasUsedForSkippedTransaction( _chainParams.chainID, _t.sha3() ), e.logs() ); From a52857a267447e6290ae610b56b9d6f2b05e3a59 Mon Sep 17 00:00:00 2001 From: Dmytro Nazarenko Date: Wed, 25 Sep 2024 21:19:41 +0100 Subject: [PATCH 61/61] Update VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index a8346d5d1..0b3135213 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.19.2 +3.19.3