Skip to content

Commit

Permalink
Wallet maintainer: Resolve deposit script type at the very end (#3719)
Browse files Browse the repository at this point in the history
The script type resolution requires access to transaction data stored on
the Bitcoin blockchain. If the given transaction hasn't actually
happened but was revealed as deposit to the `Bridge`, the maintainer
will not be able to resolve the deposit script type. So far, an error
was returned in that case and the maintainer stopped the entire deposit
sweep task. This cannot happen as the maintainer can be blocked on
deposit sweeps for a long time. Instead, the maintainer should log an
error and leave the deposit type unresolved.
  • Loading branch information
tomaszslabon authored Sep 20, 2023
2 parents f559b3e + 65a0f26 commit 968ac3e
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions pkg/maintainer/wallet/deposit_sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,6 @@ func FindDeposits(

logger.Debugf("getting details of deposit %d/%d", i+1, len(depositRevealedEvents))

depositTransaction, err := btcChain.GetTransaction(
event.FundingTxHash,
)
if err != nil {
return result, fmt.Errorf(
"failed to get deposit transaction: [%w]",
err,
)
}

publicKeyScript := depositTransaction.Outputs[event.FundingOutputIndex].PublicKeyScript
scriptType := bitcoin.GetScriptType(publicKeyScript)

depositKey := chain.BuildDepositKey(event.FundingTxHash, event.FundingOutputIndex)

depositRequest, found, err := chain.GetDepositRequest(
Expand Down Expand Up @@ -172,6 +159,20 @@ func FindDeposits(
continue
}

var scriptType bitcoin.ScriptType
depositTransaction, err := btcChain.GetTransaction(
event.FundingTxHash,
)
if err != nil {
logger.Errorf(
"failed to get deposit transaction data: [%v]",
err,
)
} else {
publicKeyScript := depositTransaction.Outputs[event.FundingOutputIndex].PublicKeyScript
scriptType = bitcoin.GetScriptType(publicKeyScript)
}

result = append(
result,
&Deposit{
Expand Down Expand Up @@ -229,7 +230,7 @@ func FindDepositsToSweep(
return nil,
fmt.Errorf(
"failed to get deposits for [%s] wallet: [%w]",
walletToSweep,
hexutils.Encode(walletToSweep[:]),
err,
)
}
Expand Down

0 comments on commit 968ac3e

Please sign in to comment.