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),
)
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.
s.markInputsPublishFailed(tx.TxIn)
s.markInputsPublishFailed(outpoints)
return err
}
@ -932,17 +937,16 @@ func (s *UtxoSweeper) markInputsPublished(tr *TxRecord,
}
// 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.
for _, input := range inputs {
pi, ok := s.pendingInputs[input.PreviousOutPoint]
for _, op := range outpoints {
pi, ok := s.pendingInputs[op]
if !ok {
// It could be that this input is an additional wallet
// input that was attached. In that case there also
// isn't a pending input to update.
log.Debugf("Skipped marking input as publish failed: "+
"%v not found in pending inputs",
input.PreviousOutPoint)
"%v not found in pending inputs", op)
continue
}
@ -950,13 +954,12 @@ func (s *UtxoSweeper) markInputsPublishFailed(inputs []*wire.TxIn) {
// Valdiate that the input is in an expected state.
if pi.state != StatePendingPublish {
log.Errorf("Expect input %v to have %v, instead it "+
"has %v", input.PreviousOutPoint,
StatePendingPublish, pi.state)
"has %v", op, StatePendingPublish, pi.state)
continue
}
log.Warnf("Failed to publish input %v", input.PreviousOutPoint)
log.Warnf("Failed to publish input %v", op)
// Update the input's state.
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
// inputInit to be skipped, and the final input to be marked as
// published.
s.markInputsPublishFailed([]*wire.TxIn{
inputNotExist, inputInit, inputPendingPublish,
s.markInputsPublishFailed([]wire.OutPoint{
inputNotExist.PreviousOutPoint,
inputInit.PreviousOutPoint,
inputPendingPublish.PreviousOutPoint,
})
// We expect unchanged number of pending inputs.