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