channeldb: add NoAmountData field to MigrateRevLogConfigImpl

Add a NoAmountData field to the MigrateRevLogConfigImpl struct and set
it for tests. This field is still a no-op in the migration.
This commit is contained in:
Elle Mouton committed 2023-02-16 20:46:05 +02:00
1 parent 70e3f8f511
commit 9c01916bc0
3 files changed
+48 -11

No files matched your search

+26 -9
View File
@@ -25,15 +25,29 @@ const recordsPerTx = 20_000
// MigrateRevLogConfig is an interface that defines the config that should be
// passed to the MigrateRevocationLog function.
type MigrateRevLogConfig interface{}
type MigrateRevLogConfig interface {
// GetNoAmountData returns true if the amount data of revoked commitment
// transactions should not be stored in the revocation log.
GetNoAmountData() bool
}
// MigrateRevLogConfigImpl implements the MigrationRevLogConfig interface.
type MigrateRevLogConfigImpl struct{}
type MigrateRevLogConfigImpl struct {
// NoAmountData if set to true will result in the amount data of revoked
// commitment transactions not being stored in the revocation log.
NoAmountData bool
}
// GetNoAmountData returns true if the amount data of revoked commitment
// transactions should not be stored in the revocation log.
func (c *MigrateRevLogConfigImpl) GetNoAmountData() bool {
return c.NoAmountData
}
// MigrateRevocationLog migrates the old revocation logs into the newer format
// and deletes them once finished, with the deletion only happens once ALL the
// old logs have been migrates.
func MigrateRevocationLog(db kvdb.Backend, _ MigrateRevLogConfig) error {
func MigrateRevocationLog(db kvdb.Backend, cfg MigrateRevLogConfig) error {
log.Infof("Migrating revocation logs, might take a while...")
var (
@@ -71,7 +85,7 @@ func MigrateRevocationLog(db kvdb.Backend, _ MigrateRevLogConfig) error {
// Process the migration.
err = kvdb.Update(db, func(tx kvdb.RwTx) error {
finished, err = processMigration(tx)
finished, err = processMigration(tx, cfg)
if err != nil {
return err
}
@@ -121,7 +135,7 @@ func MigrateRevocationLog(db kvdb.Backend, _ MigrateRevLogConfig) error {
// processMigration finds the next un-migrated revocation logs, reads a max
// number of `recordsPerTx` records, converts them into the new revocation logs
// and save them to disk.
func processMigration(tx kvdb.RwTx) (bool, error) {
func processMigration(tx kvdb.RwTx, cfg MigrateRevLogConfig) (bool, error) {
openChanBucket := tx.ReadWriteBucket(openChannelBucket)
// If no bucket is found, we can exit early.
@@ -141,7 +155,7 @@ func processMigration(tx kvdb.RwTx) (bool, error) {
}
// Read a list of old revocation logs.
entryMap, err := readOldRevocationLogs(openChanBucket, locator)
entryMap, err := readOldRevocationLogs(openChanBucket, locator, cfg)
if err != nil {
return false, fmt.Errorf("read old logs err: %v", err)
}
@@ -375,7 +389,7 @@ type result struct {
// readOldRevocationLogs finds a list of old revocation logs and converts them
// into the new revocation logs.
func readOldRevocationLogs(openChanBucket kvdb.RwBucket,
locator *updateLocator) (logEntries, error) {
locator *updateLocator, cfg MigrateRevLogConfig) (logEntries, error) {
entries := make(logEntries)
results := make([]*result, 0)
@@ -422,7 +436,9 @@ func readOldRevocationLogs(openChanBucket kvdb.RwBucket,
// Convert the old logs into the new logs. We do this early in
// the read tx so the old large revocation log can be set to
// nil here so save us some memory space.
newLog, err := convertRevocationLog(&c, ourIndex, theirIndex)
newLog, err := convertRevocationLog(
&c, ourIndex, theirIndex, cfg.GetNoAmountData(),
)
if err != nil {
r.errChan <- err
}
@@ -526,7 +542,8 @@ func readOldRevocationLogs(openChanBucket kvdb.RwBucket,
// convertRevocationLog uses the fields `CommitTx` and `Htlcs` from a
// ChannelCommitment to construct a revocation log entry.
func convertRevocationLog(commit *mig.ChannelCommitment,
ourOutputIndex, theirOutputIndex uint32) (*RevocationLog, error) {
ourOutputIndex, theirOutputIndex uint32,
noAmtData bool) (*RevocationLog, error) {
// Sanity check that the output indexes can be safely converted.
if ourOutputIndex > math.MaxUint16 {