Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions sei-tendermint/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ type MempoolConfig struct {
// valid again in the future.
KeepInvalidTxsInCache bool `mapstructure:"keep-invalid-txs-in-cache"`

// Maximum size of a single transaction
// NOTE: the max size of a tx transmitted over the network is {max-tx-bytes}.
// Maximum size of a single transaction.
// XXX: Unused. Admission uses the protocol gossip limit. A different value logs a warning.
MaxTxBytes int `mapstructure:"max-tx-bytes"`
Comment thread
shemnon marked this conversation as resolved.

// Maximum size of a batch of transactions to send to a peer
Expand Down
2 changes: 1 addition & 1 deletion sei-tendermint/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ duplicate-txs-cache-size = "{{ .Mempool.DuplicateTxsCacheSize }}"
keep-invalid-txs-in-cache = {{ .Mempool.KeepInvalidTxsInCache }}

# Maximum size of a single transaction.
# NOTE: the max size of a tx transmitted over the network is {max-tx-bytes}.
# XXX: Unused. Admission uses the protocol gossip limit. A different value logs a warning.
Comment thread
shemnon marked this conversation as resolved.
max-tx-bytes = {{ .Mempool.MaxTxBytes }}

# Maximum size of a batch of transactions to send to a peer
Expand Down
15 changes: 10 additions & 5 deletions sei-tendermint/internal/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ type Config struct {
// valid again in the future.
KeepInvalidTxsInCache bool

// Maximum size of a single transaction
// NOTE: the max size of a tx transmitted over the network is {max-tx-bytes}.
// Maximum size of a single transaction.
// XXX: Unused. Admission uses the protocol gossip limit. A different value logs a warning.
MaxTxBytes int

// time after which transaction is removed from mempool.
Expand Down Expand Up @@ -129,7 +129,7 @@ func DefaultConfig() *Config {
MaxTxsBytes: 1024 * 1024 * 1024, // 1GB
CacheSize: 10000,
DuplicateTxsCacheSize: 100000,
MaxTxBytes: 1024 * 1024, // 1MB
MaxTxBytes: types.MaxGossipTxBytes,
TTLDuration: utils.Some(5 * time.Second), // prevent stale txs from filling mempool
TTLNumBlocks: utils.Some(int64(10)), // remove txs after 10 blocks
TxNotifyThreshold: 0,
Expand Down Expand Up @@ -209,6 +209,11 @@ func NewTxMempool(
app *proxy.Proxy,
txConstraintsFetcher TxConstraintsFetcher,
) *TxMempool {
if cfg.MaxTxBytes != types.MaxGossipTxBytes {
logger.Warn("mempool max-tx-bytes differs from the protocol gossip limit; admission uses the protocol limit",
"max-tx-bytes", cfg.MaxTxBytes,
"protocol", types.MaxGossipTxBytes)
}
txmp := &TxMempool{
config: cfg,
app: app,
Expand Down Expand Up @@ -291,8 +296,8 @@ func (txmp *TxMempool) CheckTx(ctx context.Context, tx types.Tx) (*abci.Response
defer txmp.mtx.RUnlock()

// Early exit if tx is too large.
if txSize := len(tx); txSize > txmp.config.MaxTxBytes {
return nil, fmt.Errorf("%w: max size is %d, but got %d", ErrTxTooLarge, txmp.config.MaxTxBytes, txSize)
if txSize := len(tx); txSize > types.MaxGossipTxBytes {
return nil, fmt.Errorf("%w: max size is %d, but got %d", ErrTxTooLarge, types.MaxGossipTxBytes, txSize)
}
hTx := newHashedTx(tx)

Expand Down
4 changes: 2 additions & 2 deletions sei-tendermint/internal/mempool/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,14 @@ func TestTxMempool_CheckTxExceedsMaxSize(t *testing.T) {
txmp := setup(cfg, proxy.New(client), NopTxConstraintsFetcher)

rng := rand.New(rand.NewSource(time.Now().UnixNano()))
tx := make([]byte, txmp.config.MaxTxBytes+1)
tx := make([]byte, types.MaxGossipTxBytes+1)
_, err := rng.Read(tx)
require.NoError(t, err)

_, err = txmp.CheckTx(ctx, tx)
require.Error(t, err)

tx = make([]byte, txmp.config.MaxTxBytes-1)
tx = make([]byte, types.MaxGossipTxBytes-1)
_, err = rng.Read(tx)
require.NoError(t, err)

Expand Down
41 changes: 26 additions & 15 deletions sei-tendermint/internal/mempool/reactor/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"runtime/debug"
"sync"

"github.com/sei-protocol/sei-chain/sei-tendermint/config"
"github.com/sei-protocol/sei-chain/sei-tendermint/internal/libs/clist"
Expand All @@ -22,6 +23,15 @@ var (
logger = seilog.NewLogger("tendermint", "internal", "mempool")

_ service.Service = (*Reactor)(nil)

// mempoolRecvMessageCapacity is the encoded size of one MaxGossipTxBytes transaction.
mempoolRecvMessageCapacity = sync.OnceValue(func() int {
return (&pb.Message{
Sum: &pb.Message_Txs{
Txs: &pb.Txs{Txs: [][]byte{make([]byte, types.MaxGossipTxBytes)}},
},
}).Size()
})
)

const MempoolChannel p2p.ChannelID = 0x30
Expand All @@ -45,7 +55,7 @@ type Reactor struct {

// NewReactor returns a reference to a new reactor.
func NewReactor(cfg *config.MempoolConfig, txmp *mempool.TxMempool, router *p2p.Router) (*Reactor, error) {
channel, err := p2p.OpenChannel(router, GetChannelDescriptor(cfg))
channel, err := p2p.OpenChannel(router, GetChannelDescriptor())
if err != nil {
return nil, fmt.Errorf("router.OpenChannel(): %w", err)
}
Expand All @@ -65,19 +75,13 @@ func (r *Reactor) MarkReadyToStart() { r.readyToStart <- struct{}{} }

// GetChannelDescriptor produces an instance of a descriptor for this package's
// required channels.
func GetChannelDescriptor(cfg *config.MempoolConfig) p2p.ChannelDescriptor[*pb.Message] {
largestTx := make([]byte, cfg.MaxTxBytes)
batchMsg := &pb.Message{
Sum: &pb.Message_Txs{
Txs: &pb.Txs{Txs: [][]byte{largestTx}},
},
}

func GetChannelDescriptor() p2p.ChannelDescriptor[*pb.Message] {
return p2p.ChannelDescriptor[*pb.Message]{
ID: MempoolChannel,
MessageType: new(pb.Message),
Priority: 5,
RecvMessageCapacity: batchMsg.Size(),
RecvMessageCapacity: mempoolRecvMessageCapacity(),
DiscardOversized: true,
RecvBufferCapacity: 128,
Name: "mempool",
}
Expand Down Expand Up @@ -239,11 +243,18 @@ func (r *Reactor) broadcastTxRoutine(ctx context.Context, peerID types.NodeID) {
}
for {
tx := next.Value()
r.channel.Send(&pb.Message{
Sum: &pb.Message_Txs{
Txs: &pb.Txs{Txs: [][]byte{tx}},
},
}, peerID)
if len(tx) > types.MaxGossipTxBytes {
logger.Debug("skipping gossip of tx above protocol size",
"tx", tx.Hash(),
"size", len(tx),
"peer", peerID)
} else {
r.channel.Send(&pb.Message{
Sum: &pb.Message_Txs{
Txs: &pb.Txs{Txs: [][]byte{tx}},
},
}, peerID)
}

next, err = next.NextWait(ctx)
if err != nil {
Expand Down
Loading
Loading