lnwallet: eliminate usage of LightningChannel.theirPrevPkScript
This commit removes the theirPrevPkScript field from the LightningChannel struct all together. It’s no longer needed as the more fundamental mutation bug has been fixed within the channel state machine.
This commit is contained in:
parent
a3fd738491
commit
4cd277c8da
@ -276,7 +276,7 @@ func (c *commitment) toChannelDelta(ourCommit bool) (*channeldb.ChannelDelta, er
|
|||||||
found bool
|
found bool
|
||||||
)
|
)
|
||||||
|
|
||||||
pkScript := p.theirPrevPkScript
|
pkScript := p.theirPkScript
|
||||||
if ourCommit {
|
if ourCommit {
|
||||||
pkScript = p.ourPkScript
|
pkScript = p.ourPkScript
|
||||||
}
|
}
|
||||||
@ -294,8 +294,8 @@ func (c *commitment) toChannelDelta(ourCommit bool) (*channeldb.ChannelDelta, er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
return 0, fmt.Errorf("could not find a matching " +
|
return 0, fmt.Errorf("unable to find htlc: script=%x, value=%v",
|
||||||
"output for the HTLC in the commitment transaction")
|
pkScript, p.Amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
return idx, nil
|
return idx, nil
|
||||||
@ -309,8 +309,8 @@ func (c *commitment) toChannelDelta(ourCommit bool) (*channeldb.ChannelDelta, er
|
|||||||
if (ourCommit && htlc.isDustLocal) ||
|
if (ourCommit && htlc.isDustLocal) ||
|
||||||
(!ourCommit && htlc.isDustRemote) {
|
(!ourCommit && htlc.isDustRemote) {
|
||||||
index = maxUint16
|
index = maxUint16
|
||||||
} else if index, err = locateOutputIndex(htlc); err != nil {
|
} else if index, err = locateOutputIndex(&htlc); err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("unable to find outgoing htlc: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
h := &channeldb.HTLC{
|
h := &channeldb.HTLC{
|
||||||
@ -328,8 +328,8 @@ func (c *commitment) toChannelDelta(ourCommit bool) (*channeldb.ChannelDelta, er
|
|||||||
if (ourCommit && htlc.isDustLocal) ||
|
if (ourCommit && htlc.isDustLocal) ||
|
||||||
(!ourCommit && htlc.isDustRemote) {
|
(!ourCommit && htlc.isDustRemote) {
|
||||||
index = maxUint16
|
index = maxUint16
|
||||||
} else if index, err = locateOutputIndex(htlc); err != nil {
|
} else if index, err = locateOutputIndex(&htlc); err != nil {
|
||||||
return nil, err
|
return nil, fmt.Errorf("unable to find incoming htlc: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
h := &channeldb.HTLC{
|
h := &channeldb.HTLC{
|
||||||
@ -2075,12 +2075,6 @@ func (lc *LightningChannel) SettleHTLC(preimage [32]byte) (uint64, error) {
|
|||||||
|
|
||||||
lc.localUpdateLog.appendUpdate(pd)
|
lc.localUpdateLog.appendUpdate(pd)
|
||||||
|
|
||||||
// Since we will not be adding this HTLC to any commitment transaction
|
|
||||||
// anymore, we should properly set theirPrevPkScript so we can generate
|
|
||||||
// a valid ChannelDelta for a revoked remote commitment.
|
|
||||||
addEntry := lc.remoteUpdateLog.lookup(targetHTLC.Index)
|
|
||||||
addEntry.theirPrevPkScript = addEntry.theirPkScript
|
|
||||||
|
|
||||||
lc.rHashMap[paymentHash][0] = nil
|
lc.rHashMap[paymentHash][0] = nil
|
||||||
lc.rHashMap[paymentHash] = lc.rHashMap[paymentHash][1:]
|
lc.rHashMap[paymentHash] = lc.rHashMap[paymentHash][1:]
|
||||||
if len(lc.rHashMap[paymentHash]) == 0 {
|
if len(lc.rHashMap[paymentHash]) == 0 {
|
||||||
@ -2117,12 +2111,6 @@ func (lc *LightningChannel) ReceiveHTLCSettle(preimage [32]byte, logIndex uint64
|
|||||||
}
|
}
|
||||||
|
|
||||||
lc.remoteUpdateLog.appendUpdate(pd)
|
lc.remoteUpdateLog.appendUpdate(pd)
|
||||||
|
|
||||||
// Since we will not be adding this HTLC to any commitment transaction
|
|
||||||
// anymore, we should properly set theirPrevPkScript so we can generate
|
|
||||||
// a valid ChannelDelta for a revoked remote commitment.
|
|
||||||
htlc.theirPrevPkScript = htlc.theirPkScript
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2150,11 +2138,6 @@ func (lc *LightningChannel) FailHTLC(rHash [32]byte) (uint64, error) {
|
|||||||
|
|
||||||
lc.localUpdateLog.appendUpdate(pd)
|
lc.localUpdateLog.appendUpdate(pd)
|
||||||
|
|
||||||
// Since we will not be adding this HTLC to any commitment transaction
|
|
||||||
// anymore, we should properly set theirPrevPkScript so we can generate
|
|
||||||
// a valid ChannelDelta for a revoked remote commitment.
|
|
||||||
addEntry.theirPrevPkScript = addEntry.theirPkScript
|
|
||||||
|
|
||||||
lc.rHashMap[rHash][0] = nil
|
lc.rHashMap[rHash][0] = nil
|
||||||
lc.rHashMap[rHash] = lc.rHashMap[rHash][1:]
|
lc.rHashMap[rHash] = lc.rHashMap[rHash][1:]
|
||||||
if len(lc.rHashMap[rHash]) == 0 {
|
if len(lc.rHashMap[rHash]) == 0 {
|
||||||
@ -2187,11 +2170,6 @@ func (lc *LightningChannel) ReceiveFailHTLC(logIndex uint64) error {
|
|||||||
|
|
||||||
lc.remoteUpdateLog.appendUpdate(pd)
|
lc.remoteUpdateLog.appendUpdate(pd)
|
||||||
|
|
||||||
// Since we will not be adding this HTLC to any commitment transaction
|
|
||||||
// anymore, we should properly set theirPrevPkScript so we can generate
|
|
||||||
// a valid ChannelDelta for a revoked remote commitment.
|
|
||||||
htlc.theirPrevPkScript = htlc.theirPkScript
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2282,7 +2260,6 @@ func (lc *LightningChannel) addHTLC(commitTx *wire.MsgTx, ourCommit bool,
|
|||||||
if ourCommit {
|
if ourCommit {
|
||||||
paymentDesc.ourPkScript = htlcP2WSH
|
paymentDesc.ourPkScript = htlcP2WSH
|
||||||
} else {
|
} else {
|
||||||
paymentDesc.theirPrevPkScript = paymentDesc.theirPkScript
|
|
||||||
paymentDesc.theirPkScript = htlcP2WSH
|
paymentDesc.theirPkScript = htlcP2WSH
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user