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

Rework p2p req resp protocol #11781

Open
wants to merge 50 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
81ce6bd
Herp
anacrolix Aug 19, 2024
170f39f
Add test demonstrating inability to sync in reasonable time
anacrolix Aug 29, 2024
4ed047e
Extreme test passes
anacrolix Aug 29, 2024
a897178
Trim just check output
anacrolix Aug 30, 2024
7868a30
Pass payload source in L2PayloadIn
anacrolix Aug 30, 2024
af7761d
Improve debugging of peer efficiency
anacrolix Aug 30, 2024
5c6b312
Maintain a single active range request
anacrolix Aug 30, 2024
681ad9a
Fix active range request ID handling
anacrolix Aug 30, 2024
02f7aff
Restore results chan for now
anacrolix Aug 30, 2024
6fcb95d
Merge branch 'develop' into anacrolix/p2p-req-resp
anacrolix Sep 2, 2024
e4e5dd2
Everything stable
anacrolix Sep 2, 2024
9969026
Fix TestMultiPeerSync
anacrolix Sep 2, 2024
d9c899e
Move SyncClient.mu closer to its fields
anacrolix Sep 2, 2024
9e2baa5
Revert to go1.21
anacrolix Sep 3, 2024
bbd9877
go1.22...
anacrolix Sep 3, 2024
c850a51
Add just test-components
anacrolix Sep 3, 2024
9cb665b
Expose P2P sync config
anacrolix Sep 3, 2024
4788b58
Switch op-stack-go Dockerfile to go1.22
anacrolix Sep 3, 2024
ce688cd
Merge branch 'develop' into anacrolix/new-p2p-req-resp
anacrolix Sep 4, 2024
6170149
Group sync client request state
anacrolix Sep 4, 2024
690ee60
Retry promoted blocks that are requested again
anacrolix Sep 4, 2024
deac586
Merge remote-tracking branch 'origin/develop' into anacrolix/new-p2p-…
anacrolix Sep 4, 2024
c6dd233
Move all the new alt sync test code into a new file
anacrolix Sep 6, 2024
bdb4728
Tidy up comments
anacrolix Sep 6, 2024
1f4f8a9
Handle the case where the range changes or next promote target change…
anacrolix Sep 6, 2024
73964b6
Set anacrolix/{chansync,sync} tagged versions
anacrolix Sep 6, 2024
25ad57e
go1.21 support
anacrolix Sep 6, 2024
3c5bf67
Try to tap into the forkchoice update event to trigger alt sync
anacrolix Sep 6, 2024
59cf37f
Merge branch 'develop' into anacrolix/p2p-req-resp
anacrolix Sep 6, 2024
e16d7e8
Merge branch 'develop' into anacrolix/p2p-req-resp
anacrolix Sep 9, 2024
7f12b76
Fix lints
anacrolix Sep 9, 2024
445f552
Reduce diff
anacrolix Sep 9, 2024
3370816
Fixes with removed custom peer IDs
anacrolix Sep 9, 2024
2f0d61a
lint
anacrolix Sep 9, 2024
9316902
Remove stringly typed payload checks to avoid type mismatches in testify
anacrolix Sep 9, 2024
41b6cb0
Tidy
anacrolix Sep 9, 2024
f6c5236
Tidy
anacrolix Sep 9, 2024
c5eefe1
Move peer ID into syncClientPeer
anacrolix Sep 9, 2024
ab05aa2
Disable stdout debugging
anacrolix Sep 9, 2024
fccd892
lint
anacrolix Sep 9, 2024
d7fbb3a
Put request reservation in another frame to simplify logic
anacrolix Sep 9, 2024
d35d700
Fix @tynes nits
anacrolix Sep 11, 2024
8ae2217
Address the final hash unused I spotted with @seb
anacrolix Sep 13, 2024
aa9c491
Pass wanted from parent rather than looking it up again
anacrolix Sep 13, 2024
0f2c725
Fix spotted race
anacrolix Sep 13, 2024
45c5747
Limit quarantined payload count
anacrolix Sep 13, 2024
d620512
Merge remote-tracking branch 'origin/develop' into anacrolix/p2p-req-…
anacrolix Sep 18, 2024
6b9af4e
Remove unnecessary docker change
anacrolix Sep 18, 2024
598d0f0
Tidy up debug deps and unsigned wrapping
anacrolix Sep 18, 2024
cc64a80
lint
anacrolix Sep 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,7 @@ devnet-logs: ## Displays logs for the local devnet
.PHONY: devnet-logs

test-unit: ## Runs unit tests for all components
make -C ./op-node test
make -C ./op-proposer test
make -C ./op-batcher test
make -C ./op-e2e test
just test-components
(cd packages/contracts-bedrock && just test)
.PHONY: test-unit

Expand Down
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ go 1.21

