github.com/ava-labs/avalanchego@v1.11.11/vms/avm/txs/mempool/mempool.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package mempool 5 6 import ( 7 "github.com/prometheus/client_golang/prometheus" 8 9 "github.com/ava-labs/avalanchego/snow/engine/common" 10 "github.com/ava-labs/avalanchego/vms/avm/txs" 11 12 txmempool "github.com/ava-labs/avalanchego/vms/txs/mempool" 13 ) 14 15 var _ Mempool = (*mempool)(nil) 16 17 // Mempool contains transactions that have not yet been put into a block. 18 type Mempool interface { 19 txmempool.Mempool[*txs.Tx] 20 21 // RequestBuildBlock notifies the consensus engine that a block should be 22 // built if there is at least one transaction in the mempool. 23 RequestBuildBlock() 24 } 25 26 type mempool struct { 27 txmempool.Mempool[*txs.Tx] 28 29 toEngine chan<- common.Message 30 } 31 32 func New( 33 namespace string, 34 registerer prometheus.Registerer, 35 toEngine chan<- common.Message, 36 ) (Mempool, error) { 37 metrics, err := txmempool.NewMetrics(namespace, registerer) 38 if err != nil { 39 return nil, err 40 } 41 pool := txmempool.New[*txs.Tx]( 42 metrics, 43 ) 44 return &mempool{ 45 Mempool: pool, 46 toEngine: toEngine, 47 }, nil 48 } 49 50 func (m *mempool) RequestBuildBlock() { 51 if m.Len() == 0 { 52 return 53 } 54 55 select { 56 case m.toEngine <- common.PendingTxs: 57 default: 58 } 59 }