OSDN Git Service

edit the rule for support 1.1.0's soft fork which will enable more VM… (#1585)
authorPaladz <yzhu101@uottawa.ca>
Mon, 25 Feb 2019 03:28:19 +0000 (11:28 +0800)
committerGitHub <noreply@github.com>
Mon, 25 Feb 2019 03:28:19 +0000 (11:28 +0800)
* edit the rule for support 1.1.0's soft fork which will enable more VM futures

* golint the unit test

* clean the old test case

protocol/validation/block.go
protocol/validation/block_test.go
test/block_test.go

index cc5b8c8..c1975af 100644 (file)
@@ -60,7 +60,7 @@ func checkCoinbaseAmount(b *bc.Block, amount uint64) error {
 
 // ValidateBlockHeader check the block's header
 func ValidateBlockHeader(b *bc.Block, parent *state.BlockNode) error {
-       if b.Version < parent.Version {
+       if b.Version != 1 {
                return errors.WithDetailf(errVersionRegression, "previous block verson %d, current block version %d", parent.Version, b.Version)
        }
        if b.Height != parent.Height+1 {
index ab0d2d2..57b1490 100644 (file)
@@ -8,8 +8,8 @@ import (
        "github.com/bytom/protocol/bc"
        "github.com/bytom/protocol/bc/types"
        "github.com/bytom/protocol/state"
-       "github.com/bytom/testutil"
        "github.com/bytom/protocol/vm/vmutil"
+       "github.com/bytom/testutil"
 )
 
 func TestCheckBlockTime(t *testing.T) {
@@ -35,9 +35,9 @@ func TestCheckBlockTime(t *testing.T) {
                },
        }
 
-       parent := &state.BlockNode{}
+       parent := &state.BlockNode{Version: 1}
        block := &bc.Block{
-               BlockHeader: &bc.BlockHeader{},
+               BlockHeader: &bc.BlockHeader{Version: 1},
        }
 
        for i, c := range cases {
@@ -105,41 +105,47 @@ func TestValidateBlockHeader(t *testing.T) {
        }{
                {
                        block: &bc.Block{BlockHeader: &bc.BlockHeader{
-                               Version: 1,
+                               Version: 2,
                        }},
                        parent: &state.BlockNode{
-                               Version: 2,
+                               Version: 1,
                        },
                        err: errVersionRegression,
                },
                {
                        block: &bc.Block{BlockHeader: &bc.BlockHeader{
-                               Height: 20,
+                               Version: 1,
+                               Height:  20,
                        }},
                        parent: &state.BlockNode{
-                               Height: 18,
+                               Version: 1,
+                               Height:  18,
                        },
                        err: errMisorderedBlockHeight,
                },
                {
                        block: &bc.Block{BlockHeader: &bc.BlockHeader{
-                               Height: 20,
-                               Bits:   0,
+                               Version: 1,
+                               Height:  20,
+                               Bits:    0,
                        }},
                        parent: &state.BlockNode{
-                               Height: 19,
-                               Bits:   2305843009214532812,
+                               Version: 1,
+                               Height:  19,
+                               Bits:    2305843009214532812,
                        },
                        err: errBadBits,
                },
                {
                        block: &bc.Block{BlockHeader: &bc.BlockHeader{
+                               Version:         1,
                                Height:          20,
                                PreviousBlockId: &bc.Hash{V0: 18},
                        }},
                        parent: &state.BlockNode{
-                               Height: 19,
-                               Hash:   bc.Hash{V0: 19},
+                               Version: 1,
+                               Height:  19,
+                               Hash:    bc.Hash{V0: 19},
                        },
                        err: errMismatchedBlock,
                },
@@ -147,6 +153,7 @@ func TestValidateBlockHeader(t *testing.T) {
                        block: &bc.Block{
                                ID: bc.Hash{V0: 0},
                                BlockHeader: &bc.BlockHeader{
+                                       Version:         1,
                                        Height:          1,
                                        Timestamp:       1523352601,
                                        PreviousBlockId: &bc.Hash{V0: 0},
@@ -154,6 +161,7 @@ func TestValidateBlockHeader(t *testing.T) {
                                },
                        },
                        parent: &state.BlockNode{
+                               Version:   1,
                                Height:    0,
                                Timestamp: 1523352600,
                                Hash:      bc.Hash{V0: 0},
@@ -166,6 +174,7 @@ func TestValidateBlockHeader(t *testing.T) {
                        block: &bc.Block{
                                ID: bc.Hash{V0: 1},
                                BlockHeader: &bc.BlockHeader{
+                                       Version:         1,
                                        Height:          1,
                                        Timestamp:       1523352601,
                                        PreviousBlockId: &bc.Hash{V0: 0},
@@ -173,6 +182,7 @@ func TestValidateBlockHeader(t *testing.T) {
                                },
                        },
                        parent: &state.BlockNode{
+                               Version:   1,
                                Height:    0,
                                Timestamp: 1523352600,
                                Hash:      bc.Hash{V0: 0},
@@ -209,21 +219,24 @@ func TestValidateMerkleRoot(t *testing.T) {
                        block: &bc.Block{
                                ID: bc.Hash{V0: 1},
                                BlockHeader: &bc.BlockHeader{
-                                       Height:          1,
-                                       Timestamp:       1523352601,
-                                       PreviousBlockId: &bc.Hash{V0: 0},
-                                       Bits:            2305843009214532812,
+                                       Version:          1,
+                                       Height:           1,
+                                       Timestamp:        1523352601,
+                                       PreviousBlockId:  &bc.Hash{V0: 0},
+                                       Bits:             2305843009214532812,
                                        TransactionsRoot: &bc.Hash{V0: 1},
                                },
                                Transactions: []*bc.Tx{
                                        types.MapTx(&types.TxData{
+                                               Version:        1,
                                                SerializedSize: 1,
-                                               Inputs:  []*types.TxInput{types.NewCoinbaseInput(nil)},
-                                               Outputs: []*types.TxOutput{types.NewTxOutput(*consensus.BTMAssetID, 41250000000, cp)},
+                                               Inputs:         []*types.TxInput{types.NewCoinbaseInput(nil)},
+                                               Outputs:        []*types.TxOutput{types.NewTxOutput(*consensus.BTMAssetID, 41250000000, cp)},
                                        }),
                                },
                        },
                        parent: &state.BlockNode{
+                               Version:   1,
                                Height:    0,
                                Timestamp: 1523352600,
                                Hash:      bc.Hash{V0: 0},
@@ -237,22 +250,25 @@ func TestValidateMerkleRoot(t *testing.T) {
                        block: &bc.Block{
                                ID: bc.Hash{V0: 1},
                                BlockHeader: &bc.BlockHeader{
-                                       Height:          1,
-                                       Timestamp:       1523352601,
-                                       PreviousBlockId: &bc.Hash{V0: 0},
-                                       Bits:            2305843009214532812,
-                                       TransactionsRoot: &bc.Hash{V0: 6294987741126419124, V1: 12520373106916389157, V2: 5040806596198303681, V3: 1151748423853876189},
+                                       Version:               1,
+                                       Height:                1,
+                                       Timestamp:             1523352601,
+                                       PreviousBlockId:       &bc.Hash{V0: 0},
+                                       Bits:                  2305843009214532812,
+                                       TransactionsRoot:      &bc.Hash{V0: 6294987741126419124, V1: 12520373106916389157, V2: 5040806596198303681, V3: 1151748423853876189},
                                        TransactionStatusHash: &bc.Hash{V0: 1},
                                },
                                Transactions: []*bc.Tx{
                                        types.MapTx(&types.TxData{
+                                               Version:        1,
                                                SerializedSize: 1,
-                                               Inputs:  []*types.TxInput{types.NewCoinbaseInput(nil)},
-                                               Outputs: []*types.TxOutput{types.NewTxOutput(*consensus.BTMAssetID, 41250000000, cp)},
+                                               Inputs:         []*types.TxInput{types.NewCoinbaseInput(nil)},
+                                               Outputs:        []*types.TxOutput{types.NewTxOutput(*consensus.BTMAssetID, 41250000000, cp)},
                                        }),
                                },
                        },
                        parent: &state.BlockNode{
+                               Version:   1,
                                Height:    0,
                                Timestamp: 1523352600,
                                Hash:      bc.Hash{V0: 0},
index 3953c96..547c34b 100644 (file)
@@ -35,18 +35,8 @@ func TestBlockHeader(t *testing.T) {
                valid      bool
        }{
                {
-                       desc:       "block version is 0",
-                       version:    func() uint64 { return 0 },
-                       prevHeight: chain.BestBlockHeight,
-                       timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
-                       prevHash:   chain.BestBlockHash,
-                       bits:       func() uint64 { return chain.BestBlockHeader().Bits },
-                       solve:      true,
-                       valid:      false,
-               },
-               {
-                       desc:       "block version grater than prevBlock.Version",
-                       version:    func() uint64 { return chain.BestBlockHeader().Version + 10 },
+                       desc:       "block version is 1",
+                       version:    func() uint64 { return 1 },
                        prevHeight: chain.BestBlockHeight,
                        timestamp:  func() uint64 { return chain.BestBlockHeader().Timestamp + 1 },
                        prevHash:   chain.BestBlockHash,