require (
github.com/BurntSushi/toml v1.4.0
github.com/anacrolix/chansync v0.6.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How important is it to use these packages? We need to be really sure when adding new packages to be certain there aren't backdoors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I definitely need chansync or I'd just end up duplicating all that again.

Some of the generic stuff is exceptionally useful for avoiding a lot of verbosity in Go.

The rest I was using for debugging.

github.com/anacrolix/generics v0.0.3-0.20240902042256-7fb2702ef0ca
github.com/andybalholm/brotli v1.1.0
github.com/btcsuite/btcd v0.24.2
github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0
Expand Down Expand Up @@ -46,7 +48,7 @@ require (
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.4
golang.org/x/crypto v0.27.0
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948
golang.org/x/sync v0.8.0
golang.org/x/term v0.24.0
golang.org/x/time v0.6.0
Expand All @@ -59,6 +61,9 @@ require (
github.com/VictoriaMetrics/fastcache v1.12.2 // indirect
github.com/adrg/xdg v0.4.0 // indirect
github.com/allegro/bigcache v1.2.1 // indirect
github.com/anacrolix/envpprof v1.3.0 // indirect
github.com/anacrolix/missinggo/v2 v2.7.4-0.20240902050650-7985420302c7 // indirect
github.com/anacrolix/sync v0.5.2 // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand Down Expand Up @@ -127,6 +132,7 @@ require (
github.com/hashicorp/raft-boltdb v0.0.0-20231211162105-6c830fa4535e // indirect
github.com/holiman/billy v0.0.0-20240216141850-2abb0c79d3c4 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/influxdata/influxdb-client-go/v2 v2.4.0 // indirect
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c // indirect
Expand Down
168 changes: 166 additions & 2 deletions go.sum

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ check-slither:

upgrade-slither:
jq '.slither = $v' --arg v $(just print-slither) <<<$(cat versions.json) > versions.json

check:
go test -failfast -run @ ./... > /dev/null

# Run unit tests for all components.
test-components:
go test -failfast ./op-{node,proposer,batcher,e2e}/...
6 changes: 3 additions & 3 deletions op-bootnode/bootnode/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

type gossipNoop struct{}

func (g *gossipNoop) OnUnsafeL2Payload(_ context.Context, _ peer.ID, _ *eth.ExecutionPayloadEnvelope) error {
func (g *gossipNoop) OnUnsafeL2Payload(_ context.Context, _ peer.ID, _ *eth.ExecutionPayloadEnvelope, _ p2p.PayloadSource) error {
return nil
}

Expand Down Expand Up @@ -62,9 +62,9 @@ func Main(cliCtx *cli.Context) error {
if err != nil {
return fmt.Errorf("failed to load p2p config: %w", err)
}
if p2pConfig.EnableReqRespSync {
if p2pConfig.ReqRespSync.Enabled {
logger.Warn("req-resp sync is enabled, bootnode does not support this feature")
p2pConfig.EnableReqRespSync = false
p2pConfig.ReqRespSync.Enabled = false
}

p2pNode, err := p2p.NewNodeP2P(ctx, config, logger, p2pConfig, &gossipNoop{}, &l2Chain{}, &gossipConfig{}, m, false)
Expand Down
9 changes: 8 additions & 1 deletion op-e2e/e2eutils/opnode/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package opnode
import (
"context"

"github.com/ethereum-optimism/optimism/op-node/p2p"

"github.com/libp2p/go-libp2p/core/peer"

"github.com/ethereum-optimism/optimism/op-node/node"
Expand All @@ -12,6 +14,7 @@ import (
type FnTracer struct {
OnNewL1HeadFn func(ctx context.Context, sig eth.L1BlockRef)
OnUnsafeL2PayloadFn func(ctx context.Context, from peer.ID, payload *eth.ExecutionPayloadEnvelope)
L2PayloadInFunc p2p.L2PayloadInFunc
OnPublishL2PayloadFn func(ctx context.Context, payload *eth.ExecutionPayloadEnvelope)
}

Expand All @@ -21,10 +24,14 @@ func (n *FnTracer) OnNewL1Head(ctx context.Context, sig eth.L1BlockRef) {
}
}

func (n *FnTracer) OnUnsafeL2Payload(ctx context.Context, from peer.ID, payload *eth.ExecutionPayloadEnvelope) {
func (n *FnTracer) OnUnsafeL2Payload(ctx context.Context, from peer.ID, payload *eth.ExecutionPayloadEnvelope, source p2p.PayloadSource) error {
if n.OnUnsafeL2PayloadFn != nil {
n.OnUnsafeL2PayloadFn(ctx, from, payload)
}
if n.L2PayloadInFunc != nil {
return n.L2PayloadInFunc(ctx, from, payload, source)
}
return nil
}

func (n *FnTracer) OnPublishL2Payload(ctx context.Context, payload *eth.ExecutionPayloadEnvelope) {
Expand Down
10 changes: 5 additions & 5 deletions op-e2e/system/e2esys/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ type SystemConfig struct {
P2PTopology map[string][]string

// Enables req-resp sync in the P2P nodes
P2PReqRespSync bool
P2PReqRespSync p2p.ReqRespSyncConfig

// If the proposer can make proposals for L2 blocks derived from L1 blocks which are not finalized on L1 yet.
NonFinalizedProposals bool
Expand Down Expand Up @@ -674,10 +674,10 @@ func (cfg SystemConfig) Start(t *testing.T, _opts ...SystemConfigOption) (*Syste
// TODO we can enable discv5 in the testnodes to test discovery of new peers.
// Would need to mock though, and the discv5 implementation does not provide nice mocks here.
p := &p2p.Prepared{
HostP2P: h,
LocalNode: nil,
UDPv5: nil,
EnableReqRespSync: cfg.P2PReqRespSync,
HostP2P: h,
LocalNode: nil,
UDPv5: nil,
ReqRespSync: cfg.P2PReqRespSync,
}
p2pNodes[name] = p
return p, nil
Expand Down
Loading
Loading