OSDN Git Service

check vote output amount (#171)
authorChengcheng Zhang <943420582@qq.com>
Thu, 13 Jun 2019 03:31:07 +0000 (11:31 +0800)
committerPaladz <yzhu101@uottawa.ca>
Thu, 13 Jun 2019 03:31:07 +0000 (11:31 +0800)
* check vote output amount

* update

consensus/general.go
protocol/state/vote_result.go
protocol/validation/tx.go

index e048217..0a42603 100644 (file)
@@ -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
index c9059b2..3ab1243 100644 (file)
@@ -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
        }
index 68bac2e..64fbde9 100644 (file)
@@ -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