Skip to content

Commit

Permalink
Do not forward rejected requests.
Browse files Browse the repository at this point in the history
Signed-off-by: Karolis Petrauskas <[email protected]>
  • Loading branch information
kape1395 committed Dec 7, 2024
1 parent a11e773 commit 3e9cd45
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
15 changes: 9 additions & 6 deletions packages/chain/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
7 changes: 4 additions & 3 deletions packages/chain/mempool/offledger_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}

//
Expand Down Expand Up @@ -134,14 +134,15 @@ 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
}

//
// update metrics and signal that the request is available
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
Expand Down

0 comments on commit 3e9cd45

Please sign in to comment.