Skip to content

Commit

Permalink
Port p2p to server API (#2769)
Browse files Browse the repository at this point in the history
* eth_gasPrice

* signing endpoints

* transaction by hash + temp fixes

* fix CI

* fix: state not persisted

* decouple state access changes from this PR

* rpc complete set

* tests modified

* tests temp modifications

* add tests to CI + minor fixes

* remove p2p

* remove old dependency

* fix suggestions

* rework tests

* rework kurtosis issue + comments

* fix post bump issues

* suggestions + logs

* remove unused imports
  • Loading branch information
advaita-saha authored Nov 2, 2024
1 parent 58cde36 commit a45ac7e
Show file tree
Hide file tree
Showing 16 changed files with 740 additions and 1,004 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kurtosis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ jobs:
cat kurtosis-network-params.yml | envsubst > assertoor.yaml
sed -i "s/el_image: .*/el_image: localtestnet/" assertoor.yaml
kurtosis run github.com/ethpandaops/ethereum-package@4.3.0 --enclave assertoor-${{ github.run_id }} --args-file assertoor.yaml
kurtosis run github.com/ethpandaops/ethereum-package --enclave assertoor-${{ github.run_id }} --args-file assertoor.yaml
enclave_dump=$(kurtosis enclave inspect assertoor-${{ github.run_id }})
Expand Down
2 changes: 1 addition & 1 deletion hive_integration/nodocker/engine/engine_env.nim
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ proc newEngineEnv*(conf: var NimbusConf, chainFile: string, enableAuth: bool): E
beaconEngine = BeaconEngineRef.new(txPool, chain)
serverApi = newServerAPI(chain, txPool)

setupServerAPI(serverApi, server)
setupServerAPI(serverApi, server, ctx)
setupEngineAPI(beaconEngine, server)
# temporary disabled
#setupDebugRpc(com, txPool, server)
Expand Down
2 changes: 1 addition & 1 deletion hive_integration/nodocker/pyspec/test_env.nim
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ proc setupELClient*(conf: ChainConfig, node: JsonNode): TestEnv =
rpcServer = newRpcHttpServer(["127.0.0.1:0"])
rpcClient = newRpcHttpClient()

setupServerAPI(serverApi, rpcServer)
setupServerAPI(serverApi, rpcServer, newEthContext())
setupEngineAPI(beaconEngine, rpcServer)

rpcServer.start()
Expand Down
16 changes: 9 additions & 7 deletions hive_integration/nodocker/rpc/test_env.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import
../../../nimbus/common,
../../../nimbus/config,
../../../nimbus/rpc,
../../../nimbus/rpc/oracle,
../../../nimbus/rpc/p2p,
../../../nimbus/rpc/server_api,
../../../nimbus/utils/utils,
../../../nimbus/core/[chain, tx_pool],
../../../tests/test_helpers,
Expand Down Expand Up @@ -46,11 +45,14 @@ proc manageAccounts(ctx: EthContext, conf: NimbusConf) =

proc setupRpcServer(ctx: EthContext, com: CommonRef,
ethNode: EthereumNode, txPool: TxPoolRef,
conf: NimbusConf): RpcServer =
let rpcServer = newRpcHttpServer([initTAddress(conf.httpAddress, conf.httpPort)])
let oracle = Oracle.new(com)
conf: NimbusConf, chain: ForkedChainRef): RpcServer =
let
rpcServer = newRpcHttpServer([initTAddress(conf.httpAddress, conf.httpPort)])
serverApi = newServerAPI(chain, txPool)


setupCommonRpc(ethNode, conf, rpcServer)
setupEthRpc(ethNode, ctx, com, txPool, oracle, rpcServer)
setupServerAPI(serverApi, rpcServer, ctx)

rpcServer.start()
rpcServer
Expand Down Expand Up @@ -92,7 +94,7 @@ proc setupEnv*(): TestEnv =
# so it can know the latest account state
doAssert txPool.smartHead(head, chainRef)

