lnwallet: return instead evaluated commitment instead of mutating
createCommitmentTx would earlier mutate the passed commitment struct after evaluating the htlc view and calculating the final balances, which was confusing since the balances are supposed to only be *after* subtracting fees. Instead we take the needed parameters as arguments, and return the final balances, tx and fee to populate the commitment struct in a proper way.
This commit is contained in:
3 files changed
+94
-60
No files matched your search
@@ -794,23 +794,32 @@ func TestCommitmentAndHTLCTransactions(t *testing.T) {
|
||||
}
|
||||
theHTLCView := htlcViewFromHTLCs(htlcs)
|
||||
|
||||
feePerKw := chainfee.SatPerKWeight(test.commitment.FeePerKw)
|
||||
isOurs := true
|
||||
height := test.commitment.CommitHeight
|
||||
|
||||
// Create unsigned commitment transaction.
|
||||
commitmentView := &commitment{
|
||||
height: test.commitment.CommitHeight,
|
||||
ourBalance: test.commitment.LocalBalance,
|
||||
theirBalance: test.commitment.RemoteBalance,
|
||||
feePerKw: chainfee.SatPerKWeight(test.commitment.FeePerKw),
|
||||
dustLimit: tc.dustLimit,
|
||||
isOurs: true,
|
||||
}
|
||||
err = channel.commitBuilder.createCommitmentTx(
|
||||
commitmentView, theHTLCView, keys,
|
||||
view, err := channel.commitBuilder.createUnsignedCommitmentTx(
|
||||
test.commitment.LocalBalance,
|
||||
test.commitment.RemoteBalance, isOurs, feePerKw,
|
||||
height, theHTLCView, keys,
|
||||
)
|
||||
if err != nil {
|
||||
t.Errorf("Case %d: Failed to create new commitment tx: %v", i, err)
|
||||
continue
|
||||
}
|
||||
|
||||
commitmentView := &commitment{
|
||||
ourBalance: view.ourBalance,
|
||||
theirBalance: view.theirBalance,
|
||||
txn: view.txn,
|
||||
fee: view.fee,
|
||||
height: height,
|
||||
feePerKw: feePerKw,
|
||||
dustLimit: tc.dustLimit,
|
||||
isOurs: isOurs,
|
||||
}
|
||||
|
||||
// Initialize LocalCommit, which is used in getSignedCommitTx.
|
||||
channelState.LocalCommitment = test.commitment
|
||||
channelState.LocalCommitment.Htlcs = htlcs
|
||||
|
||||
Reference in new issue
Block a user