Skip to content

Commit

Permalink
[DVT-1207][DVT-1208] Fix forkid peering (#186)
Browse files Browse the repository at this point in the history
* fix peering

* update docs

* go mod tidy

* upgrade go-ethereum

* update fork id

* fix ttl

* update logging levels

* fix protocol length

* add block header and body requests to rlpx

* update default fork id

* update docs

* use string again
  • Loading branch information
minhd-vu authored Jan 11, 2024
1 parent 822d658 commit 96494b5
Show file tree
Hide file tree
Showing 42 changed files with 465 additions and 354 deletions.
4 changes: 2 additions & 2 deletions cmd/dbbench/pebbledb.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewWrappedPebbleDB() (*PebbleDBWrapper, error) {
memTableSize := *cacheSize * 1024 * 1024 / 2 / memTableLimit
opt := &pebble.Options{
Cache: pebble.NewCache(int64(*cacheSize * 1024 * 1024)),
MemTableSize: memTableSize,
MemTableSize: uint64(memTableSize),
MemTableStopWritesThreshold: memTableLimit,
MaxConcurrentCompactions: func() int { return runtime.NumCPU() },
Levels: []pebble.LevelOptions{
Expand Down Expand Up @@ -69,7 +69,7 @@ func (p *PebbleDBWrapper) NewIterator() iterator.Iterator {
OnlyReadGuaranteedDurable: false,
UseL6Filters: false,
}
iter := p.handle.NewIter(&io)
iter, _ := p.handle.NewIter(&io)
wrappedIter := WrappedPebbleIterator{iter, &p.Mutex}
return &wrappedIter
}
Expand Down
15 changes: 15 additions & 0 deletions cmd/p2p/sensor/sensor.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/forkid"
"github.com/ethereum/go-ethereum/crypto"
ethp2p "github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/enode"
Expand Down Expand Up @@ -52,9 +53,11 @@ type (
RPC string
GenesisFile string
GenesisHash string
ForkID []byte
DialRatio int
NAT string
QuickStart bool
TTL time.Duration

bootnodes []*enode.Node
nodes []*enode.Node
Expand Down Expand Up @@ -154,6 +157,7 @@ var SensorCmd = &cobra.Command{
ShouldWriteBlockEvents: inputSensorParams.ShouldWriteBlockEvents,
ShouldWriteTransactions: inputSensorParams.ShouldWriteTransactions,
ShouldWriteTransactionEvents: inputSensorParams.ShouldWriteTransactionEvents,
TTL: inputSensorParams.TTL,
})

// Fetch the latest block which will be used later when crafting the status
Expand Down Expand Up @@ -181,6 +185,7 @@ var SensorCmd = &cobra.Command{
Head: &head,
HeadMutex: &sync.RWMutex{},
Count: &p2p.MessageCount{},
ForkID: forkid.ID{Hash: [4]byte(inputSensorParams.ForkID)},
}

config := ethp2p.Config{
Expand Down Expand Up @@ -217,6 +222,10 @@ var SensorCmd = &cobra.Command{
}
defer server.Stop()

events := make(chan *ethp2p.PeerEvent)
sub := server.SubscribeEvents(events)
defer sub.Unsubscribe()

ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()

Expand Down Expand Up @@ -250,6 +259,10 @@ var SensorCmd = &cobra.Command{
// the nodes file.
log.Info().Msg("Stopping sensor...")
return nil
case event := <-events:
log.Debug().Any("event", event).Send()
case err := <-sub.Err():
log.Error().Err(err).Send()
}
}
},
Expand Down Expand Up @@ -319,6 +332,7 @@ significantly increase CPU and memory usage.`)
SensorCmd.Flags().StringVar(&inputSensorParams.RPC, "rpc", "https://polygon-rpc.com", "RPC endpoint used to fetch the latest block")
SensorCmd.Flags().StringVar(&inputSensorParams.GenesisFile, "genesis", "genesis.json", "Genesis file")
SensorCmd.Flags().StringVar(&inputSensorParams.GenesisHash, "genesis-hash", "0xa9c28ce2141b56c474f1dc504bee9b01eb1bd7d1a507580d5519d4437a97de1b", "The genesis block hash")
SensorCmd.Flags().BytesHexVar(&inputSensorParams.ForkID, "fork-id", []byte{220, 8, 134, 92}, "The hex encoded fork id (omit the 0x)")
SensorCmd.Flags().IntVar(&inputSensorParams.DialRatio, "dial-ratio", 0,
`Ratio of inbound to dialed connections. A dial ratio of 2 allows 1/2 of
connections to be dialed. Setting this to 0 defaults it to 3.`)
Expand All @@ -328,4 +342,5 @@ connections to be dialed. Setting this to 0 defaults it to 3.`)
This produces faster development cycles but can prevent the sensor from being to
connect to new peers if the nodes.json file is large.`)
SensorCmd.Flags().StringVar(&inputSensorParams.TrustedNodesFile, "trusted-nodes", "", "Trusted nodes file")
SensorCmd.Flags().DurationVar(&inputSensorParams.TTL, "ttl", 14*24*time.Hour, "Time to live")
}
3 changes: 2 additions & 1 deletion cmd/p2p/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ polycli p2p sensor nodes.json \
--network-id 80001 \
--sensor-id sensor \
--rpc "https://polygon-mumbai-bor.publicnode.com" \
--genesis-hash 0x7b66506a9ebdbf30d32b43c5f15a3b1216269a1ec3a75aa3182b86176a2b1ca7
--genesis-hash 0x7b66506a9ebdbf30d32b43c5f15a3b1216269a1ec3a75aa3182b86176a2b1ca7 \
--fork-id 0c015a91
```

### Crawl
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func NewPolycliCommand() *cobra.Command {

// Define flags and configuration settings.
cmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.polygon-cli.yaml)")
cmd.PersistentFlags().IntVarP(&verbosity, "verbosity", "v", 400, "0 - Silent\n100 Fatal\n200 Error\n300 Warning\n400 Info\n500 Debug\n600 Trace")
cmd.PersistentFlags().IntVarP(&verbosity, "verbosity", "v", 500, "0 - Silent\n100 Panic\n200 Fatal\n300 Error\n400 Warning\n500 Info\n600 Debug\n700 Trace")
cmd.PersistentFlags().BoolVar(&pretty, "pretty-logs", true, "Should logs be in pretty format or JSON")

// Define local flags which will only run when this action is called directly.
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ Polycli is a collection of tools that are meant to be useful while building, tes
--pretty-logs Should logs be in pretty format or JSON (default true)
-t, --toggle Help message for toggle
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```

## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_abi.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,13 @@ The command also inherits flags from parent commands.
--config string config file (default is $HOME/.polygon-cli.yaml)
--pretty-logs Should logs be in pretty format or JSON (default true)
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```

## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_abi_decode.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ The command also inherits flags from parent commands.
--config string config file (default is $HOME/.polygon-cli.yaml)
--pretty-logs Should logs be in pretty format or JSON (default true)
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```

## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_abi_encode.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ The command also inherits flags from parent commands.
--config string config file (default is $HOME/.polygon-cli.yaml)
--pretty-logs Should logs be in pretty format or JSON (default true)
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```

## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_dbbench.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,13 @@ The command also inherits flags from parent commands.
--config string config file (default is $HOME/.polygon-cli.yaml)
--pretty-logs Should logs be in pretty format or JSON (default true)
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```
## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_dumpblocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ The command also inherits flags from parent commands.
--config string config file (default is $HOME/.polygon-cli.yaml)
--pretty-logs Should logs be in pretty format or JSON (default true)
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```
## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_enr.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ The command also inherits flags from parent commands.
--config string config file (default is $HOME/.polygon-cli.yaml)
--pretty-logs Should logs be in pretty format or JSON (default true)
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```
## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_fork.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ The command also inherits flags from parent commands.
--config string config file (default is $HOME/.polygon-cli.yaml)
--pretty-logs Should logs be in pretty format or JSON (default true)
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```

## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_fund.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,13 @@ The command also inherits flags from parent commands.
--config string config file (default is $HOME/.polygon-cli.yaml)
--pretty-logs Should logs be in pretty format or JSON (default true)
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```

## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_hash.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ The command also inherits flags from parent commands.
--config string config file (default is $HOME/.polygon-cli.yaml)
--pretty-logs Should logs be in pretty format or JSON (default true)
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```

## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_loadtest.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,13 @@ The command also inherits flags from parent commands.
--config string config file (default is $HOME/.polygon-cli.yaml)
--pretty-logs Should logs be in pretty format or JSON (default true)
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```
## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_loadtest_uniswapv3.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ The command also inherits flags from parent commands.
--to-address string The address that we're going to send to (default "0xDEADBEEFDEADBEEFDEADBEEFDEADBEEFDEADBEEF")
--to-random When doing a transfer test, should we send to random addresses rather than DEADBEEFx5
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```
## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_metrics-to-dash.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ The command also inherits flags from parent commands.
--config string config file (default is $HOME/.polygon-cli.yaml)
--pretty-logs Should logs be in pretty format or JSON (default true)
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```

## See also
Expand Down
13 changes: 7 additions & 6 deletions doc/polycli_mnemonic.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ The command also inherits flags from parent commands.
--config string config file (default is $HOME/.polygon-cli.yaml)
--pretty-logs Should logs be in pretty format or JSON (default true)
-v, --verbosity int 0 - Silent
100 Fatal
200 Error
300 Warning
400 Info
500 Debug
600 Trace (default 400)
100 Panic
200 Fatal
300 Error
400 Warning
500 Info
600 Debug
700 Trace (default 500)
```

## See also
Expand Down
Loading

0 comments on commit 96494b5

Please sign in to comment.