Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blockchain: Harden and optimize utxo cache. #2995

Merged
merged 19 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions internal/blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,8 @@ func countSpentStakeOutputs(block *dcrutil.Block) int {
continue
}

// Exclude TreasuryBase and TSpend.
// Exclude treasurybase and treasury spends since neither have any
// inputs.
if stake.IsTreasuryBase(stx) || stake.IsTSpend(stx) {
continue
}
Expand Down Expand Up @@ -2211,7 +2212,7 @@ func New(ctx context.Context, config *Config) (*BlockChain, error) {

// Initialize the UTXO state. This entails running any database migrations
// as necessary as well as initializing the UTXO cache.
if err := b.utxoCache.Initialize(ctx, &b, b.bestChain.tip()); err != nil {
if err := b.utxoCache.Initialize(ctx, &b); err != nil {
return nil, err
}

Expand Down
6 changes: 4 additions & 2 deletions internal/blockchain/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,10 @@ func (g *chaingenHarness) ExpectUtxoSetState(blockName string) {
lastFlushHash: block.BlockHash(),
}
if !reflect.DeepEqual(gotState, wantState) {
g.t.Fatalf("mismatched utxo set state:\nwant: %+v\n got: %+v\n", wantState,
gotState)
g.t.Fatalf("mismatched utxo set state:\nwant: hash %s, height %d\n "+
"got: hash %s, height %d\n", wantState.lastFlushHash,
wantState.lastFlushHeight, gotState.lastFlushHash,
gotState.lastFlushHeight)
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/blockchain/indexers/indexsubscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ func (s *IndexSubscriber) findLowestIndexTipHeight(queryer ChainQueryer) (int64,
return lowestHeight, bestHeight, nil
}

// CatchUp syncs all subscribed indexes to the the main chain by connecting
// blocks from after the lowest index tip to the current main chain tip.
// CatchUp syncs all subscribed indexes to the main chain by connecting blocks
// from after the lowest index tip to the current main chain tip.
//
// This should be called after all indexes have subscribed for updates.
func (s *IndexSubscriber) CatchUp(ctx context.Context, db database.DB, queryer ChainQueryer) error {
Expand Down
3 changes: 1 addition & 2 deletions internal/blockchain/indexers/txindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ func (tc *testChain) MainChainHasBlock(hash *chainhash.Hash) bool {
return ok
}

// Best returns the height and block hash of the the current
// chain tip.
// Best returns the height and block hash of the current chain tip.
func (tc *testChain) Best() (int64, *chainhash.Hash) {
tc.mtx.Lock()
defer tc.mtx.Unlock()
Expand Down
Loading