mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2025-01-18 08:38:46 +00:00
ef84972e7c
This PR mirrors https://github.com/testinprod-io/op-erigon/pull/54. Actual implementation for `admin_addPeer` method. RPC Spec: Refer to https://geth.ethereum.org/docs/interacting-with-geth/rpc/ns-admin. > The addPeer administrative method requests adding a new remote node to the list of tracked static nodes. The node will try to maintain connectivity to these nodes at all times, reconnecting every once in a while if the remote connection goes down. Requires https://github.com/ledgerwatch/erigon-lib/pull/1033/ After https://github.com/ledgerwatch/erigon-lib/pull/1033 is merged, will update erigon-lib version, removing replace at go.mod. Note that even if RPC response returns `true`, it does not guarantee that RLPx protocol is established between peers. It just adds node entrypoint to its static peer list, and periodically tries and tests connections. ## Testing This RPC needs integration testing, so I made some scenario. Use below command for testing: Spin up two dev nodes which p2p enabled: Start Node 1: RPC running at port 8545: ```sh ./build/bin/erigon --datadir=dev --chain=dev --port=30303 --http.port=8545 --authrpc.port=8551 --torrent.port=42069 --no-downloader --nodiscover --private.api.addr=127.0.0.1:9090 --http --ws --http.api=admin --p2p.allowed-ports=30306,30307,30308 --authrpc.jwtsecret=/tmp/jwt1 --p2p.protocol=67,68 --log.console.verbosity=5 ``` Start Node 2: RPC running at port 8546: ```sh ./build/bin/erigon --datadir=dev2 --chain=dev --port=30304 --http.port=8546 --authrpc.port=8552 --torrent.port=42068 --no-downloader --nodiscover --private.api.addr=127.0.0.1:9091 --http --ws --http.api=admin --p2p.allowed-ports=30309,30310,30311 --authrpc.jwtsecret=/tmp/jwt2 --p2p.protocol=67,68 --log.console.verbosity=5 ``` Get nodeInfo of node 1 using `admin_nodeInfo` RPC: ```sh curl --location 'localhost:8545/' \ --header 'Content-Type: application/json' \ --data '{ "jsonrpc":"2.0", "method":"admin_nodeInfo", "params":[], "id":1 }' ``` Example response: ``` { "jsonrpc": "2.0", "id": 1, "result": { "id": "b75e0c4d2113b6f144ea8fd356a8f90e612a2a5f48a13c78d7e0e176e5724eb2", "name": "erigon/v2.47.0-dev-5d86cdb5/darwin-arm64/go1.19.6", "enode": "enode://05ab575d947f2d73065ea0f795dc2d96ed0ad603f3e730ab90dc881122d552c9f59ffcb148fe50546bec8b319daeb3c22ec02e7d12a7c4f2ac4cd26456a04a7c@127.0.0.1:30303?discport=0", ... ``` Get nodeInfo of node 2 using `admin_nodeInfo` RPC: ```sh curl --location 'localhost:8546/' \ --header 'Content-Type: application/json' \ --data '{ "jsonrpc":"2.0", "method":"admin_nodeInfo", "params":[], "id":2 }' ``` Example response: ``` { "jsonrpc": "2.0", "id": 2, "result": { "id": "32d721e4d75219b021d7f83235f1f1eb8b705d6f85e634bccde564b8f7f94d78", "name": "erigon/v2.47.0-dev-5d86cdb5/darwin-arm64/go1.19.6", "enode": "enode://1abb8579647779e13b7f68d18f9c776cbd29281841c7f950e9cf9afa996e31120a6f481cea8e90e0f42a0eb1aa00aeafee81c4bae6c31aa16810b795c6d6e069@127.0.0.1:30304?discport=0", ... ``` Call `admin_addPeer` RPC to node 2: ```sh curl --location 'localhost:8546/' \ --header 'Content-Type: application/json' \ --data '{ "jsonrpc":"2.0", "method":"admin_addPeer", "params":["enode://05ab575d947f2d73065ea0f795dc2d96ed0ad603f3e730ab90dc881122d552c9f59ffcb148fe50546bec8b319daeb3c22ec02e7d12a7c4f2ac4cd26456a04a7c@127.0.0.1:30303"], "id":2 }' ``` Example response: ``` { "jsonrpc": "2.0", "id": 2, "result": true } ``` Check peer info of node 1 using `admin_peers` RPC: ```sh curl --location 'localhost:8545/' \ --header 'Content-Type: application/json' \ --data '{ "jsonrpc":"2.0", "method":"admin_peers", "params":[], "id":1 }' ``` Example response: ``` { "jsonrpc": "2.0", "id": 1, "result": [ { "enode": "enode://1abb8579647779e13b7f68d18f9c776cbd29281841c7f950e9cf9afa996e31120a6f481cea8e90e0f42a0eb1aa00aeafee81c4bae6c31aa16810b795c6d6e069@127.0.0.1:55426", "id": "32d721e4d75219b021d7f83235f1f1eb8b705d6f85e634bccde564b8f7f94d78", "name": "erigon/v2.47.0-dev-5d86cdb5/darwin-arm64/go1.19.6", "caps": [ "eth/66", "eth/67" ], "network": { "localAddress": "127.0.0.1:30303", "remoteAddress": "127.0.0.1:55426", "inbound": true, "trusted": false, "static": false }, "protocols": null } ] } ``` --------- Co-authored-by: alex.sharov <AskAlexSharov@gmail.com> |
||
---|---|---|
.. | ||
contracts | ||
admin_api.go | ||
bor_api.go | ||
bor_helper.go | ||
bor_snapshot.go | ||
call_traces_test.go | ||
corner_cases_support_test.go | ||
daemon.go | ||
db_api_deprecated.go | ||
debug_api_test.go | ||
debug_api.go | ||
erigon_api.go | ||
erigon_block.go | ||
erigon_cache_check.go | ||
erigon_nodeInfo.go | ||
erigon_receipts_test.go | ||
erigon_receipts.go | ||
erigon_system.go | ||
error_messages.go | ||
eth_accounts.go | ||
eth_api_test.go | ||
eth_api.go | ||
eth_block_test.go | ||
eth_block.go | ||
eth_call_test.go | ||
eth_call.go | ||
eth_callMany_test.go | ||
eth_callMany.go | ||
eth_deprecated.go | ||
eth_filters_test.go | ||
eth_filters.go | ||
eth_mining_test.go | ||
eth_mining.go | ||
eth_receipts.go | ||
eth_subscribe_test.go | ||
eth_system_test.go | ||
eth_system.go | ||
eth_txs.go | ||
eth_uncles.go | ||
gen_traces_test.go | ||
get_chain_config_test.go | ||
graphql_api.go | ||
net_api.go | ||
otterscan_api.go | ||
otterscan_block_details.go | ||
otterscan_contract_creator_test.go | ||
otterscan_contract_creator.go | ||
otterscan_default_tracer.go | ||
otterscan_generic_tracer.go | ||
otterscan_has_code.go | ||
otterscan_search_backward_multi_test.go | ||
otterscan_search_backward_test.go | ||
otterscan_search_backward.go | ||
otterscan_search_forward_multi_test.go | ||
otterscan_search_forward_test.go | ||
otterscan_search_forward.go | ||
otterscan_search_multi.go | ||
otterscan_search_test.go | ||
otterscan_search_trace.go | ||
otterscan_trace_contract_creator.go | ||
otterscan_trace_operations.go | ||
otterscan_trace_touch.go | ||
otterscan_trace_transaction.go | ||
otterscan_transaction_by_sender_and_nonce_test.go | ||
otterscan_transaction_by_sender_and_nonce.go | ||
otterscan_transaction_error.go | ||
otterscan_types.go | ||
parity_api_test.go | ||
parity_api.go | ||
send_transaction_test.go | ||
send_transaction.go | ||
storage_range.go | ||
trace_adhoc_test.go | ||
trace_adhoc.go | ||
trace_api.go | ||
trace_filtering.go | ||
trace_types.go | ||
tracing.go | ||
txpool_api_test.go | ||
txpool_api.go | ||
validator_set.go | ||
web3_api.go |