multi: start consumers with a starting blockbeat

This is needed so the consumers have an initial state about the current
block.
This commit is contained in:
yyforyongyu committed 2024-12-20 17:54:02 +08:00
1 parent 802353036e
commit 545cea0546
5 files changed
+60 -10

No files matched your search

+4 -1
View File
@@ -795,13 +795,16 @@ type monitorRecord struct {
// Start starts the publisher by subscribing to block epoch updates and kicking
// off the monitor loop.
func (t *TxPublisher) Start() error {
func (t *TxPublisher) Start(beat chainio.Blockbeat) error {
log.Info("TxPublisher starting...")
if t.started.Swap(true) {
return fmt.Errorf("TxPublisher started more than once")
}
// Set the current height.
t.currentHeight.Store(beat.Height())
t.wg.Add(1)
go t.monitor()
+4 -1
View File
@@ -441,7 +441,7 @@ func New(cfg *UtxoSweeperConfig) *UtxoSweeper {
}
// Start starts the process of constructing and publish sweep txes.
func (s *UtxoSweeper) Start() error {
func (s *UtxoSweeper) Start(beat chainio.Blockbeat) error {
if !atomic.CompareAndSwapUint32(&s.started, 0, 1) {
return nil
}
@@ -452,6 +452,9 @@ func (s *UtxoSweeper) Start() error {
// not change from here on.
s.relayFeeRate = s.cfg.FeeEstimator.RelayFeePerKW()
// Set the current height.
s.currentHeight = beat.Height()
// Start sweeper main loop.
s.wg.Add(1)
go s.collector()