Skip to content

Commit af17d5c

Browse files
sync: coreth PR #1141: update tx gossip rate limit dynamically (#1716)
1 parent 1cc49ae commit af17d5c

File tree

10 files changed

+158
-95
lines changed

10 files changed

+158
-95
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
- name: Setup Contracts
9898
run: ./scripts/run_task.sh setup-contracts
9999
- name: Run Warp E2E Tests
100-
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@4f5acfc0485a8203bc4fedd76c73889fd12d43ca
100+
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@c2563d13031197962d20f25b576560d029c5125c
101101
with:
102102
run: ./scripts/run_task.sh test-e2e-warp-ci
103103
artifact_prefix: warp
@@ -118,7 +118,7 @@ jobs:
118118
with:
119119
go-version-file: "go.mod"
120120
- name: Run E2E Load Tests
121-
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@4f5acfc0485a8203bc4fedd76c73889fd12d43ca
121+
uses: ava-labs/avalanchego/.github/actions/run-monitored-tmpnet-cmd@c2563d13031197962d20f25b576560d029c5125c
122122
with:
123123
run: ./scripts/run_task.sh test-e2e-load-ci
124124
artifact_prefix: load

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ go 1.23.9
55
require (
66
github.com/VictoriaMetrics/fastcache v1.12.1
77
github.com/antithesishq/antithesis-sdk-go v0.3.8
8-
github.com/ava-labs/avalanchego v1.13.5-rc.0
9-
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.11
8+
github.com/ava-labs/avalanchego v1.13.5
9+
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.12
1010
github.com/ava-labs/libevm v1.13.14-0.3.0.rc.6
1111
github.com/davecgh/go-spew v1.1.1
1212
github.com/deckarep/golang-set/v2 v2.1.0
@@ -46,7 +46,7 @@ require (
4646
github.com/DataDog/zstd v1.5.2 // indirect
4747
github.com/Microsoft/go-winio v0.6.1 // indirect
4848
github.com/StephenButtolph/canoto v0.17.1 // indirect
49-
github.com/ava-labs/coreth v0.15.3-rc.5 // indirect
49+
github.com/ava-labs/coreth v0.15.4-rc.3 // indirect
5050
github.com/beorn7/perks v1.0.1 // indirect
5151
github.com/bits-and-blooms/bitset v1.10.0 // indirect
5252
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ github.com/antithesishq/antithesis-sdk-go v0.3.8/go.mod h1:IUpT2DPAKh6i/YhSbt6Gl
2424
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
2525
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
2626
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
27-
github.com/ava-labs/avalanchego v1.13.5-rc.0 h1:73nIYhUoiwtjzlxWugvPlNkfCtsozRTwnhIxz3kO5og=
28-
github.com/ava-labs/avalanchego v1.13.5-rc.0/go.mod h1:I4AHk5hn0sbzF0rEbi/C9ql+u9sttiVIHSgDcVvMtPg=
29-
github.com/ava-labs/coreth v0.15.3-rc.5 h1:zGk1LaFeZOEkA6uPF1g9BNCjbZOrONx9fm5WtiH5NWg=
30-
github.com/ava-labs/coreth v0.15.3-rc.5/go.mod h1:sEqzSu2f4FJEGFL7CP3zNOQtQ0MupWJdzTp7W65EDf8=
31-
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.11 h1:V9XDirIJ0oveor+sAPuOB0WMQ+b7FoDStScMdyGlBQ4=
32-
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.11/go.mod h1:cq89ua3iiZ5wPBALTEQS5eG8DIZcs7ov6OiL4YR1BVY=
27+
github.com/ava-labs/avalanchego v1.13.5 h1:uOZDhGOdwITPXA496KwF9RNBheEq3pOH4w7w+QLValo=
28+
github.com/ava-labs/avalanchego v1.13.5/go.mod h1:/eugkYcDQfCt9czHr/Jlw3MW/1DIoI7Cm0maqNkuWMs=
29+
github.com/ava-labs/coreth v0.15.4-rc.3 h1:v33OOerxpGIKa1MpljXMBB3Yljy23xzsez3E/dn7TzY=
30+
github.com/ava-labs/coreth v0.15.4-rc.3/go.mod h1:Esb0FK+KJr6co7rrhtBWsmSMXEL5JWelEsijlqAHdq0=
31+
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.12 h1:aMcrLbpJ/dyu2kZDf/Di/4JIWsUcYPyTDKymiHpejt0=
32+
github.com/ava-labs/firewood-go-ethhash/ffi v0.0.12/go.mod h1:cq89ua3iiZ5wPBALTEQS5eG8DIZcs7ov6OiL4YR1BVY=
3333
github.com/ava-labs/libevm v1.13.14-0.3.0.rc.6 h1:tyM659nDOknwTeU4A0fUVsGNIU7k0v738wYN92nqs/Y=
3434
github.com/ava-labs/libevm v1.13.14-0.3.0.rc.6/go.mod h1:zP/DOcABRWargBmUWv1jXplyWNcfmBy9cxr0lw3LW3g=
3535
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=

network/network.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ type Network interface {
8585
Size() uint32
8686

8787
// NewClient returns a client to send messages with for the given protocol
88-
NewClient(protocol uint64, options ...p2p.ClientOption) *p2p.Client
88+
NewClient(protocol uint64) *p2p.Client
8989
// AddHandler registers a server handler for an application protocol
9090
AddHandler(protocol uint64, handler p2p.Handler) error
9191

@@ -127,7 +127,19 @@ func NewNetwork(
127127
maxActiveAppRequests int64,
128128
registerer prometheus.Registerer,
129129
) (Network, error) {
130-
p2pNetwork, err := p2p.NewNetwork(ctx.Log, appSender, registerer, "p2p")
130+
p2pValidators := p2p.NewValidators(
131+
ctx.Log,
132+
ctx.SubnetID,
133+
ctx.ValidatorState,
134+
maxValidatorSetStaleness,
135+
)
136+
p2pNetwork, err := p2p.NewNetwork(
137+
ctx.Log,
138+
appSender,
139+
registerer,
140+
"p2p",
141+
p2pValidators,
142+
)
131143
if err != nil {
132144
return nil, fmt.Errorf("failed to initialize p2p network: %w", err)
133145
}
@@ -141,7 +153,7 @@ func NewNetwork(
141153
appRequestHandler: message.NoopRequestHandler{},
142154
peers: NewPeerTracker(),
143155
appStats: stats.NewRequestHandlerStats(),
144-
p2pValidators: p2p.NewValidators(p2pNetwork.Peers, ctx.Log, ctx.SubnetID, ctx.ValidatorState, maxValidatorSetStaleness),
156+
p2pValidators: p2pValidators,
145157
}, nil
146158
}
147159

@@ -478,8 +490,8 @@ func (n *network) SendSyncedAppRequest(ctx context.Context, nodeID ids.NodeID, r
478490
return waitingHandler.WaitForResult(ctx)
479491
}
480492

481-
func (n *network) NewClient(protocol uint64, options ...p2p.ClientOption) *p2p.Client {
482-
return n.sdkNetwork.NewClient(protocol, options...)
493+
func (n *network) NewClient(protocol uint64) *p2p.Client {
494+
return n.sdkNetwork.NewClient(protocol, n.p2pValidators)
483495
}
484496

485497
func (n *network) AddHandler(protocol uint64, handler p2p.Handler) error {

plugin/evm/config/constants.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const (
1616
TxGossipBloomChurnMultiplier = 3
1717
PushGossipDiscardedElements = 16_384
1818
TxGossipTargetMessageSize = 20 * units.KiB
19-
TxGossipThrottlingPeriod = 10 * time.Second
20-
TxGossipThrottlingLimit = 2
21-
TxGossipPollSize = 1
19+
TxGossipThrottlingPeriod = time.Hour
20+
// TxGossipRequestsPerPeer = TxGossipThrottlingPeriod / Config.PullGossipFrequency
21+
TxGossipRequestsPerPeer = 3600
22+
TxGossipPollSize = 1
2223
)

plugin/evm/gossip.go renamed to plugin/evm/eth_gossiper.go

Lines changed: 11 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
22
// See the file LICENSE for licensing terms.
33

4+
// TODO: move to network
5+
46
package evm
57

68
import (
79
"context"
810
"fmt"
911
"sync"
1012
"sync/atomic"
11-
"time"
1213

1314
"github.com/ava-labs/avalanchego/ids"
14-
"github.com/ava-labs/avalanchego/network/p2p"
1515
"github.com/ava-labs/avalanchego/network/p2p/gossip"
16-
"github.com/ava-labs/avalanchego/snow/engine/common"
17-
"github.com/ava-labs/avalanchego/utils/logging"
1816
"github.com/ava-labs/libevm/core/types"
1917
"github.com/ava-labs/libevm/log"
2018
"github.com/prometheus/client_golang/prometheus"
@@ -30,67 +28,21 @@ import (
3028
const pendingTxsBuffer = 10
3129

3230
var (
33-
_ p2p.Handler = (*txGossipHandler)(nil)
34-
3531
_ gossip.Gossipable = (*GossipEthTx)(nil)
3632
_ gossip.Marshaller[*GossipEthTx] = (*GossipEthTxMarshaller)(nil)
3733
_ gossip.Set[*GossipEthTx] = (*GossipEthTxPool)(nil)
3834

3935
_ eth.PushGossiper = (*EthPushGossiper)(nil)
4036
)
4137

42-
func newTxGossipHandler[T gossip.Gossipable](
43-
log logging.Logger,
44-
marshaller gossip.Marshaller[T],
45-
mempool gossip.Set[T],
46-
metrics gossip.Metrics,
47-
maxMessageSize int,
48-
throttlingPeriod time.Duration,
49-
throttlingLimit int,
50-
validators p2p.ValidatorSet,
51-
) txGossipHandler {
52-
// push gossip messages can be handled from any peer
53-
handler := gossip.NewHandler(
54-
log,
55-
marshaller,
56-
mempool,
57-
metrics,
58-
maxMessageSize,
59-
)
60-
61-
// pull gossip requests are filtered by validators and are throttled
62-
// to prevent spamming
63-
validatorHandler := p2p.NewValidatorHandler(
64-
p2p.NewThrottlerHandler(
65-
handler,
66-
p2p.NewSlidingWindowThrottler(throttlingPeriod, throttlingLimit),
67-
log,
68-
),
69-
validators,
70-
log,
71-
)
72-
73-
return txGossipHandler{
74-
appGossipHandler: handler,
75-
appRequestHandler: validatorHandler,
76-
}
77-
}
78-
79-
type txGossipHandler struct {
80-
appGossipHandler p2p.Handler
81-
appRequestHandler p2p.Handler
82-
}
83-
84-
func (t txGossipHandler) AppGossip(ctx context.Context, nodeID ids.NodeID, gossipBytes []byte) {
85-
t.appGossipHandler.AppGossip(ctx, nodeID, gossipBytes)
86-
}
87-
88-
func (t txGossipHandler) AppRequest(ctx context.Context, nodeID ids.NodeID, deadline time.Time, requestBytes []byte) ([]byte, *common.AppError) {
89-
return t.appRequestHandler.AppRequest(ctx, nodeID, deadline, requestBytes)
90-
}
91-
9238
func NewGossipEthTxPool(mempool *txpool.TxPool, registerer prometheus.Registerer) (*GossipEthTxPool, error) {
93-
bloom, err := gossip.NewBloomFilter(registerer, "eth_tx_bloom_filter", config.TxGossipBloomMinTargetElements, config.TxGossipBloomTargetFalsePositiveRate, config.TxGossipBloomResetFalsePositiveRate)
39+
bloom, err := gossip.NewBloomFilter(
40+
registerer,
41+
"eth_tx_bloom_filter",
42+
config.TxGossipBloomMinTargetElements,
43+
config.TxGossipBloomTargetFalsePositiveRate,
44+
config.TxGossipBloomResetFalsePositiveRate,
45+
)
9446
if err != nil {
9547
return nil, fmt.Errorf("failed to initialize bloom filter: %w", err)
9648
}
@@ -189,11 +141,11 @@ func (g *GossipEthTxPool) GetFilter() ([]byte, []byte) {
189141

190142
type GossipEthTxMarshaller struct{}
191143

192-
func (g GossipEthTxMarshaller) MarshalGossip(tx *GossipEthTx) ([]byte, error) {
144+
func (GossipEthTxMarshaller) MarshalGossip(tx *GossipEthTx) ([]byte, error) {
193145
return tx.Tx.MarshalBinary()
194146
}
195147

196-
func (g GossipEthTxMarshaller) UnmarshalGossip(bytes []byte) (*GossipEthTx, error) {
148+
func (GossipEthTxMarshaller) UnmarshalGossip(bytes []byte) (*GossipEthTx, error) {
197149
tx := &GossipEthTx{
198150
Tx: &types.Transaction{},
199151
}

plugin/evm/gossip/handler.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
2+
// See the file LICENSE for licensing terms.
3+
4+
package gossip
5+
6+
import (
7+
"context"
8+
"fmt"
9+
"time"
10+
11+
"github.com/ava-labs/avalanchego/ids"
12+
"github.com/ava-labs/avalanchego/network/p2p"
13+
"github.com/ava-labs/avalanchego/network/p2p/gossip"
14+
"github.com/ava-labs/avalanchego/snow/engine/common"
15+
"github.com/ava-labs/avalanchego/utils/logging"
16+
"github.com/prometheus/client_golang/prometheus"
17+
)
18+
19+
var _ p2p.Handler = (*txGossipHandler)(nil)
20+
21+
func NewTxGossipHandler[T gossip.Gossipable](
22+
log logging.Logger,
23+
marshaller gossip.Marshaller[T],
24+
mempool gossip.Set[T],
25+
metrics gossip.Metrics,
26+
maxMessageSize int,
27+
throttlingPeriod time.Duration,
28+
requestsPerPeer float64,
29+
validators p2p.ValidatorSet,
30+
registerer prometheus.Registerer,
31+
namespace string,
32+
) (*txGossipHandler, error) {
33+
// push gossip messages can be handled from any peer
34+
handler := gossip.NewHandler(
35+
log,
36+
marshaller,
37+
mempool,
38+
metrics,
39+
maxMessageSize,
40+
)
41+
42+
throttledHandler, err := p2p.NewDynamicThrottlerHandler(
43+
log,
44+
handler,
45+
validators,
46+
throttlingPeriod,
47+
requestsPerPeer,
48+
registerer,
49+
namespace,
50+
)
51+
if err != nil {
52+
return nil, fmt.Errorf("failed to initialize throttler handler: %w", err)
53+
}
54+
55+
// pull gossip requests are filtered by validators and are throttled
56+
// to prevent spamming
57+
validatorHandler := p2p.NewValidatorHandler(
58+
throttledHandler,
59+
validators,
60+
log,
61+
)
62+
63+
return &txGossipHandler{
64+
appGossipHandler: handler,
65+
appRequestHandler: validatorHandler,
66+
}, nil
67+
}
68+
69+
type txGossipHandler struct {
70+
appGossipHandler p2p.Handler
71+
appRequestHandler p2p.Handler
72+
}
73+
74+
func (t *txGossipHandler) AppGossip(ctx context.Context, nodeID ids.NodeID, gossipBytes []byte) {
75+
t.appGossipHandler.AppGossip(ctx, nodeID, gossipBytes)
76+
}
77+
78+
func (t *txGossipHandler) AppRequest(ctx context.Context, nodeID ids.NodeID, deadline time.Time, requestBytes []byte) ([]byte, *common.AppError) {
79+
return t.appRequestHandler.AppRequest(ctx, nodeID, deadline, requestBytes)
80+
}

plugin/evm/gossip_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func TestGossipSubscribe(t *testing.T) {
7474
// Notify mempool about txs
7575
errs := txPool.AddRemotesSync(ethTxs)
7676
for _, err := range errs {
77-
require.NoError(err, "failed adding subnet-evm tx to remote mempool")
77+
require.NoError(err, "failed adding tx to remote mempool")
7878
}
7979

8080
require.EventuallyWithTf(

plugin/evm/tx_gossip_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,21 @@ func TestEthTxGossip(t *testing.T) {
6767
SentAppRequest: make(chan []byte, 1),
6868
}
6969

70-
network, err := p2p.NewNetwork(logging.NoLog{}, peerSender, prometheus.NewRegistry(), "")
70+
validatorSet := p2p.NewValidators(
71+
logging.NoLog{},
72+
snowCtx.SubnetID,
73+
validatorState,
74+
0,
75+
)
76+
network, err := p2p.NewNetwork(
77+
logging.NoLog{},
78+
peerSender,
79+
prometheus.NewRegistry(),
80+
"",
81+
validatorSet,
82+
)
7183
require.NoError(err)
72-
client := network.NewClient(p2p.TxGossipHandlerID)
84+
client := network.NewClient(p2p.TxGossipHandlerID, validatorSet)
7385

7486
// we only accept gossip requests from validators
7587
requestingNodeID := ids.GenerateTestNodeID()

0 commit comments

Comments
 (0)