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-v4]: Harden and optimize utxo cache. #3006

Merged
merged 17 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
93fb5da
[blockchain-v4] blockchain: Address some linter complaints.
davecgh Jun 23, 2022
f031538
[blockchain-v4] blockchain: Misc consistency cleanup pass.
davecgh Sep 13, 2022
48c0fbe
[blockchain-v4] blockchain: Pre-allocate in-flight utxoview tx map.
davecgh Sep 13, 2022
fd8c445
[blockchain-v4] blockchain: Remove unused utxo cache add entry err.
davecgh Sep 13, 2022
4298a39
[blockchain-v4] blockchain: Allow tests to override cache flushing.
davecgh Sep 13, 2022
cfb451e
[blockchain-v4] blockchain: Improve utxo cache initialize tests.
davecgh Sep 13, 2022
3d67a80
[blockchain-v4] blockchain: Fix rare unclean utxo cache recovery.
davecgh Sep 13, 2022
0140aa1
[blockchain-v4] blockchain: Don't fetch trsy{base,spend} inputs.
davecgh Sep 13, 2022
e8fcff4
[blockchain-v4] blockchain: Don't add treasurybase utxos.
davecgh Sep 13, 2022
25b7ec5
[blockchain-v4] blockchain: Consolidate utxo cache test entries.
davecgh Sep 13, 2022
1b5a2a6
[blockchain-v4] blockchain: Rework utxo cache spend entry tests.
davecgh Sep 13, 2022
b4b2079
[blockchain-v4] blockchain: Rework utxo cache commit tests.
davecgh Sep 13, 2022
a48f7a3
[blockchain-v4] blockchain: Rework utxo cache add entry tests.
davecgh Sep 13, 2022
b52d0cb
[blockchain-v4] blockchain: Separate utxo cache vs view state.
davecgh Sep 13, 2022
4b78608
[blockchain-v4] blockchain: Improve utxo cache spend robustness.
davecgh Sep 13, 2022
1bcc533
[blockchain-v4] blockchain: Split regular/stake view tx connect.
davecgh Sep 13, 2022
8208daf
[blockchain-v4] blockchain: Bypass utxo cache for zero conf spends.
davecgh Sep 13, 2022
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
3 changes: 2 additions & 1 deletion blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,8 @@ func countSpentStakeOutputs(block *dcrutil.Block, isTreasuryEnabled bool) 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
6 changes: 3 additions & 3 deletions blockchain/chainio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func TestBlockIndexDecodeErrors(t *testing.T) {
// Ensure the expected error type is returned.
gotBytesRead, err := decodeBlockIndexEntry(test.serialized,
&test.entry)
if !errors.As(err, &test.errType) {
if !errors.Is(err, test.errType) {
t.Errorf("%q: expected error type does not match - got %T, want %T",
test.name, err, test.errType)
continue
Expand Down Expand Up @@ -525,7 +525,7 @@ func TestStxoDecodeErrors(t *testing.T) {
gotBytesRead, err := decodeSpentTxOut(test.serialized,
&test.stxo, test.stxo.amount, test.stxo.blockHeight, test.stxo.blockIndex,
test.txOutIndex)
if !errors.As(err, &test.errType) {
if !errors.Is(err, test.errType) {
t.Errorf("%q: expected error type does not match - got %T, want %T",
test.name, err, test.errType)
continue
Expand Down Expand Up @@ -777,7 +777,7 @@ func TestSpendJournalErrors(t *testing.T) {
// slice is nil.
stxos, err := deserializeSpendJournalEntry(test.serialized,
test.blockTxns, noTreasury)
if !errors.As(err, &test.errType) {
if !errors.Is(err, test.errType) {
t.Errorf("%q: expected error type does not match - got %T, want %T",
test.name, err, test.errType)
continue
Expand Down
6 changes: 4 additions & 2 deletions blockchain/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -926,8 +926,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
9 changes: 9 additions & 0 deletions blockchain/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ func (e AssertError) Error() string {
return "assertion failed: " + string(e)
}

// Is implements the interface to work with the standard library's errors.Is.
//
// It returns true in the following cases:
// - The target is AssertError
func (e AssertError) Is(target error) bool {
var err AssertError
return errors.As(target, &err)
}

// ErrorKind identifies a kind of error. It has full support for errors.Is and
// errors.As, so the caller can directly check against an error kind when
// determining the reason for an error.
Expand Down
4 changes: 2 additions & 2 deletions blockchain/indexers/indexsubscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,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 blockchain/indexers/txindex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,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
2 changes: 1 addition & 1 deletion blockchain/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestBlockIndexDecodeErrorsV2(t *testing.T) {
// Ensure the expected error type is returned.
gotBytesRead, err := decodeBlockIndexEntryV2(test.serialized,
&test.entry)
if !errors.As(err, &test.errType) {
if !errors.Is(err, test.errType) {
t.Errorf("decodeBlockIndexEntry (%s): expected error "+
"type does not match - got %T, want %T",
test.name, err, test.errType)
Expand Down
Loading