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 2023-10-25 14:01:36 +08:00
parent d4c1937572
commit e86843da6e
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
4 changed files with 12 additions and 16 deletions

View File

@ -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() {})
}

View File

@ -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
}

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 {
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)
}

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
// 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