diff --git a/auctioneer/batch.go b/auctioneer/batch.go index 3f752b6..5c6e653 100644 --- a/auctioneer/batch.go +++ b/auctioneer/batch.go @@ -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() } diff --git a/funding/manager.go b/funding/manager.go index b35dee2..a78046f 100644 --- a/funding/manager.go +++ b/funding/manager.go @@ -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 { diff --git a/server.go b/server.go index 36656fb..442aa6f 100644 --- a/server.go +++ b/server.go @@ -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 {