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

blockchain: check errors and remove ineffectual assignments. #689

Merged
merged 1 commit into from
Jul 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions blockchain/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions blockchain/fullblocktests/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions blockchain/reorganization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand Down
6 changes: 6 additions & 0 deletions blockchain/stake/staketx.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
1 change: 0 additions & 1 deletion blockchain/stakeversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ func TestCalcStakeVersionCorners(t *testing.T) {
bc.bestNode = currentNode

}
height += runCount
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that right? It seems like it is needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

height is not used after.


if !bc.isStakeMajorityVersion(0, currentNode) {
t.Fatalf("invalid StakeVersion expected 0 -> true")
Expand Down
3 changes: 3 additions & 0 deletions blockchain/subsidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down