OSDN Git Service

Casper config (#1986)
authorPoseidon <shenao.78@163.com>
Thu, 24 Jun 2021 02:53:50 +0000 (10:53 +0800)
committerGitHub <noreply@github.com>
Thu, 24 Jun 2021 02:53:50 +0000 (10:53 +0800)
* casper config

* casper config

* revert dashboard

Co-authored-by: Paladz <yzhu101@uottawa.ca>
12 files changed:
consensus/general.go
database/store.go
proposal/proposal.go
protocol/apply_block.go
protocol/auth_verification.go
protocol/auth_verification_test.go
protocol/casper.go
protocol/state/checkpoint.go
protocol/state/reward.go
protocol/validation/block.go
protocol/validation/block_test.go
wallet/utxo.go

index d687c35..f67323e 100644 (file)
@@ -19,7 +19,6 @@ const (
 
        // config parameter for coinbase reward
        CoinbasePendingBlockNumber = uint64(100)
 
        // config parameter for coinbase reward
        CoinbasePendingBlockNumber = uint64(100)
-       VotePendingBlockNumber     = uint64(181440)
        MinVoteOutputAmount        = uint64(100000000)
        subsidyReductionInterval   = uint64(840000)
        baseSubsidy                = uint64(41250000000)
        MinVoteOutputAmount        = uint64(100000000)
        subsidyReductionInterval   = uint64(840000)
        baseSubsidy                = uint64(41250000000)
@@ -27,7 +26,6 @@ const (
 
        // MaxTimeOffsetSeconds is the maximum number of seconds a block time is allowed to be ahead of the current time
        MaxTimeOffsetSeconds = uint64(60 * 60)
 
        // MaxTimeOffsetSeconds is the maximum number of seconds a block time is allowed to be ahead of the current time
        MaxTimeOffsetSeconds = uint64(60 * 60)
-       MedianTimeBlocks     = 11
 
        PayToWitnessPubKeyHashDataSize = 20
        PayToWitnessScriptHashDataSize = 32
 
        PayToWitnessPubKeyHashDataSize = 20
        PayToWitnessScriptHashDataSize = 32
@@ -45,6 +43,15 @@ type CasperConfig struct {
 
        // MaxTimeOffsetMs represent the max number of seconds a block time is allowed to be ahead of the current time
        MaxTimeOffsetMs uint64
 
        // MaxTimeOffsetMs represent the max number of seconds a block time is allowed to be ahead of the current time
        MaxTimeOffsetMs uint64
+
+       // BlocksOfEpoch represent the block num in one epoch
+       BlocksOfEpoch uint64
+
+       // MinValidatorVoteNum is the minimum vote number of become validator
+       MinValidatorVoteNum uint64
+
+       // VotePendingBlockNumber is the locked block number of vote utxo
+       VotePendingBlockNumber uint64
 }
 
 // BTMAssetID is BTM's asset id, the soul asset of Bytom
 }
 
 // BTMAssetID is BTM's asset id, the soul asset of Bytom
@@ -128,7 +135,13 @@ var MainNetParams = Params{
        Bech32HRPSegwit: "bm",
        DefaultPort:     "46657",
        DNSSeeds:        []string{"www.mainnetseed.bytom.io"},
        Bech32HRPSegwit: "bm",
        DefaultPort:     "46657",
        DNSSeeds:        []string{"www.mainnetseed.bytom.io"},
-       CasperConfig:    CasperConfig{BlockTimeInterval: 6000, MaxTimeOffsetMs: 24000},
+       CasperConfig: CasperConfig{
+               BlockTimeInterval:      6000,
+               MaxTimeOffsetMs:        24000,
+               BlocksOfEpoch:          100,
+               MinValidatorVoteNum:    1E14,
+               VotePendingBlockNumber: 181440,
+       },
        Checkpoints: []Checkpoint{
                {10000, bc.NewHash([32]byte{0x93, 0xe1, 0xeb, 0x78, 0x21, 0xd2, 0xb4, 0xad, 0x0f, 0x5b, 0x1c, 0xea, 0x82, 0xe8, 0x43, 0xad, 0x8c, 0x09, 0x9a, 0xb6, 0x5d, 0x8f, 0x70, 0xc5, 0x84, 0xca, 0xa2, 0xdd, 0xf1, 0x74, 0x65, 0x2c})},
                {20000, bc.NewHash([32]byte{0x7d, 0x38, 0x61, 0xf3, 0x2c, 0xc0, 0x03, 0x81, 0xbb, 0xcd, 0x9a, 0x37, 0x6f, 0x10, 0x5d, 0xfe, 0x6f, 0xfe, 0x2d, 0xa5, 0xea, 0x88, 0xa5, 0xe3, 0x42, 0xed, 0xa1, 0x17, 0x9b, 0xa8, 0x0b, 0x7c})},
        Checkpoints: []Checkpoint{
                {10000, bc.NewHash([32]byte{0x93, 0xe1, 0xeb, 0x78, 0x21, 0xd2, 0xb4, 0xad, 0x0f, 0x5b, 0x1c, 0xea, 0x82, 0xe8, 0x43, 0xad, 0x8c, 0x09, 0x9a, 0xb6, 0x5d, 0x8f, 0x70, 0xc5, 0x84, 0xca, 0xa2, 0xdd, 0xf1, 0x74, 0x65, 0x2c})},
                {20000, bc.NewHash([32]byte{0x7d, 0x38, 0x61, 0xf3, 0x2c, 0xc0, 0x03, 0x81, 0xbb, 0xcd, 0x9a, 0x37, 0x6f, 0x10, 0x5d, 0xfe, 0x6f, 0xfe, 0x2d, 0xa5, 0xea, 0x88, 0xa5, 0xe3, 0x42, 0xed, 0xa1, 0x17, 0x9b, 0xa8, 0x0b, 0x7c})},
@@ -167,7 +180,13 @@ var TestNetParams = Params{
        Bech32HRPSegwit: "tm",
        DefaultPort:     "46656",
        DNSSeeds:        []string{"www.testnetseed.bytom.io"},
        Bech32HRPSegwit: "tm",
        DefaultPort:     "46656",
        DNSSeeds:        []string{"www.testnetseed.bytom.io"},
-       CasperConfig:    CasperConfig{BlockTimeInterval: 6000, MaxTimeOffsetMs: 24000},
+       CasperConfig: CasperConfig{
+               BlockTimeInterval:      6000,
+               MaxTimeOffsetMs:        24000,
+               BlocksOfEpoch:          100,
+               MinValidatorVoteNum:    1E8,
+               VotePendingBlockNumber: 10,
+       },
        Checkpoints: []Checkpoint{
                {10303, bc.NewHash([32]byte{0x3e, 0x94, 0x5d, 0x35, 0x70, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c})},
                {40000, bc.NewHash([32]byte{0x6b, 0x13, 0x9a, 0x5b, 0x76, 0x77, 0x9b, 0xd4, 0x1c, 0xec, 0x53, 0x68, 0x44, 0xbf, 0xf4, 0x48, 0x94, 0x3d, 0x16, 0xe3, 0x9b, 0x2e, 0xe8, 0xa1, 0x0f, 0xa0, 0xbc, 0x7d, 0x2b, 0x17, 0x55, 0xfc})},
        Checkpoints: []Checkpoint{
                {10303, bc.NewHash([32]byte{0x3e, 0x94, 0x5d, 0x35, 0x70, 0x30, 0xd4, 0x3b, 0x3d, 0xe3, 0xdd, 0x80, 0x67, 0x29, 0x9a, 0x5e, 0x09, 0xf9, 0xfb, 0x2b, 0xad, 0x5f, 0x92, 0xc8, 0x69, 0xd1, 0x42, 0x39, 0x74, 0x9a, 0xd1, 0x1c})},
                {40000, bc.NewHash([32]byte{0x6b, 0x13, 0x9a, 0x5b, 0x76, 0x77, 0x9b, 0xd4, 0x1c, 0xec, 0x53, 0x68, 0x44, 0xbf, 0xf4, 0x48, 0x94, 0x3d, 0x16, 0xe3, 0x9b, 0x2e, 0xe8, 0xa1, 0x0f, 0xa0, 0xbc, 0x7d, 0x2b, 0x17, 0x55, 0xfc})},
@@ -189,6 +208,12 @@ var TestNetParams = Params{
 var SoloNetParams = Params{
        Name:            "solo",
        Bech32HRPSegwit: "sm",
 var SoloNetParams = Params{
        Name:            "solo",
        Bech32HRPSegwit: "sm",
-       CasperConfig:    CasperConfig{BlockTimeInterval: 6000, MaxTimeOffsetMs: 24000},
-       Checkpoints:     []Checkpoint{},
+       CasperConfig: CasperConfig{
+               BlockTimeInterval:      6000,
+               MaxTimeOffsetMs:        24000,
+               BlocksOfEpoch:          100,
+               MinValidatorVoteNum:    1E8,
+               VotePendingBlockNumber: 10,
+       },
+       Checkpoints: []Checkpoint{},
 }
 }
index 01524f2..d8682a0 100644 (file)
@@ -340,7 +340,7 @@ func (s *Store) saveCheckpoints(batch dbm.Batch, checkpoints []*state.Checkpoint
                        return err
                }
 
                        return err
                }
 
-               if checkpoint.Height%state.BlocksOfEpoch != 1 {
+               if checkpoint.Height%consensus.ActiveNetParams.BlocksOfEpoch != 1 {
                        header, err := s.GetBlockHeader(&checkpoint.Hash)
                        if err != nil {
                                return err
                        header, err := s.GetBlockHeader(&checkpoint.Hash)
                        if err != nil {
                                return err
index f4799ae..8f80b3b 100644 (file)
@@ -165,7 +165,7 @@ func (b *blockBuilder) createCoinbaseTx() (tx *types.Tx, err error) {
                return nil, err
        }
 
                return nil, err
        }
 
-       if b.block.Height%state.BlocksOfEpoch == 1 && b.block.Height != 1 {
+       if b.block.Height%consensus.ActiveNetParams.BlocksOfEpoch == 1 && b.block.Height != 1 {
                for controlProgram, amount := range checkpoint.Rewards {
                        if controlProgram == hex.EncodeToString(script) {
                                builder.Outputs()[0].Amount = amount
                for controlProgram, amount := range checkpoint.Rewards {
                        if controlProgram == hex.EncodeToString(script) {
                                builder.Outputs()[0].Amount = amount
index ccd59a8..2ee17de 100644 (file)
@@ -6,6 +6,7 @@ import (
        "github.com/sirupsen/logrus"
 
        "github.com/bytom/bytom/config"
        "github.com/sirupsen/logrus"
 
        "github.com/bytom/bytom/config"
+       "github.com/bytom/bytom/consensus"
        "github.com/bytom/bytom/errors"
        "github.com/bytom/bytom/math/checked"
        "github.com/bytom/bytom/protocol/bc"
        "github.com/bytom/bytom/errors"
        "github.com/bytom/bytom/math/checked"
        "github.com/bytom/bytom/protocol/bc"
@@ -24,7 +25,7 @@ type applyBlockReply struct {
 // it will return verification when an epoch is reached and the current node is the validator, otherwise return nil
 // the chain module must broadcast the verification
 func (c *Casper) ApplyBlock(block *types.Block) (*applyBlockReply, error) {
 // it will return verification when an epoch is reached and the current node is the validator, otherwise return nil
 // the chain module must broadcast the verification
 func (c *Casper) ApplyBlock(block *types.Block) (*applyBlockReply, error) {
-       if block.Height%state.BlocksOfEpoch == 1 {
+       if block.Height%consensus.ActiveNetParams.BlocksOfEpoch == 1 {
                c.newEpochCh <- block.PreviousBlockHash
        }
 
                c.newEpochCh <- block.PreviousBlockHash
        }
 
@@ -69,7 +70,7 @@ func (c *Casper) applyBlockToCheckpoint(block *types.Block) (*state.Checkpoint,
        }
 
        checkpoint := node.checkpoint
        }
 
        checkpoint := node.checkpoint
-       if mod := block.Height % state.BlocksOfEpoch; mod == 1 {
+       if mod := block.Height % consensus.ActiveNetParams.BlocksOfEpoch; mod == 1 {
                parent := checkpoint
                checkpoint = state.NewCheckpoint(parent)
                node.addChild(&treeNode{checkpoint: checkpoint})
                parent := checkpoint
                checkpoint = state.NewCheckpoint(parent)
                node.addChild(&treeNode{checkpoint: checkpoint})
@@ -107,7 +108,7 @@ func (c *Casper) replayCheckpoint(hash bc.Hash) (*treeNode, error) {
                        return nil, err
                }
 
                        return nil, err
                }
 
-               if prevBlock.Height%state.BlocksOfEpoch == 0 {
+               if prevBlock.Height%consensus.ActiveNetParams.BlocksOfEpoch == 0 {
                        break
                }
 
                        break
                }
 
@@ -146,12 +147,6 @@ func applyTransactions(target *state.Checkpoint, transactions []*types.Tx) error
                                        return err
                                }
                        }
                                        return err
                                }
                        }
-
-                       if isGuarantyProgram(input.ControlProgram()) {
-                               if err := processWithdrawal(decodeGuarantyArgs(input.ControlProgram()), target); err != nil {
-                                       return err
-                               }
-                       }
                }
 
                for _, output := range tx.Outputs {
                }
 
                for _, output := range tx.Outputs {
@@ -160,12 +155,6 @@ func applyTransactions(target *state.Checkpoint, transactions []*types.Tx) error
                                        return err
                                }
                        }
                                        return err
                                }
                        }
-
-                       if isGuarantyProgram(output.ControlProgram) {
-                               if err := processGuaranty(decodeGuarantyArgs(output.ControlProgram), target); err != nil {
-                                       return err
-                               }
-                       }
                }
        }
        return nil
                }
        }
        return nil
@@ -174,7 +163,7 @@ func applyTransactions(target *state.Checkpoint, transactions []*types.Tx) error
 // applySupLinks copy the block's supLink to the checkpoint
 func (c *Casper) applySupLinks(target *state.Checkpoint, supLinks []*types.SupLink, validators map[string]*state.Validator) ([]*state.Checkpoint, error) {
        affectedCheckpoints := []*state.Checkpoint{target}
 // applySupLinks copy the block's supLink to the checkpoint
 func (c *Casper) applySupLinks(target *state.Checkpoint, supLinks []*types.SupLink, validators map[string]*state.Validator) ([]*state.Checkpoint, error) {
        affectedCheckpoints := []*state.Checkpoint{target}
-       if target.Height%state.BlocksOfEpoch != 0 {
+       if target.Height%consensus.ActiveNetParams.BlocksOfEpoch != 0 {
                return nil, nil
        }
 
                return nil, nil
        }
 
@@ -216,7 +205,7 @@ func (c *Casper) applyMyVerification(target *state.Checkpoint, block *types.Bloc
 }
 
 func (c *Casper) myVerification(target *state.Checkpoint, validators map[string]*state.Validator) (*Verification, error) {
 }
 
 func (c *Casper) myVerification(target *state.Checkpoint, validators map[string]*state.Validator) (*Verification, error) {
-       if target.Height%state.BlocksOfEpoch != 0 {
+       if target.Height%consensus.ActiveNetParams.BlocksOfEpoch != 0 {
                return nil, nil
        }
 
                return nil, nil
        }
 
@@ -253,48 +242,6 @@ func (c *Casper) myVerification(target *state.Checkpoint, validators map[string]
        return nil, nil
 }
 
        return nil, nil
 }
 
-type guarantyArgs struct {
-       Amount uint64
-       PubKey []byte
-}
-
-func isGuarantyProgram(program []byte) bool {
-       return false
-}
-
-func decodeGuarantyArgs(program []byte) *guarantyArgs {
-       return nil
-}
-
-func processWithdrawal(guarantyArgs *guarantyArgs, checkpoint *state.Checkpoint) error {
-       pubKey := hex.EncodeToString(guarantyArgs.PubKey)
-       guarantyNum := checkpoint.Guaranties[pubKey]
-       guarantyNum, ok := checked.SubUint64(guarantyNum, guarantyArgs.Amount)
-       if !ok {
-               return checked.ErrOverflow
-       }
-
-       checkpoint.Guaranties[pubKey] = guarantyNum
-       // TODO delete the evil validator when receive the confiscate transaction
-       return nil
-}
-
-func processGuaranty(guarantyArgs *guarantyArgs, checkpoint *state.Checkpoint) error {
-       if guarantyArgs.Amount < minGuaranty {
-               return errGuarantyLessThanMinimum
-       }
-
-       pubKey := hex.EncodeToString(guarantyArgs.PubKey)
-       guarantyNum := checkpoint.Guaranties[pubKey]
-       guarantyNum, ok := checked.AddUint64(guarantyNum, guarantyArgs.Amount)
-       if !ok {
-               return checked.ErrOverflow
-       }
-
-       checkpoint.Guaranties[pubKey] = guarantyNum
-       return nil
-}
-
 func processVeto(input *types.VetoInput, checkpoint *state.Checkpoint) error {
        pubKey := hex.EncodeToString(input.Vote)
        voteNum := checkpoint.Votes[pubKey]
 func processVeto(input *types.VetoInput, checkpoint *state.Checkpoint) error {
        pubKey := hex.EncodeToString(input.Vote)
        voteNum := checkpoint.Votes[pubKey]
@@ -310,10 +257,6 @@ func processVeto(input *types.VetoInput, checkpoint *state.Checkpoint) error {
 func processVote(output *types.TxOutput, checkpoint *state.Checkpoint) error {
        voteOutput := output.TypedOutput.(*types.VoteOutput)
        pubKey := hex.EncodeToString(voteOutput.Vote)
 func processVote(output *types.TxOutput, checkpoint *state.Checkpoint) error {
        voteOutput := output.TypedOutput.(*types.VoteOutput)
        pubKey := hex.EncodeToString(voteOutput.Vote)
-       if checkpoint.Guaranties[pubKey] < minGuaranty {
-               return errVoteToNonValidator
-       }
-
        voteNum := checkpoint.Votes[pubKey]
        voteNum, ok := checked.AddUint64(voteNum, output.Amount)
        if !ok {
        voteNum := checkpoint.Votes[pubKey]
        voteNum, ok := checked.AddUint64(voteNum, output.Amount)
        if !ok {
index 8c77b03..76a4480 100644 (file)
@@ -6,6 +6,7 @@ import (
 
        log "github.com/sirupsen/logrus"
 
 
        log "github.com/sirupsen/logrus"
 
+       "github.com/bytom/bytom/consensus"
        "github.com/bytom/bytom/protocol/bc"
        "github.com/bytom/bytom/protocol/state"
 )
        "github.com/bytom/bytom/protocol/bc"
        "github.com/bytom/bytom/protocol/state"
 )
@@ -238,7 +239,8 @@ func makeVerification(supLink *state.SupLink, checkpoint *state.Checkpoint, pubK
 }
 
 func validate(v *Verification) error {
 }
 
 func validate(v *Verification) error {
-       if v.SourceHeight%state.BlocksOfEpoch != 0 || v.TargetHeight%state.BlocksOfEpoch != 0 {
+       blocksOfEpoch := consensus.ActiveNetParams.BlocksOfEpoch
+       if v.SourceHeight%blocksOfEpoch != 0 || v.TargetHeight%blocksOfEpoch != 0 {
                return errVoteToGrowingCheckpoint
        }
 
                return errVoteToGrowingCheckpoint
        }
 
index f5ed51a..2e9dc9e 100644 (file)
@@ -23,8 +23,8 @@ var (
                        Hash:   testutil.MustDecodeHash("a1770c17493b87c43e85c2ab811023a8566907838c2237e7d72071c5f4713c5b"),
                        Status: state.Justified,
                        Votes: map[string]uint64{
                        Hash:   testutil.MustDecodeHash("a1770c17493b87c43e85c2ab811023a8566907838c2237e7d72071c5f4713c5b"),
                        Status: state.Justified,
                        Votes: map[string]uint64{
-                               "a2c5cbbc128485dccf41b7baec85ec9c7bd9418bc0c5ea23f4eeb621725bf9f0f863e6920e6ffc7a9a4ed8e43de568067ef8277fd45d3188c528a9f148f8d2f5": 1e8,
-                               "a7ac9f585075d9f30313e290fc7a4e35e6af741cffe020e0ffd4f2e4527f0080746bd53f43d5559da7ba5b134e3f67bd851ca66d2c6955e3493abbb32c68d6fa": 1e8,
+                               "a2c5cbbc128485dccf41b7baec85ec9c7bd9418bc0c5ea23f4eeb621725bf9f0f863e6920e6ffc7a9a4ed8e43de568067ef8277fd45d3188c528a9f148f8d2f5": 1e14,
+                               "a7ac9f585075d9f30313e290fc7a4e35e6af741cffe020e0ffd4f2e4527f0080746bd53f43d5559da7ba5b134e3f67bd851ca66d2c6955e3493abbb32c68d6fa": 1e14,
                        },
                },
                {
                        },
                },
                {
index 9d2cc95..607c2a7 100644 (file)
@@ -6,6 +6,7 @@ import (
        log "github.com/sirupsen/logrus"
 
        "github.com/bytom/bytom/common"
        log "github.com/sirupsen/logrus"
 
        "github.com/bytom/bytom/common"
+       "github.com/bytom/bytom/consensus"
        "github.com/bytom/bytom/errors"
        "github.com/bytom/bytom/protocol/bc"
        "github.com/bytom/bytom/protocol/state"
        "github.com/bytom/bytom/errors"
        "github.com/bytom/bytom/protocol/bc"
        "github.com/bytom/bytom/protocol/state"
@@ -21,8 +22,6 @@ var (
        errGuarantyLessThanMinimum  = errors.New("guaranty less than minimum")
 )
 
        errGuarantyLessThanMinimum  = errors.New("guaranty less than minimum")
 )
 
-const minGuaranty = 0
-
 // Casper is BFT based proof of stack consensus algorithm, it provides safety and liveness in theory,
 // it's design mainly refers to https://github.com/ethereum/research/blob/master/papers/casper-basics/casper_basics.pdf
 type Casper struct {
 // Casper is BFT based proof of stack consensus algorithm, it provides safety and liveness in theory,
 // it's design mainly refers to https://github.com/ethereum/research/blob/master/papers/casper-basics/casper_basics.pdf
 type Casper struct {
@@ -196,7 +195,7 @@ func (c *Casper) parentCheckpointHashByPrevHash(prevBlockHash *bc.Hash) (*bc.Has
                        return nil, err
                }
 
                        return nil, err
                }
 
-               if prevBlock.Height%state.BlocksOfEpoch == 0 {
+               if prevBlock.Height%consensus.ActiveNetParams.BlocksOfEpoch == 0 {
                        c.prevCheckpointCache.Add(*prevBlockHash, prevHash)
                        return prevHash, nil
                }
                        c.prevCheckpointCache.Add(*prevBlockHash, prevHash)
                        return prevHash, nil
                }
index 7977902..0576a03 100644 (file)
@@ -10,12 +10,6 @@ import (
        "github.com/bytom/bytom/protocol/bc/types"
 )
 
        "github.com/bytom/bytom/protocol/bc/types"
 )
 
-const (
-       // BlocksOfEpoch represent the block num in one epoch
-       BlocksOfEpoch = 100
-       minMortgage   = 1000000
-)
-
 // CheckpointStatus represent current status of checkpoint
 type CheckpointStatus uint8
 
 // CheckpointStatus represent current status of checkpoint
 type CheckpointStatus uint8
 
@@ -70,7 +64,6 @@ type Checkpoint struct {
 
        Rewards    map[string]uint64 // controlProgram -> num of reward
        Votes      map[string]uint64 // pubKey -> num of vote
 
        Rewards    map[string]uint64 // controlProgram -> num of reward
        Votes      map[string]uint64 // pubKey -> num of vote
-       Guaranties map[string]uint64 // pubKey -> num of guaranty
 
        MergeCheckpoint func(bc.Hash) `json:"-"`
 }
 
        MergeCheckpoint func(bc.Hash) `json:"-"`
 }
@@ -83,15 +76,11 @@ func NewCheckpoint(parent *Checkpoint) *Checkpoint {
                Status:     Growing,
                Rewards:    make(map[string]uint64),
                Votes:      make(map[string]uint64),
                Status:     Growing,
                Rewards:    make(map[string]uint64),
                Votes:      make(map[string]uint64),
-               Guaranties: make(map[string]uint64),
        }
 
        for pubKey, num := range parent.Votes {
                checkpoint.Votes[pubKey] = num
        }
        }
 
        for pubKey, num := range parent.Votes {
                checkpoint.Votes[pubKey] = num
        }
-       for pubKey, num := range parent.Guaranties {
-               checkpoint.Guaranties[pubKey] = num
-       }
        return checkpoint
 }
 
        return checkpoint
 }
 
@@ -148,7 +137,6 @@ type Validator struct {
        PubKey   string
        Order    int
        Vote     uint64
        PubKey   string
        Order    int
        Vote     uint64
-       Guaranty uint64
 }
 
 // Validators return next epoch of validators, if the status of checkpoint is growing, return empty
 }
 
 // Validators return next epoch of validators, if the status of checkpoint is growing, return empty
@@ -158,13 +146,11 @@ func (c *Checkpoint) Validators() map[string]*Validator {
                return nil
        }
 
                return nil
        }
 
-       //  todo use vote num to generate validators in test version
-       for pubKey, mortgageNum := range c.Votes {
-               if mortgageNum >= minMortgage {
+       for pubKey, voteNum := range c.Votes {
+               if voteNum >= consensus.ActiveNetParams.MinValidatorVoteNum {
                        validators = append(validators, &Validator{
                                PubKey:   pubKey,
                                Vote:     c.Votes[pubKey],
                        validators = append(validators, &Validator{
                                PubKey:   pubKey,
                                Vote:     c.Votes[pubKey],
-                               Guaranty: mortgageNum,
                        })
                }
        }
                        })
                }
        }
@@ -174,8 +160,8 @@ func (c *Checkpoint) Validators() map[string]*Validator {
        }
 
        sort.Slice(validators, func(i, j int) bool {
        }
 
        sort.Slice(validators, func(i, j int) bool {
-               numI := validators[i].Guaranty+validators[i].Vote
-               numJ := validators[j].Guaranty+validators[j].Vote
+               numI := validators[i].Vote
+               numJ := validators[j].Vote
                if numI != numJ {
                        return numI > numJ
                }
                if numI != numJ {
                        return numI > numJ
                }
index 3280e45..435e02d 100644 (file)
@@ -50,12 +50,6 @@ func pledgeRate(checkpoint *Checkpoint) (float64, error) {
                }
        }
 
                }
        }
 
-       for _, guaranty := range checkpoint.Guaranties {
-               if totalVotes, ok = checked.AddUint64(totalVotes, guaranty); !ok {
-                       return 0.0, errors.Wrap(checked.ErrOverflow)
-               }
-       }
-
        if totalVotes > totalSupply {
                return 0.0, errors.New("validators total votes exceed total supply")
        }
        if totalVotes > totalSupply {
                return 0.0, errors.New("validators total votes exceed total supply")
        }
@@ -118,7 +112,7 @@ func (c *Checkpoint) ApplyFederationReward() error {
        }
 
        federationScript := config.CommonConfig.Federation.FederationScript
        }
 
        federationScript := config.CommonConfig.Federation.FederationScript
-       c.Rewards[federationScript] = federationReward * BlocksOfEpoch
+       c.Rewards[federationScript] = federationReward * consensus.ActiveNetParams.BlocksOfEpoch
        return nil
 }
 
        return nil
 }
 
index 2dfbb6d..845de56 100644 (file)
@@ -47,7 +47,7 @@ func checkCoinbaseAmount(b *bc.Block, checkpoint *state.Checkpoint) error {
                return errors.Wrap(ErrWrongCoinbaseTransaction, "tx header resultIds is empty")
        }
 
                return errors.Wrap(ErrWrongCoinbaseTransaction, "tx header resultIds is empty")
        }
 
-       if b.Height%state.BlocksOfEpoch != 1 || b.Height == 1 {
+       if b.Height%consensus.ActiveNetParams.BlocksOfEpoch != 1 || b.Height == 1 {
                output, err := tx.OriginalOutput(*tx.TxHeader.ResultIds[0])
                if err != nil {
                        return err
                output, err := tx.OriginalOutput(*tx.TxHeader.ResultIds[0])
                if err != nil {
                        return err
index 14cff87..b3bb16e 100644 (file)
@@ -91,7 +91,7 @@ func TestCheckCoinbaseAmount(t *testing.T) {
                },
                {
                        block: &types.Block{
                },
                {
                        block: &types.Block{
-                               BlockHeader: types.BlockHeader{Height: state.BlocksOfEpoch + 1},
+                               BlockHeader: types.BlockHeader{Height: consensus.ActiveNetParams.BlocksOfEpoch + 1},
                                Transactions: []*types.Tx{
                                        types.NewTx(types.TxData{
                                                Inputs: []*types.TxInput{types.NewCoinbaseInput(nil)},
                                Transactions: []*types.Tx{
                                        types.NewTx(types.TxData{
                                                Inputs: []*types.TxInput{types.NewCoinbaseInput(nil)},
@@ -108,7 +108,7 @@ func TestCheckCoinbaseAmount(t *testing.T) {
                },
                {
                        block: &types.Block{
                },
                {
                        block: &types.Block{
-                               BlockHeader: types.BlockHeader{Height: state.BlocksOfEpoch + 1},
+                               BlockHeader: types.BlockHeader{Height: consensus.ActiveNetParams.BlocksOfEpoch + 1},
                                Transactions: []*types.Tx{
                                        types.NewTx(types.TxData{
                                                Inputs: []*types.TxInput{types.NewCoinbaseInput(nil)},
                                Transactions: []*types.Tx{
                                        types.NewTx(types.TxData{
                                                Inputs: []*types.TxInput{types.NewCoinbaseInput(nil)},
@@ -126,7 +126,7 @@ func TestCheckCoinbaseAmount(t *testing.T) {
                },
                {
                        block: &types.Block{
                },
                {
                        block: &types.Block{
-                               BlockHeader: types.BlockHeader{Height: state.BlocksOfEpoch + 1},
+                               BlockHeader: types.BlockHeader{Height: consensus.ActiveNetParams.BlocksOfEpoch + 1},
                                Transactions: []*types.Tx{
                                        types.NewTx(types.TxData{
                                                Inputs: []*types.TxInput{types.NewCoinbaseInput(nil)},
                                Transactions: []*types.Tx{
                                        types.NewTx(types.TxData{
                                                Inputs: []*types.TxInput{types.NewCoinbaseInput(nil)},
@@ -144,7 +144,7 @@ func TestCheckCoinbaseAmount(t *testing.T) {
                },
                {
                        block: &types.Block{
                },
                {
                        block: &types.Block{
-                               BlockHeader: types.BlockHeader{Height: state.BlocksOfEpoch + 1},
+                               BlockHeader: types.BlockHeader{Height: consensus.ActiveNetParams.BlocksOfEpoch + 1},
                                Transactions: []*types.Tx{
                                        types.NewTx(types.TxData{
                                                Inputs: []*types.TxInput{types.NewCoinbaseInput(nil)},
                                Transactions: []*types.Tx{
                                        types.NewTx(types.TxData{
                                                Inputs: []*types.TxInput{types.NewCoinbaseInput(nil)},
@@ -297,7 +297,7 @@ func TestValidateBlock(t *testing.T) {
        cp, _ := vmutil.DefaultCoinbaseProgram()
        parent := &types.BlockHeader{
                Version:   1,
        cp, _ := vmutil.DefaultCoinbaseProgram()
        parent := &types.BlockHeader{
                Version:   1,
-               Height:    state.BlocksOfEpoch,
+               Height:    consensus.ActiveNetParams.BlocksOfEpoch,
                Timestamp: 1523352600,
        }
        parentHash := parent.Hash()
                Timestamp: 1523352600,
        }
        parentHash := parent.Hash()
@@ -315,7 +315,7 @@ func TestValidateBlock(t *testing.T) {
                                ID: bc.Hash{V0: 1},
                                BlockHeader: &bc.BlockHeader{
                                        Version:          1,
                                ID: bc.Hash{V0: 1},
                                BlockHeader: &bc.BlockHeader{
                                        Version:          1,
-                                       Height:           state.BlocksOfEpoch + 1,
+                                       Height:           consensus.ActiveNetParams.BlocksOfEpoch + 1,
                                        Timestamp:        1523358600,
                                        PreviousBlockId:  &parentHash,
                                        TransactionsRoot: &bc.Hash{V0: 1},
                                        Timestamp:        1523358600,
                                        PreviousBlockId:  &parentHash,
                                        TransactionsRoot: &bc.Hash{V0: 1},
@@ -341,7 +341,7 @@ func TestValidateBlock(t *testing.T) {
                                ID: bc.Hash{V0: 1},
                                BlockHeader: &bc.BlockHeader{
                                        Version:          1,
                                ID: bc.Hash{V0: 1},
                                BlockHeader: &bc.BlockHeader{
                                        Version:          1,
-                                       Height:           state.BlocksOfEpoch + 1,
+                                       Height:           consensus.ActiveNetParams.BlocksOfEpoch + 1,
                                        Timestamp:        1523358600,
                                        PreviousBlockId:  &parentHash,
                                        TransactionsRoot: &bc.Hash{V0: 6294987741126419124, V1: 12520373106916389157, V2: 5040806596198303681, V3: 1151748423853876189},
                                        Timestamp:        1523358600,
                                        PreviousBlockId:  &parentHash,
                                        TransactionsRoot: &bc.Hash{V0: 6294987741126419124, V1: 12520373106916389157, V2: 5040806596198303681, V3: 1151748423853876189},
index 0952191..291d9b3 100644 (file)
@@ -226,7 +226,7 @@ func txOutToUtxos(tx *types.Tx, blockHeight uint64) []*account.UTXO {
                        }
 
                case *bc.VoteOutput:
                        }
 
                case *bc.VoteOutput:
-                       voteValidHeight := blockHeight + consensus.VotePendingBlockNumber
+                       voteValidHeight := blockHeight + consensus.ActiveNetParams.VotePendingBlockNumber
                        if validHeight < voteValidHeight {
                                validHeight = voteValidHeight
                        }
                        if validHeight < voteValidHeight {
                                validHeight = voteValidHeight
                        }