"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"
}
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 {
}
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
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 {
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{
log "github.com/sirupsen/logrus"
+ "github.com/vapor/consensus"
"github.com/vapor/errors"
"github.com/vapor/protocol/bc/types"
"github.com/vapor/toolbar/common"
}
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,
}
}
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