chain icon indicating copy to clipboard operation
chain copied to clipboard

[Mempool] Implement custom mempool

Open colmazia opened this issue 9 months ago • 2 comments
trafficstars

Implementation details

Please ensure the following requirements are met before submitting a pull request:

  • [ ] The pull request is targeted against the correct target branch
  • [ ] The pull request is linked to an issue with appropriate discussion and an accepted design OR is linked to a spec that describes the work.
  • [ ] The pull request includes a description of the implementation/work done in detail.
  • [ ] The pull request includes any and all appropriate unit/integration tests
  • [ ] You have added a relevant changelog entry to CHANGELOG_UNRELEASED.md
  • [ ] You have re-reviewed the files affected by the pull request (e.g. using the Files changed tab in the Github PR explorer)

colmazia avatar Feb 17 '25 06:02 colmazia

@CodiumAI-Agent /review

RogerKSI avatar Apr 04 '25 06:04 RogerKSI

PR Reviewer Guide 🔍

(Review updated until commit https://github.com/bandprotocol/chain/commit/c2f9455002833cedfdb1dba14519d6f612740dd6)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Concurrency Safety

The blocked flag and internal state (e.g., txIndex) are accessed without synchronization in methods like SetBlocked and readers in FillProposal. This can cause data races under concurrent mempool operations.

// SetBlocked sets the blocked flag to the given value.
func (l *Lane) SetBlocked(blocked bool) {
	l.blocked = blocked
}
Boundary Condition

The loop in FillProposal and the post‐fill callback use IsReachedBy, which treats reaching the limit as a break condition. Confirm whether equal-to-limit transactions should be included or excluded.

	// We can tolerate a few bytes/gas over the limit, since we limit the size of each transaction.
	if laneLimit.IsReachedBy(blockUsed) {
		break
	}

	tx := iterator.Tx()
	txInfo, err := l.getTxInfo(tx)
	if err != nil {
		// If the transaction is not valid, we skip it.
		// This should never happen, but we log it for debugging purposes.
		l.logger.Error("failed to get tx info with err:", err)
		continue
	}

	// Add the transaction to the proposal.
	if err := proposal.Add(txInfo); err != nil {
		l.logger.Info(
			"failed to add tx to proposal",
			"lane", l.name,
			"tx_hash", txInfo.Hash,
			"err", err,
		)

		break
	}

	blockUsed = blockUsed.Add(txInfo.BlockSpace)
}

// call the callback function of the lane after fill proposal.
if l.callbackAfterFillProposal != nil {
	l.callbackAfterFillProposal(laneLimit.IsReachedBy(blockUsed))
}
Unimplemented Select

Mempool.Select returns nil, deviating from the SDK mempool interface. Downstream components expecting a valid iterator may malfunction.

func (m *Mempool) Select(ctx context.Context, txs [][]byte) sdkmempool.Iterator {
	return nil
}

CodiumAI-Agent avatar Apr 04 '25 06:04 CodiumAI-Agent

Persistent review updated to latest commit https://github.com/bandprotocol/chain/commit/adfd33283f85ef3780244d3804113270ba95ab40

CodiumAI-Agent avatar May 13 '25 08:05 CodiumAI-Agent

Persistent review updated to latest commit https://github.com/bandprotocol/chain/commit/c2f9455002833cedfdb1dba14519d6f612740dd6

CodiumAI-Agent avatar May 19 '25 09:05 CodiumAI-Agent