Skip to content

Commit

Permalink
Improve the order of the context free tests (btcsuite#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlyp authored Oct 6, 2016
1 parent ccc3b7a commit 27f6efc
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions blockchain/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,6 @@ func CheckTransactionSanity(tx *dcrutil.Tx, params *chaincfg.Params) error {
}
}

// Check for duplicate transaction inputs.
existingTxOut := make(map[wire.OutPoint]struct{})
for _, txIn := range msgTx.TxIn {
if _, exists := existingTxOut[txIn.PreviousOutPoint]; exists {
return ruleError(ErrDuplicateTxInputs, "transaction "+
"contains duplicate inputs")
}
existingTxOut[txIn.PreviousOutPoint] = struct{}{}
}

isSSGen, _ := stake.IsSSGen(tx)

// Coinbase script length must be between min and max length.
Expand Down Expand Up @@ -252,6 +242,16 @@ func CheckTransactionSanity(tx *dcrutil.Tx, params *chaincfg.Params) error {
}
}

// Check for duplicate transaction inputs.
existingTxOut := make(map[wire.OutPoint]struct{})
for _, txIn := range msgTx.TxIn {
if _, exists := existingTxOut[txIn.PreviousOutPoint]; exists {
return ruleError(ErrDuplicateTxInputs, "transaction "+
"contains duplicate inputs")
}
existingTxOut[txIn.PreviousOutPoint] = struct{}{}
}

return nil
}

Expand Down Expand Up @@ -473,15 +473,16 @@ func checkBlockSanity(block *dcrutil.Block, timeSource MedianTimeSource,
totalVotes := 0
totalRevocations := 0
for _, stx := range block.STransactions() {
err := CheckTransactionSanity(stx, chainParams)
if err != nil {
return err
}

txType := stake.DetermineTxType(stx)
if txType == stake.TxTypeRegular {
errStr := fmt.Sprintf("found regular tx in stake tx tree")
return ruleError(ErrRegTxInStakeTree, errStr)
}
err := CheckTransactionSanity(stx, chainParams)
if err != nil {
return err
}

switch txType {
case stake.TxTypeSStx:
Expand Down

0 comments on commit 27f6efc

Please sign in to comment.