channeldb: add local and remote balance to revocation log
This commit re-adds the LocalBalance and RemoteBalance fields to the RevocationLog. The channeldb/migration30 is also adjusted so that anyone who has not yet run the optional migration will not lose these fields if they run the migration after this commit. The reason for re-adding these fields is that they are needed if we want to reconstruct all the info of the lnwallet.BreachRetribution without having access to the breach spend transaction. In most cases we would have access to the spend tx since we would see it on-chain at which time we would want to reconstruct the retribution info. However, for the watchtower subsystem, we sometimes want to construct the retribution info withouth having access to the spend transaction. A user can use the `--no-rev-log-amt-data` flag to opt-out of storing these amount fields.
This commit is contained in:
6 files changed
+313
-46
No files matched your search
@@ -80,6 +80,12 @@ var (
|
||||
// logHeight1 is the CommitHeight used by oldLog1.
|
||||
logHeight1 = uint64(0)
|
||||
|
||||
// localBalance1 is the LocalBalance used in oldLog1.
|
||||
localBalance1 = lnwire.MilliSatoshi(990_950_000)
|
||||
|
||||
// remoteBalance1 is the RemoteBalance used in oldLog1.
|
||||
remoteBalance1 = lnwire.MilliSatoshi(0)
|
||||
|
||||
// oldLog1 defines an old revocation that has no HTLCs.
|
||||
oldLog1 = mig.ChannelCommitment{
|
||||
CommitHeight: logHeight1,
|
||||
@@ -87,18 +93,29 @@ var (
|
||||
LocalHtlcIndex: 0,
|
||||
RemoteLogIndex: 0,
|
||||
RemoteHtlcIndex: 0,
|
||||
LocalBalance: lnwire.MilliSatoshi(990_950_000),
|
||||
RemoteBalance: 0,
|
||||
LocalBalance: localBalance1,
|
||||
RemoteBalance: remoteBalance1,
|
||||
CommitTx: commitTx1,
|
||||
}
|
||||
|
||||
// newLog1 is the new version of oldLog1.
|
||||
// newLog1 is the new version of oldLog1 in the case were we don't want
|
||||
// to store any balance data.
|
||||
newLog1 = RevocationLog{
|
||||
OurOutputIndex: 0,
|
||||
TheirOutputIndex: OutputIndexEmpty,
|
||||
CommitTxHash: commitTx1.TxHash(),
|
||||
}
|
||||
|
||||
// newLog1WithAmts is the new version of oldLog1 in the case were we do
|
||||
// want to store balance data.
|
||||
newLog1WithAmts = RevocationLog{
|
||||
OurOutputIndex: 0,
|
||||
TheirOutputIndex: OutputIndexEmpty,
|
||||
CommitTxHash: commitTx1.TxHash(),
|
||||
OurBalance: &localBalance1,
|
||||
TheirBalance: &remoteBalance1,
|
||||
}
|
||||
|
||||
// preimage2 defines the second revocation preimage used in the test,
|
||||
// generated from itest.
|
||||
preimage2 = []byte{
|
||||
@@ -148,6 +165,12 @@ var (
|
||||
// logHeight2 is the CommitHeight used by oldLog2.
|
||||
logHeight2 = uint64(1)
|
||||
|
||||
// localBalance2 is the LocalBalance used in oldLog2.
|
||||
localBalance2 = lnwire.MilliSatoshi(888_800_000)
|
||||
|
||||
// remoteBalance2 is the RemoteBalance used in oldLog2.
|
||||
remoteBalance2 = lnwire.MilliSatoshi(0)
|
||||
|
||||
// oldLog2 defines an old revocation that has one HTLC.
|
||||
oldLog2 = mig.ChannelCommitment{
|
||||
CommitHeight: logHeight2,
|
||||
@@ -155,13 +178,14 @@ var (
|
||||
LocalHtlcIndex: 1,
|
||||
RemoteLogIndex: 0,
|
||||
RemoteHtlcIndex: 0,
|
||||
LocalBalance: lnwire.MilliSatoshi(888_800_000),
|
||||
RemoteBalance: 0,
|
||||
LocalBalance: localBalance2,
|
||||
RemoteBalance: remoteBalance2,
|
||||
CommitTx: commitTx2,
|
||||
Htlcs: []mig.HTLC{htlc},
|
||||
}
|
||||
|
||||
// newLog2 is the new version of the oldLog2.
|
||||
// newLog2 is the new version of the oldLog2 in the case were we don't
|
||||
// want to store any balance data.
|
||||
newLog2 = RevocationLog{
|
||||
OurOutputIndex: 1,
|
||||
TheirOutputIndex: OutputIndexEmpty,
|
||||
@@ -177,6 +201,25 @@ var (
|
||||
},
|
||||
}
|
||||
|
||||
// newLog2WithAmts is the new version of oldLog2 in the case were we do
|
||||
// want to store balance data.
|
||||
newLog2WithAmts = RevocationLog{
|
||||
OurOutputIndex: 1,
|
||||
TheirOutputIndex: OutputIndexEmpty,
|
||||
CommitTxHash: commitTx2.TxHash(),
|
||||
OurBalance: &localBalance2,
|
||||
TheirBalance: &remoteBalance2,
|
||||
HTLCEntries: []*HTLCEntry{
|
||||
{
|
||||
RHash: rHash,
|
||||
RefundTimeout: 489,
|
||||
OutputIndex: 0,
|
||||
Incoming: false,
|
||||
Amt: btcutil.Amount(100_000),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// newLog3 defines an revocation log that's been created after v0.15.0.
|
||||
newLog3 = mig.ChannelCommitment{
|
||||
CommitHeight: logHeight2 + 1,
|
||||
@@ -565,4 +608,9 @@ func init() {
|
||||
if rand.Intn(2) == 0 {
|
||||
withAmtData = true
|
||||
}
|
||||
|
||||
if withAmtData {
|
||||
newLog1 = newLog1WithAmts
|
||||
newLog2 = newLog2WithAmts
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user