-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7879 from ziggie1984/remove-last-sweep-logic
Remove publishing last sweep tx logic during startup.
- Loading branch information
Showing
12 changed files
with
116 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package migration31 | ||
|
||
import ( | ||
"github.com/btcsuite/btclog" | ||
) | ||
|
||
// log is a logger that is initialized as disabled. This means the package will | ||
// not perform any logging by default until a logger is set. | ||
var log = btclog.Disabled | ||
|
||
// UseLogger uses a specified Logger to output package logging info. | ||
func UseLogger(logger btclog.Logger) { | ||
log = logger | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package migration31 | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/btcsuite/btcwallet/walletdb" | ||
"github.com/lightningnetwork/lnd/kvdb" | ||
) | ||
|
||
// DeleteLastPublishedTxTLB deletes the top level bucket with the key | ||
// "sweeper-last-tx". | ||
func DeleteLastPublishedTxTLB(tx kvdb.RwTx) error { | ||
log.Infof("Deleting top-level bucket: %x ...", lastTxBucketKey) | ||
|
||
err := tx.DeleteTopLevelBucket(lastTxBucketKey) | ||
if err != nil && !errors.Is(err, walletdb.ErrBucketNotFound) { | ||
return err | ||
} | ||
|
||
log.Infof("Deleted top-level bucket: %x", lastTxBucketKey) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package migration31 | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/lightningnetwork/lnd/channeldb/migtest" | ||
"github.com/lightningnetwork/lnd/kvdb" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
var ( | ||
hexStr = migtest.Hex | ||
|
||
// lastTxBefore is the "sweeper-last-tx" bucket before the migration. | ||
// We fill the last-tx value with a dummy hex string because the actual | ||
// value is not important when deleting the bucket. | ||
lastTxBefore = map[string]interface{}{ | ||
"sweeper-last-tx": hexStr("0000"), | ||
} | ||
) | ||
|
||
// TestDeleteLastPublishTxTLP asserts that the sweeper-last-tx bucket is | ||
// properly deleted. | ||
func TestDeleteLastPublishTxTLP(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Prime the database with the populated sweeper-last-tx bucket. | ||
before := func(tx kvdb.RwTx) error { | ||
return migtest.RestoreDB(tx, lastTxBucketKey, lastTxBefore) | ||
} | ||
|
||
// After the migration, ensure that the sweeper-last-tx bucket was | ||
// properly deleted. | ||
after := func(tx kvdb.RwTx) error { | ||
err := migtest.VerifyDB(tx, lastTxBucketKey, nil) | ||
require.ErrorContains( | ||
t, err, | ||
fmt.Sprintf("bucket %s not found", lastTxBucketKey), | ||
) | ||
|
||
return nil | ||
} | ||
|
||
migtest.ApplyMigration( | ||
t, before, after, DeleteLastPublishedTxTLB, false, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package migration31 | ||
|
||
var ( | ||
// lastTxBucketKey is the key that points to a bucket containing a | ||
// single item storing the last published sweep tx. | ||
// | ||
// maps: lastTxKey -> serialized_tx | ||
lastTxBucketKey = []byte("sweeper-last-tx") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.