Skip to content

vms/platformvm: Remove EnableAdding and DisableAdding from Mempool interface #2463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions vms/platformvm/block/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,7 @@ func (b *builder) ShutdownBlockTimer() {
// This method removes the transactions from the returned
// blocks from the mempool.
func (b *builder) BuildBlock(context.Context) (snowman.Block, error) {
b.Mempool.DisableAdding()
Copy link
Contributor

@patrick-ogrady patrick-ogrady Dec 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add some locking to the mempool now? I think there are a number of internal fields (like bytesAvailable) modified on the call to Add, for example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the context lock is held when the Add function is called

defer func() {
b.Mempool.EnableAdding()
// If we need to advance the chain's timestamp in a standard block, but
// we build an invalid block, then we need to re-trigger block building.
//
Expand Down
21 changes: 0 additions & 21 deletions vms/platformvm/txs/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ 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 @@ -86,9 +81,6 @@ 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 @@ -137,24 +129,11 @@ func New(

droppedTxIDs: &cache.LRU[ids.ID, error]{Size: droppedTxIDsCacheSize},
consumedUTXOs: set.NewSet[ids.ID](initialConsumedUTXOsSize),
dropIncoming: false, // enable tx adding by default
toEngine: toEngine,
}, 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: 0 additions & 24 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.