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

multi: Remove agenda flags from DetermineTxType. #2922

Merged
merged 12 commits into from
May 8, 2022
2 changes: 1 addition & 1 deletion blockchain/agendas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

"github.com/decred/dcrd/blockchain/stake/v4"
"github.com/decred/dcrd/blockchain/stake/v5"
"github.com/decred/dcrd/blockchain/v5/chaingen"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/dcrutil/v4"
Expand Down
4 changes: 2 additions & 2 deletions blockchain/blockindex.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2013-2017 The btcsuite developers
// Copyright (c) 2018-2021 The Decred developers
// Copyright (c) 2018-2022 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand All @@ -13,7 +13,7 @@ import (
"sync"
"time"

"github.com/decred/dcrd/blockchain/stake/v4"
"github.com/decred/dcrd/blockchain/stake/v5"
"github.com/decred/dcrd/blockchain/standalone/v2"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/database/v3"
Expand Down
45 changes: 15 additions & 30 deletions blockchain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import (
"sync"
"time"

"github.com/decred/dcrd/blockchain/stake/v4"
"github.com/decred/dcrd/blockchain/stake/v5"
"github.com/decred/dcrd/blockchain/standalone/v2"
"github.com/decred/dcrd/blockchain/v5/indexers"
"github.com/decred/dcrd/blockchain/v5/internal/spendpruner"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/database/v3"
"github.com/decred/dcrd/dcrutil/v4"
"github.com/decred/dcrd/gcs/v3"
"github.com/decred/dcrd/gcs/v3/blockcf2"
"github.com/decred/dcrd/gcs/v4"
"github.com/decred/dcrd/gcs/v4/blockcf2"
"github.com/decred/dcrd/lru"
"github.com/decred/dcrd/txscript/v4"
"github.com/decred/dcrd/wire"
Expand Down Expand Up @@ -647,10 +647,10 @@ func (b *BlockChain) connectBlock(node *blockNode, block, parent *dcrutil.Block,
isTreasuryEnabled := checkTxFlags.IsTreasuryEnabled()

// Sanity check the correct number of stxos are provided.
if len(stxos) != countSpentOutputs(block, isTreasuryEnabled) {
if len(stxos) != countSpentOutputs(block) {
panicf("provided %v stxos for block %v (height %v) which spends %v "+
"outputs", len(stxos), node.hash, node.height,
countSpentOutputs(block, isTreasuryEnabled))
countSpentOutputs(block))
}

// Write any modified block index entries to the database before
Expand Down Expand Up @@ -689,7 +689,7 @@ func (b *BlockChain) connectBlock(node *blockNode, block, parent *dcrutil.Block,
curTotalTxns := b.stateSnapshot.TotalTxns
curTotalSubsidy := b.stateSnapshot.TotalSubsidy
b.stateLock.RUnlock()
subsidy := calculateAddedSubsidy(block, parent, isTreasuryEnabled)
subsidy := calculateAddedSubsidy(block, parent)
numTxns := uint64(len(block.Transactions()) + len(block.STransactions()))
blockSize := uint64(block.MsgBlock().Header.Size)
state := newBestState(node, blockSize, numTxns, curTotalTxns+numTxns,
Expand Down Expand Up @@ -879,7 +879,6 @@ func (b *BlockChain) disconnectBlock(node *blockNode, block, parent *dcrutil.Blo
if err != nil {
return err
}
isTreasuryEnabled := checkTxFlags.IsTreasuryEnabled()

// Write any modified block index entries to the database before
// updating the best state.
Expand Down Expand Up @@ -908,7 +907,7 @@ func (b *BlockChain) disconnectBlock(node *blockNode, block, parent *dcrutil.Blo
numParentTxns := uint64(len(parent.Transactions()) + len(parent.STransactions()))
numBlockTxns := uint64(len(block.Transactions()) + len(block.STransactions()))
newTotalTxns := curTotalTxns - numBlockTxns
subsidy := calculateAddedSubsidy(block, parent, isTreasuryEnabled)
subsidy := calculateAddedSubsidy(block, parent)
newTotalSubsidy := curTotalSubsidy - subsidy
prevNode := node.parent
state := newBestState(prevNode, parentBlockSize, numParentTxns,
Expand Down Expand Up @@ -1010,11 +1009,11 @@ func countSpentRegularOutputs(block *dcrutil.Block) int {

// countSpentStakeOutputs returns the number of utxos the stake transactions in
// the passed block spend.
func countSpentStakeOutputs(block *dcrutil.Block, isTreasuryEnabled bool) int {
func countSpentStakeOutputs(block *dcrutil.Block) int {
var numSpent int
for _, stx := range block.MsgBlock().STransactions {
// Exclude the vote stakebase since it has no input.
if stake.IsSSGen(stx, isTreasuryEnabled) {
if stake.IsSSGen(stx) {
numSpent++
continue
}
Expand All @@ -1030,9 +1029,8 @@ func countSpentStakeOutputs(block *dcrutil.Block, isTreasuryEnabled bool) int {
}

// countSpentOutputs returns the number of utxos the passed block spends.
func countSpentOutputs(block *dcrutil.Block, isTreasuryEnabled bool) int {
return countSpentRegularOutputs(block) +
countSpentStakeOutputs(block, isTreasuryEnabled)
func countSpentOutputs(block *dcrutil.Block) int {
return countSpentRegularOutputs(block) + countSpentStakeOutputs(block)
}

// loadOrCreateFilter attempts to load and return the version 2 GCS filter for
Expand Down Expand Up @@ -1147,12 +1145,6 @@ func (b *BlockChain) reorganizeChainInternal(target *blockNode) error {
return err
}

// Determine if the automatic ticket revocations agenda is active.
isAutoRevocationsEnabled, err := b.isAutoRevocationsAgendaActive(n.parent)
if err != nil {
return err
}

// Load all of the spent txos for the block from the spend journal.
var stxos []spentTxOut
err = b.db.View(func(dbTx database.Tx) error {
Expand All @@ -1166,8 +1158,7 @@ func (b *BlockChain) reorganizeChainInternal(target *blockNode) error {
// Update the view to unspend all of the spent txos and remove the utxos
// created by the block. Also, if the block votes against its parent,
// reconnect all of the regular transactions.
err = view.disconnectBlock(block, parent, stxos, isTreasuryEnabled,
isAutoRevocationsEnabled)
err = view.disconnectBlock(block, parent, stxos, isTreasuryEnabled)
if err != nil {
return err
}
Expand Down Expand Up @@ -1243,16 +1234,10 @@ func (b *BlockChain) reorganizeChainInternal(target *blockNode) error {
return err
}

// Determine if the automatic ticket revocations agenda is active.
isAutoRevocationsEnabled, err := b.isAutoRevocationsAgendaActive(n.parent)
if err != nil {
return err
}

// Skip validation if the block has already been validated. However,
// the utxo view still needs to be updated and the stxos and header
// commitment data are still needed.
numSpentOutputs := countSpentOutputs(block, isTreasuryEnabled)
numSpentOutputs := countSpentOutputs(block)
stxos := make([]spentTxOut, 0, numSpentOutputs)
var hdrCommitments headerCommitmentData
if b.index.NodeStatus(n).HasValidated() {
Expand All @@ -1262,7 +1247,7 @@ func (b *BlockChain) reorganizeChainInternal(target *blockNode) error {
// all of the regular transactions in the parent block. Finally,
// provide an stxo slice so the spent txout details are generated.
err := view.connectBlock(b.db, block, parent, &stxos,
isTreasuryEnabled, isAutoRevocationsEnabled)
isTreasuryEnabled)
if err != nil {
return err
}
Expand Down Expand Up @@ -2109,7 +2094,7 @@ func stxosToScriptSource(block *dcrutil.Block, stxos []spentTxOut, isTreasuryEna
continue
}

isVote := stake.IsSSGen(tx, isTreasuryEnabled)
isVote := stake.IsSSGen(tx)
for txInIdx, txIn := range tx.TxIn {
// Ignore stakebase since it has no input.
if isVote && txInIdx == 0 {
Expand Down
5 changes: 0 additions & 5 deletions blockchain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ const (
// it is inactive. It is used to increase the readability of the
// tests.
noTreasury = false

// noAutoRevocations signifies the automatic ticket revocations agenda should
// be treated as though it is inactive. It is used to increase the
// readability of the tests.
noAutoRevocations = false
)

// cloneParams returns a deep copy of the provided parameters so the caller is
Expand Down
15 changes: 7 additions & 8 deletions blockchain/chainio.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
"math/big"
"time"

"github.com/decred/dcrd/blockchain/stake/v4"
"github.com/decred/dcrd/blockchain/stake/v5"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/chaincfg/v3"
"github.com/decred/dcrd/database/v3"
"github.com/decred/dcrd/dcrutil/v4"
"github.com/decred/dcrd/gcs/v3"
"github.com/decred/dcrd/gcs/v3/blockcf2"
"github.com/decred/dcrd/gcs/v4"
"github.com/decred/dcrd/gcs/v4/blockcf2"
"github.com/decred/dcrd/wire"
)

Expand Down Expand Up @@ -646,11 +646,11 @@ func decodeSpentTxOut(serialized []byte, stxo *spentTxOut, amount int64,
// format comments, this function also requires the transactions that spend the
// txouts and a utxo view that contains any remaining existing utxos in the
// transactions referenced by the inputs to the passed transactions.
func deserializeSpendJournalEntry(serialized []byte, txns []*wire.MsgTx, isTreasuryEnabled bool) ([]spentTxOut, error) {
func deserializeSpendJournalEntry(serialized []byte, txns []*wire.MsgTx) ([]spentTxOut, error) {
// Calculate the total number of stxos.
var numStxos int
for _, tx := range txns {
if stake.IsSSGen(tx, isTreasuryEnabled) {
if stake.IsSSGen(tx) {
numStxos++
continue
}
Expand Down Expand Up @@ -678,7 +678,7 @@ func deserializeSpendJournalEntry(serialized []byte, txns []*wire.MsgTx, isTreas
stxos := make([]spentTxOut, numStxos)
for txIdx := len(txns) - 1; txIdx > -1; txIdx-- {
tx := txns[txIdx]
isVote := stake.IsSSGen(tx, isTreasuryEnabled)
isVote := stake.IsSSGen(tx)

// Loop backwards through all of the transaction inputs and read
// the associated stxo.
Expand Down Expand Up @@ -769,8 +769,7 @@ func dbFetchSpendJournalEntry(dbTx database.Tx, block *dcrutil.Block, isTreasury
panicf("missing spend journal data for %s", block.Hash())
}

stxos, err := deserializeSpendJournalEntry(serialized, blockTxns,
isTreasuryEnabled)
stxos, err := deserializeSpendJournalEntry(serialized, blockTxns)
if err != nil {
// Ensure any deserialization errors are returned as database
// corruption errors.
Expand Down
6 changes: 3 additions & 3 deletions blockchain/chainio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"testing"
"time"

"github.com/decred/dcrd/blockchain/stake/v4"
"github.com/decred/dcrd/blockchain/stake/v5"
"github.com/decred/dcrd/blockchain/standalone/v2"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/chaincfg/v3"
Expand Down Expand Up @@ -706,7 +706,7 @@ func TestSpendJournalSerialization(t *testing.T) {

// Deserialize to a spend journal entry.
gotEntry, err := deserializeSpendJournalEntry(test.serialized,
test.blockTxns, noTreasury)
test.blockTxns)
if err != nil {
t.Errorf("%q: unexpected error: %v", test.name, err)
continue
Expand Down Expand Up @@ -778,7 +778,7 @@ func TestSpendJournalErrors(t *testing.T) {
// Ensure the expected error type is returned and the returned
// slice is nil.
stxos, err := deserializeSpendJournalEntry(test.serialized,
test.blockTxns, noTreasury)
test.blockTxns)
if !errors.As(err, &test.errType) {
t.Errorf("%q: expected error type does not match - got %T, want %T",
test.name, err, test.errType)
Expand Down
2 changes: 1 addition & 1 deletion blockchain/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"testing"
"time"

"github.com/decred/dcrd/blockchain/stake/v4"
"github.com/decred/dcrd/blockchain/stake/v5"
"github.com/decred/dcrd/blockchain/v5/chaingen"
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/chaincfg/v3"
Expand Down
4 changes: 2 additions & 2 deletions blockchain/compress.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (c) 2015-2016 The btcsuite developers
// Copyright (c) 2015-2021 The Decred developers
// Copyright (c) 2015-2022 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand All @@ -8,7 +8,7 @@ package blockchain
import (
"fmt"

"github.com/decred/dcrd/blockchain/stake/v4"
"github.com/decred/dcrd/blockchain/stake/v5"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
"github.com/decred/dcrd/txscript/v4"
)
Expand Down
9 changes: 7 additions & 2 deletions blockchain/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ module github.com/decred/dcrd/blockchain/v5
go 1.17

require (
github.com/decred/dcrd/blockchain/stake/v4 v4.0.0
github.com/decred/dcrd/blockchain/stake/v5 v5.0.0
github.com/decred/dcrd/blockchain/standalone/v2 v2.1.0
github.com/decred/dcrd/chaincfg/chainhash v1.0.3
github.com/decred/dcrd/chaincfg/v3 v3.1.1
github.com/decred/dcrd/database/v3 v3.0.0
github.com/decred/dcrd/dcrec v1.0.0
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1
github.com/decred/dcrd/dcrutil/v4 v4.0.0
github.com/decred/dcrd/gcs/v3 v3.0.0
github.com/decred/dcrd/gcs/v4 v4.0.0
github.com/decred/dcrd/lru v1.1.1
github.com/decred/dcrd/txscript/v4 v4.0.0
github.com/decred/dcrd/wire v1.5.0
Expand All @@ -28,3 +28,8 @@ require (
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
)

replace (
github.com/decred/dcrd/blockchain/stake/v5 => ./stake
github.com/decred/dcrd/gcs/v4 => ../gcs
)
8 changes: 4 additions & 4 deletions blockchain/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/dchest/siphash v1.2.2 h1:9DFz8tQwl9pTVt5iok/9zKyzA1Q6bRGiF3HPiEEVr9I=
github.com/dchest/siphash v1.2.2/go.mod h1:q+IRvb2gOSrUnYoPqHiyHXS0FOBBOdl6tONBlVnOnt4=
github.com/decred/base58 v1.0.3 h1:KGZuh8d1WEMIrK0leQRM47W85KqCAdl2N+uagbctdDI=
github.com/decred/base58 v1.0.3/go.mod h1:pXP9cXCfM2sFLb2viz2FNIdeMWmZDBKG3ZBYbiSM78E=
github.com/decred/dcrd/blockchain/stake/v4 v4.0.0 h1:PwoCjCTbRvDUZKKs6N2Haus8XcbVXCJ9iGVs8C9sKwQ=
github.com/decred/dcrd/blockchain/stake/v4 v4.0.0/go.mod h1:bOgG7YTbTOWQgtHLL2l1Y9gBHIuM86zwVcQtsoGlZlQ=
github.com/decred/dcrd/blockchain/stake/v5 v5.0.0 h1:PwoCjCTbRvDUZKKs6N2Haus8XcbVXCJ9iGVs8C9sKwQ=
github.com/decred/dcrd/blockchain/stake/v5 v5.0.0/go.mod h1:bOgG7YTbTOWQgtHLL2l1Y9gBHIuM86zwVcQtsoGlZlQ=
github.com/decred/dcrd/blockchain/standalone/v2 v2.1.0 h1:aXh7a+86p+H65MGy0QKu4Juf3/j+Y5koVSyVYFMdqP0=
github.com/decred/dcrd/blockchain/standalone/v2 v2.1.0/go.mod h1:t2qaZ3hNnxHZ5kzVJDgW5sp47/8T5hYJt7SR+/JtRhI=
github.com/decred/dcrd/chaincfg/chainhash v1.0.2/go.mod h1:BpbrGgrPTr3YJYRN3Bm+D9NuaFd+zGyNeIKgrhCXK60=
Expand All @@ -30,8 +30,8 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
github.com/decred/dcrd/dcrutil/v4 v4.0.0 h1:AY00fWy/ETrMHN0DNV3XUbH1aip2RG1AoTy5dp0+sJE=
github.com/decred/dcrd/dcrutil/v4 v4.0.0/go.mod h1:QQpX5WVH3/ixVtiW15xZMe+neugXX3l2bsrYgq6nz4M=
github.com/decred/dcrd/gcs/v3 v3.0.0 h1:MjWevhoAzKENUgpaJAbZkJlKDN4HIz2nR/i3laZAT5c=
github.com/decred/dcrd/gcs/v3 v3.0.0/go.mod h1:/OVb/rYrAz4TCtxcPneYfBs0+YI1pGIp8RA6RUNqOp4=
github.com/decred/dcrd/gcs/v4 v4.0.0 h1:MjWevhoAzKENUgpaJAbZkJlKDN4HIz2nR/i3laZAT5c=
github.com/decred/dcrd/gcs/v4 v4.0.0/go.mod h1:/OVb/rYrAz4TCtxcPneYfBs0+YI1pGIp8RA6RUNqOp4=
github.com/decred/dcrd/lru v1.1.1 h1:kWFDaW0OWx6AD6Ki342c+JPmHbiVdE6rK81pT3fuo/Y=
github.com/decred/dcrd/lru v1.1.1/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/decred/dcrd/txscript/v4 v4.0.0 h1:BwaBUCMCmg58MCYoBhxVjL8ZZKUIfoJuxu/djmh8h58=
Expand Down
16 changes: 4 additions & 12 deletions blockchain/headercmt.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019-2021 The Decred developers
// Copyright (c) 2019-2022 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

Expand All @@ -10,7 +10,7 @@ import (
"github.com/decred/dcrd/chaincfg/chainhash"
"github.com/decred/dcrd/database/v3"
"github.com/decred/dcrd/dcrutil/v4"
"github.com/decred/dcrd/gcs/v3"
"github.com/decred/dcrd/gcs/v4"
"github.com/decred/dcrd/wire"
)

Expand Down Expand Up @@ -91,12 +91,6 @@ func (b *BlockChain) FetchUtxoViewParentTemplate(block *wire.MsgBlock) (*UtxoVie
return nil, err
}

// Determine if the automatic ticket revocations agenda is active.
isAutoRevocationsEnabled, err := b.isAutoRevocationsAgendaActive(tip.parent)
if err != nil {
return nil, err
}

// Load all of the spent txos for the tip block from the spend journal.
var stxos []spentTxOut
err = b.db.View(func(dbTx database.Tx) error {
Expand All @@ -110,8 +104,7 @@ func (b *BlockChain) FetchUtxoViewParentTemplate(block *wire.MsgBlock) (*UtxoVie
// Update the view to unspend all of the spent txos and remove the utxos
// created by the tip block. Also, if the block votes against its parent,
// reconnect all of the regular transactions.
err = view.disconnectBlock(tipBlock, parent, stxos, isTreasuryEnabled,
isAutoRevocationsEnabled)
err = view.disconnectBlock(tipBlock, parent, stxos, isTreasuryEnabled)
if err != nil {
return nil, err
}
Expand All @@ -124,8 +117,7 @@ func (b *BlockChain) FetchUtxoViewParentTemplate(block *wire.MsgBlock) (*UtxoVie
// the parent, also disconnect all of the regular transactions in the parent
// block.
utilBlock := dcrutil.NewBlock(block)
err = view.connectBlock(b.db, utilBlock, parent, nil, isTreasuryEnabled,
isAutoRevocationsEnabled)
err = view.connectBlock(b.db, utilBlock, parent, nil, isTreasuryEnabled)
if err != nil {
return nil, err
}
Expand Down
Loading