nimbus-eth1
nimbus-eth1 copied to clipboard
Initial state network bridge implementation
Based on existing bridges in fluffy/tools
implement state network bridge.
To build the bridge: make portal_bridge
State bridge file but without actual implementation is here right now: https://github.com/status-im/nimbus-eth1/blob/master/fluffy/tools/portal_bridge/portal_bridge_state.nim#L33 , see TODO there also.
I believe we can implement the state network bridge without pulling in the EVM or needing to read era1 files by simply calling these JSON-RPC endpoints:
- trace_replayBlockTransactions
- eth_getBlockByNumber
trace_replayBlockTransactions is required to get the state diff for each block and eth_getBlockByNumber is needed to get the withdrawals after the merge. We will also need to calculate minor rewards for premerge separately. Erigon, reth and Besu support trace_replayBlockTransactions and so I believe we should also aim to implement it in Nimbus at some point.
We will want to use the 'stateDiff' option in the parameters. For example:
{
"jsonrpc": "2.0",
"method": "trace_replayBlockTransactions",
"id": 100,
"params": ["0xAAAAA", ["stateDiff"]]
}
The Fluffy state network bridge logic would look something like this:
- Start from genesis and create an empty state trie backed by rocksdb or another database that supports transactions.
- For each block, fetch the data from trace_replayBlockTransactions and eth_getBlockByNumber.
- Apply the state diff to the state trie. Note that we would need to manage additional storage tries for each contract account.
- After pushing the state updates through the trie/s, collect the list of updated trie nodes and then commit these to the database.
- Check that the trie state root matches the expected stateRoot value in block header.
- For each updated trie node, build a proof using the trie state.
- Convert each trie proof into a portal state network offer.
- Send each offer to the portal state network by calling portal_stateGossip or perhaps another special purpose custom endpoint defined in Fluffy that supports batching.