Skip to content

Commit

Permalink
restore enable and disable adding
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu committed Nov 29, 2023
1 parent e2c7817 commit b331747
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
22 changes: 22 additions & 0 deletions vms/platformvm/txs/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ var (
)

type Mempool interface {
// we may want to be able to stop valid transactions
// from entering the mempool, e.g. during blocks creation
EnableAdding()
DisableAdding()

Add(tx *txs.Tx) error
Has(txID ids.ID) bool
Get(txID ids.ID) *txs.Tx
Expand Down Expand Up @@ -76,6 +81,9 @@ type Mempool interface {
// Transactions from clients that have not yet been put into blocks and added to
// consensus
type mempool struct {
// If true, drop transactions added to the mempool via Add.
dropIncoming bool

bytesAvailableMetric prometheus.Gauge
bytesAvailable int

Expand Down Expand Up @@ -116,6 +124,8 @@ func New(

bytesAvailableMetric.Set(maxMempoolSize)
return &mempool{
dropIncoming: false, // enable tx adding by default

bytesAvailableMetric: bytesAvailableMetric,
bytesAvailable: maxMempoolSize,

Expand All @@ -128,7 +138,19 @@ func New(
}, nil
}

func (m *mempool) EnableAdding() {
m.dropIncoming = false
}

func (m *mempool) DisableAdding() {
m.dropIncoming = true
}

func (m *mempool) Add(tx *txs.Tx) error {
if m.dropIncoming {
return fmt.Errorf("tx %s not added because mempool is closed", tx.ID())
}

switch tx.Unsigned.(type) {
case *txs.AdvanceTimeTx:
return errCantIssueAdvanceTimeTx
Expand Down
24 changes: 24 additions & 0 deletions vms/platformvm/txs/mempool/mock_mempool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b331747

Please sign in to comment.