Skip to content

Commit

Permalink
fix devp2p (#473)
Browse files Browse the repository at this point in the history
* fix devp2p

* add new acc for devp2p genesis
  • Loading branch information
error2215 authored Feb 29, 2024
1 parent 03bdb5a commit ca313e5
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 14 deletions.
7 changes: 5 additions & 2 deletions cmd/devp2p/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ unintended connections to the global DHT is listening on `127.0.0.1`.

Now get the ENR of your node and store it in the `NODE` environment variable.

Start the test by running `devp2p discv5 test -listen1 127.0.0.1 -listen2 127.0.0.2 $NODE`.
Start the test by running `devp2p discv5 test -listen1 127.0.0.1 -listen2 127.0.0.2 $NODE`.

For discv4 tests run the node locally and then start the test by running
`./devp2p discv4 test -remote {ENR}`

### Xcb Protocol Test Suite

Expand All @@ -96,7 +99,7 @@ gocore --datadir <datadir> --nodiscover --nat=none --networkid 19763 --verbosity

Then, run the following command, replacing `<enode ID>` with the enode of the gocore node:
```
devp2p rlpx xcb-test <enode ID> cmd/devp2p/internal/xcbtest/testdata/fullchain.rlp cmd/devp2p/internal/xcbtest/testdata/genesis.json
devp2p rlpx xcb-test <enode ID> cmd/devp2p/internal/xcbtest/testdata/chain.rlp cmd/devp2p/internal/xcbtest/testdata/genesis.json
```

[xcb]: https://github.com/core/devp2p/blob/master/caps/xcb.md
Expand Down
6 changes: 2 additions & 4 deletions cmd/devp2p/internal/xcbtest/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ func loadChain(chainfile string, genesis string) (*Chain, error) {
if err := json.Unmarshal(chainConfig, &gen); err != nil {
return nil, err
}
gblock := gen.ToBlock(nil)

// Load chain.rlp.
fh, err := os.Open(chainfile)
Expand All @@ -147,16 +146,15 @@ func loadChain(chainfile string, genesis string) (*Chain, error) {
}
}
stream := rlp.NewStream(reader, 0)
var blocks = make([]*types.Block, 1)
blocks[0] = gblock
var blocks = make([]*types.Block, 0)
for i := 0; ; i++ {
var b types.Block
if err := stream.Decode(&b); err == io.EOF {
break
} else if err != nil {
return nil, fmt.Errorf("at block index %d: %v", i, err)
}
if b.NumberU64() != uint64(i+1) {
if b.NumberU64() != uint64(i) {
return nil, fmt.Errorf("block at index %d has wrong number %d", i, b.NumberU64())
}
blocks = append(blocks, &b)
Expand Down
4 changes: 3 additions & 1 deletion cmd/devp2p/internal/xcbtest/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/stretchr/testify/assert"

"github.com/core-coin/go-core/v2/common"
"github.com/core-coin/go-core/v2/p2p"
)

Expand Down Expand Up @@ -74,7 +75,7 @@ func TestXcbProtocolNegotiation(t *testing.T) {
// TestChain_GetHeaders tests whether the test suite can correctly
// respond to a GetBlockHeaders request from a node.
func TestChain_GetHeaders(t *testing.T) {
t.Skip("")
common.DefaultNetworkID = 19763
chainFile, err := filepath.Abs("./testdata/chain.rlp")
if err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -149,4 +150,5 @@ func TestChain_GetHeaders(t *testing.T) {
assert.Equal(t, headers, tt.expected)
})
}
common.DefaultNetworkID = 1
}
5 changes: 2 additions & 3 deletions cmd/devp2p/internal/xcbtest/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewSuite(dest *enode.Node, chainfile string, genesisfile string) *Suite {
}
return &Suite{
Dest: dest,
chain: chain.Shorten(1000),
chain: chain.Shorten(11),
fullChain: chain,
}
}
Expand Down Expand Up @@ -181,7 +181,7 @@ func (s *Suite) TestGetBlockBodies(t *utesting.T) {
conn.handshake(t)
conn.statusExchange(t, s.chain, nil)
// create block bodies request
req := &GetBlockBodies{s.chain.blocks[54].Hash(), s.chain.blocks[75].Hash()}
req := &GetBlockBodies{s.chain.blocks[4].Hash(), s.chain.blocks[8].Hash()}
if err := conn.Write(req); err != nil {
t.Fatalf("could not write to connection: %v", err)
}
Expand Down Expand Up @@ -405,7 +405,6 @@ func (s *Suite) dial() (*Conn, error) {
func (s *Suite) TestTransaction(t *utesting.T) {
tests := []*types.Transaction{
getNextTxFromChain(t, s),
unknownTx(t, s),
}
for i, tx := range tests {
t.Logf("Testing tx propagation: %v\n", i)
Expand Down
Binary file modified cmd/devp2p/internal/xcbtest/testdata/chain.rlp
100644 → 100755
Binary file not shown.
9 changes: 6 additions & 3 deletions cmd/devp2p/internal/xcbtest/testdata/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
"timestamp": "0x0",
"extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
"energyLimit": "0x80000000",
"difficulty": "0x20000",
"coinbase": "0x0000000000000000000000000000000000000000",
"difficulty": "0x20",
"coinbase": "ce450000000000000000000000000000000000000000",
"alloc": {
"71562b71999873db5b286df957af199ec94617f7": {
"ce9571562b71999873db5b286df957af199ec94617f7": {
"balance": "0xffffffffffffffffffffffffff"
},
"ce65db416ff2f9c53dabaf34f81142db30350ea7b144": {
"balance": "0xffffffffffffffffffffffffff"
}
},
Expand Down
Binary file modified cmd/devp2p/internal/xcbtest/testdata/halfchain.rlp
100644 → 100755
Binary file not shown.
2 changes: 1 addition & 1 deletion cmd/devp2p/internal/xcbtest/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func sendSuccessfulTx(t *utesting.T, s *Suite, tx *types.Transaction) {
t.Fatalf("received transactions do not match send: %v", txHashes)
}
if tx.Hash() != txHashes[len(txHashes)-1] {
t.Fatalf("wrong announcement received, wanted %v got %v", tx, txHashes)
t.Fatalf("wrong announcement received, wanted %v got %v", tx.Hash().Hex(), common.Bytes2Hex(txHashes[len(txHashes)-1][:]))
}
default:
t.Fatalf("unexpected message in sendSuccessfulTx: %s", pretty.Sdump(msg))
Expand Down
2 changes: 2 additions & 0 deletions cmd/devp2p/rlpxcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"gopkg.in/urfave/cli.v1"

xcbtest "github.com/core-coin/go-core/v2/cmd/devp2p/internal/xcbtest"
"github.com/core-coin/go-core/v2/common"
"github.com/core-coin/go-core/v2/crypto"
"github.com/core-coin/go-core/v2/p2p"
"github.com/core-coin/go-core/v2/p2p/rlpx"
Expand Down Expand Up @@ -96,6 +97,7 @@ func rlpxXcbTest(ctx *cli.Context) error {
if ctx.NArg() < 3 {
exit("missing path to chain.rlp as command-line argument")
}
common.DefaultNetworkID = 19763
suite := xcbtest.NewSuite(getNodeArg(ctx), ctx.Args()[1], ctx.Args()[2])
return runTests(ctx, suite.AllTests())
}

0 comments on commit ca313e5

Please sign in to comment.