lnwallet: use channel type to derive keys
We abstract away how keys are generated for the different channel types types (currently tweak(less)). Intention is that more of the logic that is unique for each commitment type lives in commitment.go, making the channel state machine oblivious to the keys and outputs being created on the commitment tx for a given channel state.
This commit is contained in:
8 files changed
+44
-52
No files matched your search
+6
-10
@@ -772,16 +772,14 @@ func (l *LightningWallet) handleFundingCancelRequest(req *fundingReserveCancelMs
|
||||
func CreateCommitmentTxns(localBalance, remoteBalance btcutil.Amount,
|
||||
ourChanCfg, theirChanCfg *channeldb.ChannelConfig,
|
||||
localCommitPoint, remoteCommitPoint *btcec.PublicKey,
|
||||
fundingTxIn wire.TxIn,
|
||||
tweaklessCommit bool) (*wire.MsgTx, *wire.MsgTx, error) {
|
||||
fundingTxIn wire.TxIn, chanType channeldb.ChannelType) (
|
||||
*wire.MsgTx, *wire.MsgTx, error) {
|
||||
|
||||
localCommitmentKeys := DeriveCommitmentKeys(
|
||||
localCommitPoint, true, tweaklessCommit, ourChanCfg,
|
||||
theirChanCfg,
|
||||
localCommitPoint, true, chanType, ourChanCfg, theirChanCfg,
|
||||
)
|
||||
remoteCommitmentKeys := DeriveCommitmentKeys(
|
||||
remoteCommitPoint, false, tweaklessCommit, ourChanCfg,
|
||||
theirChanCfg,
|
||||
remoteCommitPoint, false, chanType, ourChanCfg, theirChanCfg,
|
||||
)
|
||||
|
||||
ourCommitTx, err := CreateCommitTx(
|
||||
@@ -930,13 +928,12 @@ func (l *LightningWallet) handleContributionMsg(req *addContributionMsg) {
|
||||
// With the funding tx complete, create both commitment transactions.
|
||||
localBalance := pendingReservation.partialState.LocalCommitment.LocalBalance.ToSatoshis()
|
||||
remoteBalance := pendingReservation.partialState.LocalCommitment.RemoteBalance.ToSatoshis()
|
||||
tweaklessCommits := pendingReservation.partialState.ChanType.IsTweakless()
|
||||
ourCommitTx, theirCommitTx, err := CreateCommitmentTxns(
|
||||
localBalance, remoteBalance, ourContribution.ChannelConfig,
|
||||
theirContribution.ChannelConfig,
|
||||
ourContribution.FirstCommitmentPoint,
|
||||
theirContribution.FirstCommitmentPoint, fundingTxIn,
|
||||
tweaklessCommits,
|
||||
pendingReservation.partialState.ChanType,
|
||||
)
|
||||
if err != nil {
|
||||
req.err <- err
|
||||
@@ -1290,14 +1287,13 @@ func (l *LightningWallet) handleSingleFunderSigs(req *addSingleFunderSigsMsg) {
|
||||
// remote node's commitment transactions.
|
||||
localBalance := pendingReservation.partialState.LocalCommitment.LocalBalance.ToSatoshis()
|
||||
remoteBalance := pendingReservation.partialState.LocalCommitment.RemoteBalance.ToSatoshis()
|
||||
tweaklessCommits := pendingReservation.partialState.ChanType.IsTweakless()
|
||||
ourCommitTx, theirCommitTx, err := CreateCommitmentTxns(
|
||||
localBalance, remoteBalance,
|
||||
pendingReservation.ourContribution.ChannelConfig,
|
||||
pendingReservation.theirContribution.ChannelConfig,
|
||||
pendingReservation.ourContribution.FirstCommitmentPoint,
|
||||
pendingReservation.theirContribution.FirstCommitmentPoint,
|
||||
*fundingTxIn, tweaklessCommits,
|
||||
*fundingTxIn, pendingReservation.partialState.ChanType,
|
||||
)
|
||||
if err != nil {
|
||||
req.err <- err
|
||||
|
||||
Reference in new issue
Block a user