diff --git a/sweep/store.go b/sweep/store.go index 916d2fa54..72d7853a4 100644 --- a/sweep/store.go +++ b/sweep/store.go @@ -39,8 +39,8 @@ type SweeperStore interface { // hash. IsOurTx(hash chainhash.Hash) (bool, error) - // NotifyPublishTx signals that we are about to publish a tx. - NotifyPublishTx(*wire.MsgTx) error + // StoreTx stores a tx hash we are about to publish. + StoreTx(chainhash.Hash) error // ListSweeps lists all the sweeps we have successfully published. ListSweeps() ([]chainhash.Hash, error) @@ -147,8 +147,8 @@ func migrateTxHashes(tx kvdb.RwTx, txHashesBucket kvdb.RwBucket, return nil } -// NotifyPublishTx signals that we are about to publish a tx. -func (s *sweeperStore) NotifyPublishTx(sweepTx *wire.MsgTx) error { +// StoreTx stores that we are about to publish a tx. +func (s *sweeperStore) StoreTx(txid chainhash.Hash) error { return kvdb.Update(s.db, func(tx kvdb.RwTx) error { txHashesBucket := tx.ReadWriteBucket(txHashesBucketKey) @@ -156,9 +156,7 @@ func (s *sweeperStore) NotifyPublishTx(sweepTx *wire.MsgTx) error { return errNoTxHashesBucket } - hash := sweepTx.TxHash() - - return txHashesBucket.Put(hash[:], []byte{}) + return txHashesBucket.Put(txid[:], []byte{}) }, func() {}) } diff --git a/sweep/store_mock.go b/sweep/store_mock.go index 53d9080d8..c8b9652f4 100644 --- a/sweep/store_mock.go +++ b/sweep/store_mock.go @@ -2,7 +2,6 @@ package sweep import ( "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/btcsuite/btcd/wire" ) // MockSweeperStore is a mock implementation of sweeper store. This type is @@ -25,10 +24,9 @@ func (s *MockSweeperStore) IsOurTx(hash chainhash.Hash) (bool, error) { return ok, nil } -// NotifyPublishTx signals that we are about to publish a tx. -func (s *MockSweeperStore) NotifyPublishTx(tx *wire.MsgTx) error { - txHash := tx.TxHash() - s.ourTxes[txHash] = struct{}{} +// StoreTx stores a tx we are about to publish. +func (s *MockSweeperStore) StoreTx(txid chainhash.Hash) error { + s.ourTxes[txid] = struct{}{} return nil } diff --git a/sweep/store_test.go b/sweep/store_test.go index 60e66b4b0..c07583dcc 100644 --- a/sweep/store_test.go +++ b/sweep/store_test.go @@ -50,7 +50,7 @@ func testStore(t *testing.T, createStore func() (SweeperStore, error)) { }, }) - err = store.NotifyPublishTx(&tx1) + err = store.StoreTx(tx1.TxHash()) if err != nil { t.Fatal(err) } @@ -63,7 +63,7 @@ func testStore(t *testing.T, createStore func() (SweeperStore, error)) { }, }) - err = store.NotifyPublishTx(&tx2) + err = store.StoreTx(tx2.TxHash()) if err != nil { t.Fatal(err) } diff --git a/sweep/sweeper.go b/sweep/sweeper.go index ebdce7d1b..99e809144 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -1176,9 +1176,9 @@ func (s *UtxoSweeper) sweep(inputs inputSet, feeRate chainfee.SatPerKWeight, // publish, we loose track of this tx. Even republication on startup // doesn't prevent this, because that call returns a double spend error // then and would also not add the hash to the store. - err = s.cfg.Store.NotifyPublishTx(tx) + err = s.cfg.Store.StoreTx(tx.TxHash()) if err != nil { - return fmt.Errorf("notify publish tx: %w", err) + return fmt.Errorf("store tx: %w", err) } // Reschedule the inputs that we just tried to sweep. This is done in