sweep: rename NotifyPublishTx to StoreTx

To properly reflect what the method really does. We also changes the
method signature so only a hash is used.
This commit is contained in:
yyforyongyu committed 2024-04-19 21:33:19 +08:00
1 parent d4c1937572
commit e86843da6e
4 files changed
+12 -16

No files matched your search

+5 -7
View File
@@ -39,8 +39,8 @@ type SweeperStore interface {
// hash. // hash.
IsOurTx(hash chainhash.Hash) (bool, error) IsOurTx(hash chainhash.Hash) (bool, error)
// NotifyPublishTx signals that we are about to publish a tx. // StoreTx stores a tx hash we are about to publish.
NotifyPublishTx(*wire.MsgTx) error StoreTx(chainhash.Hash) error
// ListSweeps lists all the sweeps we have successfully published. // ListSweeps lists all the sweeps we have successfully published.
ListSweeps() ([]chainhash.Hash, error) ListSweeps() ([]chainhash.Hash, error)
@@ -147,8 +147,8 @@ func migrateTxHashes(tx kvdb.RwTx, txHashesBucket kvdb.RwBucket,
return nil return nil
} }
// NotifyPublishTx signals that we are about to publish a tx. // StoreTx stores that we are about to publish a tx.
func (s *sweeperStore) NotifyPublishTx(sweepTx *wire.MsgTx) error { func (s *sweeperStore) StoreTx(txid chainhash.Hash) error {
return kvdb.Update(s.db, func(tx kvdb.RwTx) error { return kvdb.Update(s.db, func(tx kvdb.RwTx) error {
txHashesBucket := tx.ReadWriteBucket(txHashesBucketKey) txHashesBucket := tx.ReadWriteBucket(txHashesBucketKey)
@@ -156,9 +156,7 @@ func (s *sweeperStore) NotifyPublishTx(sweepTx *wire.MsgTx) error {
return errNoTxHashesBucket return errNoTxHashesBucket
} }
hash := sweepTx.TxHash() return txHashesBucket.Put(txid[:], []byte{})
return txHashesBucket.Put(hash[:], []byte{})
}, func() {}) }, func() {})
} }
+3 -5
View File
@@ -2,7 +2,6 @@ package sweep
import ( import (
"github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/btcsuite/btcd/wire"
) )
// MockSweeperStore is a mock implementation of sweeper store. This type is // 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 return ok, nil
} }
// NotifyPublishTx signals that we are about to publish a tx. // StoreTx stores a tx we are about to publish.
func (s *MockSweeperStore) NotifyPublishTx(tx *wire.MsgTx) error { func (s *MockSweeperStore) StoreTx(txid chainhash.Hash) error {
txHash := tx.TxHash() s.ourTxes[txid] = struct{}{}
s.ourTxes[txHash] = struct{}{}
return nil return nil
} }
+2 -2
View File
@@ -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 { if err != nil {
t.Fatal(err) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
+2 -2
View File
@@ -1176,9 +1176,9 @@ func (s *UtxoSweeper) sweep(inputs inputSet, feeRate chainfee.SatPerKWeight,
// publish, we loose track of this tx. Even republication on startup // publish, we loose track of this tx. Even republication on startup
// doesn't prevent this, because that call returns a double spend error // doesn't prevent this, because that call returns a double spend error
// then and would also not add the hash to the store. // 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 { 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 // Reschedule the inputs that we just tried to sweep. This is done in