lnwallet/test_utils: set up asymmetric commits

The remote and local commits are not symmetric, so we correctly set them
up pointing to the correct commitment tx.
This commit is contained in:
Johan T. Halseth 2020-11-18 22:45:35 +01:00
parent c58589db3b
commit 18f79e20d5
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

View File

@ -262,7 +262,7 @@ func CreateTestChannels(chanType channeldb.ChannelType) (
) )
bobBalance := lnwire.NewMSatFromSatoshis(channelBal) bobBalance := lnwire.NewMSatFromSatoshis(channelBal)
aliceCommit := channeldb.ChannelCommitment{ aliceLocalCommit := channeldb.ChannelCommitment{
CommitHeight: 0, CommitHeight: 0,
LocalBalance: aliceBalance, LocalBalance: aliceBalance,
RemoteBalance: bobBalance, RemoteBalance: bobBalance,
@ -271,7 +271,16 @@ func CreateTestChannels(chanType channeldb.ChannelType) (
CommitTx: aliceCommitTx, CommitTx: aliceCommitTx,
CommitSig: testSigBytes, CommitSig: testSigBytes,
} }
bobCommit := channeldb.ChannelCommitment{ aliceRemoteCommit := channeldb.ChannelCommitment{
CommitHeight: 0,
LocalBalance: aliceBalance,
RemoteBalance: bobBalance,
CommitFee: commitFee,
FeePerKw: btcutil.Amount(feePerKw),
CommitTx: bobCommitTx,
CommitSig: testSigBytes,
}
bobLocalCommit := channeldb.ChannelCommitment{
CommitHeight: 0, CommitHeight: 0,
LocalBalance: bobBalance, LocalBalance: bobBalance,
RemoteBalance: aliceBalance, RemoteBalance: aliceBalance,
@ -280,6 +289,15 @@ func CreateTestChannels(chanType channeldb.ChannelType) (
CommitTx: bobCommitTx, CommitTx: bobCommitTx,
CommitSig: testSigBytes, CommitSig: testSigBytes,
} }
bobRemoteCommit := channeldb.ChannelCommitment{
CommitHeight: 0,
LocalBalance: bobBalance,
RemoteBalance: aliceBalance,
CommitFee: commitFee,
FeePerKw: btcutil.Amount(feePerKw),
CommitTx: aliceCommitTx,
CommitSig: testSigBytes,
}
var chanIDBytes [8]byte var chanIDBytes [8]byte
if _, err := io.ReadFull(rand.Reader, chanIDBytes[:]); err != nil { if _, err := io.ReadFull(rand.Reader, chanIDBytes[:]); err != nil {
@ -302,8 +320,8 @@ func CreateTestChannels(chanType channeldb.ChannelType) (
RemoteCurrentRevocation: bobCommitPoint, RemoteCurrentRevocation: bobCommitPoint,
RevocationProducer: alicePreimageProducer, RevocationProducer: alicePreimageProducer,
RevocationStore: shachain.NewRevocationStore(), RevocationStore: shachain.NewRevocationStore(),
LocalCommitment: aliceCommit, LocalCommitment: aliceLocalCommit,
RemoteCommitment: aliceCommit, RemoteCommitment: aliceRemoteCommit,
Db: dbAlice, Db: dbAlice,
Packager: channeldb.NewChannelPackager(shortChanID), Packager: channeldb.NewChannelPackager(shortChanID),
FundingTxn: testTx, FundingTxn: testTx,
@ -320,8 +338,8 @@ func CreateTestChannels(chanType channeldb.ChannelType) (
RemoteCurrentRevocation: aliceCommitPoint, RemoteCurrentRevocation: aliceCommitPoint,
RevocationProducer: bobPreimageProducer, RevocationProducer: bobPreimageProducer,
RevocationStore: shachain.NewRevocationStore(), RevocationStore: shachain.NewRevocationStore(),
LocalCommitment: bobCommit, LocalCommitment: bobLocalCommit,
RemoteCommitment: bobCommit, RemoteCommitment: bobRemoteCommit,
Db: dbBob, Db: dbBob,
Packager: channeldb.NewChannelPackager(shortChanID), Packager: channeldb.NewChannelPackager(shortChanID),
} }