From 3e9cd458205c7b14eea4f7b21f4f8a0c991c7b26 Mon Sep 17 00:00:00 2001 From: Karolis Petrauskas Date: Sat, 7 Dec 2024 17:17:26 +0200 Subject: [PATCH] Do not forward rejected requests. Signed-off-by: Karolis Petrauskas --- packages/chain/mempool/mempool.go | 15 +++++++++------ packages/chain/mempool/offledger_pool.go | 7 ++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/chain/mempool/mempool.go b/packages/chain/mempool/mempool.go index f6819f3a40..32e0c4507b 100644 --- a/packages/chain/mempool/mempool.go +++ b/packages/chain/mempool/mempool.go @@ -505,8 +505,7 @@ func (mpi *mempoolImpl) distSyncRequestReceivedCB(request isc.Request) bool { return false } if err := mpi.shouldAddOffledgerRequest(offLedgerReq); err == nil { - mpi.addOffledger(offLedgerReq) - return true + return mpi.addOffledger(offLedgerReq) } return false } @@ -558,10 +557,13 @@ func (mpi *mempoolImpl) shouldAddOffledgerRequest(req isc.OffLedgerRequest) erro return nil } -func (mpi *mempoolImpl) addOffledger(request isc.OffLedgerRequest) { - mpi.offLedgerPool.Add(request) +func (mpi *mempoolImpl) addOffledger(request isc.OffLedgerRequest) bool { + if !mpi.offLedgerPool.Add(request) { + return false + } mpi.metrics.IncRequestsReceived(request) mpi.log.Debugf("accepted by the mempool, requestID: %s", request.ID().String()) + return true } func (mpi *mempoolImpl) handleServerNodesUpdated(recv *reqServerNodesUpdated) { @@ -806,8 +808,9 @@ func (mpi *mempoolImpl) handleReceiveOnLedgerRequest(request isc.OnLedgerRequest func (mpi *mempoolImpl) handleReceiveOffLedgerRequest(request isc.OffLedgerRequest) { mpi.log.Debugf("Received request %v from outside.", request.ID()) - mpi.addOffledger(request) - mpi.sendMessages(mpi.distSync.Input(distsync.NewInputPublishRequest(request))) + if mpi.addOffledger(request) { + mpi.sendMessages(mpi.distSync.Input(distsync.NewInputPublishRequest(request))) + } } func (mpi *mempoolImpl) handleTangleTimeUpdated(tangleTime time.Time) { diff --git a/packages/chain/mempool/offledger_pool.go b/packages/chain/mempool/offledger_pool.go index ef06097874..7fdc02b8c4 100644 --- a/packages/chain/mempool/offledger_pool.go +++ b/packages/chain/mempool/offledger_pool.go @@ -67,7 +67,7 @@ func (p *OffLedgerPool) Get(reqRef *isc.RequestRef) isc.OffLedgerRequest { return entry.req } -func (p *OffLedgerPool) Add(request isc.OffLedgerRequest) { +func (p *OffLedgerPool) Add(request isc.OffLedgerRequest) bool { ref := isc.RequestRefFromRequest(request) entry := &OrderedPoolEntry{req: request, ts: time.Now()} account := request.SenderAccount().String() @@ -76,7 +76,7 @@ func (p *OffLedgerPool) Add(request isc.OffLedgerRequest) { // add the request to the "request ref" Lookup Table if !p.refLUT.Set(ref.AsKey(), entry) { p.log.Debugf("NOT ADDED, already exists. reqID: %v as key=%v, senderAccount: ", request.ID(), ref, account) - return // not added already exists + return true // not added already exists } // @@ -134,7 +134,7 @@ func (p *OffLedgerPool) Add(request isc.OffLedgerRequest) { deleted := p.LimitPoolSize() if lo.Contains(deleted, entry) { // this exact request was deleted from the pool, do not update metrics, or mark available - return + return false } // @@ -142,6 +142,7 @@ func (p *OffLedgerPool) Add(request isc.OffLedgerRequest) { p.log.Debugf("ADD %v as key=%v, senderAccount: %s", request.ID(), ref, account) p.sizeMetric(p.refLUT.Size()) p.waitReq.MarkAvailable(request) + return true } // LimitPoolSize drops the txs with the lowest price if the total number of requests is too big