lnwallet: update restoreStateLogs to be aware of new commitment scheme
This commit is contained in:
parent
b9da43a2b8
commit
5a78f80ffe
@ -1352,6 +1352,12 @@ func (lc *LightningChannel) restoreStateLogs() error {
|
|||||||
pastHeight = lc.currentHeight - 1
|
pastHeight = lc.currentHeight - 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Obtain the local and remote channel configurations. These house all
|
||||||
|
// the relevant public keys and points we'll need in order to restore
|
||||||
|
// the state log.
|
||||||
|
localChanCfg := lc.localChanCfg
|
||||||
|
remoteChanCfg := lc.remoteChanCfg
|
||||||
|
|
||||||
// In order to reconstruct the pkScripts on each of the pending HTLC
|
// In order to reconstruct the pkScripts on each of the pending HTLC
|
||||||
// outputs (if any) we'll need to regenerate the current revocation for
|
// outputs (if any) we'll need to regenerate the current revocation for
|
||||||
// this current un-revoked state.
|
// this current un-revoked state.
|
||||||
@ -1359,19 +1365,41 @@ func (lc *LightningChannel) restoreStateLogs() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ourRevocation := sha256.Sum256(ourRevPreImage[:])
|
|
||||||
theirRevocation := lc.channelState.TheirCurrentRevocationHash
|
|
||||||
|
|
||||||
// Additionally, we'll fetch the current sent to commitment keys and
|
// With the commitment secret recovered, we'll generate the revocation
|
||||||
// CSV delay values which are also required to fully generate the
|
// used on the *local* commitment transaction. This is computed using
|
||||||
// scripts.
|
// the point derived from the commitment secret at the remote party's
|
||||||
localKey := lc.channelState.OurCommitKey
|
// revocation based.
|
||||||
remoteKey := lc.channelState.TheirCommitKey
|
localCommitPoint := ComputeCommitmentPoint(ourRevPreImage[:])
|
||||||
ourDelay := lc.channelState.LocalCsvDelay
|
localRevocation := DeriveRevocationPubkey(
|
||||||
theirDelay := lc.channelState.RemoteCsvDelay
|
remoteChanCfg.RevocationBasePoint,
|
||||||
|
localCommitPoint,
|
||||||
|
)
|
||||||
|
remoteCommitPoint := lc.channelState.RemoteCurrentRevocation
|
||||||
|
remoteRevocation := DeriveRevocationPubkey(
|
||||||
|
localChanCfg.RevocationBasePoint,
|
||||||
|
remoteCommitPoint,
|
||||||
|
)
|
||||||
|
|
||||||
|
// Additionally, we'll fetch the current payment base points which are
|
||||||
|
// required to fully generate the scripts.
|
||||||
|
localCommitLocalKey := TweakPubKey(localChanCfg.PaymentBasePoint,
|
||||||
|
localCommitPoint)
|
||||||
|
localCommitRemoteKey := TweakPubKey(remoteChanCfg.PaymentBasePoint,
|
||||||
|
localCommitPoint)
|
||||||
|
|
||||||
|
remoteCommitLocalKey := TweakPubKey(localChanCfg.PaymentBasePoint,
|
||||||
|
remoteCommitPoint)
|
||||||
|
remoteCommitRemoteKey := TweakPubKey(remoteChanCfg.PaymentBasePoint,
|
||||||
|
remoteCommitPoint)
|
||||||
|
|
||||||
var ourCounter, theirCounter uint64
|
var ourCounter, theirCounter uint64
|
||||||
|
|
||||||
|
// Grab the current fee rate as we'll need this to determine if the
|
||||||
|
// prior HTLC's were considered dust or not at this particular
|
||||||
|
// commitment sate.
|
||||||
|
feeRate := lc.channelState.FeePerKw
|
||||||
|
|
||||||
// TODO(roasbeef): partition entries added based on our current review
|
// TODO(roasbeef): partition entries added based on our current review
|
||||||
// an our view of them from the log?
|
// an our view of them from the log?
|
||||||
for _, htlc := range lc.channelState.Htlcs {
|
for _, htlc := range lc.channelState.Htlcs {
|
||||||
@ -1382,7 +1410,7 @@ func (lc *LightningChannel) restoreStateLogs() error {
|
|||||||
// The proper pkScripts for this PaymentDescriptor must be
|
// The proper pkScripts for this PaymentDescriptor must be
|
||||||
// generated so we can easily locate them within the commitment
|
// generated so we can easily locate them within the commitment
|
||||||
// transaction in the future.
|
// transaction in the future.
|
||||||
var ourP2WSH, theirP2WSH []byte
|
var ourP2WSH, theirP2WSH, ourWitnessScript, theirWitnessScript []byte
|
||||||
|
|
||||||
// If the either outputs is dust from the local or remote
|
// If the either outputs is dust from the local or remote
|
||||||
// node's perspective, then we don't need to generate the
|
// node's perspective, then we don't need to generate the
|
||||||
@ -1395,17 +1423,19 @@ func (lc *LightningChannel) restoreStateLogs() error {
|
|||||||
isDustRemote := htlcIsDust(htlc.Incoming, false, feeRate,
|
isDustRemote := htlcIsDust(htlc.Incoming, false, feeRate,
|
||||||
htlc.Amt, remoteChanCfg.DustLimit)
|
htlc.Amt, remoteChanCfg.DustLimit)
|
||||||
if !isDustLocal {
|
if !isDustLocal {
|
||||||
ourP2WSH, err = lc.genHtlcScript(htlc.Incoming, true,
|
ourP2WSH, ourWitnessScript, err = lc.genHtlcScript(
|
||||||
htlc.RefundTimeout, ourDelay, remoteKey,
|
htlc.Incoming, true, htlc.RefundTimeout, htlc.RHash,
|
||||||
localKey, ourRevocation, htlc.RHash)
|
localCommitLocalKey, localCommitRemoteKey,
|
||||||
|
localRevocation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !isDustRemote {
|
if !isDustRemote {
|
||||||
theirP2WSH, err = lc.genHtlcScript(htlc.Incoming, false,
|
theirP2WSH, theirWitnessScript, err = lc.genHtlcScript(
|
||||||
htlc.RefundTimeout, theirDelay, remoteKey,
|
htlc.Incoming, false, htlc.RefundTimeout, htlc.RHash,
|
||||||
localKey, theirRevocation, htlc.RHash)
|
remoteCommitLocalKey, remoteCommitRemoteKey,
|
||||||
|
remoteRevocation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1419,7 +1449,9 @@ func (lc *LightningChannel) restoreStateLogs() error {
|
|||||||
addCommitHeightRemote: pastHeight,
|
addCommitHeightRemote: pastHeight,
|
||||||
addCommitHeightLocal: pastHeight,
|
addCommitHeightLocal: pastHeight,
|
||||||
ourPkScript: ourP2WSH,
|
ourPkScript: ourP2WSH,
|
||||||
|
ourWitnessScript: ourWitnessScript,
|
||||||
theirPkScript: theirP2WSH,
|
theirPkScript: theirP2WSH,
|
||||||
|
theirWitnessScript: theirWitnessScript,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !htlc.Incoming {
|
if !htlc.Incoming {
|
||||||
@ -1922,8 +1954,6 @@ func genRemoteHtlcSigJobs(commitPoint *btcec.PublicKey,
|
|||||||
localChanCfg, remoteChanCfg *channeldb.ChannelConfig,
|
localChanCfg, remoteChanCfg *channeldb.ChannelConfig,
|
||||||
remoteCommitView *commitment) ([]signJob, chan struct{}, error) {
|
remoteCommitView *commitment) ([]signJob, chan struct{}, error) {
|
||||||
|
|
||||||
// TODO(roasbeef): make the below into a sig pool job as well
|
|
||||||
|
|
||||||
// First, we'll generate all the keys required to generate the scripts
|
// First, we'll generate all the keys required to generate the scripts
|
||||||
// for each HTLC output and transaction.
|
// for each HTLC output and transaction.
|
||||||
//
|
//
|
||||||
@ -2063,8 +2093,10 @@ func genRemoteHtlcSigJobs(commitPoint *btcec.PublicKey,
|
|||||||
// decrements the available revocation window by 1. After a successful method
|
// decrements the available revocation window by 1. After a successful method
|
||||||
// call, the remote party's commitment chain is extended by a new commitment
|
// call, the remote party's commitment chain is extended by a new commitment
|
||||||
// which includes all updates to the HTLC log prior to this method invocation.
|
// which includes all updates to the HTLC log prior to this method invocation.
|
||||||
//
|
// The first return parameter it he signature for the commitment transaction
|
||||||
// TODO(roasbeef): update to detail second param
|
// itself, while the second parameter is a slice of all HTLC signatures (if
|
||||||
|
// any). The HTLC signatures are sorted according to the BIP 69 order of the
|
||||||
|
// HTLC's on the commitment transaction.
|
||||||
func (lc *LightningChannel) SignNextCommitment() (*btcec.Signature, []*btcec.Signature, error) {
|
func (lc *LightningChannel) SignNextCommitment() (*btcec.Signature, []*btcec.Signature, error) {
|
||||||
lc.Lock()
|
lc.Lock()
|
||||||
defer lc.Unlock()
|
defer lc.Unlock()
|
||||||
@ -2127,7 +2159,6 @@ func (lc *LightningChannel) SignNextCommitment() (*btcec.Signature, []*btcec.Sig
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
// TODO(roasbeef): make fully async?
|
|
||||||
lc.sigPool.SubmitSignBatch(sigBatch)
|
lc.sigPool.SubmitSignBatch(sigBatch)
|
||||||
|
|
||||||
// While the jobs are being carried out, we'll Sign their version of
|
// While the jobs are being carried out, we'll Sign their version of
|
||||||
@ -2987,8 +3018,6 @@ func (lc *LightningChannel) ShortChanID() lnwire.ShortChannelID {
|
|||||||
// genHtlcScript generates the proper P2WSH public key scripts for the
|
// genHtlcScript generates the proper P2WSH public key scripts for the
|
||||||
// HTLC output modified by two-bits denoting if this is an incoming HTLC, and
|
// HTLC output modified by two-bits denoting if this is an incoming HTLC, and
|
||||||
// if the HTLC is being applied to their commitment transaction or ours.
|
// if the HTLC is being applied to their commitment transaction or ours.
|
||||||
//
|
|
||||||
// TODO(roasbeef): update comment
|
|
||||||
func (lc *LightningChannel) genHtlcScript(isIncoming, ourCommit bool,
|
func (lc *LightningChannel) genHtlcScript(isIncoming, ourCommit bool,
|
||||||
timeout uint32, rHash [32]byte, localKey, remoteKey *btcec.PublicKey,
|
timeout uint32, rHash [32]byte, localKey, remoteKey *btcec.PublicKey,
|
||||||
revocationKey *btcec.PublicKey) ([]byte, []byte, error) {
|
revocationKey *btcec.PublicKey) ([]byte, []byte, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user