Skip to content

Commit

Permalink
drop spendingTxs cache. add scan checkpoint cache
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Oct 12, 2021
1 parent 0bca468 commit d5f0540
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 103 deletions.
15 changes: 10 additions & 5 deletions client/asset/btc/btc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ type testData struct {
blockchainMtx sync.RWMutex
verboseBlocks map[string]*msgBlockWithHeight
dbBlockForTx map[chainhash.Hash]*hashEntry
dbSpendingTxs map[outPoint]*hashEntry
mainchain map[int64]*chainhash.Hash

getBestBlockHashErr error
Expand Down Expand Up @@ -172,6 +171,7 @@ type testData struct {
// spv
fetchInputInfoTx *wire.MsgTx
getCFilterScripts map[chainhash.Hash][][]byte
checkpoints map[outPoint]*scanCheckpoint
confs uint32
confsSpent bool
confsErr error
Expand All @@ -186,15 +186,15 @@ func newTestData() *testData {
verboseBlocks: map[string]*msgBlockWithHeight{
genesisHash.String(): {msgBlock: &wire.MsgBlock{}},
},
dbBlockForTx: make(map[chainhash.Hash]*hashEntry),
dbSpendingTxs: make(map[outPoint]*hashEntry),
dbBlockForTx: make(map[chainhash.Hash]*hashEntry),
mainchain: map[int64]*chainhash.Hash{
0: genesisHash,
},
mempoolTxs: make(map[chainhash.Hash]*wire.MsgTx),
fetchInputInfoTx: dummyTx(),
getCFilterScripts: make(map[chainhash.Hash][][]byte),
confsErr: WalletTransactionNotFound,
checkpoints: make(map[outPoint]*scanCheckpoint),
}
}

Expand Down Expand Up @@ -599,7 +599,7 @@ func tNewWallet(segwit bool, walletType string) (*ExchangeWallet, *testData, fun
chainClient: nil,
acctNum: 0,
txBlocks: data.dbBlockForTx,
spendingTxs: data.dbSpendingTxs,
checkpoints: data.checkpoints,
log: cfg.Logger.SubLogger("SPV"),
loader: nil,
}
Expand Down Expand Up @@ -1938,6 +1938,7 @@ func testAuditContract(t *testing.T, segwit bool, walletType string) {

txHash := tx.TxHash()
const vout = 0
outPt := newOutPoint(&txHash, vout)

audit, err := wallet.AuditContract(toCoinID(&txHash, vout), contract, nil, now)
if err != nil {
Expand All @@ -1962,6 +1963,7 @@ func testAuditContract(t *testing.T, segwit bool, walletType string) {
// GetTxOut error
node.txOutErr = tErr
delete(node.getCFilterScripts, *blockHash)
delete(node.checkpoints, outPt)
_, err = wallet.AuditContract(toCoinID(&txHash, vout), contract, nil, now)
if err == nil {
t.Fatalf("no error for unknown txout")
Expand Down Expand Up @@ -2147,8 +2149,10 @@ func testRefund(t *testing.T, segwit bool, walletType string) {
node.privKeyForAddr = wif

tx := makeRawTx([]dex.Bytes{pkScript}, []*wire.TxIn{dummyInput()})
tx.TxOut[0].Value = 1e8
const vout = 0
tx.TxOut[vout].Value = 1e8
txHash := tx.TxHash()
outPt := newOutPoint(&txHash, vout)
blockHash, _ := node.addRawTx(1, tx)
node.getCFilterScripts[*blockHash] = [][]byte{pkScript}
node.getTransactionErr = WalletTransactionNotFound
Expand All @@ -2171,6 +2175,7 @@ func testRefund(t *testing.T, segwit bool, walletType string) {
// gettxout error
node.txOutErr = tErr
node.getCFilterScripts[*blockHash] = nil
delete(node.checkpoints, outPt)
_, err = wallet.Refund(contractOutput.ID(), contract)
if err == nil {
t.Fatalf("no error for missing utxo")
Expand Down
Loading

0 comments on commit d5f0540

Please sign in to comment.