chainio: implement Blockbeat
In this commit, a minimal implementation of `Blockbeat` is added to synchronize block heights, which will be used in `ChainArb`, `Sweeper`, and `TxPublisher` so blocks are processed sequentially among them.
This commit is contained in:
3 files changed
+98
-3
No files matched your search
+16
-3
@@ -1,9 +1,11 @@
|
||||
package chainio
|
||||
|
||||
import "github.com/btcsuite/btclog/v2"
|
||||
|
||||
// Blockbeat defines an interface that can be used by subsystems to retrieve
|
||||
// block data. It is sent by the BlockbeatDispatcher whenever a new block is
|
||||
// received. Once the subsystem finishes processing the block, it must signal
|
||||
// it by calling NotifyBlockProcessed.
|
||||
// block data. It is sent by the BlockbeatDispatcher to all the registered
|
||||
// consumers whenever a new block is received. Once the consumer finishes
|
||||
// processing the block, it must signal it by calling `NotifyBlockProcessed`.
|
||||
//
|
||||
// The blockchain is a state machine - whenever there's a state change, it's
|
||||
// manifested in a block. The blockbeat is a way to notify subsystems of this
|
||||
@@ -11,10 +13,21 @@ package chainio
|
||||
// other words, subsystems must react to this state change and should consider
|
||||
// being driven by the blockbeat in their own state machines.
|
||||
type Blockbeat interface {
|
||||
// blockbeat is a private interface that's only used in this package.
|
||||
blockbeat
|
||||
|
||||
// Height returns the current block height.
|
||||
Height() int32
|
||||
}
|
||||
|
||||
// blockbeat defines a set of private methods used in this package to make
|
||||
// interaction with the blockbeat easier.
|
||||
type blockbeat interface {
|
||||
// logger returns the internal logger used by the blockbeat which has a
|
||||
// block height prefix.
|
||||
logger() btclog.Logger
|
||||
}
|
||||
|
||||
// Consumer defines a blockbeat consumer interface. Subsystems that need block
|
||||
// info must implement it.
|
||||
type Consumer interface {
|
||||
|
||||
Reference in new issue
Block a user