From: Chengcheng Zhang <943420582@qq.com> Date: Thu, 13 Jun 2019 03:31:07 +0000 (+0800) Subject: check vote output amount (#171) X-Git-Tag: v1.0.5~208^2~34 X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=commitdiff_plain;h=b62a559ff00dffbffe1e2b87288e91f8908e6d04 check vote output amount (#171) * check vote output amount * update --- diff --git a/consensus/general.go b/consensus/general.go index e048217e..0a42603a 100644 --- a/consensus/general.go +++ b/consensus/general.go @@ -23,10 +23,11 @@ const ( VotePendingBlockNumber = uint64(10000) //DPOS parameter - NumOfConsensusNode = 10 - BlockNumEachNode = 12 - RoundVoteBlockNums = NumOfConsensusNode * BlockNumEachNode * 10 - MinVoteNum = 10000000 + NumOfConsensusNode = 10 + BlockNumEachNode = 12 + RoundVoteBlockNums = NumOfConsensusNode * BlockNumEachNode * 10 + MinConsensusNodeVoteNum = uint64(100000000000000) // min is 1 million BTM + MinVoteOutputAmount = uint64(100000000) // min is 1 BTM // BlockTimeInterval indicate product one block per 500 milliseconds BlockTimeInterval = 500 diff --git a/protocol/state/vote_result.go b/protocol/state/vote_result.go index c9059b2c..3ab12433 100644 --- a/protocol/state/vote_result.go +++ b/protocol/state/vote_result.go @@ -4,8 +4,8 @@ import ( "encoding/hex" "sort" - "github.com/vapor/consensus" "github.com/vapor/config" + "github.com/vapor/consensus" "github.com/vapor/crypto/ed25519/chainkd" "github.com/vapor/errors" "github.com/vapor/math/checked" @@ -96,7 +96,7 @@ func (v *VoteResult) ApplyBlock(block *types.Block) error { func (v *VoteResult) ConsensusNodes() (map[string]*ConsensusNode, error) { var nodes []*ConsensusNode for pubkey, voteNum := range v.NumOfVote { - if voteNum >= consensus.MinVoteNum { + if voteNum >= consensus.MinConsensusNodeVoteNum { var xpub chainkd.XPub if err := xpub.UnmarshalText([]byte(pubkey)); err != nil { return nil, err @@ -113,7 +113,7 @@ func (v *VoteResult) ConsensusNodes() (map[string]*ConsensusNode, error) { nodes[i].Order = uint64(i) result[nodes[i].XPub.String()] = nodes[i] } - + if len(result) != 0 { return result, nil } diff --git a/protocol/validation/tx.go b/protocol/validation/tx.go index 68bac2ea..64fbde95 100644 --- a/protocol/validation/tx.go +++ b/protocol/validation/tx.go @@ -39,6 +39,7 @@ var ( ErrOverGasCredit = errors.New("all gas credit has been spend") ErrGasCalculate = errors.New("gas usage calculate got a math error") ErrVotePubKey = errors.New("invalid public key of vote") + ErrVoteOutputAmount = errors.New("invalid vote amount") ) // GasState record the gas usage status @@ -236,6 +237,9 @@ func checkValid(vs *validationState, e bc.Entry) (err error) { if err = checkValidSrc(&vs2, e.Source); err != nil { return errors.Wrap(err, "checking vote output source") } + if e.Source.Value.Amount < consensus.MinVoteOutputAmount { + return ErrVoteOutputAmount + } case *bc.Retirement: vs2 := *vs