Skip to content

Commit

Permalink
blockchain: Remove unused db update tracking.
Browse files Browse the repository at this point in the history
Many years ago, the various threshold states were stored in the database
due to performance reasons.  However, that logic was removed when the
code was updated to support voting since other changes made it quite
efficient to simply calculate the states at startup.

However, it appears that the dbUpdates field was not removed even though
it's not actually used anymore.  This removes the field and associated
logic accordingly.
  • Loading branch information
davecgh committed Feb 28, 2023
1 parent 5218eb1 commit 961b019
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
3 changes: 1 addition & 2 deletions internal/blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -2072,8 +2072,7 @@ func extractDeployments(params *chaincfg.Params) (map[string]deploymentInfo, err
deployment: deployment,
forcedState: forcedState,
cache: &thresholdStateCache{
entries: make(map[chainhash.Hash]ThresholdStateTuple),
dbUpdates: make(map[chainhash.Hash]ThresholdStateTuple),
entries: make(map[chainhash.Hash]ThresholdStateTuple),
},
}
}
Expand Down
15 changes: 2 additions & 13 deletions internal/blockchain/thresholdstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ type thresholdConditionChecker interface {
// threshold window for a set of IDs. It also keeps track of which entries have
// been modified and therefore need to be written to the database.
type thresholdStateCache struct {
dbUpdates map[chainhash.Hash]ThresholdStateTuple
entries map[chainhash.Hash]ThresholdStateTuple
entries map[chainhash.Hash]ThresholdStateTuple
}

// Lookup returns the threshold state associated with the given hash along with
Expand All @@ -184,25 +183,15 @@ func (c *thresholdStateCache) Lookup(hash chainhash.Hash) (ThresholdStateTuple,
}

// Update updates the cache to contain the provided hash to threshold state
// mapping while properly tracking needed updates flush changes to the database.
// mapping.
func (c *thresholdStateCache) Update(hash chainhash.Hash, state ThresholdStateTuple) {
if existing, ok := c.entries[hash]; ok && existing == state {
return
}

c.dbUpdates[hash] = state
c.entries[hash] = state
}

// MarkFlushed marks all of the current updates as flushed to the database.
// This is useful so the caller can ensure the needed database updates are not
// lost until they have successfully been written to the database.
func (c *thresholdStateCache) MarkFlushed() {
for hash := range c.dbUpdates {
delete(c.dbUpdates, hash)
}
}

// currentDeploymentVersion returns the highest deployment version that is
// defined in the given network parameters. Zero is returned if no deployments
// are defined.
Expand Down

0 comments on commit 961b019

Please sign in to comment.