htlcswitch/mailbox: fail on duplicate adds

This commit is contained in:
Conner Fromknecht committed 2020-04-14 10:50:25 -07:00
1 parent e7ece11c29
commit 16ad0274c9
2 files changed
+56 -6

No files matched your search

+11 -5
View File
@@ -12,9 +12,15 @@ import (
"github.com/lightningnetwork/lnd/lnwire"
)
// ErrMailBoxShuttingDown is returned when the mailbox is interrupted by a
// shutdown request.
var ErrMailBoxShuttingDown = errors.New("mailbox is shutting down")
var (
// ErrMailBoxShuttingDown is returned when the mailbox is interrupted by
// a shutdown request.
ErrMailBoxShuttingDown = errors.New("mailbox is shutting down")
// ErrPacketAlreadyExists signals that an attempt to add a packet failed
// because it already exists in the mailbox.
ErrPacketAlreadyExists = errors.New("mailbox already has packet")
)
// MailBox is an interface which represents a concurrent-safe, in-order
// delivery queue for messages from the network and also from the main switch.
@@ -564,7 +570,7 @@ func (m *memoryMailBox) AddPacket(pkt *htlcPacket) error {
case *lnwire.UpdateFulfillHTLC, *lnwire.UpdateFailHTLC:
if _, ok := m.pktIndex[pkt.inKey()]; ok {
m.pktCond.L.Unlock()
return nil
return ErrPacketAlreadyExists
}
entry := m.htlcPkts.PushBack(pkt)
@@ -577,7 +583,7 @@ func (m *memoryMailBox) AddPacket(pkt *htlcPacket) error {
case *lnwire.UpdateAddHTLC:
if _, ok := m.addIndex[pkt.inKey()]; ok {
m.pktCond.L.Unlock()
return nil
return ErrPacketAlreadyExists
}
entry := m.addPkts.PushBack(&pktWithExpiry{