Skip to content

Commit

Permalink
blockchain: Remove unused params.
Browse files Browse the repository at this point in the history
  • Loading branch information
dajohi authored and davecgh committed Apr 11, 2022
1 parent ab6d2fb commit 2b9a9cc
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 74 deletions.
6 changes: 3 additions & 3 deletions blockchain/chaingen/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -1907,7 +1907,7 @@ func (g *Generator) connectLiveTickets(blockHash *chainhash.Hash, height uint32,

// addMissedVotes adds any of the passed winning tickets as missed votes if the
// passed block does not cast those votes.
func (g *Generator) addMissedVotes(blockHash *chainhash.Hash, stakeTxns []*wire.MsgTx, winners []*stakeTicket) {
func (g *Generator) addMissedVotes(stakeTxns []*wire.MsgTx, winners []*stakeTicket) {
// Nothing to do before there are any winning tickets.
if len(winners) == 0 {
return
Expand Down Expand Up @@ -1994,7 +1994,7 @@ func (g *Generator) connectBlockTickets(b *wire.MsgBlock) {
}

// Keep track of any missed votes.
g.addMissedVotes(&blockHash, b.STransactions, winners)
g.addMissedVotes(b.STransactions, winners)

// Keep track of revocations.
g.connectRevocations(&blockHash, b.STransactions)
Expand Down Expand Up @@ -2448,7 +2448,7 @@ func (g *Generator) NextBlock(blockName string, spend *SpendableOut, ticketSpend
// it.
g.originalParents[blockHash] = prevHash
}
g.addMissedVotes(&blockHash, block.STransactions, ticketWinners)
g.addMissedVotes(block.STransactions, ticketWinners)
g.connectRevocations(&blockHash, block.STransactions)
g.connectLiveTickets(&blockHash, nextHeight, ticketWinners,
ticketPurchases)
Expand Down
11 changes: 4 additions & 7 deletions blockchain/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -931,13 +931,13 @@ func dbPutDatabaseInfo(dbTx database.Tx, dbi *databaseInfo) error {

// dbFetchDatabaseInfo uses an existing database transaction to fetch the
// database versioning and creation information.
func dbFetchDatabaseInfo(dbTx database.Tx) (*databaseInfo, error) {
func dbFetchDatabaseInfo(dbTx database.Tx) *databaseInfo {
meta := dbTx.Metadata()
bucket := meta.Bucket(bcdbInfoBucketName)

// Uninitialized state.
if bucket == nil {
return nil, nil
return nil
}

// Load the database version.
Expand Down Expand Up @@ -985,7 +985,7 @@ func dbFetchDatabaseInfo(dbTx database.Tx) (*databaseInfo, error) {
bidxVer: bidxVer,
created: created,
stxoVer: stxoVer,
}, nil
}
}

// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -1455,10 +1455,7 @@ func (b *BlockChain) initChainState(ctx context.Context,
var isStateInitialized bool
err = b.db.View(func(dbTx database.Tx) error {
// Fetch the database versioning information.
dbInfo, err := dbFetchDatabaseInfo(dbTx)
if err != nil {
return err
}
dbInfo := dbFetchDatabaseInfo(dbTx)

// The database bucket for the versioning information is missing.
if dbInfo == nil {
Expand Down
12 changes: 6 additions & 6 deletions blockchain/indexers/addrindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ func (idx *AddrIndex) indexBlock(data writeIndexData, block *dcrutil.Block, prev

// connectBlock adds a mapping for all addresses associated with transactions in
// the provided block.
func (idx *AddrIndex) connectBlock(dbTx database.Tx, block, parent *dcrutil.Block, prevScripts PrevScripter, isTreasuryEnabled bool) error {
func (idx *AddrIndex) connectBlock(dbTx database.Tx, block *dcrutil.Block, prevScripts PrevScripter, isTreasuryEnabled bool) error {
// NOTE: The fact that the block can disapprove the regular tree of the
// previous block is ignored for this index because even though the
// disapproved transactions no longer apply spend semantics, they still
Expand Down Expand Up @@ -925,7 +925,7 @@ func (idx *AddrIndex) connectBlock(dbTx database.Tx, block, parent *dcrutil.Bloc

// disconnectBlock removes the mappings for addresses associated with
// transactions in the provided block.
func (idx *AddrIndex) disconnectBlock(dbTx database.Tx, block, parent *dcrutil.Block, prevScripts PrevScripter, isTreasuryEnabled bool) error {
func (idx *AddrIndex) disconnectBlock(dbTx database.Tx, block *dcrutil.Block, prevScripts PrevScripter, isTreasuryEnabled bool) error {
// NOTE: The fact that the block can disapprove the regular tree of the
// previous block is ignored for this index because even though the
// disapproved transactions no longer apply spend semantics, they still
Expand Down Expand Up @@ -1187,8 +1187,8 @@ func (*AddrIndex) DropIndex(ctx context.Context, db database.DB) error {
func (idx *AddrIndex) ProcessNotification(dbTx database.Tx, ntfn *IndexNtfn) error {
switch ntfn.NtfnType {
case ConnectNtfn:
err := idx.connectBlock(dbTx, ntfn.Block, ntfn.Parent,
ntfn.PrevScripts, ntfn.IsTreasuryEnabled)
err := idx.connectBlock(dbTx, ntfn.Block, ntfn.PrevScripts,
ntfn.IsTreasuryEnabled)
if err != nil {
msg := fmt.Sprintf("%s: unable to connect block: %v",
idx.Name(), err)
Expand All @@ -1198,8 +1198,8 @@ func (idx *AddrIndex) ProcessNotification(dbTx database.Tx, ntfn *IndexNtfn) err
idx.consumer.UpdateTip(ntfn.Block.Hash())

case DisconnectNtfn:
err := idx.disconnectBlock(dbTx, ntfn.Block, ntfn.Parent,
ntfn.PrevScripts, ntfn.IsTreasuryEnabled)
err := idx.disconnectBlock(dbTx, ntfn.Block, ntfn.PrevScripts,
ntfn.IsTreasuryEnabled)
if err != nil {
msg := fmt.Sprintf("%s: unable to disconnect block: %v",
idx.Name(), err)
Expand Down
12 changes: 6 additions & 6 deletions blockchain/indexers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func dbPutIndexerVersion(dbTx database.Tx, idxKey []byte, version uint32) error
}

// existsIndex returns whether the index keyed by idxKey exists in the database.
func existsIndex(db database.DB, idxKey []byte, idxName string) (bool, error) {
func existsIndex(db database.DB, idxKey []byte) (bool, error) {
var exists bool
err := db.View(func(dbTx database.Tx) error {
indexesBucket := dbTx.Metadata().Bucket(indexTipsBucketName)
Expand Down Expand Up @@ -331,7 +331,7 @@ func indexDropKey(idxKey []byte) []byte {

// dropIndexMetadata drops the passed index from the database by removing the
// top level bucket for the index, the index tip, and any in-progress drop flag.
func dropIndexMetadata(db database.DB, idxKey []byte, idxName string) error {
func dropIndexMetadata(db database.DB, idxKey []byte) error {
return db.Update(func(dbTx database.Tx) error {
meta := dbTx.Metadata()
indexesBucket := meta.Bucket(indexTipsBucketName)
Expand Down Expand Up @@ -362,7 +362,7 @@ func dropIndexMetadata(db database.DB, idxKey []byte, idxName string) error {
// before it is done before the index can be used again.
func dropFlatIndex(ctx context.Context, db database.DB, idxKey []byte, idxName string) error {
// Nothing to do if the index doesn't already exist.
exists, err := existsIndex(db, idxKey, idxName)
exists, err := existsIndex(db, idxKey)
if err != nil {
return err
}
Expand Down Expand Up @@ -394,7 +394,7 @@ func dropFlatIndex(ctx context.Context, db database.DB, idxKey []byte, idxName s

// Remove the index tip, version, bucket, and in-progress drop flag now that
// all index entries have been removed.
err = dropIndexMetadata(db, idxKey, idxName)
err = dropIndexMetadata(db, idxKey)
if err != nil {
return err
}
Expand All @@ -408,7 +408,7 @@ func dropFlatIndex(ctx context.Context, db database.DB, idxKey []byte, idxName s
// which can not be deleted with dropFlatIndex.
func dropIndex(db database.DB, idxKey []byte, idxName string) error {
// Nothing to do if the index doesn't already exist.
exists, err := existsIndex(db, idxKey, idxName)
exists, err := existsIndex(db, idxKey)
if err != nil {
return err
}
Expand All @@ -431,7 +431,7 @@ func dropIndex(db database.DB, idxKey []byte, idxName string) error {
// Remove the index tip, version, bucket, and in-progress drop flag.
// Removing the index bucket also recursively removes all values saved to
// the index.
err = dropIndexMetadata(db, idxKey, idxName)
err = dropIndexMetadata(db, idxKey)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions blockchain/indexers/dropcfindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
// DropCfIndex drops the CF index from the provided database if it exists.
func DropCfIndex(ctx context.Context, db database.DB) error {
// Nothing to do if the index doesn't already exist.
exists, err := existsIndex(db, cfIndexParentBucketKey, cfIndexName)
exists, err := existsIndex(db, cfIndexParentBucketKey)
if err != nil {
return err
}
Expand All @@ -38,7 +38,7 @@ func DropCfIndex(ctx context.Context, db database.DB) error {

// Remove the index tip, version, bucket, and in-progress drop flag now
// that all index entries have been removed.
err = dropIndexMetadata(db, cfIndexParentBucketKey, cfIndexName)
err = dropIndexMetadata(db, cfIndexParentBucketKey)
if err != nil {
return err
}
Expand Down
16 changes: 7 additions & 9 deletions blockchain/indexers/existsaddrindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (idx *ExistsAddrIndex) ExistsAddresses(addrs []stdaddr.Address) ([]bool, er
// provided block.
//
// This is part of the Indexer interface.
func (idx *ExistsAddrIndex) connectBlock(dbTx database.Tx, block, parent *dcrutil.Block, _ PrevScripter, isTreasuryEnabled bool) error {
func (idx *ExistsAddrIndex) connectBlock(dbTx database.Tx, block *dcrutil.Block) error {
// NOTE: The fact that the block can disapprove the regular tree of the
// previous block is ignored for this index because even though technically
// the address might become unused again if its only use was in a
Expand Down Expand Up @@ -429,7 +429,7 @@ func (idx *ExistsAddrIndex) connectBlock(dbTx database.Tx, block, parent *dcruti
// addresses, even in the case of a reorg.
//
// This is part of the Indexer interface.
func (idx *ExistsAddrIndex) disconnectBlock(dbTx database.Tx, block, parent *dcrutil.Block, _ PrevScripter, _ bool) error {
func (idx *ExistsAddrIndex) disconnectBlock(dbTx database.Tx, block *dcrutil.Block) error {
// The primary purpose of this index is to track whether or not addresses
// have ever been seen, so even if they ultimately end up technically
// becoming unused due to being in a block that was disconnected and the
Expand All @@ -452,7 +452,7 @@ func (idx *ExistsAddrIndex) disconnectBlock(dbTx database.Tx, block, parent *dcr
// unconfirmed (memory-only) exists address index.
//
// This function MUST be called with the unconfirmed lock held.
func (idx *ExistsAddrIndex) addUnconfirmedTx(tx *wire.MsgTx, isTreasuryEnabled bool) {
func (idx *ExistsAddrIndex) addUnconfirmedTx(tx *wire.MsgTx) {
isSStx := stake.IsSStx(tx)
for _, txIn := range tx.TxIn {
// Note that the functions used here require v0 scripts. Hence it is
Expand Down Expand Up @@ -518,9 +518,9 @@ func (idx *ExistsAddrIndex) addUnconfirmedTx(tx *wire.MsgTx, isTreasuryEnabled b
// unconfirmed (memory-only) exists address index.
//
// This function is safe for concurrent access.
func (idx *ExistsAddrIndex) AddUnconfirmedTx(tx *wire.MsgTx, isTreasuryEnabled bool) {
func (idx *ExistsAddrIndex) AddUnconfirmedTx(tx *wire.MsgTx) {
idx.unconfirmedLock.Lock()
idx.addUnconfirmedTx(tx, isTreasuryEnabled)
idx.addUnconfirmedTx(tx)
idx.unconfirmedLock.Unlock()
}

Expand All @@ -543,17 +543,15 @@ func (*ExistsAddrIndex) DropIndex(ctx context.Context, db database.DB) error {
func (idx *ExistsAddrIndex) ProcessNotification(dbTx database.Tx, ntfn *IndexNtfn) error {
switch ntfn.NtfnType {
case ConnectNtfn:
err := idx.connectBlock(dbTx, ntfn.Block, ntfn.Parent,
ntfn.PrevScripts, ntfn.IsTreasuryEnabled)
err := idx.connectBlock(dbTx, ntfn.Block)
if err != nil {
msg := fmt.Sprintf("%s: unable to connect block: %v",
idx.Name(), err)
return indexerError(ErrConnectBlock, msg)
}

case DisconnectNtfn:
err := idx.disconnectBlock(dbTx, ntfn.Block, ntfn.Parent,
ntfn.PrevScripts, ntfn.IsTreasuryEnabled)
err := idx.disconnectBlock(dbTx, ntfn.Block)
if err != nil {
msg := fmt.Sprintf("%s: unable to disconnect block: %v",
idx.Name(), err)
Expand Down
14 changes: 6 additions & 8 deletions blockchain/indexers/txindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func (idx *TxIndex) Create(dbTx database.Tx) error {

// connectBlock adds a hash-to-transaction mapping for every transaction in
// the passed block.
func (idx *TxIndex) connectBlock(dbTx database.Tx, block, parent *dcrutil.Block, _ PrevScripter, _ bool) error {
func (idx *TxIndex) connectBlock(dbTx database.Tx, block *dcrutil.Block) error {
// NOTE: The fact that the block can disapprove the regular tree of the
// previous block is ignored for this index because even though the
// disapproved transactions no longer apply spend semantics, they still
Expand Down Expand Up @@ -568,7 +568,7 @@ func (idx *TxIndex) connectBlock(dbTx database.Tx, block, parent *dcrutil.Block,

// disconnectBlock removes the hash-to-transaction mapping for every
// transaction in the passed block.
func (idx *TxIndex) disconnectBlock(dbTx database.Tx, block, parent *dcrutil.Block, _ PrevScripter, _ bool) error {
func (idx *TxIndex) disconnectBlock(dbTx database.Tx, block *dcrutil.Block) error {
// NOTE: The fact that the block can disapprove the regular tree of the
// previous block is ignored when disconnecting blocks because it is also
// ignored when connecting the block. See the comments in ConnectBlock for
Expand Down Expand Up @@ -653,7 +653,7 @@ func dropBlockIDIndex(db database.DB) error {
// dropped when it exists.
func DropTxIndex(ctx context.Context, db database.DB) error {
// Nothing to do if the index doesn't already exist.
exists, err := existsIndex(db, txIndexKey, txIndexName)
exists, err := existsIndex(db, txIndexKey)
if err != nil {
return err
}
Expand Down Expand Up @@ -698,7 +698,7 @@ func DropTxIndex(ctx context.Context, db database.DB) error {

// Remove the index tip, version, bucket, and in-progress drop flag now
// that all index entries have been removed.
err = dropIndexMetadata(db, txIndexKey, txIndexName)
err = dropIndexMetadata(db, txIndexKey)
if err != nil {
return err
}
Expand All @@ -721,17 +721,15 @@ func (*TxIndex) DropIndex(ctx context.Context, db database.DB) error {
func (idx *TxIndex) ProcessNotification(dbTx database.Tx, ntfn *IndexNtfn) error {
switch ntfn.NtfnType {
case ConnectNtfn:
err := idx.connectBlock(dbTx, ntfn.Block, ntfn.Parent,
ntfn.PrevScripts, ntfn.IsTreasuryEnabled)
err := idx.connectBlock(dbTx, ntfn.Block)
if err != nil {
msg := fmt.Sprintf("%s: unable to connect block: %v",
idx.Name(), err)
return indexerError(ErrConnectBlock, msg)
}

case DisconnectNtfn:
err := idx.disconnectBlock(dbTx, ntfn.Block, ntfn.Parent,
ntfn.PrevScripts, ntfn.IsTreasuryEnabled)
err := idx.disconnectBlock(dbTx, ntfn.Block)
if err != nil {
msg := fmt.Sprintf("%s: unable to disconnect block: %v",
idx.Name(), err)
Expand Down
16 changes: 5 additions & 11 deletions blockchain/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,13 @@ func TestProcessOrder(t *testing.T) {
// \-> b4h -> b5h@ -> b6h -> b7h
// \-> b4i -> b5i -> b6i@ -> b7i -> b8i
// \-> b4j -> b5j -> b6j -> b7j@
func genSharedProcessTestBlocks(t *testing.T) (*chaingen.Generator, error) {
func genSharedProcessTestBlocks(t *testing.T) *chaingen.Generator {
processTestGeneratorLock.Lock()
defer processTestGeneratorLock.Unlock()

// Only generate the process test chain once.
if processTestGenerator != nil {
return processTestGenerator, nil
return processTestGenerator
}

// Create a new database and chain instance needed to create the generator
Expand Down Expand Up @@ -511,7 +511,7 @@ func genSharedProcessTestBlocks(t *testing.T) (*chaingen.Generator, error) {
g.NextBlock("b7j", outs[2], ticketOuts[6]) // Double spend

processTestGenerator = g.Generator
return processTestGenerator, nil
return processTestGenerator
}

// TestProcessLogic ensures processing a mix of headers and blocks under a wide
Expand All @@ -524,10 +524,7 @@ func TestProcessLogic(t *testing.T) {
// some branches are valid and others contain invalid headers and/or blocks
// with multiple valid descendants as well as further forks at various
// heights from those invalid branches.
sharedGen, err := genSharedProcessTestBlocks(t)
if err != nil {
t.Fatalf("Failed to create generator: %v", err)
}
sharedGen := genSharedProcessTestBlocks(t)

// Create a new database and chain instance to run tests against.
g := newChaingenHarnessWithGen(t, sharedGen)
Expand Down Expand Up @@ -1179,10 +1176,7 @@ func TestInvalidateReconsider(t *testing.T) {
// some branches are valid and others contain invalid headers and/or blocks
// with multiple valid descendants as well as further forks at various
// heights from those invalid branches.
sharedGen, err := genSharedProcessTestBlocks(t)
if err != nil {
t.Fatalf("Failed to create generator: %v", err)
}
sharedGen := genSharedProcessTestBlocks(t)

// Create a new database and chain instance to run tests against.
g := newChaingenHarnessWithGen(t, sharedGen)
Expand Down
10 changes: 5 additions & 5 deletions blockchain/thresholdstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -974,14 +974,14 @@ type VoteCounts struct {
// current rule change activation interval.
//
// This function MUST be called with the chain state lock held (for writes).
func (b *BlockChain) getVoteCounts(node *blockNode, version uint32, d *chaincfg.ConsensusDeployment) (VoteCounts, error) {
func (b *BlockChain) getVoteCounts(node *blockNode, version uint32, d *chaincfg.ConsensusDeployment) VoteCounts {
// Don't try to count votes before the stake validation height since there
// could not possibly have been any.
svh := b.chainParams.StakeValidationHeight
if node.height < svh {
return VoteCounts{
VoteChoices: make([]uint32, len(d.Vote.Choices)),
}, nil
}
}

// Calculate the final height of the prior interval.
Expand Down Expand Up @@ -1016,7 +1016,7 @@ func (b *BlockChain) getVoteCounts(node *blockNode, version uint32, d *chaincfg.
countNode = countNode.parent
}

return result, nil
return result
}

// GetVoteCounts returns the vote counts for the specified version and
Expand All @@ -1028,9 +1028,9 @@ func (b *BlockChain) GetVoteCounts(version uint32, deploymentID string) (VoteCou
deployment := &b.chainParams.Deployments[version][k]
if deployment.Vote.Id == deploymentID {
b.chainLock.Lock()
counts, err := b.getVoteCounts(b.bestChain.Tip(), version, deployment)
counts := b.getVoteCounts(b.bestChain.Tip(), version, deployment)
b.chainLock.Unlock()
return counts, err
return counts, nil
}
}
str := fmt.Sprintf("deployment ID %s does not exist", deploymentID)
Expand Down
10 changes: 4 additions & 6 deletions blockchain/treasury_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -883,15 +883,13 @@ func TestTSpendVoteCount(t *testing.T) {

// getTreasuryState retrieves the treasury state for the provided hash.
func getTreasuryState(g *chaingenHarness, hash chainhash.Hash) (*treasuryState, error) {
var (
tsr *treasuryState
err error
)
err = g.chain.db.View(func(dbTx database.Tx) error {
var tsr *treasuryState
err := g.chain.db.View(func(dbTx database.Tx) error {
var err error
tsr, err = dbFetchTreasuryBalance(dbTx, hash)
return err
})
return tsr, nil
return tsr, err
}

// TestTSpendEmptyTreasury tests that we can't generate a tspend that spends
Expand Down
Loading

0 comments on commit 2b9a9cc

Please sign in to comment.