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:
7 files changed
+61
-49
No files matched your search
+13
-13
@@ -1880,7 +1880,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||
// within the final witness.
|
||||
remoteDelay := uint32(chanState.RemoteChanCfg.CsvDelay)
|
||||
remotePkScript, err := input.CommitScriptToSelf(
|
||||
remoteDelay, keyRing.DelayKey, keyRing.RevocationKey,
|
||||
remoteDelay, keyRing.ToLocalKey, keyRing.RevocationKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1889,7 +1889,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
localPkScript, err := input.CommitScriptUnencumbered(keyRing.NoDelayKey)
|
||||
localPkScript, err := input.CommitScriptUnencumbered(keyRing.ToRemoteKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1984,7 +1984,7 @@ func NewBreachRetribution(chanState *channeldb.OpenChannel, stateNum uint64,
|
||||
// remote commitment transaction, and *they* go to the second
|
||||
// level.
|
||||
secondLevelWitnessScript, err := input.SecondLevelHtlcScript(
|
||||
keyRing.RevocationKey, keyRing.DelayKey, remoteDelay,
|
||||
keyRing.RevocationKey, keyRing.ToLocalKey, remoteDelay,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -2563,7 +2563,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
|
||||
sigJob.Tx, err = createHtlcTimeoutTx(
|
||||
op, outputAmt, htlc.Timeout,
|
||||
uint32(remoteChanCfg.CsvDelay),
|
||||
keyRing.RevocationKey, keyRing.DelayKey,
|
||||
keyRing.RevocationKey, keyRing.ToLocalKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -2614,7 +2614,7 @@ func genRemoteHtlcSigJobs(keyRing *CommitmentKeyRing,
|
||||
}
|
||||
sigJob.Tx, err = createHtlcSuccessTx(
|
||||
op, outputAmt, uint32(remoteChanCfg.CsvDelay),
|
||||
keyRing.RevocationKey, keyRing.DelayKey,
|
||||
keyRing.RevocationKey, keyRing.ToLocalKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
@@ -3526,7 +3526,7 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
|
||||
|
||||
successTx, err := createHtlcSuccessTx(op,
|
||||
outputAmt, uint32(localChanCfg.CsvDelay),
|
||||
keyRing.RevocationKey, keyRing.DelayKey)
|
||||
keyRing.RevocationKey, keyRing.ToLocalKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -3579,7 +3579,7 @@ func genHtlcSigValidationJobs(localCommitmentView *commitment,
|
||||
timeoutTx, err := createHtlcTimeoutTx(op,
|
||||
outputAmt, htlc.Timeout,
|
||||
uint32(localChanCfg.CsvDelay),
|
||||
keyRing.RevocationKey, keyRing.DelayKey,
|
||||
keyRing.RevocationKey, keyRing.ToLocalKey,
|
||||
)
|
||||
if err != nil {
|
||||
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
|
||||
// locate the output index of our non-delayed output on the commitment
|
||||
// transaction.
|
||||
selfP2WKH, err := input.CommitScriptUnencumbered(keyRing.NoDelayKey)
|
||||
selfP2WKH, err := input.CommitScriptUnencumbered(keyRing.ToRemoteKey)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to create self commit "+
|
||||
"script: %v", err)
|
||||
@@ -5015,7 +5015,7 @@ func newOutgoingHtlcResolution(signer input.Signer,
|
||||
// transaction.
|
||||
timeoutTx, err := createHtlcTimeoutTx(
|
||||
op, secondLevelOutputAmt, htlc.RefundTimeout, csvDelay,
|
||||
keyRing.RevocationKey, keyRing.DelayKey,
|
||||
keyRing.RevocationKey, keyRing.ToLocalKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -5055,7 +5055,7 @@ func newOutgoingHtlcResolution(signer input.Signer,
|
||||
// transaction creates so we can generate the signDesc required to
|
||||
// complete the claim process after a delay period.
|
||||
htlcSweepScript, err := input.SecondLevelHtlcScript(
|
||||
keyRing.RevocationKey, keyRing.DelayKey, csvDelay,
|
||||
keyRing.RevocationKey, keyRing.ToLocalKey, csvDelay,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -5149,7 +5149,7 @@ func newIncomingHtlcResolution(signer input.Signer, localChanCfg *channeldb.Chan
|
||||
secondLevelOutputAmt := htlc.Amt.ToSatoshis() - htlcFee
|
||||
successTx, err := createHtlcSuccessTx(
|
||||
op, secondLevelOutputAmt, csvDelay,
|
||||
keyRing.RevocationKey, keyRing.DelayKey,
|
||||
keyRing.RevocationKey, keyRing.ToLocalKey,
|
||||
)
|
||||
if err != nil {
|
||||
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
|
||||
// CSV delay has passed.
|
||||
htlcSweepScript, err := input.SecondLevelHtlcScript(
|
||||
keyRing.RevocationKey, keyRing.DelayKey, csvDelay,
|
||||
keyRing.RevocationKey, keyRing.ToLocalKey, csvDelay,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -5410,7 +5410,7 @@ func NewLocalForceCloseSummary(chanState *channeldb.OpenChannel, signer input.Si
|
||||
commitPoint, true, chanState.ChanType.IsTweakless(),
|
||||
&chanState.LocalChanCfg, &chanState.RemoteChanCfg,
|
||||
)
|
||||
selfScript, err := input.CommitScriptToSelf(csvTimeout, keyRing.DelayKey,
|
||||
selfScript, err := input.CommitScriptToSelf(csvTimeout, keyRing.ToLocalKey,
|
||||
keyRing.RevocationKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
+32
-20
@@ -59,18 +59,30 @@ type CommitmentKeyRing struct {
|
||||
// of whether this is our commit or not.
|
||||
RemoteHtlcKey *btcec.PublicKey
|
||||
|
||||
// DelayKey is the commitment transaction owner's key which is included
|
||||
// in HTLC success and timeout transaction scripts.
|
||||
DelayKey *btcec.PublicKey
|
||||
// ToLocalKey is the commitment transaction owner's key which is
|
||||
// included in HTLC success and timeout transaction scripts. This is
|
||||
// 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.
|
||||
// This is the key used to generate the unencumbered output within the
|
||||
// ToRemoteKey is the non-owner's payment key in the commitment tx.
|
||||
// This is the key used to generate the to_remote output within the
|
||||
// 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
|
||||
// redeem outputs from a revoked commitment transaction if it were to
|
||||
// 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
|
||||
}
|
||||
|
||||
@@ -100,29 +112,29 @@ func DeriveCommitmentKeys(commitPoint *btcec.PublicKey,
|
||||
),
|
||||
}
|
||||
|
||||
// We'll now compute the delay, no delay, and revocation key based on
|
||||
// the current commitment point. All keys are tweaked each state in
|
||||
// We'll now compute the to_local, to_remote, and revocation key based
|
||||
// on the current commitment point. All keys are tweaked each state in
|
||||
// order to ensure the keys from each state are unlinkable. To create
|
||||
// the revocation key, we take the opposite party's revocation base
|
||||
// point and combine that with the current commitment point.
|
||||
var (
|
||||
delayBasePoint *btcec.PublicKey
|
||||
noDelayBasePoint *btcec.PublicKey
|
||||
toLocalBasePoint *btcec.PublicKey
|
||||
toRemoteBasePoint *btcec.PublicKey
|
||||
revocationBasePoint *btcec.PublicKey
|
||||
)
|
||||
if isOurCommit {
|
||||
delayBasePoint = localChanCfg.DelayBasePoint.PubKey
|
||||
noDelayBasePoint = remoteChanCfg.PaymentBasePoint.PubKey
|
||||
toLocalBasePoint = localChanCfg.DelayBasePoint.PubKey
|
||||
toRemoteBasePoint = remoteChanCfg.PaymentBasePoint.PubKey
|
||||
revocationBasePoint = remoteChanCfg.RevocationBasePoint.PubKey
|
||||
} else {
|
||||
delayBasePoint = remoteChanCfg.DelayBasePoint.PubKey
|
||||
noDelayBasePoint = localChanCfg.PaymentBasePoint.PubKey
|
||||
toLocalBasePoint = remoteChanCfg.DelayBasePoint.PubKey
|
||||
toRemoteBasePoint = localChanCfg.PaymentBasePoint.PubKey
|
||||
revocationBasePoint = localChanCfg.RevocationBasePoint.PubKey
|
||||
}
|
||||
|
||||
// With the base points assigned, we can now derive the actual keys
|
||||
// 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(
|
||||
revocationBasePoint, commitPoint,
|
||||
)
|
||||
@@ -130,10 +142,10 @@ func DeriveCommitmentKeys(commitPoint *btcec.PublicKey,
|
||||
// If this commitment should omit the tweak for the remote point, then
|
||||
// we'll use that directly, and ignore the commitPoint tweak.
|
||||
if tweaklessCommit {
|
||||
keyRing.NoDelayKey = noDelayBasePoint
|
||||
keyRing.ToRemoteKey = toRemoteBasePoint
|
||||
} else {
|
||||
keyRing.NoDelayKey = input.TweakPubKey(
|
||||
noDelayBasePoint, commitPoint,
|
||||
keyRing.ToRemoteKey = input.TweakPubKey(
|
||||
toRemoteBasePoint, commitPoint,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -377,7 +389,7 @@ func CreateCommitTx(fundingOutput wire.TxIn, keyRing *CommitmentKeyRing,
|
||||
// the funds with the revocation key if we broadcast a revoked
|
||||
// commitment transaction.
|
||||
toLocalRedeemScript, err := input.CommitScriptToSelf(
|
||||
uint32(localChanCfg.CsvDelay), keyRing.DelayKey,
|
||||
uint32(localChanCfg.CsvDelay), keyRing.ToLocalKey,
|
||||
keyRing.RevocationKey,
|
||||
)
|
||||
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
|
||||
// regular P2WPKH output, without any added CSV delay.
|
||||
toRemoteWitnessKeyHash, err := input.CommitScriptUnencumbered(
|
||||
keyRing.NoDelayKey,
|
||||
keyRing.ToRemoteKey,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -439,8 +439,8 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
|
||||
LocalHtlcKeyTweak: tweak,
|
||||
LocalHtlcKey: tc.localPaymentPubKey,
|
||||
RemoteHtlcKey: tc.remotePaymentPubKey,
|
||||
DelayKey: tc.localDelayPubKey,
|
||||
NoDelayKey: tc.remotePaymentPubKey,
|
||||
ToLocalKey: tc.localDelayPubKey,
|
||||
ToRemoteKey: tc.remotePaymentPubKey,
|
||||
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
|
||||
// immediately with either the revocation key, or his regular key.
|
||||
keyRing := &CommitmentKeyRing{
|
||||
DelayKey: aliceDelayKey,
|
||||
ToLocalKey: aliceDelayKey,
|
||||
RevocationKey: revokePubKey,
|
||||
NoDelayKey: bobPayKey,
|
||||
ToRemoteKey: bobPayKey,
|
||||
}
|
||||
commitmentTx, err := CreateCommitTx(
|
||||
*fakeFundingTxIn, keyRing, aliceChanCfg, bobChanCfg,
|
||||
|
||||
Reference in new issue
Block a user