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:
yyforyongyu
2024-06-27 08:41:53 +08:00
parent 060ff013c1
commit 01ac713aec
3 changed files with 98 additions and 3 deletions

28
chainio/blockbeat_test.go Normal file
View File

@@ -0,0 +1,28 @@
package chainio
import (
"errors"
"testing"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/stretchr/testify/require"
)
var errDummy = errors.New("dummy error")
// TestNewBeat tests the NewBeat and Height functions.
func TestNewBeat(t *testing.T) {
t.Parallel()
// Create a testing epoch.
epoch := chainntnfs.BlockEpoch{
Height: 1,
}
// Create the beat and check the internal state.
beat := NewBeat(epoch)
require.Equal(t, epoch, beat.epoch)
// Check the height function.
require.Equal(t, epoch.Height, beat.Height())
}