Skip to content

Commit 9893371

Browse files
kevjueKevin Jue
authored and
Joshua Gutow
committed
Notify proxied validator engine of new epoch (#1240)
* notify proxied validator engine on new peoch * added comment * clarified comment Co-authored-by: Kevin Jue <[email protected]>
1 parent cd46c61 commit 9893371

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

consensus/istanbul/backend/handler.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ func (sb *Backend) newChainHead(newBlock *types.Block) {
320320

321321
// If this is the last block of the epoch:
322322
// * Print an easy to find log message giving our address and whether we're elected in next epoch.
323-
// * if this is a proxy or a non proxied validator, refresh the validator enode table.
323+
// * If this is a node maintaining validator connections (e.g. a proxy or a standalone validator), refresh the validator enode table.
324+
// * If this is a proxied validator, notify the proxied validator engine of a new epoch.
324325
if istanbul.IsLastBlockOfEpoch(newBlock.Number().Uint64(), sb.config.Epoch) {
325326

326327
sb.coreMu.RLock()
@@ -337,6 +338,12 @@ func (sb *Backend) newChainHead(newBlock *types.Block) {
337338
sb.logger.Warn("Error refreshing validator peers", "err", err)
338339
}
339340
}
341+
342+
if sb.IsProxiedValidator() {
343+
if err := sb.proxiedValidatorEngine.NewEpoch(); err != nil {
344+
sb.logger.Warn("Error while notifying proxied validator engine of new epoch", "err", err)
345+
}
346+
}
340347
}
341348

342349
sb.blocksFinalizedTransactionsGauge.Update(int64(len(newBlock.Transactions())))

consensus/istanbul/proxy/proxied_validator_engine.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,22 @@ func (pv *proxiedValidatorEngine) SendForwardMsgToAllProxies(finalDestAddresses
356356
return nil
357357
}
358358

359+
// NewEpoch will notify the proxied validator's thread that a new epoch started
360+
func (pv *proxiedValidatorEngine) NewEpoch() error {
361+
if !pv.Running() {
362+
return istanbul.ErrStoppedProxiedValidatorEngine
363+
}
364+
365+
select {
366+
case pv.newBlockchainEpoch <- struct{}{}:
367+
368+
case <-pv.quit:
369+
return istanbul.ErrStoppedProxiedValidatorEngine
370+
}
371+
372+
return nil
373+
}
374+
359375
// run handles changes to proxies and validator assignments
360376
func (pv *proxiedValidatorEngine) threadRun() {
361377
var (

consensus/istanbul/proxy/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ type ProxiedValidatorEngine interface {
123123

124124
// IsProxyPeer will check if the peerID is a proxy.
125125
IsProxyPeer(peerID enode.ID) (bool, error)
126+
127+
// NewEpoch will notify the proxied validator's thread that a new epoch started
128+
NewEpoch() error
126129
}
127130

128131
// ==============================================

0 commit comments

Comments
 (0)