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+
46package evm
57
68import (
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 (
3028const pendingTxsBuffer = 10
3129
3230var (
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-
9238func 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
190142type 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 }
0 commit comments