Skip to content

Commit d8d5087

Browse files
committed
tapgarden: drop batch state from CancelResp
In this commit, we redefine the batch state reported in cancelResp to be a bool instead of an actual batch state. The provided batch state was not being used by any callers of Cancel(), including the planter.
1 parent 47568ee commit d8d5087

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

tapgarden/caretaker.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,50 +196,50 @@ func (b *BatchCaretaker) Cancel() error {
196196
switch batchState {
197197
// In the pending state, the batch seedlings have not sprouted yet.
198198
case BatchStatePending, BatchStateFrozen:
199-
finalBatchState := BatchStateSeedlingCancelled
200199
err := b.cfg.Log.UpdateBatchState(
201200
ctx, b.cfg.Batch.BatchKey.PubKey,
202-
finalBatchState,
201+
BatchStateSeedlingCancelled,
203202
)
204203
if err != nil {
205204
err = fmt.Errorf("BatchCaretaker(%x), batch state(%v), "+
206205
"cancel failed: %w", batchKey, batchState, err)
207206
}
208207

209-
cancelResp = CancelResp{&finalBatchState, err}
208+
cancelResp = CancelResp{true, err}
210209

211210
case BatchStateCommitted:
212-
finalBatchState := BatchStateSproutCancelled
213211
err := b.cfg.Log.UpdateBatchState(
214212
ctx, b.cfg.Batch.BatchKey.PubKey,
215-
finalBatchState,
213+
BatchStateSproutCancelled,
216214
)
217215
if err != nil {
218216
err = fmt.Errorf("BatchCaretaker(%x), batch state(%v), "+
219217
"cancel failed: %w", batchKey, batchState, err)
220218
}
221219

222-
cancelResp = CancelResp{&finalBatchState, err}
220+
cancelResp = CancelResp{true, err}
223221

224222
default:
225223
err := fmt.Errorf("BatchCaretaker(%x), batch not cancellable",
226224
b.cfg.Batch.BatchKey.PubKey.SerializeCompressed())
227-
cancelResp = CancelResp{nil, err}
225+
cancelResp = CancelResp{false, err}
228226
}
229227

230228
b.cfg.CancelRespChan <- cancelResp
231229

232-
// If the batch was cancellable, the finalState of the cancel response
233-
// will be non-nil. If the cancellation failed, that error will be
234-
// handled by the planter. At this point, the caretaker should always
235-
// shut down gracefully.
236-
if cancelResp.finalState != nil {
230+
// If the batch was cancellable, the final write of the cancelled batch
231+
// may still have failed. That error will be handled by the planter. At
232+
// this point, the caretaker should shut down gracefully if cancellation
233+
// was attempted.
234+
if cancelResp.cancelAttempted {
237235
log.Infof("BatchCaretaker(%x), attempted batch cancellation, "+
238236
"shutting down", b.batchKey[:])
239237

240238
return nil
241239
}
242240

241+
// If the cancellation failed, that error will be handled by the
242+
// planter.
243243
return fmt.Errorf("BatchCaretaker(%x) cancellation failed",
244244
b.batchKey[:])
245245
}

tapgarden/planter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ type BatchKey = asset.SerializedKey
9191

9292
// CancelResp is the response from a caretaker attempting to cancel a batch.
9393
type CancelResp struct {
94-
finalState *BatchState
95-
err error
94+
cancelAttempted bool
95+
err error
9696
}
9797

9898
type stateRequest interface {
@@ -448,7 +448,7 @@ func (c *ChainPlanter) cancelMintingBatch(ctx context.Context,
448448
// cancellation was possible and attempted. This means
449449
// that the caretaker is shut down and the planter
450450
// must delete it.
451-
if cancelResp.finalState != nil {
451+
if cancelResp.cancelAttempted {
452452
delete(c.caretakers, batchKeySerialized)
453453
}
454454

0 commit comments

Comments
 (0)