core/vote: wait some blocks beforing voting since mining begin
This commit is contained in:
parent
4b107c5303
commit
b3df096358
@ -15,6 +15,8 @@ import (
|
||||
"github.com/ethereum/go-ethereum/metrics"
|
||||
)
|
||||
|
||||
const blocksNumberSinceMining = 5 // the number of blocks need to wait before voting, counting from the validator begin to mine
|
||||
|
||||
var votesManagerCounter = metrics.NewRegisteredCounter("votesManager/local", nil)
|
||||
|
||||
// Backend wraps all methods required for voting.
|
||||
@ -95,6 +97,7 @@ func (voteManager *VoteManager) loop() {
|
||||
dlEventCh := events.Chan()
|
||||
|
||||
startVote := true
|
||||
blockCountSinceMining := 0
|
||||
var once sync.Once
|
||||
for {
|
||||
select {
|
||||
@ -120,9 +123,15 @@ func (voteManager *VoteManager) loop() {
|
||||
continue
|
||||
}
|
||||
if !voteManager.eth.IsMining() {
|
||||
blockCountSinceMining = 0
|
||||
log.Debug("skip voting because mining is disabled, continue")
|
||||
continue
|
||||
}
|
||||
blockCountSinceMining++
|
||||
if blockCountSinceMining <= blocksNumberSinceMining {
|
||||
log.Debug("skip voting", "blockCountSinceMining", blockCountSinceMining, "blocksNumberSinceMining", blocksNumberSinceMining)
|
||||
continue
|
||||
}
|
||||
|
||||
if cHead.Block == nil {
|
||||
log.Debug("cHead.Block is nil, continue")
|
||||
|
@ -190,7 +190,7 @@ func testVotePool(t *testing.T, isValidRules bool) {
|
||||
if _, err := chain.InsertChain(bs); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := 0; i < 10+blocksNumberSinceMining; i++ {
|
||||
bs, _ = core.GenerateChain(params.TestChainConfig, bs[len(bs)-1], ethash.NewFaker(), db, 1, nil)
|
||||
if _, err := chain.InsertChain(bs); err != nil {
|
||||
panic(err)
|
||||
|
Loading…
Reference in New Issue
Block a user