multi: use funding manager as BatchCleaner

If we detect we have a pending batch in the local database that was
replaced by a different transaction, we try to clean up funding shims
and pending channels on startup as well.
To allow that, we use the funding manager as the BatchCleaner
implementation.
This commit is contained in:
Oliver Gugger 2020-12-08 11:44:13 +01:00
parent 5098fe1ccb
commit 671f430b88
No known key found for this signature in database
GPG key ID: 8E4256593F177720
3 changed files with 29 additions and 1 deletions

View file

@ -10,6 +10,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightninglabs/pool/account"
"github.com/lightninglabs/pool/clientdb"
"github.com/lightninglabs/pool/order"
"github.com/lightninglabs/pool/poolrpc"
)
@ -33,6 +34,14 @@ type BatchCleaner interface {
// batch without applying its staged updates to accounts and orders. If
// no pending batch exists, this acts as a no-op.
DeletePendingBatch() error
// RemovePendingBatchArtifacts removes any funding shims or pending
// channels from a batch that was never finalized. Some non-terminal
// errors are logged only and not returned. Therefore if this method
// returns an error, it should be handled as terminal error.
RemovePendingBatchArtifacts(
matchedOrders map[order.Nonce][]*order.MatchedOrder,
batchTx *wire.MsgTx) error
}
// checkPendingBatch cross-checks the trader's pending batch with what the
@ -61,6 +70,14 @@ func (c *Client) checkPendingBatch() error {
}
if snapshot.BatchTX.TxHash() != finalizedTx.TxHash() {
err := c.cfg.BatchCleaner.RemovePendingBatchArtifacts(
snapshot.MatchedOrders, snapshot.BatchTX,
)
if err != nil {
return fmt.Errorf("error removing pending batch "+
"artifacts: %v", err)
}
return c.cfg.BatchCleaner.DeletePendingBatch()
}

View file

@ -607,10 +607,21 @@ func (m *Manager) BatchChannelSetup(batch *order.Batch,
return channelKeys, nil
}
// DeletePendingBatch removes all references to the current pending batch
// without applying its staged updates to accounts and orders. If no pending
// batch exists, this acts as a no-op.
//
// NOTE: This is part of the auctioneer.BatchCleaner interface.
func (m *Manager) DeletePendingBatch() error {
return m.DB.DeletePendingBatch()
}
// RemovePendingBatchArtifacts removes any funding shims or pending channels
// from a batch that was never finalized. Some non-terminal errors are logged
// only and not returned. Therefore if this method returns an error, it should
// be handled as terminal error.
//
// NOTE: This is part of the auctioneer.BatchCleaner interface.
func (m *Manager) RemovePendingBatchArtifacts(
matchedOrders map[order.Nonce][]*order.MatchedOrder,
batchTx *wire.MsgTx) error {

View file

@ -465,7 +465,7 @@ func (s *Server) setupClient() error {
MinBackoff: s.cfg.MinBackoff,
MaxBackoff: s.cfg.MaxBackoff,
BatchSource: s.db,
BatchCleaner: s.db,
BatchCleaner: s.fundingManager,
}
s.AuctioneerClient, err = auctioneer.NewClient(clientCfg)
if err != nil {