multi: add new NoRevLogAmtData config option
In this commit, a new `--db.no-rev-log-amt-data` flag is added. The config option is passed though to everywhere that it will be used. Note that it is still a no-op in this commit. An upcoming commit will make use of the flag.
This commit is contained in:
11 files changed
+55
-12
No files matched your search
@@ -2657,8 +2657,8 @@ func (c *OpenChannel) AdvanceCommitChainTail(fwdPkg *FwdPkg,
|
||||
// With the commitment pointer swapped, we can now add the
|
||||
// revoked (prior) state to the revocation log.
|
||||
err = putRevocationLog(
|
||||
logBucket, &c.RemoteCommitment,
|
||||
ourOutputIndex, theirOutputIndex,
|
||||
logBucket, &c.RemoteCommitment, ourOutputIndex,
|
||||
theirOutputIndex, c.Db.parent.noRevLogAmtData,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
+8
-1
@@ -324,6 +324,10 @@ type DB struct {
|
||||
dryRun bool
|
||||
keepFailedPaymentAttempts bool
|
||||
storeFinalHtlcResolutions bool
|
||||
|
||||
// noRevLogAmtData if true, means that commitment transaction amount
|
||||
// data should not be stored in the revocation log.
|
||||
noRevLogAmtData bool
|
||||
}
|
||||
|
||||
// Open opens or creates channeldb. Any necessary schemas migrations due
|
||||
@@ -382,6 +386,7 @@ func CreateWithBackend(backend kvdb.Backend,
|
||||
dryRun: opts.dryRun,
|
||||
keepFailedPaymentAttempts: opts.keepFailedPaymentAttempts,
|
||||
storeFinalHtlcResolutions: opts.storeFinalHtlcResolutions,
|
||||
noRevLogAmtData: opts.NoRevLogAmtData,
|
||||
}
|
||||
|
||||
// Set the parent pointer (only used in tests).
|
||||
@@ -1562,7 +1567,9 @@ func (d *DB) applyOptionalVersions(cfg OptionalMiragtionConfig) error {
|
||||
log.Infof("Performing database optional migration: %s", version.name)
|
||||
|
||||
migrationCfg := &MigrationConfigImpl{
|
||||
migration30.MigrateRevLogConfigImpl{},
|
||||
migration30.MigrateRevLogConfigImpl{
|
||||
NoAmountData: d.noRevLogAmtData,
|
||||
},
|
||||
}
|
||||
|
||||
// Migrate the data.
|
||||
|
||||
@@ -223,7 +223,7 @@ type RevocationLog struct {
|
||||
// disk. It also saves our output index and their output index, which are
|
||||
// useful when creating breach retribution.
|
||||
func putRevocationLog(bucket kvdb.RwBucket, commit *mig.ChannelCommitment,
|
||||
ourOutputIndex, theirOutputIndex uint32) error {
|
||||
ourOutputIndex, theirOutputIndex uint32, noAmtData bool) error {
|
||||
|
||||
// Sanity check that the output indexes can be safely converted.
|
||||
if ourOutputIndex > math.MaxUint16 {
|
||||
|
||||
@@ -306,7 +306,7 @@ func setupTestLogs(db kvdb.Backend, c *mig26.OpenChannel,
|
||||
}
|
||||
|
||||
// Create new logs.
|
||||
return writeNewRevocationLogs(chanBucket, newLogs)
|
||||
return writeNewRevocationLogs(chanBucket, newLogs, !withAmtData)
|
||||
}, func() {})
|
||||
}
|
||||
|
||||
@@ -460,7 +460,7 @@ func writeOldRevocationLogs(chanBucket kvdb.RwBucket,
|
||||
|
||||
// writeNewRevocationLogs saves a new revocation log to db.
|
||||
func writeNewRevocationLogs(chanBucket kvdb.RwBucket,
|
||||
oldLogs []mig.ChannelCommitment) error {
|
||||
oldLogs []mig.ChannelCommitment, noAmtData bool) error {
|
||||
|
||||
// Don't bother continue if the logs are empty.
|
||||
if len(oldLogs) == 0 {
|
||||
@@ -480,7 +480,7 @@ func writeNewRevocationLogs(chanBucket kvdb.RwBucket,
|
||||
// old commit tx. We do this intentionally so we can
|
||||
// distinguish a newly created log from an already saved one.
|
||||
err := putRevocationLog(
|
||||
logBucket, &c, testOurIndex, testTheirIndex,
|
||||
logBucket, &c, testOurIndex, testTheirIndex, noAmtData,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -64,6 +64,10 @@ type Options struct {
|
||||
// applications that use the channeldb package as a library.
|
||||
NoMigration bool
|
||||
|
||||
// NoRevLogAmtData when set to true, indicates that amount data should
|
||||
// not be stored in the revocation log.
|
||||
NoRevLogAmtData bool
|
||||
|
||||
// clock is the time source used by the database.
|
||||
clock clock.Clock
|
||||
|
||||
@@ -130,6 +134,14 @@ func OptionSetUseGraphCache(use bool) OptionModifier {
|
||||
}
|
||||
}
|
||||
|
||||
// OptionNoRevLogAmtData sets the NoRevLogAmtData option to the given value. If
|
||||
// it is set to true then amount data will not be stored in the revocation log.
|
||||
func OptionNoRevLogAmtData(noAmtData bool) OptionModifier {
|
||||
return func(o *Options) {
|
||||
o.NoRevLogAmtData = noAmtData
|
||||
}
|
||||
}
|
||||
|
||||
// OptionSetSyncFreelist allows the database to sync its freelist.
|
||||
func OptionSetSyncFreelist(b bool) OptionModifier {
|
||||
return func(o *Options) {
|
||||
|
||||
@@ -211,7 +211,7 @@ type RevocationLog struct {
|
||||
// disk. It also saves our output index and their output index, which are
|
||||
// useful when creating breach retribution.
|
||||
func putRevocationLog(bucket kvdb.RwBucket, commit *ChannelCommitment,
|
||||
ourOutputIndex, theirOutputIndex uint32) error {
|
||||
ourOutputIndex, theirOutputIndex uint32, noAmtData bool) error {
|
||||
|
||||
// Sanity check that the output indexes can be safely converted.
|
||||
if ourOutputIndex > math.MaxUint16 {
|
||||
|
||||
@@ -368,6 +368,7 @@ func TestPutRevocationLog(t *testing.T) {
|
||||
commit ChannelCommitment
|
||||
ourIndex uint32
|
||||
theirIndex uint32
|
||||
noAmtData bool
|
||||
expectedErr error
|
||||
expectedLog RevocationLog
|
||||
}{
|
||||
@@ -435,6 +436,7 @@ func TestPutRevocationLog(t *testing.T) {
|
||||
// Save the log.
|
||||
err = putRevocationLog(
|
||||
bucket, &tc.commit, tc.ourIndex, tc.theirIndex,
|
||||
tc.noAmtData,
|
||||
)
|
||||
if err != nil {
|
||||
return RevocationLog{}, err
|
||||
@@ -542,7 +544,7 @@ func TestFetchRevocationLogCompatible(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
err = putRevocationLog(
|
||||
lb, &testChannelCommit, 0, 1,
|
||||
lb, &testChannelCommit, 0, 1, false,
|
||||
)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user