Skip to content

Commit

Permalink
ALL-4448 - Update archive conditions (#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hathoriel authored Feb 13, 2024
1 parent 392535a commit 09a0acd
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 34 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [4.2.7] - 2024.2.12

### Updated

- Updated archive condition for evm rpc calls

## [4.2.6] - 2024.2.12

### Added
Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,28 @@ All RPC calls are implemented in the `tatum.rpc.*` submodule.

See the [RPC API Reference](https://docs.tatum.io/docs/rpc-api-reference) for more about supported chains and methods.

### Distinguishing Between Archive and Full Nodes

When interacting with the blockchain, it's essential to know whether a JSON RPC call requires an archive node or can be serviced by a full node. The distinction hinges on the type of data requested and the historical depth of that data. Here's a breakdown of the conditions under which a call is classified for an archive or a full node:

#### Archive Node Calls

Archive nodes store the entire history of the blockchain, including the state of all accounts at every block. Calls that require an archive node typically involve querying historical states. Conditions include:

1. **Calls to Methods `getCode` or `call`**: Always require an archive node because they may query the state at any block height.

2. **Calls Including `debug` or `trace` Methods**: These methods require historical data not available on full nodes.

3. **Parameters Indicating a Specific Block Number**: For following methods, if the call specifies a block number, it requires an archive node. This includes:
- `getStorageAt` with a specific block number.
- `getBalance` with a specific block number.
- `getBlockByNumber` when a block number is specified.
- `getLogs` calls where `fromBlock` or `toBlock` specify a block number other than the latest.

#### Full Node Calls

Any other calls not meeting the conditions for archive node calls can be serviced by a full node. These calls typically involve querying the current state of the blockchain.

### Status Pages
This section provides a list of various blockchain network status pages, powered by Tatum. These links direct you to real-time status updates for each network.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tatumio/tatum",
"version": "4.2.6",
"version": "4.2.7",
"description": "Tatum JS SDK",
"author": "Tatum",
"repository": "https://github.com/tatumio/tatum-js",
Expand Down
42 changes: 42 additions & 0 deletions src/service/rpc/evm/EvmUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { EvmUtils } from './EvmUtils'

describe('EvmUtils', () => {
describe('isArchiveMethod', () => {
it.each([
['eth_getCode', true],
['eth_call', true],
['debug', true],
['trace', true],
['getStorageAt', false],
['eth_call', true],
['getBalance', false],
['eth_getCode', true],
['getBlockByNumber', false],
['getLogs', false],
['other', false],
])('archive method %s -> %s', (method, expected) => {
expect(EvmUtils.isArchiveMethod({ method, id: 2, jsonrpc: 'test' })).toBe(expected)
})

it.each([
['getStorageAt', [1, 2], false],
['getStorageAt', [1, 2, 'latest'], false],
['getStorageAt', [1, 2, 3], true],
['getStorageAt', [], false],
['getBalance', [1], false],
['getBalance', [1, 'latest'], false],
['getBalance', [1, 2], true],
['getBalance', [], false],
['getBlockByNumber', [], false],
['getBlockByNumber', ['latest'], false],
['getBlockByNumber', [1], true],
['getLogs', [1, { fromBlock: 'latest' }], false],
['getLogs', [1, { fromBlock: 'latest', toBlock: 'latest' }], false],
['getLogs', [1, { toBlock: 'latest' }], false],
['getLogs', [1, { toBlock: 1 }], true],
['getLogs', [1, { fromBlock: 1 }], true],
])('archive method & param %s -> %s', (method, params, expected) => {
expect(EvmUtils.isArchiveMethod({ method, params, id: 2, jsonrpc: 'test' })).toBe(expected)
})
})
})
38 changes: 5 additions & 33 deletions src/service/rpc/evm/EvmUtils.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,19 @@
import { JsonRpcCall } from '../../../dto'

export const ARCHIVE_METHODS = [
// Archival information
'debug_getBadBlocks',
'debug_storageRangeAt',
'debug_traceCall',
'debug_traceTransaction',
'debug_traceBlock',
'debug_traceBlockByHash',
'debug_traceBlockByNumber',
'trace_block',
'trace_call',
'trace_callMany',
'trace_rawTransaction',
'trace_replayBlockTransactions',

// Network state
'getBlockByHash',
'getTransactionByHash',
'getTransactionReceipt',
'getUncleCountByBlockHash',
'getUncleCountByBlockNumber',
'getBlockTransactionCountByHash',
'getBlockTransactionCountByNumber',
'getBlockReceipts',
'getTransactionByBlockHashAndIndex',
'getTransactionByBlockNumberAndIndex',
'getTransactionCount',
'getProof',
]
export const ARCHIVE_METHODS = ['getCode', 'call']

export const POSSIBLE_ARCHIVE_METHODS = [
// Network state
{ method: 'getStorageAt', index: 2 },
{ method: 'call', index: 1 },
{ method: 'getBalance', index: 1 },
{ method: 'getCode', index: 1 },
{ method: 'getBlockByNumber', index: 0 },
]

export const EvmUtils = {
isArchiveMethod(rpc: JsonRpcCall): boolean {
const isArchiveMethod = ARCHIVE_METHODS.find((method) => rpc.method.includes(method))
const isArchiveMethod =
ARCHIVE_METHODS.find((method) => rpc.method.includes(method)) ||
rpc.method?.includes('debug') ||
rpc.method?.includes('trace')
if (isArchiveMethod) {
return true
}
Expand Down

0 comments on commit 09a0acd

Please sign in to comment.