let rpcServer = setupRpcServer(ethCtx, com, ethNode, txPool, conf)
let rpcServer = setupRpcServer(ethCtx, com, ethNode, txPool, conf, chainRef)
let rpcClient = newRpcHttpClient()
waitFor rpcClient.connect("127.0.0.1", Port(8545), false)
let stopServer = stopRpcHttpServer
Expand Down
4 changes: 2 additions & 2 deletions kurtosis-network-params.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ participants:
el_extra_params: ["--log-level=DEBUG"]
cl_type: nimbus
cl_image: statusim/nimbus-eth2:multiarch-latest
cl_extra_params: ["--log-level=DEBUG;INFO:gossip_eth2,attpool,libp2p,gossipsub,pubsubpeer,pubsub,switch,networking,sync,dialer,identify,syncman,connmanager,beacnde,lightcl,requman,gossip_lc,clearance,lpstream,mplexchannel,nodes-verification,tcptransport,chaindag,noise,eth,p2p,discv5,muxedupgrade,multistream,connection,secure,fee_recipient,mplex,syncpool,multiaddress,peer_proto;WARN:message_router"]
cl_extra_params: ["--log-level=DEBUG"]
use_separate_vc: false
additional_services:
- tx_spammer
Expand All @@ -23,7 +23,7 @@ additional_services:
- blob_spammer
mev_type: null
assertoor_params:
image: "ethpandaops/assertoor:latest"
image: "ethpandaops/assertoor"
run_stability_check: false
run_block_proposal_check: true
run_transaction_test: true
Expand Down
5 changes: 5 additions & 0 deletions nimbus/beacon/api_handler/api_newpayload.nim
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ proc newPayload*(ben: BeaconEngineRef,
hash = blockHash, number = header.number
let vres = ben.chain.importBlock(blk)
if vres.isErr:
warn "Error importing block",
number = header.number,
hash = blockHash.short,
parent = header.parentHash.short,
error = vres.error()
ben.setInvalidAncestor(header, blockHash)
let blockHash = latestValidHash(db, parent, ttd)
return invalidStatus(blockHash, vres.error())
Expand Down
11 changes: 10 additions & 1 deletion nimbus/core/chain/forked_chain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ proc validateBlock(c: ForkedChainRef,

ok()

proc replaySegment(c: ForkedChainRef, target: Hash32) =
proc replaySegment*(c: ForkedChainRef, target: Hash32) =
# Replay from base+1 to target block
var
prevHash = target
Expand Down Expand Up @@ -635,9 +635,18 @@ func baseHash*(c: ForkedChainRef): Hash32 =
func txRecords*(c: ForkedChainRef, txHash: Hash32): (Hash32, uint64) =
c.txRecords.getOrDefault(txHash, (Hash32.default, 0'u64))

func isInMemory*(c: ForkedChainRef, blockHash: Hash32): bool =
c.blocks.hasKey(blockHash)

func memoryBlock*(c: ForkedChainRef, blockHash: Hash32): BlockDesc =
c.blocks.getOrDefault(blockHash)

func memoryTransaction*(c: ForkedChainRef, txHash: Hash32): Opt[Transaction] =
let (blockHash, index) = c.txRecords.getOrDefault(txHash, (Hash32.default, 0'u64))
c.blocks.withValue(blockHash, val) do:
return Opt.some(val.blk.transactions[index])
return Opt.none(Transaction)

proc latestBlock*(c: ForkedChainRef): Block =
c.blocks.withValue(c.cursorHash, val) do:
return val.blk
Expand Down
2 changes: 1 addition & 1 deletion nimbus/rpc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func installRPC(server: RpcServer,
setupCommonRpc(nimbus.ethNode, conf, server)

if RpcFlag.Eth in flags:
setupServerAPI(serverApi, server)
setupServerAPI(serverApi, server, nimbus.ctx)

# # Tracer is currently disabled
# if RpcFlag.Debug in flags:
Expand Down
Loading

0 comments on commit a45ac7e

Please sign in to comment.