Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miner/worker :: add : start commit work only after connecting to peers #977

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ func makeExtraData(extra []byte) []byte {
return extra
}

func (s *Ethereum) PeerCount() int {
return s.p2pServer.PeerCount()
}

// APIs return the collection of RPC services the ethereum package offers.
// NOTE, some of these services probably need to be moved to somewhere else.
func (s *Ethereum) APIs() []rpc.API {
Expand Down
5 changes: 5 additions & 0 deletions miner/fake_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ type mockBackend struct {
txPool *txpool.TxPool
}

// PeerCount implements Backend.
func (*mockBackend) PeerCount() int {
panic("unimplemented")
}

func NewMockBackend(bc *core.BlockChain, txPool *txpool.TxPool) *mockBackend {
return &mockBackend{
bc: bc,
Expand Down
1 change: 1 addition & 0 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
type Backend interface {
BlockChain() *core.BlockChain
TxPool() *txpool.TxPool
PeerCount() int
}

// Config is the configuration parameters of mining.
Expand Down
5 changes: 5 additions & 0 deletions miner/test_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ type testWorkerBackend struct {
uncleBlock *types.Block
}

// PeerCount implements Backend.
func (*testWorkerBackend) PeerCount() int {
panic("unimplemented")
}

func newTestWorkerBackend(t TensingObject, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database, n int) *testWorkerBackend {
var gspec = core.Genesis{
Config: chainConfig,
Expand Down
8 changes: 7 additions & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,13 @@ func (w *worker) mainLoop(ctx context.Context) {
select {
case req := <-w.newWorkCh:
//nolint:contextcheck
w.commitWork(req.ctx, req.interrupt, req.noempty, req.timestamp)
if w.chainConfig.ChainID.Cmp(params.BorMainnetChainConfig.ChainID) == 0 || w.chainConfig.ChainID.Cmp(params.MumbaiChainConfig.ChainID) == 0 {
if w.eth.PeerCount() > 0 {
w.commitWork(req.ctx, req.interrupt, req.noempty, req.timestamp)
}
} else {
w.commitWork(req.ctx, req.interrupt, req.noempty, req.timestamp)
}

case req := <-w.getWorkCh:
block, fees, err := w.generateWork(req.ctx, req.params)
Expand Down
4 changes: 2 additions & 2 deletions params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ var (

// BorTestChainConfig contains the chain parameters to run a node on the Test network.
BorTestChainConfig = &ChainConfig{
ChainID: big.NewInt(80001),
ChainID: big.NewInt(80002),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
Expand Down Expand Up @@ -264,7 +264,7 @@ var (
},
}
BorUnittestChainConfig = &ChainConfig{
ChainID: big.NewInt(80001),
ChainID: big.NewInt(80003),
HomesteadBlock: big.NewInt(0),
DAOForkBlock: nil,
DAOForkSupport: true,
Expand Down