Skip to content

Commit 6d0d935

Browse files
committed
tapgarden: remove duplicate batch freeze
In this commit, we update the caretaker start logic to remove an unnecessary batch write. Before we start the caretaker, we write the batch with the Frozen state, but we don't update the in-memory pending batch to move from the Pending to Frozen state. This causes the caretaker to write the batch again on start. We can address this by updating the in-memory batch after a successful batch freeze.
1 parent 75ee8c8 commit 6d0d935

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

tapgarden/planter.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,6 @@ func (c *ChainPlanter) gardener() {
636636
}
637637

638638
delete(c.caretakers, batchKeySerial)
639-
c.pendingBatch = nil
640-
continue
641639

642640
case <-c.Quit:
643641
return
@@ -677,10 +675,6 @@ func (c *ChainPlanter) gardener() {
677675
func (c *ChainPlanter) finalizeBatch(
678676
feeRate *chainfee.SatPerKWeight) (*BatchCaretaker, error) {
679677

680-
// Prep the new care taker that'll be launched assuming the call below
681-
// to freeze the batch succeeds.
682-
caretaker := c.newCaretakerForBatch(c.pendingBatch, feeRate)
683-
684678
// At this point, we have a non-empty batch, so we'll first finalize it
685679
// on disk. This means no further seedlings can be added to this batch.
686680
ctx, cancel := c.WithCtxQuit()
@@ -691,9 +685,11 @@ func (c *ChainPlanter) finalizeBatch(
691685
err)
692686
}
693687

694-
// Now that the batch has been frozen, we'll launch a new caretaker
695-
// state machine for the batch that'll drive all the seedlings do
696-
// adulthood.
688+
// Now that the batch has been frozen on disk, we can update the batch
689+
// state to frozen before launching a new caretaker state machine for
690+
// the batch that'll drive all the seedlings do adulthood.
691+
c.pendingBatch.UpdateState(BatchStateFrozen)
692+
caretaker := c.newCaretakerForBatch(c.pendingBatch, feeRate)
697693
if err := caretaker.Start(); err != nil {
698694
return nil, fmt.Errorf("unable to start new caretaker: %w", err)
699695
}

0 commit comments

Comments
 (0)