OSDN Git Service

check vote output amount
authorChengcheng Zhang <943420582@qq.com>
Thu, 13 Jun 2019 02:52:53 +0000 (10:52 +0800)
committerChengcheng Zhang <943420582@qq.com>
Thu, 13 Jun 2019 02:52:53 +0000 (10:52 +0800)
consensus/general.go
protocol/validation/tx.go

index e048217..61b8660 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
+       MinVoteNum          = 10000000
+       MinVoteOutputAmount = uint64(100000000)
 
        // BlockTimeInterval indicate product one block per 500 milliseconds
        BlockTimeInterval = 500
index 68bac2e..763d98a 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 err = checkVoteOutputAmount(e.Source); err != nil {
+                       return errors.Wrap(err, "checking vote output amount")
+               }
 
        case *bc.Retirement:
                vs2 := *vs
@@ -571,3 +575,10 @@ func ValidateTx(tx *bc.Tx, block *bc.Block) (*GasState, error) {
        }
        return vs.gasStatus, checkValid(vs, tx.TxHeader)
 }
+
+func checkVoteOutputAmount(vs *bc.ValueSource) error {
+       if vs.Value.Amount < consensus.MinVoteOutputAmount {
+               return ErrVoteOutputAmount
+       }
+       return nil
+}