lnwallet: rename DelayKey->ToLocalKey, NoDelayKey->ToRemoteKey

Since both parties are going to have their ouputs delayed, we move way
from the DelayKey naming, and instead use ToLocalKey and ToRemoteKey.
This commit is contained in:
Johan T. Halseth 2020-01-06 11:42:04 +01:00
parent 7b9c54996b
commit 4fde31229c
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
7 changed files with 61 additions and 49 deletions

@ -351,7 +351,7 @@ func isOurCommitment(localChanCfg, remoteChanCfg channeldb.ChannelConfig,
// With the keys derived, we'll construct the remote script that'll be // With the keys derived, we'll construct the remote script that'll be
// present if they have a non-dust balance on the commitment. // present if they have a non-dust balance on the commitment.
remotePkScript, err := input.CommitScriptUnencumbered( remotePkScript, err := input.CommitScriptUnencumbered(
commitKeyRing.NoDelayKey, commitKeyRing.ToRemoteKey,
) )
if err != nil { if err != nil {
return false, err return false, err
@ -361,7 +361,7 @@ func isOurCommitment(localChanCfg, remoteChanCfg channeldb.ChannelConfig,
// the remote party allowing them to claim this output before the CSV // the remote party allowing them to claim this output before the CSV
// delay if we breach. // delay if we breach.
localScript, err := input.CommitScriptToSelf( localScript, err := input.CommitScriptToSelf(
uint32(localChanCfg.CsvDelay), commitKeyRing.DelayKey, uint32(localChanCfg.CsvDelay), commitKeyRing.ToLocalKey,
commitKeyRing.RevocationKey, commitKeyRing.RevocationKey,
) )
if err != nil { if err != nil {
@ -928,8 +928,8 @@ func (c *chainWatcher) dispatchContractBreach(spendEvent *chainntnfs.SpendDetail
retribution.KeyRing.CommitPoint.Curve = nil retribution.KeyRing.CommitPoint.Curve = nil
retribution.KeyRing.LocalHtlcKey = nil retribution.KeyRing.LocalHtlcKey = nil
retribution.KeyRing.RemoteHtlcKey = nil retribution.KeyRing.RemoteHtlcKey = nil
retribution.KeyRing.DelayKey = nil retribution.KeyRing.ToLocalKey = nil
retribution.KeyRing.NoDelayKey = nil retribution.KeyRing.ToRemoteKey = nil
retribution.KeyRing.RevocationKey = nil retribution.KeyRing.RevocationKey = nil
return spew.Sdump(retribution) return spew.Sdump(retribution)
})) }))

@ -1880,7 +1880,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
// within the final witness. // within the final witness.
remoteDelay := uint32(chanState.RemoteChanCfg.CsvDelay) remoteDelay := uint32(chanState.RemoteChanCfg.CsvDelay)
remotePkScript, err := input.CommitScriptToSelf( remotePkScript, err := input.CommitScriptToSelf(
remoteDelay, keyRing.DelayKey, keyRing.RevocationKey, remoteDelay, keyRing.ToLocalKey, keyRing.RevocationKey,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -1889,7 +1889,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
if err != nil { if err != nil {
return nil, err return nil, err
} }
localPkScript, err := input.CommitScriptUnencumbered(keyRing.NoDelayKey) localPkScript, err := input.CommitScriptUnencumbered(keyRing.ToRemoteKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1984,7 +1984,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
// remote commitment transaction, and *they* go to the second // remote commitment transaction, and *they* go to the second
// level. // level.
secondLevelWitnessScript, err := input.SecondLevelHtlcScript( secondLevelWitnessScript, err := input.SecondLevelHtlcScript(
keyRing.RevocationKey, keyRing.DelayKey, remoteDelay, keyRing.RevocationKey, keyRing.ToLocalKey, remoteDelay,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -2563,7 +2563,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
sigJob.Tx, err = createHtlcTimeoutTx( sigJob.Tx, err = createHtlcTimeoutTx(
op, outputAmt, htlc.Timeout, op, outputAmt, htlc.Timeout,
uint32(remoteChanCfg.CsvDelay), uint32(remoteChanCfg.CsvDelay),
keyRing.RevocationKey, keyRing.DelayKey, keyRing.RevocationKey, keyRing.ToLocalKey,
) )
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -2614,7 +2614,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
} }
sigJob.Tx, err = createHtlcSuccessTx( sigJob.Tx, err = createHtlcSuccessTx(
op, outputAmt, uint32(remoteChanCfg.CsvDelay), op, outputAmt, uint32(remoteChanCfg.CsvDelay),
keyRing.RevocationKey, keyRing.DelayKey, keyRing.RevocationKey, keyRing.ToLocalKey,
) )
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@ -3526,7 +3526,7 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
successTx, err := createHtlcSuccessTx(op, successTx, err := createHtlcSuccessTx(op,
outputAmt, uint32(localChanCfg.CsvDelay), outputAmt, uint32(localChanCfg.CsvDelay),
keyRing.RevocationKey, keyRing.DelayKey) keyRing.RevocationKey, keyRing.ToLocalKey)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -3579,7 +3579,7 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
timeoutTx, err := createHtlcTimeoutTx(op, timeoutTx, err := createHtlcTimeoutTx(op,
outputAmt, htlc.Timeout, outputAmt, htlc.Timeout,
uint32(localChanCfg.CsvDelay), uint32(localChanCfg.CsvDelay),
keyRing.RevocationKey, keyRing.DelayKey, keyRing.RevocationKey, keyRing.ToLocalKey,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -4772,7 +4772,7 @@ func NewUnilateralCloseSummary(chanState *channeldb.OpenChannel, signer input.Si
// Before we can generate the proper sign descriptor, we'll need to // Before we can generate the proper sign descriptor, we'll need to
// locate the output index of our non-delayed output on the commitment // locate the output index of our non-delayed output on the commitment
// transaction. // transaction.
selfP2WKH, err := input.CommitScriptUnencumbered(keyRing.NoDelayKey) selfP2WKH, err := input.CommitScriptUnencumbered(keyRing.ToRemoteKey)
if err != nil { if err != nil {
return nil, fmt.Errorf("unable to create self commit "+ return nil, fmt.Errorf("unable to create self commit "+
"script: %v", err) "script: %v", err)
@ -5015,7 +5015,7 @@ func newOutgoingHtlcResolution(signer input.Signer,
// transaction. // transaction.
timeoutTx, err := createHtlcTimeoutTx( timeoutTx, err := createHtlcTimeoutTx(
op, secondLevelOutputAmt, htlc.RefundTimeout, csvDelay, op, secondLevelOutputAmt, htlc.RefundTimeout, csvDelay,
keyRing.RevocationKey, keyRing.DelayKey, keyRing.RevocationKey, keyRing.ToLocalKey,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -5055,7 +5055,7 @@ func newOutgoingHtlcResolution(signer input.Signer,
// transaction creates so we can generate the signDesc required to // transaction creates so we can generate the signDesc required to
// complete the claim process after a delay period. // complete the claim process after a delay period.
htlcSweepScript, err := input.SecondLevelHtlcScript( htlcSweepScript, err := input.SecondLevelHtlcScript(
keyRing.RevocationKey, keyRing.DelayKey, csvDelay, keyRing.RevocationKey, keyRing.ToLocalKey, csvDelay,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -5149,7 +5149,7 @@ func newIncomingHtlcResolution(signer input.Signer, localChanCfg *channeldb.Chan
secondLevelOutputAmt := htlc.Amt.ToSatoshis() - htlcFee secondLevelOutputAmt := htlc.Amt.ToSatoshis() - htlcFee
successTx, err := createHtlcSuccessTx( successTx, err := createHtlcSuccessTx(
op, secondLevelOutputAmt, csvDelay, op, secondLevelOutputAmt, csvDelay,
keyRing.RevocationKey, keyRing.DelayKey, keyRing.RevocationKey, keyRing.ToLocalKey,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -5192,7 +5192,7 @@ func newIncomingHtlcResolution(signer input.Signer, localChanCfg *channeldb.Chan
// creates so we can generate the proper signDesc to sweep it after the // creates so we can generate the proper signDesc to sweep it after the
// CSV delay has passed. // CSV delay has passed.
htlcSweepScript, err := input.SecondLevelHtlcScript( htlcSweepScript, err := input.SecondLevelHtlcScript(
keyRing.RevocationKey, keyRing.DelayKey, csvDelay, keyRing.RevocationKey, keyRing.ToLocalKey, csvDelay,
) )
if err != nil { if err != nil {
return nil, err return nil, err
@ -5410,7 +5410,7 @@ func NewLocalForceCloseSummary(chanState *channeldb.OpenChannel, signer input.Si
commitPoint, true, chanState.ChanType.IsTweakless(), commitPoint, true, chanState.ChanType.IsTweakless(),
&chanState.LocalChanCfg, &chanState.RemoteChanCfg, &chanState.LocalChanCfg, &chanState.RemoteChanCfg,
) )
selfScript, err := input.CommitScriptToSelf(csvTimeout, keyRing.DelayKey, selfScript, err := input.CommitScriptToSelf(csvTimeout, keyRing.ToLocalKey,
keyRing.RevocationKey) keyRing.RevocationKey)
if err != nil { if err != nil {
return nil, err return nil, err

@ -59,18 +59,30 @@ type CommitmentKeyRing struct {
// of whether this is our commit or not. // of whether this is our commit or not.
RemoteHtlcKey *btcec.PublicKey RemoteHtlcKey *btcec.PublicKey
// DelayKey is the commitment transaction owner's key which is included // ToLocalKey is the commitment transaction owner's key which is
// in HTLC success and timeout transaction scripts. // included in HTLC success and timeout transaction scripts. This is
DelayKey *btcec.PublicKey // the public key used for the to_local output of the commitment
// transaction.
//
// NOTE: Who's key this is depends on the current perspective. If this
// is our commitment this will be our key.
ToLocalKey *btcec.PublicKey
// NoDelayKey is the other party's payment key in the commitment tx. // ToRemoteKey is the non-owner's payment key in the commitment tx.
// This is the key used to generate the unencumbered output within the // This is the key used to generate the to_remote output within the
// commitment transaction. // commitment transaction.
NoDelayKey *btcec.PublicKey //
// NOTE: Who's key this is depends on the current perspective. If this
// is our commitment this will be their key.
ToRemoteKey *btcec.PublicKey
// RevocationKey is the key that can be used by the other party to // RevocationKey is the key that can be used by the other party to
// redeem outputs from a revoked commitment transaction if it were to // redeem outputs from a revoked commitment transaction if it were to
// be published. // be published.
//
// NOTE: Who can sign for this key depends on the current perspective.
// If this is our commitment, it means the remote node can sign for
// this key in case of a breach.
RevocationKey *btcec.PublicKey RevocationKey *btcec.PublicKey
} }
@ -100,29 +112,29 @@ func DeriveCommitmentKeys(commitPoint *btcec.PublicKey,
), ),
} }
// We'll now compute the delay, no delay, and revocation key based on // We'll now compute the to_local, to_remote, and revocation key based
// the current commitment point. All keys are tweaked each state in // on the current commitment point. All keys are tweaked each state in
// order to ensure the keys from each state are unlinkable. To create // order to ensure the keys from each state are unlinkable. To create
// the revocation key, we take the opposite party's revocation base // the revocation key, we take the opposite party's revocation base
// point and combine that with the current commitment point. // point and combine that with the current commitment point.
var ( var (
delayBasePoint *btcec.PublicKey toLocalBasePoint *btcec.PublicKey
noDelayBasePoint *btcec.PublicKey toRemoteBasePoint *btcec.PublicKey
revocationBasePoint *btcec.PublicKey revocationBasePoint *btcec.PublicKey
) )
if isOurCommit { if isOurCommit {
delayBasePoint = localChanCfg.DelayBasePoint.PubKey toLocalBasePoint = localChanCfg.DelayBasePoint.PubKey
noDelayBasePoint = remoteChanCfg.PaymentBasePoint.PubKey toRemoteBasePoint = remoteChanCfg.PaymentBasePoint.PubKey
revocationBasePoint = remoteChanCfg.RevocationBasePoint.PubKey revocationBasePoint = remoteChanCfg.RevocationBasePoint.PubKey
} else { } else {
delayBasePoint = remoteChanCfg.DelayBasePoint.PubKey toLocalBasePoint = remoteChanCfg.DelayBasePoint.PubKey
noDelayBasePoint = localChanCfg.PaymentBasePoint.PubKey toRemoteBasePoint = localChanCfg.PaymentBasePoint.PubKey
revocationBasePoint = localChanCfg.RevocationBasePoint.PubKey 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
// using the base point, and the current commitment tweak. // using the base point, and the current commitment tweak.
keyRing.DelayKey = input.TweakPubKey(delayBasePoint, commitPoint) keyRing.ToLocalKey = input.TweakPubKey(toLocalBasePoint, commitPoint)
keyRing.RevocationKey = input.DeriveRevocationPubkey( keyRing.RevocationKey = input.DeriveRevocationPubkey(
revocationBasePoint, commitPoint, revocationBasePoint, commitPoint,
) )
@ -130,10 +142,10 @@ func DeriveCommitmentKeys(commitPoint *btcec.PublicKey,
// If this commitment should omit the tweak for the remote point, then // If this commitment should omit the tweak for the remote point, then
// we'll use that directly, and ignore the commitPoint tweak. // we'll use that directly, and ignore the commitPoint tweak.
if tweaklessCommit { if tweaklessCommit {
keyRing.NoDelayKey = noDelayBasePoint keyRing.ToRemoteKey = toRemoteBasePoint
} else { } else {
keyRing.NoDelayKey = input.TweakPubKey( keyRing.ToRemoteKey = input.TweakPubKey(
noDelayBasePoint, commitPoint, toRemoteBasePoint, commitPoint,
) )
} }
@ -377,7 +389,7 @@ func CreateCommitTx(fundingOutput wire.TxIn, keyRing *CommitmentKeyRing,
// the funds with the revocation key if we broadcast a revoked // the funds with the revocation key if we broadcast a revoked
// commitment transaction. // commitment transaction.
toLocalRedeemScript, err := input.CommitScriptToSelf( toLocalRedeemScript, err := input.CommitScriptToSelf(
uint32(localChanCfg.CsvDelay), keyRing.DelayKey, uint32(localChanCfg.CsvDelay), keyRing.ToLocalKey,
keyRing.RevocationKey, keyRing.RevocationKey,
) )
if err != nil { if err != nil {
@ -393,7 +405,7 @@ func CreateCommitTx(fundingOutput wire.TxIn, keyRing *CommitmentKeyRing,
// Next, we create the script paying to the remote. This is just a // Next, we create the script paying to the remote. This is just a
// regular P2WPKH output, without any added CSV delay. // regular P2WPKH output, without any added CSV delay.
toRemoteWitnessKeyHash, err := input.CommitScriptUnencumbered( toRemoteWitnessKeyHash, err := input.CommitScriptUnencumbered(
keyRing.NoDelayKey, keyRing.ToRemoteKey,
) )
if err != nil { if err != nil {
return nil, err return nil, err

@ -439,8 +439,8 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
LocalHtlcKeyTweak: tweak, LocalHtlcKeyTweak: tweak,
LocalHtlcKey: tc.localPaymentPubKey, LocalHtlcKey: tc.localPaymentPubKey,
RemoteHtlcKey: tc.remotePaymentPubKey, RemoteHtlcKey: tc.remotePaymentPubKey,
DelayKey: tc.localDelayPubKey, ToLocalKey: tc.localDelayPubKey,
NoDelayKey: tc.remotePaymentPubKey, ToRemoteKey: tc.remotePaymentPubKey,
RevocationKey: tc.localRevocationPubKey, RevocationKey: tc.localRevocationPubKey,
} }
@ -1081,9 +1081,9 @@ func testSpendValidation(t *testing.T, tweakless bool) {
// of 5 blocks before sweeping the output, while bob can spend // of 5 blocks before sweeping the output, while bob can spend
// immediately with either the revocation key, or his regular key. // immediately with either the revocation key, or his regular key.
keyRing := &CommitmentKeyRing{ keyRing := &CommitmentKeyRing{
DelayKey: aliceDelayKey, ToLocalKey: aliceDelayKey,
RevocationKey: revokePubKey, RevocationKey: revokePubKey,
NoDelayKey: bobPayKey, ToRemoteKey: bobPayKey,
} }
commitmentTx, err := CreateCommitTx( commitmentTx, err := CreateCommitTx(
*fakeFundingTxIn, keyRing, aliceChanCfg, bobChanCfg, *fakeFundingTxIn, keyRing, aliceChanCfg, bobChanCfg,

@ -189,7 +189,7 @@ func (t *backupTask) craftSessionPayload(
justiceKit := &blob.JusticeKit{ justiceKit := &blob.JusticeKit{
SweepAddress: t.sweepPkScript, SweepAddress: t.sweepPkScript,
RevocationPubKey: toBlobPubKey(keyRing.RevocationKey), RevocationPubKey: toBlobPubKey(keyRing.RevocationKey),
LocalDelayPubKey: toBlobPubKey(keyRing.DelayKey), LocalDelayPubKey: toBlobPubKey(keyRing.ToLocalKey),
CSVDelay: t.breachInfo.RemoteDelay, CSVDelay: t.breachInfo.RemoteDelay,
} }
@ -199,7 +199,7 @@ func (t *backupTask) craftSessionPayload(
// output to spend from. // output to spend from.
if t.toRemoteInput != nil { if t.toRemoteInput != nil {
justiceKit.CommitToRemotePubKey = toBlobPubKey( justiceKit.CommitToRemotePubKey = toBlobPubKey(
keyRing.NoDelayKey, keyRing.ToRemoteKey,
) )
} }

@ -121,8 +121,8 @@ func genTaskTest(
BreachTransaction: breachTxn, BreachTransaction: breachTxn,
KeyRing: &lnwallet.CommitmentKeyRing{ KeyRing: &lnwallet.CommitmentKeyRing{
RevocationKey: revPK, RevocationKey: revPK,
DelayKey: toLocalPK, ToLocalKey: toLocalPK,
NoDelayKey: toRemotePK, ToRemoteKey: toRemotePK,
}, },
RemoteDelay: csvDelay, RemoteDelay: csvDelay,
} }
@ -565,9 +565,9 @@ func testBackupTask(t *testing.T, test backupTaskTest) {
} }
keyRing := test.breachInfo.KeyRing keyRing := test.breachInfo.KeyRing
expToLocalPK := keyRing.DelayKey.SerializeCompressed() expToLocalPK := keyRing.ToLocalKey.SerializeCompressed()
expRevPK := keyRing.RevocationKey.SerializeCompressed() expRevPK := keyRing.RevocationKey.SerializeCompressed()
expToRemotePK := keyRing.NoDelayKey.SerializeCompressed() expToRemotePK := keyRing.ToRemoteKey.SerializeCompressed()
// Assert that the blob contained the serialized revocation and to-local // Assert that the blob contained the serialized revocation and to-local
// pubkeys. // pubkeys.

@ -291,8 +291,8 @@ func (c *mockChannel) createRemoteCommitTx(t *testing.T) {
commitKeyRing := &lnwallet.CommitmentKeyRing{ commitKeyRing := &lnwallet.CommitmentKeyRing{
RevocationKey: c.revPK, RevocationKey: c.revPK,
NoDelayKey: c.toLocalPK, ToRemoteKey: c.toLocalPK,
DelayKey: c.toRemotePK, ToLocalKey: c.toRemotePK,
} }
retribution := &lnwallet.BreachRetribution{ retribution := &lnwallet.BreachRetribution{