Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/devp2p: implement snap protocol testing #24276

Merged
merged 6 commits into from Feb 4, 2022
Merged

Conversation

holiman
Copy link
Contributor

@holiman holiman commented Jan 23, 2022

This is a WIP

This PR adds support in the devp2p binary to perform testing of the snap protocol.

  • GetAccountRange
  • GetStorageRange
  • GetByteCodes
  • GetTrieNodes

Later on, the idea is to use this functionality for Hive-testing.

Testing locally

In case other client implementors want to try out the testcases, here are two scripts that can be used for running it.

A script to set up the Node Under Test (customize this for your node):

$ cat setup.sh 
geth=~/go/src/github.com/ethereum/go-ethereum/build/bin/geth
ddir=./foo
genesis=~/go/src/github.com/ethereum/go-ethereum/cmd/devp2p/internal/ethtest/testdata/genesis.json
chain=~/go/src/github.com/ethereum/go-ethereum/cmd/devp2p/internal/ethtest/testdata/halfchain.rlp

set -e

rm -rf $ddir
# init
$geth --datadir $ddir --nodiscover --nat=none --networkid 19763 --verbosity 5 init $genesis
# import 
$geth --datadir $ddir --nodiscover --nat=none --networkid 19763 --verbosity 5 import $chain
# run
$geth --datadir $ddir --nodiscover --nat=none --networkid 19763 --verbosity 5 --nodekeyhex 1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff console

And this is how I run the tests:

$ cat testit.sh 
devp2p=~/go/src/github.com/ethereum/go-ethereum/devp2p
genesis=~/go/src/github.com/ethereum/go-ethereum/cmd/devp2p/internal/ethtest/testdata/genesis.json
chain=~/go/src/github.com/ethereum/go-ethereum/cmd/devp2p/internal/ethtest/testdata/halfchain.rlp


enode="enode://a6c36f0904a863815b366120df8536f0c1477d9213fcc2421a0efa4eae64abf83ac9370090ecfa1acf605a1d96313356b5e15ba238393a939939cadd214d88d2@127.0.0.1:30303"
$devp2p rlpx snap-test $enode $chain $genesis

Snap protocol changes

  1. When 0 bytes are requested in GetAccountRange, this PR returns 1 account instead of 0. In all other cases, e.g. 1 byte, we overflow the bytes, and only stop once overflown. Also, if we return 0 elements, the VerifyRangeProof fails, telling us there are more elements on the right side. So with this change, we're internally consistent. Surfaced in a test.
  2. Before this PR, the GetByteCodes handler used the non-prefixed code lookup. This PR makes it use prefixed lookup, lowering the server side db lookups by a factor of 2. Surfaced in a test.

@holiman holiman marked this pull request as ready for review Jan 24, 2022
@holiman
Copy link
Contributor Author

holiman commented Jan 25, 2022

Triage discussion: the protocol handler changes seem ok

@fjl fjl merged commit 6ce4670 into ethereum:master Feb 4, 2022
1 check passed
sidhujag pushed a commit to syscoin/go-ethereum that referenced this pull request Feb 6, 2022
This also contains some changes to the protocol handler to
make the tests pass.
zsfelfoldi pushed a commit to zsfelfoldi/go-ethereum that referenced this pull request Feb 14, 2022
This also contains some changes to the protocol handler to
make the tests pass.
MariusVanDerWijden pushed a commit to holiman/go-ethereum that referenced this pull request Feb 25, 2022
This also contains some changes to the protocol handler to
make the tests pass.
JacekGlen pushed a commit to JacekGlen/go-ethereum that referenced this pull request May 26, 2022
This also contains some changes to the protocol handler to
make the tests pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants