mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
node waits to his turn until there is a new block comes in
This commit is contained in:
parent
5a771ed6f0
commit
f65014512d
3 changed files with 12 additions and 13 deletions
|
|
@ -49,7 +49,6 @@ var (
|
|||
blockInsertTimer = metrics.NewRegisteredTimer("chain/inserts", nil)
|
||||
CheckpointCh = make(chan int)
|
||||
M1Ch = make(chan int)
|
||||
NewBlockCh = make(chan int)
|
||||
ErrNoGenesis = errors.New("Genesis not found in chain")
|
||||
)
|
||||
|
||||
|
|
@ -1244,7 +1243,6 @@ func (st *insertStats) report(chain []*types.Block, index int, cache common.Stor
|
|||
context = append(context, []interface{}{"ignored", st.ignored}...)
|
||||
}
|
||||
log.Info("Imported new chain segment", context...)
|
||||
NewBlockCh <- 1
|
||||
*st = insertStats{startTime: now, lastIndex: index + 1}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -471,8 +471,8 @@ func (s *Ethereum) StartStaking(local bool) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (s *Ethereum) StopStaking() { s.miner.Stop() }
|
||||
func (s *Ethereum) IsStaking() bool { return s.miner.Mining() }
|
||||
func (s *Ethereum) StopStaking() { s.miner.Stop() }
|
||||
func (s *Ethereum) IsStaking() bool { return s.miner.Mining() }
|
||||
func (s *Ethereum) Miner() *miner.Miner { return s.miner }
|
||||
|
||||
func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager }
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ const (
|
|||
// chainSideChanSize is the size of channel listening to ChainSideEvent.
|
||||
chainSideChanSize = 10
|
||||
// Timeout waiting for M1
|
||||
m1Timeout = 1000
|
||||
m1Timeout = 1
|
||||
)
|
||||
|
||||
// Agent can register themself with the worker
|
||||
|
|
@ -475,16 +475,17 @@ func (self *worker) commitNewWork() {
|
|||
gap := int64(c.GetPeriod()) * int64(h)
|
||||
log.Info("Distance from the parent block", "seconds", gap, "hops", h)
|
||||
L:
|
||||
for {
|
||||
select {
|
||||
case <-core.NewBlockCh:
|
||||
log.Info("New block has came already. Skip this turn")
|
||||
select {
|
||||
case newBlock := <-self.chainHeadCh:
|
||||
if newBlock.Block.NumberU64() > parent.NumberU64() {
|
||||
log.Info("New block has came already. Skip this turn", "new block", newBlock.Block.NumberU64(), "current block", parent.NumberU64())
|
||||
self.chainHeadCh <- newBlock
|
||||
return
|
||||
case <-time.After(time.Duration(gap+m1Timeout) * time.Second):
|
||||
// wait enough. It's my turn
|
||||
log.Info("Wait enough. It's my turn", "waited seconds", gap+m1Timeout)
|
||||
break L
|
||||
}
|
||||
case <-time.After(time.Duration(gap+m1Timeout) * time.Second):
|
||||
// wait enough. It's my turn
|
||||
log.Info("Wait enough. It's my turn", "waited seconds", gap+m1Timeout)
|
||||
break L
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue