Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fee Verification for SPV #42

Merged
merged 1 commit into from Apr 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 12 additions & 21 deletions spv/ancestors_binary.go
Expand Up @@ -149,6 +149,18 @@ func VerifyAncestors(ctx context.Context, ancestry *Ancestry, mpv MerkleProofVer
ancestors[paymentTxID] = &Ancestor{
Tx: ancestry.PaymentTx,
}
if opts.fees {
if opts.feeQuote == nil {
return ErrNoFeeQuoteSupplied
}
ok, err := ancestry.PaymentTx.IsFeePaidEnough(opts.feeQuote)
if err != nil {
return err
}
if !ok {
return ErrFeePaidNotEnough
}
}
for _, ancestor := range ancestors {
inputsToCheck := make(map[[32]byte]*extendedInput)
if len(ancestor.Tx.Inputs) == 0 {
Expand Down Expand Up @@ -206,27 +218,6 @@ func VerifyAncestors(ctx context.Context, ancestry *Ancestry, mpv MerkleProofVer
}
}
}
if opts.fees {
if opts.feeQuote == nil {
return ErrNoFeeQuoteSupplied
}
// no need to check fees for transactions we have proofs for
if ancestor.Proof == nil {
// add satoshi amounts to all inputs which correspond to outputs we have
for inputID, extendedInput := range inputsToCheck {
if ancestry.Ancestors[inputID] == nil {
return ErrCannotCalculateFeePaid
}
sats := ancestry.Ancestors[inputID].Tx.Outputs[extendedInput.input.PreviousTxOutIndex].Satoshis
ancestor.Tx.Inputs[extendedInput.vin].PreviousTxSatoshis = sats
}
// check the fees
ok, err := ancestor.Tx.IsFeePaidEnough(opts.feeQuote)
if err != nil || !ok {
return ErrFeePaidNotEnough
}
}
}
}
return nil
}
Expand Down