channeldb: stricter validation of invoice updates

This commit is contained in:
Joost Jager
2019-11-27 13:20:14 +01:00
parent a4a3c41924
commit 00d93ed87b
4 changed files with 221 additions and 94 deletions

View File

@@ -138,11 +138,9 @@ func updateInvoice(ctx *invoiceUpdateCtx, inv *channeldb.Invoice) (
// We do accept or settle the HTLC.
switch inv.State {
case channeldb.ContractAccepted:
update.State = channeldb.ContractAccepted
return &update, resultDuplicateToAccepted, nil
case channeldb.ContractSettled:
update.State = channeldb.ContractSettled
return &update, resultDuplicateToSettled, nil
}
@@ -150,12 +148,16 @@ func updateInvoice(ctx *invoiceUpdateCtx, inv *channeldb.Invoice) (
// to wait for the preimage.
holdInvoice := inv.Terms.PaymentPreimage == channeldb.UnknownPreimage
if holdInvoice {
update.State = channeldb.ContractAccepted
update.State = &channeldb.InvoiceStateUpdateDesc{
NewState: channeldb.ContractAccepted,
}
return &update, resultAccepted, nil
}
update.Preimage = inv.Terms.PaymentPreimage
update.State = channeldb.ContractSettled
update.State = &channeldb.InvoiceStateUpdateDesc{
NewState: channeldb.ContractSettled,
Preimage: inv.Terms.PaymentPreimage,
}
return &update, resultSettled, nil
}