From f4bbe5ca40eee27eafdb743c454357022a4f9693 Mon Sep 17 00:00:00 2001 From: terence Date: Fri, 4 Jul 2025 08:57:33 -0700 Subject: [PATCH] Add batch verifier limit (#15467) --- beacon-chain/node/node.go | 1 + beacon-chain/sync/batch_verifier.go | 4 +--- beacon-chain/sync/batch_verifier_test.go | 1 + beacon-chain/sync/options.go | 8 ++++++++ beacon-chain/sync/pending_attestations_queue_test.go | 2 ++ beacon-chain/sync/service.go | 4 +++- changelog/tt_noodles.md | 7 +++++++ cmd/beacon-chain/flags/base.go | 6 ++++++ cmd/beacon-chain/main.go | 1 + cmd/beacon-chain/usage.go | 1 + 10 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 changelog/tt_noodles.md diff --git a/beacon-chain/node/node.go b/beacon-chain/node/node.go index f0692affdc..2b9a2f189e 100644 --- a/beacon-chain/node/node.go +++ b/beacon-chain/node/node.go @@ -889,6 +889,7 @@ func (b *BeaconNode) registerSyncService(initialSyncComplete chan struct{}, bFil regularsync.WithCustodyInfo(b.custodyInfo), regularsync.WithSlasherEnabled(b.slasherEnabled), regularsync.WithLightClientStore(b.lcStore), + regularsync.WithBatchVerifierLimit(b.cliCtx.Int(flags.BatchVerifierLimit.Name)), ) return b.services.RegisterService(rs) } diff --git a/beacon-chain/sync/batch_verifier.go b/beacon-chain/sync/batch_verifier.go index 890f550ef9..d86f3fe267 100644 --- a/beacon-chain/sync/batch_verifier.go +++ b/beacon-chain/sync/batch_verifier.go @@ -13,8 +13,6 @@ import ( const signatureVerificationInterval = 50 * time.Millisecond -const verifierLimit = 50 - type signatureVerifier struct { set *bls.SignatureBatch resChan chan error @@ -36,7 +34,7 @@ func (s *Service) verifierRoutine() { return case sig := <-s.signatureChan: verifierBatch = append(verifierBatch, sig) - if len(verifierBatch) >= verifierLimit { + if len(verifierBatch) >= s.cfg.batchVerifierLimit { verifyBatch(verifierBatch) verifierBatch = []*signatureVerifier{} } diff --git a/beacon-chain/sync/batch_verifier_test.go b/beacon-chain/sync/batch_verifier_test.go index 23f8478db5..aaa27fdffd 100644 --- a/beacon-chain/sync/batch_verifier_test.go +++ b/beacon-chain/sync/batch_verifier_test.go @@ -67,6 +67,7 @@ func TestValidateWithBatchVerifier(t *testing.T) { ctx, cancel := context.WithCancel(t.Context()) svc := &Service{ ctx: ctx, + cfg: &config{batchVerifierLimit: verifierLimit}, cancel: cancel, signatureChan: make(chan *signatureVerifier, verifierLimit), } diff --git a/beacon-chain/sync/options.go b/beacon-chain/sync/options.go index 01ab90b2af..677420c687 100644 --- a/beacon-chain/sync/options.go +++ b/beacon-chain/sync/options.go @@ -222,3 +222,11 @@ func WithLightClientStore(lcs *lightClient.Store) Option { return nil } } + +// WithBatchVerifierLimit sets the maximum number of signatures to batch verify at once. +func WithBatchVerifierLimit(limit int) Option { + return func(s *Service) error { + s.cfg.batchVerifierLimit = limit + return nil + } +} diff --git a/beacon-chain/sync/pending_attestations_queue_test.go b/beacon-chain/sync/pending_attestations_queue_test.go index c9e3c8975f..b3c907795e 100644 --- a/beacon-chain/sync/pending_attestations_queue_test.go +++ b/beacon-chain/sync/pending_attestations_queue_test.go @@ -40,6 +40,8 @@ import ( logTest "github.com/sirupsen/logrus/hooks/test" ) +var verifierLimit = 1000 + func TestProcessPendingAtts_NoBlockRequestBlock(t *testing.T) { hook := logTest.NewGlobal() db := dbtest.SetupDB(t) diff --git a/beacon-chain/sync/service.go b/beacon-chain/sync/service.go index 94b5223c54..aacf213a56 100644 --- a/beacon-chain/sync/service.go +++ b/beacon-chain/sync/service.go @@ -106,6 +106,7 @@ type config struct { blobStorage *filesystem.BlobStorage dataColumnStorage *filesystem.DataColumnStorage custodyInfo *peerdas.CustodyInfo + batchVerifierLimit int } // This defines the interface for interacting with block chain service @@ -189,7 +190,6 @@ func NewService(ctx context.Context, opts ...Option) *Service { slotToPendingBlocks: gcache.New(pendingBlockExpTime /* exp time */, 0 /* disable janitor */), seenPendingBlocks: make(map[[32]byte]bool), blkRootToPendingAtts: make(map[[32]byte][]ethpb.SignedAggregateAttAndProof), - signatureChan: make(chan *signatureVerifier, verifierLimit), dataColumnLogCh: make(chan dataColumnLogEntry, 1000), reconstructionRandGen: rand.NewGenerator(), } @@ -199,6 +199,8 @@ func NewService(ctx context.Context, opts ...Option) *Service { return nil } } + // Initialize signature channel with configured limit + r.signatureChan = make(chan *signatureVerifier, r.cfg.batchVerifierLimit) // Correctly remove it from our seen pending block map. // The eviction method always assumes that the mutex is held. r.slotToPendingBlocks.OnEvicted(func(s string, i interface{}) { diff --git a/changelog/tt_noodles.md b/changelog/tt_noodles.md new file mode 100644 index 0000000000..74b3c0b3d3 --- /dev/null +++ b/changelog/tt_noodles.md @@ -0,0 +1,7 @@ +### Added + +- new `--batch-verifier-limit` flag to configure max number of signatures to batch verify on gossip + +### Changed + +- default batch signature verification limit increased from 50 to 1000 \ No newline at end of file diff --git a/cmd/beacon-chain/flags/base.go b/cmd/beacon-chain/flags/base.go index 8a61ad395f..d5ed1bf0f3 100644 --- a/cmd/beacon-chain/flags/base.go +++ b/cmd/beacon-chain/flags/base.go @@ -338,4 +338,10 @@ var ( Name: "subscribe-all-data-subnets", Usage: "Enable subscription to all data subnets.", } + // BatchVerifierLimit sets the maximum number of signatures to batch verify at once. + BatchVerifierLimit = &cli.IntFlag{ + Name: "batch-verifier-limit", + Usage: "Maximum number of signatures to batch verify at once for beacon attestation p2p gossip.", + Value: 1000, + } ) diff --git a/cmd/beacon-chain/main.go b/cmd/beacon-chain/main.go index 6ea8f0c241..f38e4f3f3f 100644 --- a/cmd/beacon-chain/main.go +++ b/cmd/beacon-chain/main.go @@ -149,6 +149,7 @@ var appFlags = []cli.Flag{ bflags.BackfillBatchSize, bflags.BackfillWorkerCount, bflags.BackfillOldestSlot, + flags.BatchVerifierLimit, } func init() { diff --git a/cmd/beacon-chain/usage.go b/cmd/beacon-chain/usage.go index c6dd596fcb..d22174b984 100644 --- a/cmd/beacon-chain/usage.go +++ b/cmd/beacon-chain/usage.go @@ -72,6 +72,7 @@ var appHelpFlagGroups = []flagGroup{ flags.NetworkID, flags.RPCHost, flags.RPCPort, + flags.BatchVerifierLimit, }, }, {