lnwallet/channel: concrete HTLC errors and ack AddRefs
This commit is contained in:
parent
0dca373bcd
commit
05308ec22c
@ -4433,6 +4433,22 @@ func (lc *LightningChannel) LoadFwdPkgs() ([]*channeldb.FwdPkg, error) {
|
||||
return lc.channelState.LoadFwdPkgs()
|
||||
}
|
||||
|
||||
// AckAddHtlcs sets a bit in the FwdFilter of a forwarding package belonging to
|
||||
// this channel, that corresponds to the given AddRef. This method also succeeds
|
||||
// if no forwarding package is found.
|
||||
func (lc *LightningChannel) AckAddHtlcs(addRef channeldb.AddRef) error {
|
||||
return lc.channelState.AckAddHtlcs(addRef)
|
||||
}
|
||||
|
||||
// AckSettleFails sets a bit in the SettleFailFilter of a forwarding package
|
||||
// belonging to this channel, that corresponds to the given SettleFailRef. This
|
||||
// method also succeeds if no forwarding package is found.
|
||||
func (lc *LightningChannel) AckSettleFails(
|
||||
settleFailRefs ...channeldb.SettleFailRef) error {
|
||||
|
||||
return lc.channelState.AckSettleFails(settleFailRefs...)
|
||||
}
|
||||
|
||||
// SetFwdFilter writes the forwarding decision for a given remote commitment
|
||||
// height.
|
||||
func (lc *LightningChannel) SetFwdFilter(height uint64,
|
||||
@ -4572,21 +4588,18 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte,
|
||||
|
||||
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
||||
if htlc == nil {
|
||||
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
||||
lc.ShortChanID())
|
||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||
}
|
||||
|
||||
// Now that we know the HTLC exists, before checking to see if the
|
||||
// preimage matches, we'll ensure that we haven't already attempted to
|
||||
// modify the HTLC.
|
||||
if lc.remoteUpdateLog.htlcHasModification(htlcIndex) {
|
||||
return fmt.Errorf("HTLC with ID %d has already been settled",
|
||||
htlcIndex)
|
||||
return ErrHtlcIndexAlreadySettled(htlcIndex)
|
||||
}
|
||||
|
||||
if htlc.RHash != sha256.Sum256(preimage[:]) {
|
||||
return fmt.Errorf("Invalid payment preimage %x for hash %x",
|
||||
preimage[:], htlc.RHash[:])
|
||||
return ErrInvalidSettlePreimage{preimage[:], htlc.RHash[:]}
|
||||
}
|
||||
|
||||
pd := &PaymentDescriptor{
|
||||
@ -4620,21 +4633,18 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, htlcIndex uint6
|
||||
|
||||
htlc := lc.localUpdateLog.lookupHtlc(htlcIndex)
|
||||
if htlc == nil {
|
||||
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
||||
lc.ShortChanID())
|
||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||
}
|
||||
|
||||
// Now that we know the HTLC exists, before checking to see if the
|
||||
// preimage matches, we'll ensure that they haven't already attempted
|
||||
// to modify the HTLC.
|
||||
if lc.localUpdateLog.htlcHasModification(htlcIndex) {
|
||||
return fmt.Errorf("HTLC with ID %d has already been settled",
|
||||
htlcIndex)
|
||||
return ErrHtlcIndexAlreadySettled(htlcIndex)
|
||||
}
|
||||
|
||||
if htlc.RHash != sha256.Sum256(preimage[:]) {
|
||||
return fmt.Errorf("Invalid payment preimage %x for hash %x",
|
||||
preimage[:], htlc.RHash[:])
|
||||
return ErrInvalidSettlePreimage{preimage[:], htlc.RHash[:]}
|
||||
}
|
||||
|
||||
pd := &PaymentDescriptor{
|
||||
@ -4688,15 +4698,13 @@ func (lc *LightningChannel) FailHTLC(htlcIndex uint64, reason []byte,
|
||||
|
||||
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
||||
if htlc == nil {
|
||||
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
||||
lc.ShortChanID())
|
||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||
}
|
||||
|
||||
// Now that we know the HTLC exists, we'll ensure that we haven't
|
||||
// already attempted to fail the HTLC.
|
||||
if lc.remoteUpdateLog.htlcHasModification(htlcIndex) {
|
||||
return fmt.Errorf("HTLC with ID %d has already been failed",
|
||||
htlcIndex)
|
||||
return ErrHtlcIndexAlreadyFailed(htlcIndex)
|
||||
}
|
||||
|
||||
pd := &PaymentDescriptor{
|
||||
@ -4740,15 +4748,13 @@ func (lc *LightningChannel) MalformedFailHTLC(htlcIndex uint64,
|
||||
|
||||
htlc := lc.remoteUpdateLog.lookupHtlc(htlcIndex)
|
||||
if htlc == nil {
|
||||
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
||||
lc.ShortChanID())
|
||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||
}
|
||||
|
||||
// Now that we know the HTLC exists, we'll ensure that we haven't
|
||||
// already attempted to fail the HTLC.
|
||||
if lc.remoteUpdateLog.htlcHasModification(htlcIndex) {
|
||||
return fmt.Errorf("HTLC with ID %d has already been failed",
|
||||
htlcIndex)
|
||||
return ErrHtlcIndexAlreadyFailed(htlcIndex)
|
||||
}
|
||||
|
||||
pd := &PaymentDescriptor{
|
||||
@ -4785,15 +4791,13 @@ func (lc *LightningChannel) ReceiveFailHTLC(htlcIndex uint64, reason []byte,
|
||||
|
||||
htlc := lc.localUpdateLog.lookupHtlc(htlcIndex)
|
||||
if htlc == nil {
|
||||
return fmt.Errorf("No HTLC with ID %d in channel %v", htlcIndex,
|
||||
lc.ShortChanID())
|
||||
return ErrUnknownHtlcIndex{lc.ShortChanID(), htlcIndex}
|
||||
}
|
||||
|
||||
// Now that we know the HTLC exists, we'll ensure that they haven't
|
||||
// already attempted to fail the HTLC.
|
||||
if lc.localUpdateLog.htlcHasModification(htlcIndex) {
|
||||
return fmt.Errorf("HTLC with ID %d has already been failed",
|
||||
htlcIndex)
|
||||
return ErrHtlcIndexAlreadyFailed(htlcIndex)
|
||||
}
|
||||
|
||||
pd := &PaymentDescriptor{
|
||||
|
Loading…
Reference in New Issue
Block a user