consensus,miner: allow mining in case of no peers if DevFakeAuthor is enabled

This commit is contained in:
Raneet Debnath 2025-06-04 10:40:32 +05:30
parent 37d853f237
commit b65f3b5b4e
No known key found for this signature in database
GPG key ID: C232FD2D870BCD3D
2 changed files with 5 additions and 4 deletions

View file

@ -231,7 +231,7 @@ type Bor struct {
// The fields below are for testing only // The fields below are for testing only
fakeDiff bool // Skip difficulty verifications fakeDiff bool // Skip difficulty verifications
devFakeAuthor bool DevFakeAuthor bool
closeOnce sync.Once closeOnce sync.Once
} }
@ -276,7 +276,7 @@ func New(
GenesisContractsClient: genesisContracts, GenesisContractsClient: genesisContracts,
HeimdallClient: heimdallClient, HeimdallClient: heimdallClient,
spanStore: spanStore, spanStore: spanStore,
devFakeAuthor: devFakeAuthor, DevFakeAuthor: devFakeAuthor,
} }
c.authorizedSigner.Store(&signer{ c.authorizedSigner.Store(&signer{
@ -539,7 +539,7 @@ func (c *Bor) verifyCascadingFields(chain consensus.ChainHeaderReader, header *t
func (c *Bor) snapshot(chain consensus.ChainHeaderReader, number uint64, hash common.Hash, parents []*types.Header) (*Snapshot, error) { func (c *Bor) snapshot(chain consensus.ChainHeaderReader, number uint64, hash common.Hash, parents []*types.Header) (*Snapshot, error) {
// Search for a snapshot in memory or on disk for checkpoints // Search for a snapshot in memory or on disk for checkpoints
signer := common.BytesToAddress(c.authorizedSigner.Load().signer.Bytes()) signer := common.BytesToAddress(c.authorizedSigner.Load().signer.Bytes())
if c.devFakeAuthor && signer.String() != "0x0000000000000000000000000000000000000000" { if c.DevFakeAuthor && signer.String() != "0x0000000000000000000000000000000000000000" {
log.Info("👨💻Using DevFakeAuthor", "signer", signer) log.Info("👨💻Using DevFakeAuthor", "signer", signer)
val := valset.NewValidator(signer, 1000) val := valset.NewValidator(signer, 1000)

View file

@ -594,11 +594,12 @@ func (w *worker) mainLoop() {
} }
}() }()
bor, _ := w.engine.(*bor.Bor)
for { for {
select { select {
case req := <-w.newWorkCh: case req := <-w.newWorkCh:
if w.chainConfig.ChainID.Cmp(params.BorMainnetChainConfig.ChainID) == 0 || w.chainConfig.ChainID.Cmp(params.MumbaiChainConfig.ChainID) == 0 || w.chainConfig.ChainID.Cmp(params.AmoyChainConfig.ChainID) == 0 { if w.chainConfig.ChainID.Cmp(params.BorMainnetChainConfig.ChainID) == 0 || w.chainConfig.ChainID.Cmp(params.MumbaiChainConfig.ChainID) == 0 || w.chainConfig.ChainID.Cmp(params.AmoyChainConfig.ChainID) == 0 {
if w.eth.PeerCount() > 0 { if w.eth.PeerCount() > 0 || bor.DevFakeAuthor {
//nolint:contextcheck //nolint:contextcheck
w.commitWork(req.interrupt, req.noempty, req.timestamp) w.commitWork(req.interrupt, req.noempty, req.timestamp)
} }