lnwallet: when creating channels in tests, properly account for commitment fee

This commit is contained in:
Olaoluwa Osuntokun 2017-07-31 20:43:30 -07:00
parent db793991ac
commit 1b61341410
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -290,16 +290,18 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
estimator := &StaticFeeEstimator{24, 6} estimator := &StaticFeeEstimator{24, 6}
feePerKw := btcutil.Amount(estimator.EstimateFeePerWeight(1) * 1000) feePerKw := btcutil.Amount(estimator.EstimateFeePerWeight(1) * 1000)
commitFee := calcStaticFee(0)
aliceChannelState := &channeldb.OpenChannel{ aliceChannelState := &channeldb.OpenChannel{
LocalChanCfg: aliceCfg, LocalChanCfg: aliceCfg,
RemoteChanCfg: bobCfg, RemoteChanCfg: bobCfg,
IdentityPub: aliceKeyPub, IdentityPub: aliceKeyPub,
CommitFee: commitFee,
FundingOutpoint: *prevOut, FundingOutpoint: *prevOut,
ChanType: channeldb.SingleFunder, ChanType: channeldb.SingleFunder,
FeePerKw: feePerKw, FeePerKw: feePerKw,
IsInitiator: true, IsInitiator: true,
Capacity: channelCapacity, Capacity: channelCapacity,
LocalBalance: channelBal, LocalBalance: channelBal - commitFee,
RemoteBalance: channelBal, RemoteBalance: channelBal,
CommitTx: *aliceCommitTx, CommitTx: *aliceCommitTx,
CommitSig: bytes.Repeat([]byte{1}, 71), CommitSig: bytes.Repeat([]byte{1}, 71),
@ -313,12 +315,13 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
RemoteChanCfg: aliceCfg, RemoteChanCfg: aliceCfg,
IdentityPub: bobKeyPub, IdentityPub: bobKeyPub,
FeePerKw: feePerKw, FeePerKw: feePerKw,
CommitFee: commitFee,
FundingOutpoint: *prevOut, FundingOutpoint: *prevOut,
ChanType: channeldb.SingleFunder, ChanType: channeldb.SingleFunder,
IsInitiator: false, IsInitiator: false,
Capacity: channelCapacity, Capacity: channelCapacity,
LocalBalance: channelBal, LocalBalance: channelBal,
RemoteBalance: channelBal, RemoteBalance: channelBal - commitFee,
CommitTx: *bobCommitTx, CommitTx: *bobCommitTx,
CommitSig: bytes.Repeat([]byte{1}, 71), CommitSig: bytes.Repeat([]byte{1}, 71),
RemoteCurrentRevocation: aliceCommitPoint, RemoteCurrentRevocation: aliceCommitPoint,
@ -361,6 +364,7 @@ func createTestChannels(revocationWindow int) (*LightningChannel, *LightningChan
// calcStaticFee calculates appropriate fees for commitment transactions. This // calcStaticFee calculates appropriate fees for commitment transactions. This
// function provides a simple way to allow test balance assertions to take fee // function provides a simple way to allow test balance assertions to take fee
// calculations into account. // calculations into account.
//
// TODO(bvu): Refactor when dynamic fee estimation is added. // TODO(bvu): Refactor when dynamic fee estimation is added.
func calcStaticFee(numHTLCs int) btcutil.Amount { func calcStaticFee(numHTLCs int) btcutil.Amount {
const ( const (