sweep: change markInputsPublishFailed to take outpoints

This way it's easier to pass values to this method in various callsites.
This commit is contained in:
yyforyongyu 2024-01-17 00:20:24 +08:00
parent db7eae97ff
commit 6202c59cb3
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868
2 changed files with 16 additions and 11 deletions

View file

@ -807,8 +807,13 @@ func (s *UtxoSweeper) sweep(set InputSet) error {
tx, labels.MakeLabel(labels.LabelTypeSweepTransaction, nil), tx, labels.MakeLabel(labels.LabelTypeSweepTransaction, nil),
) )
if err != nil { if err != nil {
outpoints := make([]wire.OutPoint, len(set.Inputs()))
for i, inp := range set.Inputs() {
outpoints[i] = *inp.OutPoint()
}
// TODO(yy): find out which input is causing the failure. // TODO(yy): find out which input is causing the failure.
s.markInputsPublishFailed(tx.TxIn) s.markInputsPublishFailed(outpoints)
return err return err
} }
@ -932,17 +937,16 @@ func (s *UtxoSweeper) markInputsPublished(tr *TxRecord,
} }
// markInputsPublishFailed marks the list of inputs as failed to be published. // markInputsPublishFailed marks the list of inputs as failed to be published.
func (s *UtxoSweeper) markInputsPublishFailed(inputs []*wire.TxIn) { func (s *UtxoSweeper) markInputsPublishFailed(outpoints []wire.OutPoint) {
// Reschedule sweep. // Reschedule sweep.
for _, input := range inputs { for _, op := range outpoints {
pi, ok := s.pendingInputs[input.PreviousOutPoint] pi, ok := s.pendingInputs[op]
if !ok { if !ok {
// It could be that this input is an additional wallet // It could be that this input is an additional wallet
// input that was attached. In that case there also // input that was attached. In that case there also
// isn't a pending input to update. // isn't a pending input to update.
log.Debugf("Skipped marking input as publish failed: "+ log.Debugf("Skipped marking input as publish failed: "+
"%v not found in pending inputs", "%v not found in pending inputs", op)
input.PreviousOutPoint)
continue continue
} }
@ -950,13 +954,12 @@ func (s *UtxoSweeper) markInputsPublishFailed(inputs []*wire.TxIn) {
// Valdiate that the input is in an expected state. // Valdiate that the input is in an expected state.
if pi.state != StatePendingPublish { if pi.state != StatePendingPublish {
log.Errorf("Expect input %v to have %v, instead it "+ log.Errorf("Expect input %v to have %v, instead it "+
"has %v", input.PreviousOutPoint, "has %v", op, StatePendingPublish, pi.state)
StatePendingPublish, pi.state)
continue continue
} }
log.Warnf("Failed to publish input %v", input.PreviousOutPoint) log.Warnf("Failed to publish input %v", op)
// Update the input's state. // Update the input's state.
pi.state = StatePublishFailed pi.state = StatePublishFailed

View file

@ -2108,8 +2108,10 @@ func TestMarkInputsPublishFailed(t *testing.T) {
// Mark the test inputs. We expect the non-exist input and the // Mark the test inputs. We expect the non-exist input and the
// inputInit to be skipped, and the final input to be marked as // inputInit to be skipped, and the final input to be marked as
// published. // published.
s.markInputsPublishFailed([]*wire.TxIn{ s.markInputsPublishFailed([]wire.OutPoint{
inputNotExist, inputInit, inputPendingPublish, inputNotExist.PreviousOutPoint,
inputInit.PreviousOutPoint,
inputPendingPublish.PreviousOutPoint,
}) })
// We expect unchanged number of pending inputs. // We expect unchanged number of pending inputs.