From 5625192be12fa30ec2aafc16bbbffd52ca602977 Mon Sep 17 00:00:00 2001 From: David Hill Date: Thu, 4 May 2017 16:45:00 -0400 Subject: [PATCH] blockchain: check errors and remove ineffectual assignments. --- blockchain/chain_test.go | 3 +++ blockchain/fullblocktests/generate.go | 4 ++-- blockchain/reorganization_test.go | 12 ++++++++++++ blockchain/stake/staketx.go | 6 ++++++ blockchain/stakeversion_test.go | 1 - blockchain/subsidy.go | 3 +++ 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/blockchain/chain_test.go b/blockchain/chain_test.go index aba09ace2a..66d9fa3fad 100644 --- a/blockchain/chain_test.go +++ b/blockchain/chain_test.go @@ -39,6 +39,9 @@ func TestBlockchainFunctions(t *testing.T) { // Load up the rest of the blocks up to HEAD~1. filename := filepath.Join("testdata/", "blocks0to168.bz2") fi, err := os.Open(filename) + if err != nil { + t.Errorf("Unable to open %s: %v", filename, err) + } bcStream := bzip2.NewReader(fi) defer fi.Close() diff --git a/blockchain/fullblocktests/generate.go b/blockchain/fullblocktests/generate.go index 61a0939551..9a3cdeee05 100644 --- a/blockchain/fullblocktests/generate.go +++ b/blockchain/fullblocktests/generate.go @@ -1045,7 +1045,7 @@ func Generate() (tests [][]TestInstance, err error) { // // OP_CHECKMULTISIG counts for 20 sigops. tooManySigOps = repeatOpcode(txscript.OP_CHECKMULTISIG, maxBlockSigOps/20) - tooManySigOps = append(manySigOps, txscript.OP_CHECKSIG) + tooManySigOps = append(tooManySigOps, txscript.OP_CHECKSIG) g.NextBlock("b38", outs[10], ticketOuts[10], replaceSpendScript(tooManySigOps)) g.AssertTipBlockSigOpsCount(maxBlockSigOps + 1) rejected(blockchain.ErrTooManySigOps) @@ -1067,7 +1067,7 @@ func Generate() (tests [][]TestInstance, err error) { // \-> b40(11) // tooManySigOps = repeatOpcode(txscript.OP_CHECKMULTISIGVERIFY, maxBlockSigOps/20) - tooManySigOps = append(manySigOps, txscript.OP_CHECKSIG) + tooManySigOps = append(tooManySigOps, txscript.OP_CHECKSIG) g.NextBlock("b40", outs[11], ticketOuts[11], replaceSpendScript(tooManySigOps)) g.AssertTipBlockSigOpsCount(maxBlockSigOps + 1) rejected(blockchain.ErrTooManySigOps) diff --git a/blockchain/reorganization_test.go b/blockchain/reorganization_test.go index 74f500fb2d..6cf76f94bb 100644 --- a/blockchain/reorganization_test.go +++ b/blockchain/reorganization_test.go @@ -40,6 +40,9 @@ func reorgTestLong(t *testing.T) { // Load up the rest of the blocks up to HEAD. filename := filepath.Join("testdata/", "reorgto179.bz2") fi, err := os.Open(filename) + if err != nil { + t.Errorf("Unable to open %s: %v", filename, err) + } bcStream := bzip2.NewReader(fi) defer fi.Close() @@ -75,6 +78,9 @@ func reorgTestLong(t *testing.T) { // Load up the rest of the blocks up to HEAD. filename = filepath.Join("testdata/", "reorgto180.bz2") fi, err = os.Open(filename) + if err != nil { + t.Errorf("Unable to open %s: %v", filename, err) + } bcStream = bzip2.NewReader(fi) defer fi.Close() @@ -149,6 +155,9 @@ func reorgTestShort(t *testing.T) { // Load up the rest of the blocks up to HEAD. filename := filepath.Join("testdata/", "reorgto179.bz2") fi, err := os.Open(filename) + if err != nil { + t.Errorf("Unable to open %s: %v", filename, err) + } bcStream := bzip2.NewReader(fi) defer fi.Close() @@ -170,6 +179,9 @@ func reorgTestShort(t *testing.T) { // Load up the rest of the blocks up to HEAD. filename = filepath.Join("testdata/", "reorgto180.bz2") fi, err = os.Open(filename) + if err != nil { + t.Errorf("Unable to open %s: %v", filename, err) + } bcStream = bzip2.NewReader(fi) defer fi.Close() diff --git a/blockchain/stake/staketx.go b/blockchain/stake/staketx.go index 28df5eb47c..6032c09ffc 100644 --- a/blockchain/stake/staketx.go +++ b/blockchain/stake/staketx.go @@ -410,6 +410,9 @@ func TxSSGenStakeOutputInfo(tx *wire.MsgTx, params *chaincfg.Params) ([]bool, "ssgen tagged output in idx %v", idx) } subClass, err := txscript.GetStakeOutSubclass(out.PkScript) + if err != nil { + return nil, nil, nil, err + } if !(subClass == txscript.PubKeyHashTy || subClass == txscript.ScriptHashTy) { return nil, nil, nil, fmt.Errorf("bad script type") @@ -494,6 +497,9 @@ func TxSSRtxStakeOutputInfo(tx *wire.MsgTx, params *chaincfg.Params) ([]bool, "ssrtx tagged output in idx %v", idx) } subClass, err := txscript.GetStakeOutSubclass(out.PkScript) + if err != nil { + return nil, nil, nil, err + } if !(subClass == txscript.PubKeyHashTy || subClass == txscript.ScriptHashTy) { return nil, nil, nil, fmt.Errorf("bad script type") diff --git a/blockchain/stakeversion_test.go b/blockchain/stakeversion_test.go index 103e19d96b..4acf67d3b2 100644 --- a/blockchain/stakeversion_test.go +++ b/blockchain/stakeversion_test.go @@ -359,7 +359,6 @@ func TestCalcStakeVersionCorners(t *testing.T) { bc.bestNode = currentNode } - height += runCount if !bc.isStakeMajorityVersion(0, currentNode) { t.Fatalf("invalid StakeVersion expected 0 -> true") diff --git a/blockchain/subsidy.go b/blockchain/subsidy.go index 62f2caa7dd..3642233539 100644 --- a/blockchain/subsidy.go +++ b/blockchain/subsidy.go @@ -250,6 +250,9 @@ func BlockOneCoinbasePaysTokens(tx *dcrutil.Tx, // There should only be one address. _, addrs, _, err := txscript.ExtractPkScriptAddrs(txout.Version, txout.PkScript, params) + if err != nil { + return ruleError(ErrBlockOneOutputs, err.Error()) + } if len(addrs) != 1 { errStr := fmt.Sprintf("too many addresses in output") return ruleError(ErrBlockOneOutputs, errStr)