OSDN Git Service

add roundVoteBlockNums
authormars <mars@bytom.io>
Thu, 18 Jul 2019 11:02:50 +0000 (19:02 +0800)
committermars <mars@bytom.io>
Thu, 18 Jul 2019 11:02:50 +0000 (19:02 +0800)
toolbar/reward/reward.go
toolbar/reward/reward/vote_reward.go

index 53b3ca2..15bc258 100644 (file)
@@ -5,6 +5,7 @@ import (
 
        "github.com/jinzhu/gorm"
 
+       "github.com/vapor/consensus"
        "github.com/vapor/errors"
        "github.com/vapor/toolbar/reward/config"
        "github.com/vapor/toolbar/reward/database/orm"
@@ -16,12 +17,13 @@ type CountReward interface {
 }
 
 type Reward struct {
-       cfg         *config.Config
-       db          *gorm.DB
-       countReward CountReward
-       VoteInfoCh  chan instance.VoteInfo
-       OverReadCh  chan struct{}
-       period      uint64
+       cfg                *config.Config
+       db                 *gorm.DB
+       countReward        CountReward
+       VoteInfoCh         chan instance.VoteInfo
+       OverReadCh         chan struct{}
+       period             uint64
+       roundVoteBlockNums uint64
 }
 
 func NewReward(db *gorm.DB, cfg *config.Config, period uint64, quit chan struct{}) *Reward {
@@ -39,12 +41,13 @@ func NewReward(db *gorm.DB, cfg *config.Config, period uint64, quit chan struct{
        }
 
        reward := &Reward{
-               cfg:         cfg,
-               db:          db,
-               countReward: countReward,
-               VoteInfoCh:  voteInfoCh,
-               OverReadCh:  overReadCh,
-               period:      period,
+               cfg:                cfg,
+               db:                 db,
+               countReward:        countReward,
+               VoteInfoCh:         voteInfoCh,
+               OverReadCh:         overReadCh,
+               period:             period,
+               roundVoteBlockNums: consensus.ActiveNetParams.DPOSConfig.RoundVoteBlockNums,
        }
 
        return reward
@@ -56,8 +59,8 @@ func (r *Reward) readVoteInfo() error {
                xpubs = append(xpubs, node.XPub)
        }
 
-       minHeight := (1 + 1200*(r.period-1))
-       maxHeight := 1200 * r.period
+       minHeight := (1 + r.roundVoteBlockNums*(r.period-1))
+       maxHeight := r.roundVoteBlockNums * r.period
 
        ticker := time.NewTicker(time.Duration(r.cfg.Chain.SyncSeconds) * time.Second)
        for ; true; <-ticker.C {
@@ -90,10 +93,10 @@ func (r *Reward) readVoteInfo() error {
                        return err
                }
 
-               if vetoHeight > minHeight && vetoHeight < 1200*r.period {
+               if vetoHeight > minHeight && vetoHeight < r.roundVoteBlockNums*r.period {
                        voteBlockNum = vetoHeight - voteHeight
                } else {
-                       voteBlockNum = 1200*r.period - voteHeight
+                       voteBlockNum = r.roundVoteBlockNums*r.period - voteHeight
                }
 
                r.VoteInfoCh <- instance.VoteInfo{
index f93d788..8314c68 100644 (file)
@@ -6,6 +6,7 @@ import (
 
        log "github.com/sirupsen/logrus"
 
+       "github.com/vapor/consensus"
        "github.com/vapor/errors"
        "github.com/vapor/protocol/bc/types"
        "github.com/vapor/toolbar/common"
@@ -27,26 +28,28 @@ type coinBaseReward struct {
 }
 
 type Vote struct {
-       nodes          []config.VoteRewardConfig
-       ch             chan VoteInfo
-       overReadCH     chan struct{}
-       quit           chan struct{}
-       voteResults    map[string]*voteResult
-       voterRewards   map[string]*voterReward
-       coinBaseReward map[string]*coinBaseReward
-       period         uint64
+       nodes              []config.VoteRewardConfig
+       ch                 chan VoteInfo
+       overReadCH         chan struct{}
+       quit               chan struct{}
+       voteResults        map[string]*voteResult
+       voterRewards       map[string]*voterReward
+       coinBaseReward     map[string]*coinBaseReward
+       period             uint64
+       roundVoteBlockNums uint64
 }
 
 func NewVote(nodes []config.VoteRewardConfig, ch chan VoteInfo, overReadCH, quit chan struct{}, period uint64) *Vote {
        return &Vote{
-               nodes:          nodes,
-               ch:             ch,
-               overReadCH:     overReadCH,
-               quit:           quit,
-               voteResults:    make(map[string]*voteResult),
-               voterRewards:   make(map[string]*voterReward),
-               coinBaseReward: make(map[string]*coinBaseReward),
-               period:         period,
+               nodes:              nodes,
+               ch:                 ch,
+               overReadCH:         overReadCH,
+               quit:               quit,
+               voteResults:        make(map[string]*voteResult),
+               voterRewards:       make(map[string]*voterReward),
+               coinBaseReward:     make(map[string]*coinBaseReward),
+               period:             period,
+               roundVoteBlockNums: consensus.ActiveNetParams.DPOSConfig.RoundVoteBlockNums,
        }
 }
 
@@ -76,12 +79,12 @@ func (v *Vote) getCoinbaseReward() error {
                                close(v.quit)
                                return errors.Wrap(err, "get block height")
                        }
-                       if h >= 1200*v.period {
+                       if h >= v.roundVoteBlockNums*v.period {
                                break
                        }
                }
 
-               coinbaseTx, err := tx.GetCoinbaseTx(1200 * v.period)
+               coinbaseTx, err := tx.GetCoinbaseTx(v.roundVoteBlockNums * v.period)
                if err != nil {
                        close(v.quit)
                        return err