multi: move all channelstate operations to ChannelStateDB

This commit is contained in:
Andras Banki-Horvath authored and Oliver Gugger committed 2021-09-29 17:00:03 +02:00
1 parent ddea833d31
commit 11cf4216e4
35 files changed
+377 -238

No files matched your search

+3 -3
View File
@@ -136,7 +136,7 @@ type BreachConfig struct {
// DB provides access to the user's channels, allowing the breach
// arbiter to determine the current state of a user's channels, and how
// it should respond to channel closure.
DB *channeldb.DB
DB *channeldb.ChannelStateDB
// Estimator is used by the breach arbiter to determine an appropriate
// fee level when generating, signing, and broadcasting sweep
@@ -1432,11 +1432,11 @@ func (b *BreachArbiter) sweepSpendableOutputsTxn(txWeight int64,
// store is to ensure that we can recover from a restart in the middle of a
// breached contract retribution.
type RetributionStore struct {
db *channeldb.DB
db kvdb.Backend
}
// NewRetributionStore creates a new instance of a RetributionStore.
func NewRetributionStore(db *channeldb.DB) *RetributionStore {
func NewRetributionStore(db kvdb.Backend) *RetributionStore {
return &RetributionStore{
db: db,
}
+6 -6
View File
@@ -987,7 +987,7 @@ func initBreachedState(t *testing.T) (*BreachArbiter,
contractBreaches := make(chan *ContractBreachEvent)
brar, cleanUpArb, err := createTestArbiter(
t, contractBreaches, alice.State().Db,
t, contractBreaches, alice.State().Db.GetParentDB(),
)
if err != nil {
t.Fatalf("unable to initialize test breach arbiter: %v", err)
@@ -1164,7 +1164,7 @@ func TestBreachHandoffFail(t *testing.T) {
assertNotPendingClosed(t, alice)
brar, cleanUpArb, err := createTestArbiter(
t, contractBreaches, alice.State().Db,
t, contractBreaches, alice.State().Db.GetParentDB(),
)
if err != nil {
t.Fatalf("unable to initialize test breach arbiter: %v", err)
@@ -2075,7 +2075,7 @@ func assertNoArbiterBreach(t *testing.T, brar *BreachArbiter,
// assertBrarCleanup blocks until the given channel point has been removed the
// retribution store and the channel is fully closed in the database.
func assertBrarCleanup(t *testing.T, brar *BreachArbiter,
chanPoint *wire.OutPoint, db *channeldb.DB) {
chanPoint *wire.OutPoint, db *channeldb.ChannelStateDB) {
t.Helper()
@@ -2174,7 +2174,7 @@ func createTestArbiter(t *testing.T, contractBreaches chan *ContractBreachEvent,
notifier := mock.MakeMockSpendNotifier()
ba := NewBreachArbiter(&BreachConfig{
CloseLink: func(_ *wire.OutPoint, _ ChannelCloseType) {},
DB: db,
DB: db.ChannelStateDB(),
Estimator: chainfee.NewStaticEstimator(12500, 0),
GenSweepScript: func() ([]byte, error) { return nil, nil },
ContractBreaches: contractBreaches,
@@ -2375,7 +2375,7 @@ func createInitChannels(revocationWindow int) (*lnwallet.LightningChannel, *lnwa
RevocationStore: shachain.NewRevocationStore(),
LocalCommitment: aliceCommit,
RemoteCommitment: aliceCommit,
Db: dbAlice,
Db: dbAlice.ChannelStateDB(),
Packager: channeldb.NewChannelPackager(shortChanID),
FundingTxn: channels.TestFundingTx,
}
@@ -2393,7 +2393,7 @@ func createInitChannels(revocationWindow int) (*lnwallet.LightningChannel, *lnwa
RevocationStore: shachain.NewRevocationStore(),
LocalCommitment: bobCommit,
RemoteCommitment: bobCommit,
Db: dbBob,
Db: dbBob.ChannelStateDB(),
Packager: channeldb.NewChannelPackager(shortChanID),
}
+11 -5
View File
@@ -258,7 +258,9 @@ func (a *arbChannel) NewAnchorResolutions() (*lnwallet.AnchorResolutions,
// same instance that is used by the link.
chanPoint := a.channel.FundingOutpoint
channel, err := a.c.chanSource.FetchChannel(nil, chanPoint)
channel, err := a.c.chanSource.ChannelStateDB().FetchChannel(
nil, chanPoint,
)
if err != nil {
return nil, err
}
@@ -301,7 +303,9 @@ func (a *arbChannel) ForceCloseChan() (*lnwallet.LocalForceCloseSummary, error)
// Now that we know the link can't mutate the channel
// state, we'll read the channel from disk the target
// channel according to its channel point.
channel, err := a.c.chanSource.FetchChannel(nil, chanPoint)
channel, err := a.c.chanSource.ChannelStateDB().FetchChannel(
nil, chanPoint,
)
if err != nil {
return nil, err
}
@@ -422,7 +426,7 @@ func (c *ChainArbitrator) ResolveContract(chanPoint wire.OutPoint) error {
// First, we'll we'll mark the channel as fully closed from the PoV of
// the channel source.
err := c.chanSource.MarkChanFullyClosed(&chanPoint)
err := c.chanSource.ChannelStateDB().MarkChanFullyClosed(&chanPoint)
if err != nil {
log.Errorf("ChainArbitrator: unable to mark ChannelPoint(%v) "+
"fully closed: %v", chanPoint, err)
@@ -480,7 +484,7 @@ func (c *ChainArbitrator) Start() error {
// First, we'll fetch all the channels that are still open, in order to
// collect them within our set of active contracts.
openChannels, err := c.chanSource.FetchAllChannels()
openChannels, err := c.chanSource.ChannelStateDB().FetchAllChannels()
if err != nil {
return err
}
@@ -538,7 +542,9 @@ func (c *ChainArbitrator) Start() error {
// In addition to the channels that we know to be open, we'll also
// launch arbitrators to finishing resolving any channels that are in
// the pending close state.
closingChannels, err := c.chanSource.FetchClosedChannels(true)
closingChannels, err := c.chanSource.ChannelStateDB().FetchClosedChannels(
true,
)
if err != nil {
return err
}
+3 -3
View File
@@ -49,7 +49,7 @@ func TestChainArbitratorRepublishCloses(t *testing.T) {
// We manually set the db here to make sure all channels are
// synced to the same db.
channel.Db = db
channel.Db = db.ChannelStateDB()
addr := &net.TCPAddr{
IP: net.ParseIP("127.0.0.1"),
@@ -165,7 +165,7 @@ func TestResolveContract(t *testing.T) {
}
defer cleanup()
channel := newChannel.State()
channel.Db = db
channel.Db = db.ChannelStateDB()
addr := &net.TCPAddr{
IP: net.ParseIP("127.0.0.1"),
Port: 18556,
@@ -205,7 +205,7 @@ func TestResolveContract(t *testing.T) {
// While the resolver are active, we'll now remove the channel from the
// database (mark is as closed).
err = db.AbandonChannel(&channel.FundingOutpoint, 4)
err = db.ChannelStateDB().AbandonChannel(&channel.FundingOutpoint, 4)
if err != nil {
t.Fatalf("unable to remove channel: %v", err)
}
+2 -2
View File
@@ -58,7 +58,7 @@ func copyChannelState(state *channeldb.OpenChannel) (
*channeldb.OpenChannel, func(), error) {
// Make a copy of the DB.
dbFile := filepath.Join(state.Db.Path(), "channel.db")
dbFile := filepath.Join(state.Db.GetParentDB().Path(), "channel.db")
tempDbPath, err := ioutil.TempDir("", "past-state")
if err != nil {
return nil, nil, err
@@ -81,7 +81,7 @@ func copyChannelState(state *channeldb.OpenChannel) (
return nil, nil, err
}
chans, err := newDb.FetchAllChannels()
chans, err := newDb.ChannelStateDB().FetchAllChannels()
if err != nil {
cleanup()
return nil, nil, err