From 27106c4e7790f07bad924ebe80140bd71c29d550 Mon Sep 17 00:00:00 2001 From: Paladz Date: Thu, 19 Sep 2019 18:48:12 +0800 Subject: [PATCH] fix the bug (#399) * fix the bug * modify soft point height * modify --- consensus/general.go | 6 ++++++ protocol/validation/tx.go | 21 ++++++++++++++++++++- version/version.go | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/consensus/general.go b/consensus/general.go index f3bab4e0..b34f19d8 100644 --- a/consensus/general.go +++ b/consensus/general.go @@ -13,6 +13,9 @@ const ( PayToWitnessPubKeyHashDataSize = 20 PayToWitnessScriptHashDataSize = 32 + + _ = iota + SoftFork001 ) // BTMAssetID is BTM's asset id, the soul asset of Bytom @@ -98,6 +101,8 @@ type Params struct { // ProducerSubsidys defines the producer subsidy by block height ProducerSubsidys []ProducerSubsidy + + SoftForkPoint map[uint64]uint64 } // ActiveNetParams is the active NetParams @@ -139,6 +144,7 @@ var MainNetParams = Params{ ProducerSubsidys: []ProducerSubsidy{ {BeginBlock: 1, EndBlock: 63072000, Subsidy: 9512938}, }, + SoftForkPoint: map[uint64]uint64{SoftFork001: 10461600}, } // TestNetParams is the config for vapor-testnet diff --git a/protocol/validation/tx.go b/protocol/validation/tx.go index bd493c52..60532702 100644 --- a/protocol/validation/tx.go +++ b/protocol/validation/tx.go @@ -41,6 +41,7 @@ var ( ErrGasCalculate = errors.New("gas usage calculate got a math error") ErrVotePubKey = errors.New("invalid public key of vote") ErrVoteOutputAmount = errors.New("invalid vote amount") + ErrVoteOutputAseet = errors.New("incorrect asset_id while checking vote asset") ) // GasState record the gas usage status @@ -239,6 +240,7 @@ func checkValid(vs *validationState, e bc.Entry) (err error) { if len(e.Vote) != 64 { return ErrVotePubKey } + vs2 := *vs vs2.sourcePos = 0 if err = checkValidSrc(&vs2, e.Source); err != nil { @@ -249,6 +251,10 @@ func checkValid(vs *validationState, e bc.Entry) (err error) { return ErrVoteOutputAmount } + if *e.Source.Value.AssetId != *consensus.BTMAssetID { + return ErrVoteOutputAseet + } + case *bc.Retirement: vs2 := *vs vs2.sourcePos = 0 @@ -579,6 +585,16 @@ func checkTimeRange(tx *bc.Tx, block *bc.Block) error { return nil } +func applySoftFork001(vs *validationState, err error) { + if err == nil || vs.block.Height < consensus.ActiveNetParams.SoftForkPoint[consensus.SoftFork001] { + return + } + + if rootErr := errors.Root(err); rootErr == ErrVotePubKey || rootErr == ErrVoteOutputAmount || rootErr == ErrVoteOutputAseet { + vs.gasStatus.GasValid = false + } +} + // ValidateTx validates a transaction. func ValidateTx(tx *bc.Tx, block *bc.Block) (*GasState, error) { gasStatus := &GasState{GasValid: false} @@ -602,7 +618,10 @@ func ValidateTx(tx *bc.Tx, block *bc.Block) (*GasState, error) { gasStatus: gasStatus, cache: make(map[bc.Hash]error), } - return vs.gasStatus, checkValid(vs, tx.TxHeader) + + err := checkValid(vs, tx.TxHeader) + applySoftFork001(vs, err) + return vs.gasStatus, err } type validateTxWork struct { diff --git a/version/version.go b/version/version.go index 4058446d..88a55644 100644 --- a/version/version.go +++ b/version/version.go @@ -47,7 +47,7 @@ const ( var ( // The full version string - Version = "1.0.1" + Version = "1.0.2" // GitCommit is set with --ldflags "-X main.gitCommit=$(git rev-parse HEAD)" GitCommit string Status *UpdateStatus -- 2.11.0