mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-22 22:25:24 +01:00
lnwallet: update state machine due to channeldb and SignDescriptor changes
This commit is contained in:
parent
705661a39e
commit
22ee0a7576
2 changed files with 101 additions and 73 deletions
|
@ -835,15 +835,18 @@ func deriveCommitmentKeys(commitPoint *btcec.PublicKey, isOurCommit bool,
|
||||||
keyRing := &CommitmentKeyRing{
|
keyRing := &CommitmentKeyRing{
|
||||||
CommitPoint: commitPoint,
|
CommitPoint: commitPoint,
|
||||||
|
|
||||||
LocalCommitKeyTweak: SingleTweakBytes(commitPoint,
|
LocalCommitKeyTweak: SingleTweakBytes(
|
||||||
localChanCfg.PaymentBasePoint),
|
commitPoint, localChanCfg.PaymentBasePoint.PubKey,
|
||||||
LocalHtlcKeyTweak: SingleTweakBytes(commitPoint,
|
),
|
||||||
localChanCfg.HtlcBasePoint),
|
LocalHtlcKeyTweak: SingleTweakBytes(
|
||||||
|
commitPoint, localChanCfg.HtlcBasePoint.PubKey,
|
||||||
LocalHtlcKey: TweakPubKey(localChanCfg.HtlcBasePoint,
|
),
|
||||||
commitPoint),
|
LocalHtlcKey: TweakPubKey(
|
||||||
RemoteHtlcKey: TweakPubKey(remoteChanCfg.HtlcBasePoint,
|
localChanCfg.HtlcBasePoint.PubKey, commitPoint,
|
||||||
commitPoint),
|
),
|
||||||
|
RemoteHtlcKey: TweakPubKey(
|
||||||
|
remoteChanCfg.HtlcBasePoint.PubKey, commitPoint,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll now compute the delay, no delay, and revocation key based on
|
// We'll now compute the delay, no delay, and revocation key based on
|
||||||
|
@ -857,13 +860,13 @@ func deriveCommitmentKeys(commitPoint *btcec.PublicKey, isOurCommit bool,
|
||||||
revocationBasePoint *btcec.PublicKey
|
revocationBasePoint *btcec.PublicKey
|
||||||
)
|
)
|
||||||
if isOurCommit {
|
if isOurCommit {
|
||||||
delayBasePoint = localChanCfg.DelayBasePoint
|
delayBasePoint = localChanCfg.DelayBasePoint.PubKey
|
||||||
noDelayBasePoint = remoteChanCfg.PaymentBasePoint
|
noDelayBasePoint = remoteChanCfg.PaymentBasePoint.PubKey
|
||||||
revocationBasePoint = remoteChanCfg.RevocationBasePoint
|
revocationBasePoint = remoteChanCfg.RevocationBasePoint.PubKey
|
||||||
} else {
|
} else {
|
||||||
delayBasePoint = remoteChanCfg.DelayBasePoint
|
delayBasePoint = remoteChanCfg.DelayBasePoint.PubKey
|
||||||
noDelayBasePoint = localChanCfg.PaymentBasePoint
|
noDelayBasePoint = localChanCfg.PaymentBasePoint.PubKey
|
||||||
revocationBasePoint = localChanCfg.RevocationBasePoint
|
revocationBasePoint = localChanCfg.RevocationBasePoint.PubKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// With the base points assigned, we can now derive the actual keys
|
// With the base points assigned, we can now derive the actual keys
|
||||||
|
@ -1241,8 +1244,8 @@ func NewLightningChannel(signer Signer, pCache PreimageCache,
|
||||||
remoteUpdateLog: remoteUpdateLog,
|
remoteUpdateLog: remoteUpdateLog,
|
||||||
ChanPoint: &state.FundingOutpoint,
|
ChanPoint: &state.FundingOutpoint,
|
||||||
Capacity: state.Capacity,
|
Capacity: state.Capacity,
|
||||||
LocalFundingKey: state.LocalChanCfg.MultiSigKey,
|
LocalFundingKey: state.LocalChanCfg.MultiSigKey.PubKey,
|
||||||
RemoteFundingKey: state.RemoteChanCfg.MultiSigKey,
|
RemoteFundingKey: state.RemoteChanCfg.MultiSigKey.PubKey,
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1277,8 +1280,8 @@ func NewLightningChannel(signer Signer, pCache PreimageCache,
|
||||||
// createSignDesc derives the SignDescriptor for commitment transactions from
|
// createSignDesc derives the SignDescriptor for commitment transactions from
|
||||||
// other fields on the LightningChannel.
|
// other fields on the LightningChannel.
|
||||||
func (lc *LightningChannel) createSignDesc() error {
|
func (lc *LightningChannel) createSignDesc() error {
|
||||||
localKey := lc.localChanCfg.MultiSigKey.SerializeCompressed()
|
localKey := lc.localChanCfg.MultiSigKey.PubKey.SerializeCompressed()
|
||||||
remoteKey := lc.remoteChanCfg.MultiSigKey.SerializeCompressed()
|
remoteKey := lc.remoteChanCfg.MultiSigKey.PubKey.SerializeCompressed()
|
||||||
|
|
||||||
multiSigScript, err := genMultiSigScript(localKey, remoteKey)
|
multiSigScript, err := genMultiSigScript(localKey, remoteKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1290,7 +1293,7 @@ func (lc *LightningChannel) createSignDesc() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
lc.signDesc = &SignDescriptor{
|
lc.signDesc = &SignDescriptor{
|
||||||
PubKey: lc.localChanCfg.MultiSigKey,
|
KeyDesc: lc.localChanCfg.MultiSigKey,
|
||||||
WitnessScript: multiSigScript,
|
WitnessScript: multiSigScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
PkScript: fundingPkScript,
|
PkScript: fundingPkScript,
|
||||||
|
@ -1310,13 +1313,13 @@ func (lc *LightningChannel) createStateHintObfuscator() {
|
||||||
state := lc.channelState
|
state := lc.channelState
|
||||||
if state.IsInitiator {
|
if state.IsInitiator {
|
||||||
lc.stateHintObfuscator = DeriveStateHintObfuscator(
|
lc.stateHintObfuscator = DeriveStateHintObfuscator(
|
||||||
state.LocalChanCfg.PaymentBasePoint,
|
state.LocalChanCfg.PaymentBasePoint.PubKey,
|
||||||
state.RemoteChanCfg.PaymentBasePoint,
|
state.RemoteChanCfg.PaymentBasePoint.PubKey,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
lc.stateHintObfuscator = DeriveStateHintObfuscator(
|
lc.stateHintObfuscator = DeriveStateHintObfuscator(
|
||||||
state.RemoteChanCfg.PaymentBasePoint,
|
state.RemoteChanCfg.PaymentBasePoint.PubKey,
|
||||||
state.LocalChanCfg.PaymentBasePoint,
|
state.LocalChanCfg.PaymentBasePoint.PubKey,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1820,7 +1823,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||||
if localAmt >= chanState.RemoteChanCfg.DustLimit {
|
if localAmt >= chanState.RemoteChanCfg.DustLimit {
|
||||||
localSignDesc = &SignDescriptor{
|
localSignDesc = &SignDescriptor{
|
||||||
SingleTweak: keyRing.LocalCommitKeyTweak,
|
SingleTweak: keyRing.LocalCommitKeyTweak,
|
||||||
PubKey: chanState.LocalChanCfg.PaymentBasePoint,
|
KeyDesc: chanState.LocalChanCfg.PaymentBasePoint,
|
||||||
WitnessScript: localPkScript,
|
WitnessScript: localPkScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
PkScript: localPkScript,
|
PkScript: localPkScript,
|
||||||
|
@ -1834,7 +1837,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||||
// limit, assemble the remote sign descriptor.
|
// limit, assemble the remote sign descriptor.
|
||||||
if remoteAmt >= chanState.RemoteChanCfg.DustLimit {
|
if remoteAmt >= chanState.RemoteChanCfg.DustLimit {
|
||||||
remoteSignDesc = &SignDescriptor{
|
remoteSignDesc = &SignDescriptor{
|
||||||
PubKey: chanState.LocalChanCfg.RevocationBasePoint,
|
KeyDesc: chanState.LocalChanCfg.RevocationBasePoint,
|
||||||
DoubleTweak: commitmentSecret,
|
DoubleTweak: commitmentSecret,
|
||||||
WitnessScript: remotePkScript,
|
WitnessScript: remotePkScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
|
@ -1894,7 +1897,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||||
|
|
||||||
htlcRetributions[i] = HtlcRetribution{
|
htlcRetributions[i] = HtlcRetribution{
|
||||||
SignDesc: SignDescriptor{
|
SignDesc: SignDescriptor{
|
||||||
PubKey: chanState.LocalChanCfg.RevocationBasePoint,
|
KeyDesc: chanState.LocalChanCfg.RevocationBasePoint,
|
||||||
DoubleTweak: commitmentSecret,
|
DoubleTweak: commitmentSecret,
|
||||||
WitnessScript: htlcScript,
|
WitnessScript: htlcScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
|
@ -2462,7 +2465,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
|
||||||
// signature to give to the remote party for this commitment
|
// signature to give to the remote party for this commitment
|
||||||
// transaction. Note we use the raw HTLC amount.
|
// transaction. Note we use the raw HTLC amount.
|
||||||
sigJob.signDesc = SignDescriptor{
|
sigJob.signDesc = SignDescriptor{
|
||||||
PubKey: localChanCfg.HtlcBasePoint,
|
KeyDesc: localChanCfg.HtlcBasePoint,
|
||||||
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
||||||
WitnessScript: htlc.theirWitnessScript,
|
WitnessScript: htlc.theirWitnessScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
|
@ -2512,7 +2515,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
|
||||||
// signature to give to the remote party for this commitment
|
// signature to give to the remote party for this commitment
|
||||||
// transaction. Note we use the raw HTLC amount.
|
// transaction. Note we use the raw HTLC amount.
|
||||||
sigJob.signDesc = SignDescriptor{
|
sigJob.signDesc = SignDescriptor{
|
||||||
PubKey: localChanCfg.HtlcBasePoint,
|
KeyDesc: localChanCfg.HtlcBasePoint,
|
||||||
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
||||||
WitnessScript: htlc.theirWitnessScript,
|
WitnessScript: htlc.theirWitnessScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
|
@ -3532,8 +3535,8 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSig lnwire.Sig,
|
||||||
// we'll ensure that the newly constructed commitment state has a valid
|
// we'll ensure that the newly constructed commitment state has a valid
|
||||||
// signature.
|
// signature.
|
||||||
verifyKey := btcec.PublicKey{
|
verifyKey := btcec.PublicKey{
|
||||||
X: lc.remoteChanCfg.MultiSigKey.X,
|
X: lc.remoteChanCfg.MultiSigKey.PubKey.X,
|
||||||
Y: lc.remoteChanCfg.MultiSigKey.Y,
|
Y: lc.remoteChanCfg.MultiSigKey.PubKey.Y,
|
||||||
Curve: btcec.S256(),
|
Curve: btcec.S256(),
|
||||||
}
|
}
|
||||||
cSig, err := commitSig.ToSignature()
|
cSig, err := commitSig.ToSignature()
|
||||||
|
@ -4145,8 +4148,8 @@ func (lc *LightningChannel) getSignedCommitTx() (*wire.MsgTx, error) {
|
||||||
|
|
||||||
// With the final signature generated, create the witness stack
|
// With the final signature generated, create the witness stack
|
||||||
// required to spend from the multi-sig output.
|
// required to spend from the multi-sig output.
|
||||||
ourKey := lc.localChanCfg.MultiSigKey.SerializeCompressed()
|
ourKey := lc.localChanCfg.MultiSigKey.PubKey.SerializeCompressed()
|
||||||
theirKey := lc.remoteChanCfg.MultiSigKey.SerializeCompressed()
|
theirKey := lc.remoteChanCfg.MultiSigKey.PubKey.SerializeCompressed()
|
||||||
|
|
||||||
commitTx.TxIn[0].Witness = SpendMultiSig(
|
commitTx.TxIn[0].Witness = SpendMultiSig(
|
||||||
lc.signDesc.WitnessScript, ourKey,
|
lc.signDesc.WitnessScript, ourKey,
|
||||||
|
@ -4267,7 +4270,7 @@ func NewUnilateralCloseSummary(chanState *channeldb.OpenChannel, signer Signer,
|
||||||
commitResolution = &CommitOutputResolution{
|
commitResolution = &CommitOutputResolution{
|
||||||
SelfOutPoint: *selfPoint,
|
SelfOutPoint: *selfPoint,
|
||||||
SelfOutputSignDesc: SignDescriptor{
|
SelfOutputSignDesc: SignDescriptor{
|
||||||
PubKey: localPayBase,
|
KeyDesc: localPayBase,
|
||||||
SingleTweak: keyRing.LocalCommitKeyTweak,
|
SingleTweak: keyRing.LocalCommitKeyTweak,
|
||||||
WitnessScript: selfP2WKH,
|
WitnessScript: selfP2WKH,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
|
@ -4435,7 +4438,7 @@ func newOutgoingHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelCon
|
||||||
Expiry: htlc.RefundTimeout,
|
Expiry: htlc.RefundTimeout,
|
||||||
ClaimOutpoint: op,
|
ClaimOutpoint: op,
|
||||||
SweepSignDesc: SignDescriptor{
|
SweepSignDesc: SignDescriptor{
|
||||||
PubKey: localChanCfg.HtlcBasePoint,
|
KeyDesc: localChanCfg.HtlcBasePoint,
|
||||||
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
||||||
WitnessScript: htlcReceiverScript,
|
WitnessScript: htlcReceiverScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
|
@ -4475,7 +4478,7 @@ func newOutgoingHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelCon
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
timeoutSignDesc := SignDescriptor{
|
timeoutSignDesc := SignDescriptor{
|
||||||
PubKey: localChanCfg.HtlcBasePoint,
|
KeyDesc: localChanCfg.HtlcBasePoint,
|
||||||
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
||||||
WitnessScript: htlcCreationScript,
|
WitnessScript: htlcCreationScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
|
@ -4509,8 +4512,9 @@ func newOutgoingHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelCon
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
localDelayTweak := SingleTweakBytes(keyRing.CommitPoint,
|
localDelayTweak := SingleTweakBytes(
|
||||||
localChanCfg.DelayBasePoint)
|
keyRing.CommitPoint, localChanCfg.DelayBasePoint.PubKey,
|
||||||
|
)
|
||||||
return &OutgoingHtlcResolution{
|
return &OutgoingHtlcResolution{
|
||||||
Expiry: htlc.RefundTimeout,
|
Expiry: htlc.RefundTimeout,
|
||||||
SignedTimeoutTx: timeoutTx,
|
SignedTimeoutTx: timeoutTx,
|
||||||
|
@ -4520,7 +4524,7 @@ func newOutgoingHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelCon
|
||||||
Index: 0,
|
Index: 0,
|
||||||
},
|
},
|
||||||
SweepSignDesc: SignDescriptor{
|
SweepSignDesc: SignDescriptor{
|
||||||
PubKey: localChanCfg.DelayBasePoint,
|
KeyDesc: localChanCfg.DelayBasePoint,
|
||||||
SingleTweak: localDelayTweak,
|
SingleTweak: localDelayTweak,
|
||||||
WitnessScript: htlcSweepScript,
|
WitnessScript: htlcSweepScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
|
@ -4573,7 +4577,7 @@ func newIncomingHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelCon
|
||||||
ClaimOutpoint: op,
|
ClaimOutpoint: op,
|
||||||
CsvDelay: csvDelay,
|
CsvDelay: csvDelay,
|
||||||
SweepSignDesc: SignDescriptor{
|
SweepSignDesc: SignDescriptor{
|
||||||
PubKey: localChanCfg.HtlcBasePoint,
|
KeyDesc: localChanCfg.HtlcBasePoint,
|
||||||
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
||||||
WitnessScript: htlcSenderScript,
|
WitnessScript: htlcSenderScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
|
@ -4609,7 +4613,7 @@ func newIncomingHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelCon
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
successSignDesc := SignDescriptor{
|
successSignDesc := SignDescriptor{
|
||||||
PubKey: localChanCfg.HtlcBasePoint,
|
KeyDesc: localChanCfg.HtlcBasePoint,
|
||||||
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
SingleTweak: keyRing.LocalHtlcKeyTweak,
|
||||||
WitnessScript: htlcCreationScript,
|
WitnessScript: htlcCreationScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
|
@ -4645,7 +4649,7 @@ func newIncomingHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelCon
|
||||||
}
|
}
|
||||||
|
|
||||||
localDelayTweak := SingleTweakBytes(
|
localDelayTweak := SingleTweakBytes(
|
||||||
keyRing.CommitPoint, localChanCfg.DelayBasePoint,
|
keyRing.CommitPoint, localChanCfg.DelayBasePoint.PubKey,
|
||||||
)
|
)
|
||||||
return &IncomingHtlcResolution{
|
return &IncomingHtlcResolution{
|
||||||
Preimage: preimage,
|
Preimage: preimage,
|
||||||
|
@ -4656,7 +4660,7 @@ func newIncomingHtlcResolution(signer Signer, localChanCfg *channeldb.ChannelCon
|
||||||
Index: 0,
|
Index: 0,
|
||||||
},
|
},
|
||||||
SweepSignDesc: SignDescriptor{
|
SweepSignDesc: SignDescriptor{
|
||||||
PubKey: localChanCfg.DelayBasePoint,
|
KeyDesc: localChanCfg.DelayBasePoint,
|
||||||
SingleTweak: localDelayTweak,
|
SingleTweak: localDelayTweak,
|
||||||
WitnessScript: htlcSweepScript,
|
WitnessScript: htlcSweepScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
|
@ -4844,8 +4848,9 @@ func (lc *LightningChannel) ForceClose() (*ForceCloseSummary, error) {
|
||||||
// nil.
|
// nil.
|
||||||
var commitResolution *CommitOutputResolution
|
var commitResolution *CommitOutputResolution
|
||||||
if len(delayScript) != 0 {
|
if len(delayScript) != 0 {
|
||||||
singleTweak := SingleTweakBytes(commitPoint,
|
singleTweak := SingleTweakBytes(
|
||||||
lc.localChanCfg.DelayBasePoint)
|
commitPoint, lc.localChanCfg.DelayBasePoint.PubKey,
|
||||||
|
)
|
||||||
localBalance := localCommitment.LocalBalance
|
localBalance := localCommitment.LocalBalance
|
||||||
commitResolution = &CommitOutputResolution{
|
commitResolution = &CommitOutputResolution{
|
||||||
SelfOutPoint: wire.OutPoint{
|
SelfOutPoint: wire.OutPoint{
|
||||||
|
@ -4853,7 +4858,7 @@ func (lc *LightningChannel) ForceClose() (*ForceCloseSummary, error) {
|
||||||
Index: delayIndex,
|
Index: delayIndex,
|
||||||
},
|
},
|
||||||
SelfOutputSignDesc: SignDescriptor{
|
SelfOutputSignDesc: SignDescriptor{
|
||||||
PubKey: lc.localChanCfg.DelayBasePoint,
|
KeyDesc: lc.localChanCfg.DelayBasePoint,
|
||||||
SingleTweak: singleTweak,
|
SingleTweak: singleTweak,
|
||||||
WitnessScript: selfScript,
|
WitnessScript: selfScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
|
@ -5012,8 +5017,8 @@ func (lc *LightningChannel) CompleteCooperativeClose(localSig, remoteSig []byte,
|
||||||
|
|
||||||
// Finally, construct the witness stack minding the order of the
|
// Finally, construct the witness stack minding the order of the
|
||||||
// pubkeys+sigs on the stack.
|
// pubkeys+sigs on the stack.
|
||||||
ourKey := lc.localChanCfg.MultiSigKey.SerializeCompressed()
|
ourKey := lc.localChanCfg.MultiSigKey.PubKey.SerializeCompressed()
|
||||||
theirKey := lc.remoteChanCfg.MultiSigKey.SerializeCompressed()
|
theirKey := lc.remoteChanCfg.MultiSigKey.PubKey.SerializeCompressed()
|
||||||
witness := SpendMultiSig(lc.signDesc.WitnessScript, ourKey,
|
witness := SpendMultiSig(lc.signDesc.WitnessScript, ourKey,
|
||||||
localSig, theirKey, remoteSig)
|
localSig, theirKey, remoteSig)
|
||||||
closeTx.TxIn[0].Witness = witness
|
closeTx.TxIn[0].Witness = witness
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/shachain"
|
"github.com/lightningnetwork/lnd/shachain"
|
||||||
"github.com/roasbeef/btcd/blockchain"
|
"github.com/roasbeef/btcd/blockchain"
|
||||||
|
@ -168,12 +169,22 @@ func createTestChannels(revocationWindow int) (*LightningChannel,
|
||||||
MinHTLC: 0,
|
MinHTLC: 0,
|
||||||
MaxAcceptedHtlcs: MaxHTLCNumber / 2,
|
MaxAcceptedHtlcs: MaxHTLCNumber / 2,
|
||||||
},
|
},
|
||||||
CsvDelay: uint16(csvTimeoutAlice),
|
CsvDelay: uint16(csvTimeoutAlice),
|
||||||
MultiSigKey: aliceKeys[0].PubKey(),
|
MultiSigKey: keychain.KeyDescriptor{
|
||||||
RevocationBasePoint: aliceKeys[1].PubKey(),
|
PubKey: aliceKeys[0].PubKey(),
|
||||||
PaymentBasePoint: aliceKeys[2].PubKey(),
|
},
|
||||||
DelayBasePoint: aliceKeys[3].PubKey(),
|
RevocationBasePoint: keychain.KeyDescriptor{
|
||||||
HtlcBasePoint: aliceKeys[4].PubKey(),
|
PubKey: aliceKeys[1].PubKey(),
|
||||||
|
},
|
||||||
|
PaymentBasePoint: keychain.KeyDescriptor{
|
||||||
|
PubKey: aliceKeys[2].PubKey(),
|
||||||
|
},
|
||||||
|
DelayBasePoint: keychain.KeyDescriptor{
|
||||||
|
PubKey: aliceKeys[3].PubKey(),
|
||||||
|
},
|
||||||
|
HtlcBasePoint: keychain.KeyDescriptor{
|
||||||
|
PubKey: aliceKeys[4].PubKey(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
bobCfg := channeldb.ChannelConfig{
|
bobCfg := channeldb.ChannelConfig{
|
||||||
ChannelConstraints: channeldb.ChannelConstraints{
|
ChannelConstraints: channeldb.ChannelConstraints{
|
||||||
|
@ -183,28 +194,40 @@ func createTestChannels(revocationWindow int) (*LightningChannel,
|
||||||
MinHTLC: 0,
|
MinHTLC: 0,
|
||||||
MaxAcceptedHtlcs: MaxHTLCNumber / 2,
|
MaxAcceptedHtlcs: MaxHTLCNumber / 2,
|
||||||
},
|
},
|
||||||
CsvDelay: uint16(csvTimeoutBob),
|
CsvDelay: uint16(csvTimeoutBob),
|
||||||
MultiSigKey: bobKeys[0].PubKey(),
|
MultiSigKey: keychain.KeyDescriptor{
|
||||||
RevocationBasePoint: bobKeys[1].PubKey(),
|
PubKey: bobKeys[0].PubKey(),
|
||||||
PaymentBasePoint: bobKeys[2].PubKey(),
|
},
|
||||||
DelayBasePoint: bobKeys[3].PubKey(),
|
RevocationBasePoint: keychain.KeyDescriptor{
|
||||||
HtlcBasePoint: bobKeys[4].PubKey(),
|
PubKey: bobKeys[1].PubKey(),
|
||||||
|
},
|
||||||
|
PaymentBasePoint: keychain.KeyDescriptor{
|
||||||
|
PubKey: bobKeys[2].PubKey(),
|
||||||
|
},
|
||||||
|
DelayBasePoint: keychain.KeyDescriptor{
|
||||||
|
PubKey: bobKeys[3].PubKey(),
|
||||||
|
},
|
||||||
|
HtlcBasePoint: keychain.KeyDescriptor{
|
||||||
|
PubKey: bobKeys[4].PubKey(),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
bobRoot := DeriveRevocationRoot(
|
bobRoot, err := chainhash.NewHash(bobKeys[0].Serialize())
|
||||||
bobKeys[0], testHdSeed, aliceKeys[0].PubKey(),
|
if err != nil {
|
||||||
)
|
return nil, nil, nil, err
|
||||||
bobPreimageProducer := shachain.NewRevocationProducer(bobRoot)
|
}
|
||||||
|
bobPreimageProducer := shachain.NewRevocationProducer(*bobRoot)
|
||||||
bobFirstRevoke, err := bobPreimageProducer.AtIndex(0)
|
bobFirstRevoke, err := bobPreimageProducer.AtIndex(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
bobCommitPoint := ComputeCommitmentPoint(bobFirstRevoke[:])
|
bobCommitPoint := ComputeCommitmentPoint(bobFirstRevoke[:])
|
||||||
|
|
||||||
aliceRoot := DeriveRevocationRoot(
|
aliceRoot, err := chainhash.NewHash(aliceKeys[0].Serialize())
|
||||||
aliceKeys[0], testHdSeed, bobKeys[0].PubKey(),
|
if err != nil {
|
||||||
)
|
return nil, nil, nil, err
|
||||||
alicePreimageProducer := shachain.NewRevocationProducer(aliceRoot)
|
}
|
||||||
|
alicePreimageProducer := shachain.NewRevocationProducer(*aliceRoot)
|
||||||
aliceFirstRevoke, err := alicePreimageProducer.AtIndex(0)
|
aliceFirstRevoke, err := alicePreimageProducer.AtIndex(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
|
@ -880,8 +903,8 @@ func TestForceClose(t *testing.T) {
|
||||||
|
|
||||||
// The rest of the close summary should have been populated properly.
|
// The rest of the close summary should have been populated properly.
|
||||||
aliceDelayPoint := aliceChannel.channelState.LocalChanCfg.DelayBasePoint
|
aliceDelayPoint := aliceChannel.channelState.LocalChanCfg.DelayBasePoint
|
||||||
if !aliceCommitResolution.SelfOutputSignDesc.PubKey.IsEqual(
|
if !aliceCommitResolution.SelfOutputSignDesc.KeyDesc.PubKey.IsEqual(
|
||||||
aliceDelayPoint,
|
aliceDelayPoint.PubKey,
|
||||||
) {
|
) {
|
||||||
t.Fatalf("alice incorrect pubkey in SelfOutputSignDesc")
|
t.Fatalf("alice incorrect pubkey in SelfOutputSignDesc")
|
||||||
}
|
}
|
||||||
|
@ -1036,7 +1059,7 @@ func TestForceClose(t *testing.T) {
|
||||||
t.Fatalf("bob fails to include to-self output in ForceCloseSummary")
|
t.Fatalf("bob fails to include to-self output in ForceCloseSummary")
|
||||||
}
|
}
|
||||||
bobDelayPoint := bobChannel.channelState.LocalChanCfg.DelayBasePoint
|
bobDelayPoint := bobChannel.channelState.LocalChanCfg.DelayBasePoint
|
||||||
if !bobCommitResolution.SelfOutputSignDesc.PubKey.IsEqual(bobDelayPoint) {
|
if !bobCommitResolution.SelfOutputSignDesc.KeyDesc.PubKey.IsEqual(bobDelayPoint.PubKey) {
|
||||||
t.Fatalf("bob incorrect pubkey in SelfOutputSignDesc")
|
t.Fatalf("bob incorrect pubkey in SelfOutputSignDesc")
|
||||||
}
|
}
|
||||||
if bobCommitResolution.SelfOutputSignDesc.Output.Value !=
|
if bobCommitResolution.SelfOutputSignDesc.Output.Value !=
|
||||||
|
@ -1156,8 +1179,8 @@ func TestForceCloseDustOutput(t *testing.T) {
|
||||||
t.Fatalf("alice fails to include to-self output in " +
|
t.Fatalf("alice fails to include to-self output in " +
|
||||||
"ForceCloseSummary")
|
"ForceCloseSummary")
|
||||||
}
|
}
|
||||||
if !commitResolution.SelfOutputSignDesc.PubKey.IsEqual(
|
if !commitResolution.SelfOutputSignDesc.KeyDesc.PubKey.IsEqual(
|
||||||
aliceChannel.channelState.LocalChanCfg.DelayBasePoint,
|
aliceChannel.channelState.LocalChanCfg.DelayBasePoint.PubKey,
|
||||||
) {
|
) {
|
||||||
t.Fatalf("alice incorrect pubkey in SelfOutputSignDesc")
|
t.Fatalf("alice incorrect pubkey in SelfOutputSignDesc")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue