lnwallet: remove duplicate chanCfg fields, use channelState
This commit is contained in:
3 files changed
+66
-65
No files matched your search
+42
-39
@@ -880,13 +880,15 @@ func (lc *LightningChannel) diskCommitToMemCommit(isLocal bool,
|
|||||||
if localCommitPoint != nil {
|
if localCommitPoint != nil {
|
||||||
localCommitKeys = DeriveCommitmentKeys(
|
localCommitKeys = DeriveCommitmentKeys(
|
||||||
localCommitPoint, true, tweaklessCommit,
|
localCommitPoint, true, tweaklessCommit,
|
||||||
lc.localChanCfg, lc.remoteChanCfg,
|
&lc.channelState.LocalChanCfg,
|
||||||
|
&lc.channelState.RemoteChanCfg,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if remoteCommitPoint != nil {
|
if remoteCommitPoint != nil {
|
||||||
remoteCommitKeys = DeriveCommitmentKeys(
|
remoteCommitKeys = DeriveCommitmentKeys(
|
||||||
remoteCommitPoint, false, tweaklessCommit,
|
remoteCommitPoint, false, tweaklessCommit,
|
||||||
lc.localChanCfg, lc.remoteChanCfg,
|
&lc.channelState.LocalChanCfg,
|
||||||
|
&lc.channelState.RemoteChanCfg,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1360,10 +1362,6 @@ type LightningChannel struct {
|
|||||||
|
|
||||||
channelState *channeldb.OpenChannel
|
channelState *channeldb.OpenChannel
|
||||||
|
|
||||||
localChanCfg *channeldb.ChannelConfig
|
|
||||||
|
|
||||||
remoteChanCfg *channeldb.ChannelConfig
|
|
||||||
|
|
||||||
// [local|remote]Log is a (mostly) append-only log storing all the HTLC
|
// [local|remote]Log is a (mostly) append-only log storing all the HTLC
|
||||||
// updates to this channel. The log is walked backwards as HTLC updates
|
// updates to this channel. The log is walked backwards as HTLC updates
|
||||||
// are applied in order to re-construct a commitment transaction from a
|
// are applied in order to re-construct a commitment transaction from a
|
||||||
@@ -1416,8 +1414,6 @@ func NewLightningChannel(signer input.Signer,
|
|||||||
remoteCommitChain: newCommitmentChain(),
|
remoteCommitChain: newCommitmentChain(),
|
||||||
localCommitChain: newCommitmentChain(),
|
localCommitChain: newCommitmentChain(),
|
||||||
channelState: state,
|
channelState: state,
|
||||||
localChanCfg: &state.LocalChanCfg,
|
|
||||||
remoteChanCfg: &state.RemoteChanCfg,
|
|
||||||
localUpdateLog: localUpdateLog,
|
localUpdateLog: localUpdateLog,
|
||||||
remoteUpdateLog: remoteUpdateLog,
|
remoteUpdateLog: remoteUpdateLog,
|
||||||
ChanPoint: &state.FundingOutpoint,
|
ChanPoint: &state.FundingOutpoint,
|
||||||
@@ -1449,8 +1445,10 @@ func NewLightningChannel(signer input.Signer,
|
|||||||
// 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.PubKey.SerializeCompressed()
|
localKey := lc.channelState.LocalChanCfg.MultiSigKey.PubKey.
|
||||||
remoteKey := lc.remoteChanCfg.MultiSigKey.PubKey.SerializeCompressed()
|
SerializeCompressed()
|
||||||
|
remoteKey := lc.channelState.RemoteChanCfg.MultiSigKey.PubKey.
|
||||||
|
SerializeCompressed()
|
||||||
|
|
||||||
multiSigScript, err := input.GenMultiSigScript(localKey, remoteKey)
|
multiSigScript, err := input.GenMultiSigScript(localKey, remoteKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1462,7 +1460,7 @@ func (lc *LightningChannel) createSignDesc() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
lc.signDesc = &input.SignDescriptor{
|
lc.signDesc = &input.SignDescriptor{
|
||||||
KeyDesc: lc.localChanCfg.MultiSigKey,
|
KeyDesc: lc.channelState.LocalChanCfg.MultiSigKey,
|
||||||
WitnessScript: multiSigScript,
|
WitnessScript: multiSigScript,
|
||||||
Output: &wire.TxOut{
|
Output: &wire.TxOut{
|
||||||
PkScript: fundingPkScript,
|
PkScript: fundingPkScript,
|
||||||
@@ -1722,7 +1720,7 @@ func (lc *LightningChannel) restoreCommitState(
|
|||||||
tweaklessCommit := lc.channelState.ChanType.IsTweakless()
|
tweaklessCommit := lc.channelState.ChanType.IsTweakless()
|
||||||
pendingRemoteKeyChain = DeriveCommitmentKeys(
|
pendingRemoteKeyChain = DeriveCommitmentKeys(
|
||||||
pendingCommitPoint, false, tweaklessCommit,
|
pendingCommitPoint, false, tweaklessCommit,
|
||||||
lc.localChanCfg, lc.remoteChanCfg,
|
&lc.channelState.LocalChanCfg, &lc.channelState.RemoteChanCfg,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2324,9 +2322,9 @@ func (lc *LightningChannel) fetchCommitmentView(remoteChain bool,
|
|||||||
// be counted for the purpose of fee calculation.
|
// be counted for the purpose of fee calculation.
|
||||||
var dustLimit btcutil.Amount
|
var dustLimit btcutil.Amount
|
||||||
if remoteChain {
|
if remoteChain {
|
||||||
dustLimit = lc.remoteChanCfg.DustLimit
|
dustLimit = lc.channelState.RemoteChanCfg.DustLimit
|
||||||
} else {
|
} else {
|
||||||
dustLimit = lc.localChanCfg.DustLimit
|
dustLimit = lc.channelState.LocalChanCfg.DustLimit
|
||||||
}
|
}
|
||||||
|
|
||||||
c := &commitment{
|
c := &commitment{
|
||||||
@@ -2434,11 +2432,11 @@ func (lc *LightningChannel) createCommitmentTx(c *commitment,
|
|||||||
delayBalance, p2wkhBalance btcutil.Amount
|
delayBalance, p2wkhBalance btcutil.Amount
|
||||||
)
|
)
|
||||||
if c.isOurs {
|
if c.isOurs {
|
||||||
delay = uint32(lc.localChanCfg.CsvDelay)
|
delay = uint32(lc.channelState.LocalChanCfg.CsvDelay)
|
||||||
delayBalance = ourBalance.ToSatoshis()
|
delayBalance = ourBalance.ToSatoshis()
|
||||||
p2wkhBalance = theirBalance.ToSatoshis()
|
p2wkhBalance = theirBalance.ToSatoshis()
|
||||||
} else {
|
} else {
|
||||||
delay = uint32(lc.remoteChanCfg.CsvDelay)
|
delay = uint32(lc.channelState.RemoteChanCfg.CsvDelay)
|
||||||
delayBalance = theirBalance.ToSatoshis()
|
delayBalance = theirBalance.ToSatoshis()
|
||||||
p2wkhBalance = ourBalance.ToSatoshis()
|
p2wkhBalance = ourBalance.ToSatoshis()
|
||||||
}
|
}
|
||||||
@@ -3143,12 +3141,12 @@ func (lc *LightningChannel) validateCommitmentSanity(theirLogCounter,
|
|||||||
switch {
|
switch {
|
||||||
case ourBalance < ourInitialBalance &&
|
case ourBalance < ourInitialBalance &&
|
||||||
ourBalance < lnwire.NewMSatFromSatoshis(
|
ourBalance < lnwire.NewMSatFromSatoshis(
|
||||||
lc.localChanCfg.ChanReserve):
|
lc.channelState.LocalChanCfg.ChanReserve):
|
||||||
|
|
||||||
return ErrBelowChanReserve
|
return ErrBelowChanReserve
|
||||||
case theirBalance < theirInitialBalance &&
|
case theirBalance < theirInitialBalance &&
|
||||||
theirBalance < lnwire.NewMSatFromSatoshis(
|
theirBalance < lnwire.NewMSatFromSatoshis(
|
||||||
lc.remoteChanCfg.ChanReserve):
|
lc.channelState.RemoteChanCfg.ChanReserve):
|
||||||
|
|
||||||
return ErrBelowChanReserve
|
return ErrBelowChanReserve
|
||||||
}
|
}
|
||||||
@@ -3199,7 +3197,7 @@ func (lc *LightningChannel) validateCommitmentSanity(theirLogCounter,
|
|||||||
// First check that the remote updates won't violate it's channel
|
// First check that the remote updates won't violate it's channel
|
||||||
// constraints.
|
// constraints.
|
||||||
err := validateUpdates(
|
err := validateUpdates(
|
||||||
filteredView.theirUpdates, lc.remoteChanCfg,
|
filteredView.theirUpdates, &lc.channelState.RemoteChanCfg,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -3208,7 +3206,7 @@ func (lc *LightningChannel) validateCommitmentSanity(theirLogCounter,
|
|||||||
// Secondly check that our updates won't violate our channel
|
// Secondly check that our updates won't violate our channel
|
||||||
// constraints.
|
// constraints.
|
||||||
err = validateUpdates(
|
err = validateUpdates(
|
||||||
filteredView.ourUpdates, lc.localChanCfg,
|
filteredView.ourUpdates, &lc.channelState.LocalChanCfg,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -3276,7 +3274,7 @@ func (lc *LightningChannel) SignNextCommitment() (lnwire.Sig, []lnwire.Sig, []ch
|
|||||||
// construct the commitment state.
|
// construct the commitment state.
|
||||||
keyRing := DeriveCommitmentKeys(
|
keyRing := DeriveCommitmentKeys(
|
||||||
commitPoint, false, lc.channelState.ChanType.IsTweakless(),
|
commitPoint, false, lc.channelState.ChanType.IsTweakless(),
|
||||||
lc.localChanCfg, lc.remoteChanCfg,
|
&lc.channelState.LocalChanCfg, &lc.channelState.RemoteChanCfg,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Create a new commitment view which will calculate the evaluated
|
// Create a new commitment view which will calculate the evaluated
|
||||||
@@ -3313,7 +3311,8 @@ func (lc *LightningChannel) SignNextCommitment() (lnwire.Sig, []lnwire.Sig, []ch
|
|||||||
// commitment state. We do so in two phases: first we generate and
|
// commitment state. We do so in two phases: first we generate and
|
||||||
// submit the set of signature jobs to the worker pool.
|
// submit the set of signature jobs to the worker pool.
|
||||||
sigBatch, cancelChan, err := genRemoteHtlcSigJobs(keyRing,
|
sigBatch, cancelChan, err := genRemoteHtlcSigJobs(keyRing,
|
||||||
lc.localChanCfg, lc.remoteChanCfg, newCommitView,
|
&lc.channelState.LocalChanCfg, &lc.channelState.RemoteChanCfg,
|
||||||
|
newCommitView,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return sig, htlcSigs, nil, err
|
return sig, htlcSigs, nil, err
|
||||||
@@ -3696,10 +3695,10 @@ func (lc *LightningChannel) computeView(view *htlcView, remoteChain bool,
|
|||||||
*htlcView) {
|
*htlcView) {
|
||||||
|
|
||||||
commitChain := lc.localCommitChain
|
commitChain := lc.localCommitChain
|
||||||
dustLimit := lc.localChanCfg.DustLimit
|
dustLimit := lc.channelState.LocalChanCfg.DustLimit
|
||||||
if remoteChain {
|
if remoteChain {
|
||||||
commitChain = lc.remoteCommitChain
|
commitChain = lc.remoteCommitChain
|
||||||
dustLimit = lc.remoteChanCfg.DustLimit
|
dustLimit = lc.channelState.RemoteChanCfg.DustLimit
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since the fetched htlc view will include all updates added after the
|
// Since the fetched htlc view will include all updates added after the
|
||||||
@@ -4033,7 +4032,7 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSig lnwire.Sig,
|
|||||||
commitPoint := input.ComputeCommitmentPoint(commitSecret[:])
|
commitPoint := input.ComputeCommitmentPoint(commitSecret[:])
|
||||||
keyRing := DeriveCommitmentKeys(
|
keyRing := DeriveCommitmentKeys(
|
||||||
commitPoint, true, lc.channelState.ChanType.IsTweakless(),
|
commitPoint, true, lc.channelState.ChanType.IsTweakless(),
|
||||||
lc.localChanCfg, lc.remoteChanCfg,
|
&lc.channelState.LocalChanCfg, &lc.channelState.RemoteChanCfg,
|
||||||
)
|
)
|
||||||
|
|
||||||
// With the current commitment point re-calculated, construct the new
|
// With the current commitment point re-calculated, construct the new
|
||||||
@@ -4081,8 +4080,8 @@ func (lc *LightningChannel) ReceiveNewCommitment(commitSig lnwire.Sig,
|
|||||||
// pool to verify each of the HTLc signatures presented. Once
|
// pool to verify each of the HTLc signatures presented. Once
|
||||||
// generated, we'll submit these jobs to the worker pool.
|
// generated, we'll submit these jobs to the worker pool.
|
||||||
verifyJobs, err := genHtlcSigValidationJobs(
|
verifyJobs, err := genHtlcSigValidationJobs(
|
||||||
localCommitmentView, keyRing, htlcSigs, lc.localChanCfg,
|
localCommitmentView, keyRing, htlcSigs,
|
||||||
lc.remoteChanCfg,
|
&lc.channelState.LocalChanCfg, &lc.channelState.RemoteChanCfg,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -4095,8 +4094,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.PubKey.X,
|
X: lc.channelState.RemoteChanCfg.MultiSigKey.PubKey.X,
|
||||||
Y: lc.remoteChanCfg.MultiSigKey.PubKey.Y,
|
Y: lc.channelState.RemoteChanCfg.MultiSigKey.PubKey.Y,
|
||||||
Curve: btcec.S256(),
|
Curve: btcec.S256(),
|
||||||
}
|
}
|
||||||
cSig, err := commitSig.ToSignature()
|
cSig, err := commitSig.ToSignature()
|
||||||
@@ -5046,8 +5045,10 @@ 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.PubKey.SerializeCompressed()
|
ourKey := lc.channelState.LocalChanCfg.MultiSigKey.PubKey.
|
||||||
theirKey := lc.remoteChanCfg.MultiSigKey.PubKey.SerializeCompressed()
|
SerializeCompressed()
|
||||||
|
theirKey := lc.channelState.RemoteChanCfg.MultiSigKey.PubKey.
|
||||||
|
SerializeCompressed()
|
||||||
|
|
||||||
commitTx.TxIn[0].Witness = input.SpendMultiSig(
|
commitTx.TxIn[0].Witness = input.SpendMultiSig(
|
||||||
lc.signDesc.WitnessScript, ourKey,
|
lc.signDesc.WitnessScript, ourKey,
|
||||||
@@ -5911,8 +5912,8 @@ func (lc *LightningChannel) CreateCloseProposal(proposedFee btcutil.Amount,
|
|||||||
}
|
}
|
||||||
|
|
||||||
closeTx := CreateCooperativeCloseTx(
|
closeTx := CreateCooperativeCloseTx(
|
||||||
lc.fundingTxIn(), lc.localChanCfg.DustLimit,
|
lc.fundingTxIn(), lc.channelState.LocalChanCfg.DustLimit,
|
||||||
lc.remoteChanCfg.DustLimit, ourBalance, theirBalance,
|
lc.channelState.RemoteChanCfg.DustLimit, ourBalance, theirBalance,
|
||||||
localDeliveryScript, remoteDeliveryScript,
|
localDeliveryScript, remoteDeliveryScript,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -5982,8 +5983,8 @@ func (lc *LightningChannel) CompleteCooperativeClose(localSig, remoteSig []byte,
|
|||||||
// on this active channel back to both parties. In this current model,
|
// on this active channel back to both parties. In this current model,
|
||||||
// the initiator pays full fees for the cooperative close transaction.
|
// the initiator pays full fees for the cooperative close transaction.
|
||||||
closeTx := CreateCooperativeCloseTx(
|
closeTx := CreateCooperativeCloseTx(
|
||||||
lc.fundingTxIn(), lc.localChanCfg.DustLimit,
|
lc.fundingTxIn(), lc.channelState.LocalChanCfg.DustLimit,
|
||||||
lc.remoteChanCfg.DustLimit, ourBalance, theirBalance,
|
lc.channelState.RemoteChanCfg.DustLimit, ourBalance, theirBalance,
|
||||||
localDeliveryScript, remoteDeliveryScript,
|
localDeliveryScript, remoteDeliveryScript,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -5998,8 +5999,10 @@ 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.PubKey.SerializeCompressed()
|
ourKey := lc.channelState.LocalChanCfg.MultiSigKey.PubKey.
|
||||||
theirKey := lc.remoteChanCfg.MultiSigKey.PubKey.SerializeCompressed()
|
SerializeCompressed()
|
||||||
|
theirKey := lc.channelState.RemoteChanCfg.MultiSigKey.PubKey.
|
||||||
|
SerializeCompressed()
|
||||||
witness := input.SpendMultiSig(lc.signDesc.WitnessScript, ourKey,
|
witness := input.SpendMultiSig(lc.signDesc.WitnessScript, ourKey,
|
||||||
localSig, theirKey, remoteSig)
|
localSig, theirKey, remoteSig)
|
||||||
closeTx.TxIn[0].Witness = witness
|
closeTx.TxIn[0].Witness = witness
|
||||||
@@ -6446,7 +6449,7 @@ func (lc *LightningChannel) ActiveHtlcs() []channeldb.HTLC {
|
|||||||
|
|
||||||
// LocalChanReserve returns our local ChanReserve requirement for the remote party.
|
// LocalChanReserve returns our local ChanReserve requirement for the remote party.
|
||||||
func (lc *LightningChannel) LocalChanReserve() btcutil.Amount {
|
func (lc *LightningChannel) LocalChanReserve() btcutil.Amount {
|
||||||
return lc.localChanCfg.ChanReserve
|
return lc.channelState.LocalChanCfg.ChanReserve
|
||||||
}
|
}
|
||||||
|
|
||||||
// NextLocalHtlcIndex returns the next unallocated local htlc index. To ensure
|
// NextLocalHtlcIndex returns the next unallocated local htlc index. To ensure
|
||||||
@@ -6471,5 +6474,5 @@ func (lc *LightningChannel) RemoteCommitHeight() uint64 {
|
|||||||
// FwdMinHtlc returns the minimum HTLC value required by the remote node, i.e.
|
// FwdMinHtlc returns the minimum HTLC value required by the remote node, i.e.
|
||||||
// the minimum value HTLC we can forward on this channel.
|
// the minimum value HTLC we can forward on this channel.
|
||||||
func (lc *LightningChannel) FwdMinHtlc() lnwire.MilliSatoshi {
|
func (lc *LightningChannel) FwdMinHtlc() lnwire.MilliSatoshi {
|
||||||
return lc.localChanCfg.MinHTLC
|
return lc.channelState.LocalChanCfg.MinHTLC
|
||||||
}
|
}
|
||||||
+20
-20
@@ -615,7 +615,7 @@ func TestForceClose(t *testing.T) {
|
|||||||
// Alice's listed CSV delay should also match the delay that was
|
// Alice's listed CSV delay should also match the delay that was
|
||||||
// pre-committed to at channel opening.
|
// pre-committed to at channel opening.
|
||||||
if aliceCommitResolution.MaturityDelay !=
|
if aliceCommitResolution.MaturityDelay !=
|
||||||
uint32(aliceChannel.localChanCfg.CsvDelay) {
|
uint32(aliceChannel.channelState.LocalChanCfg.CsvDelay) {
|
||||||
|
|
||||||
t.Fatalf("alice: incorrect local CSV delay in ForceCloseSummary, "+
|
t.Fatalf("alice: incorrect local CSV delay in ForceCloseSummary, "+
|
||||||
"expected %v, got %v",
|
"expected %v, got %v",
|
||||||
@@ -816,10 +816,10 @@ func TestForceCloseDustOutput(t *testing.T) {
|
|||||||
// We set both node's channel reserves to 0, to make sure
|
// We set both node's channel reserves to 0, to make sure
|
||||||
// they can create small dust ouputs without going under
|
// they can create small dust ouputs without going under
|
||||||
// their channel reserves.
|
// their channel reserves.
|
||||||
aliceChannel.localChanCfg.ChanReserve = 0
|
aliceChannel.channelState.LocalChanCfg.ChanReserve = 0
|
||||||
bobChannel.localChanCfg.ChanReserve = 0
|
bobChannel.channelState.LocalChanCfg.ChanReserve = 0
|
||||||
aliceChannel.remoteChanCfg.ChanReserve = 0
|
aliceChannel.channelState.RemoteChanCfg.ChanReserve = 0
|
||||||
bobChannel.remoteChanCfg.ChanReserve = 0
|
bobChannel.channelState.RemoteChanCfg.ChanReserve = 0
|
||||||
|
|
||||||
htlcAmount := lnwire.NewMSatFromSatoshis(500)
|
htlcAmount := lnwire.NewMSatFromSatoshis(500)
|
||||||
|
|
||||||
@@ -1268,8 +1268,8 @@ func TestChannelBalanceDustLimit(t *testing.T) {
|
|||||||
|
|
||||||
// To allow Alice's balance to get beneath her dust limit, set the
|
// To allow Alice's balance to get beneath her dust limit, set the
|
||||||
// channel reserve to be 0.
|
// channel reserve to be 0.
|
||||||
aliceChannel.localChanCfg.ChanReserve = 0
|
aliceChannel.channelState.LocalChanCfg.ChanReserve = 0
|
||||||
bobChannel.remoteChanCfg.ChanReserve = 0
|
bobChannel.channelState.RemoteChanCfg.ChanReserve = 0
|
||||||
|
|
||||||
// This amount should leave an amount larger than Alice's dust limit
|
// This amount should leave an amount larger than Alice's dust limit
|
||||||
// once fees have been subtracted, but smaller than Bob's dust limit.
|
// once fees have been subtracted, but smaller than Bob's dust limit.
|
||||||
@@ -2553,7 +2553,7 @@ func TestAddHTLCNegativeBalance(t *testing.T) {
|
|||||||
|
|
||||||
// We set the channel reserve to 0, such that we can add HTLCs all the
|
// We set the channel reserve to 0, such that we can add HTLCs all the
|
||||||
// way to a negative balance.
|
// way to a negative balance.
|
||||||
aliceChannel.localChanCfg.ChanReserve = 0
|
aliceChannel.channelState.LocalChanCfg.ChanReserve = 0
|
||||||
|
|
||||||
// First, we'll add 3 HTLCs of 1 BTC each to Alice's commitment.
|
// First, we'll add 3 HTLCs of 1 BTC each to Alice's commitment.
|
||||||
const numHTLCs = 3
|
const numHTLCs = 3
|
||||||
@@ -5346,14 +5346,14 @@ func TestMaxAcceptedHTLCs(t *testing.T) {
|
|||||||
|
|
||||||
// Set the remote's required MaxAcceptedHtlcs. This means that alice
|
// Set the remote's required MaxAcceptedHtlcs. This means that alice
|
||||||
// can only offer the remote up to numHTLCs HTLCs.
|
// can only offer the remote up to numHTLCs HTLCs.
|
||||||
aliceChannel.localChanCfg.MaxAcceptedHtlcs = numHTLCs
|
aliceChannel.channelState.LocalChanCfg.MaxAcceptedHtlcs = numHTLCs
|
||||||
bobChannel.remoteChanCfg.MaxAcceptedHtlcs = numHTLCs
|
bobChannel.channelState.RemoteChanCfg.MaxAcceptedHtlcs = numHTLCs
|
||||||
|
|
||||||
// Similarly, set the remote config's MaxAcceptedHtlcs. This means
|
// Similarly, set the remote config's MaxAcceptedHtlcs. This means
|
||||||
// that the remote will be aware that Alice will only accept up to
|
// that the remote will be aware that Alice will only accept up to
|
||||||
// numHTLCsRecevied at a time.
|
// numHTLCsRecevied at a time.
|
||||||
aliceChannel.remoteChanCfg.MaxAcceptedHtlcs = numHTLCsReceived
|
aliceChannel.channelState.RemoteChanCfg.MaxAcceptedHtlcs = numHTLCsReceived
|
||||||
bobChannel.localChanCfg.MaxAcceptedHtlcs = numHTLCsReceived
|
bobChannel.channelState.LocalChanCfg.MaxAcceptedHtlcs = numHTLCsReceived
|
||||||
|
|
||||||
// Each HTLC amount is 0.1 BTC.
|
// Each HTLC amount is 0.1 BTC.
|
||||||
htlcAmt := lnwire.NewMSatFromSatoshis(0.1 * btcutil.SatoshiPerBitcoin)
|
htlcAmt := lnwire.NewMSatFromSatoshis(0.1 * btcutil.SatoshiPerBitcoin)
|
||||||
@@ -5409,8 +5409,8 @@ func TestMaxPendingAmount(t *testing.T) {
|
|||||||
// We set the max pending amount of Alice's config. This mean that she
|
// We set the max pending amount of Alice's config. This mean that she
|
||||||
// cannot offer Bob HTLCs with a total value above this limit at a given
|
// cannot offer Bob HTLCs with a total value above this limit at a given
|
||||||
// time.
|
// time.
|
||||||
aliceChannel.localChanCfg.MaxPendingAmount = maxPending
|
aliceChannel.channelState.LocalChanCfg.MaxPendingAmount = maxPending
|
||||||
bobChannel.remoteChanCfg.MaxPendingAmount = maxPending
|
bobChannel.channelState.RemoteChanCfg.MaxPendingAmount = maxPending
|
||||||
|
|
||||||
// First, we'll add 2 HTLCs of 1.5 BTC each to Alice's commitment.
|
// First, we'll add 2 HTLCs of 1.5 BTC each to Alice's commitment.
|
||||||
// This won't trigger Alice's ErrMaxPendingAmount error.
|
// This won't trigger Alice's ErrMaxPendingAmount error.
|
||||||
@@ -5498,20 +5498,20 @@ func TestChanReserve(t *testing.T) {
|
|||||||
|
|
||||||
// Alice will need to keep her reserve above aliceMinReserve,
|
// Alice will need to keep her reserve above aliceMinReserve,
|
||||||
// so set this limit to here local config.
|
// so set this limit to here local config.
|
||||||
aliceChannel.localChanCfg.ChanReserve = aliceMinReserve
|
aliceChannel.channelState.LocalChanCfg.ChanReserve = aliceMinReserve
|
||||||
|
|
||||||
// During channel opening Bob will also get to know Alice's
|
// During channel opening Bob will also get to know Alice's
|
||||||
// minimum reserve, and this will be found in his remote
|
// minimum reserve, and this will be found in his remote
|
||||||
// config.
|
// config.
|
||||||
bobChannel.remoteChanCfg.ChanReserve = aliceMinReserve
|
bobChannel.channelState.RemoteChanCfg.ChanReserve = aliceMinReserve
|
||||||
|
|
||||||
// We set Bob's channel reserve to a value that is larger than
|
// We set Bob's channel reserve to a value that is larger than
|
||||||
// his current balance in the channel. This will ensure that
|
// his current balance in the channel. This will ensure that
|
||||||
// after a channel is first opened, Bob can still receive HTLCs
|
// after a channel is first opened, Bob can still receive HTLCs
|
||||||
// even though his balance is less than his channel reserve.
|
// even though his balance is less than his channel reserve.
|
||||||
bobMinReserve := btcutil.Amount(6 * btcutil.SatoshiPerBitcoin)
|
bobMinReserve := btcutil.Amount(6 * btcutil.SatoshiPerBitcoin)
|
||||||
bobChannel.localChanCfg.ChanReserve = bobMinReserve
|
bobChannel.channelState.LocalChanCfg.ChanReserve = bobMinReserve
|
||||||
aliceChannel.remoteChanCfg.ChanReserve = bobMinReserve
|
aliceChannel.channelState.RemoteChanCfg.ChanReserve = bobMinReserve
|
||||||
|
|
||||||
return aliceChannel, bobChannel, cleanUp
|
return aliceChannel, bobChannel, cleanUp
|
||||||
}
|
}
|
||||||
@@ -5713,8 +5713,8 @@ func TestMinHTLC(t *testing.T) {
|
|||||||
|
|
||||||
// Setting the min value in Alice's local config means that the
|
// Setting the min value in Alice's local config means that the
|
||||||
// remote will not accept any HTLCs of value less than specified.
|
// remote will not accept any HTLCs of value less than specified.
|
||||||
aliceChannel.localChanCfg.MinHTLC = minValue
|
aliceChannel.channelState.LocalChanCfg.MinHTLC = minValue
|
||||||
bobChannel.remoteChanCfg.MinHTLC = minValue
|
bobChannel.channelState.RemoteChanCfg.MinHTLC = minValue
|
||||||
|
|
||||||
// First, we will add an HTLC of 0.5 BTC. This will not trigger
|
// First, we will add an HTLC of 0.5 BTC. This will not trigger
|
||||||
// ErrBelowMinHTLC.
|
// ErrBelowMinHTLC.
|
||||||
|
|||||||
@@ -421,10 +421,8 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
|
|||||||
// Construct a LightningChannel manually because we don't have nor need all
|
// Construct a LightningChannel manually because we don't have nor need all
|
||||||
// of the dependencies.
|
// of the dependencies.
|
||||||
channel := LightningChannel{
|
channel := LightningChannel{
|
||||||
channelState: &channelState,
|
channelState: &channelState,
|
||||||
Signer: signer,
|
Signer: signer,
|
||||||
localChanCfg: &channelState.LocalChanCfg,
|
|
||||||
remoteChanCfg: &channelState.RemoteChanCfg,
|
|
||||||
}
|
}
|
||||||
err = channel.createSignDesc()
|
err = channel.createSignDesc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -845,8 +843,8 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
|
|||||||
// commitment tx.
|
// commitment tx.
|
||||||
htlcResolutions, err := extractHtlcResolutions(
|
htlcResolutions, err := extractHtlcResolutions(
|
||||||
chainfee.SatPerKWeight(test.commitment.FeePerKw), true, signer,
|
chainfee.SatPerKWeight(test.commitment.FeePerKw), true, signer,
|
||||||
htlcs, keys, channel.localChanCfg, channel.remoteChanCfg,
|
htlcs, keys, &channel.channelState.LocalChanCfg,
|
||||||
commitTx.TxHash(),
|
&channel.channelState.RemoteChanCfg, commitTx.TxHash(),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Case %d: Failed to extract HTLC resolutions: %v", i, err)
|
t.Errorf("Case %d: Failed to extract HTLC resolutions: %v", i, err)
|
||||||
|
|||||||
Reference in new issue
Block a user