mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
miner/worker :: add : start commit work only after connecting to peers (#977)
* add : start commit work only after connecting to peers * fix : chainconfig fix * chg : change test and unitTest chainconfigs chainID from 80001 * fix : p2p server deadlock
This commit is contained in:
parent
aea4881517
commit
4d96b145e4
7 changed files with 30 additions and 4 deletions
|
|
@ -351,6 +351,10 @@ func makeExtraData(extra []byte) []byte {
|
||||||
return extra
|
return extra
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Ethereum) PeerCount() int {
|
||||||
|
return s.p2pServer.PeerCount()
|
||||||
|
}
|
||||||
|
|
||||||
// APIs return the collection of RPC services the ethereum package offers.
|
// APIs return the collection of RPC services the ethereum package offers.
|
||||||
// NOTE, some of these services probably need to be moved to somewhere else.
|
// NOTE, some of these services probably need to be moved to somewhere else.
|
||||||
func (s *Ethereum) APIs() []rpc.API {
|
func (s *Ethereum) APIs() []rpc.API {
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,11 @@ type mockBackend struct {
|
||||||
txPool *txpool.TxPool
|
txPool *txpool.TxPool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PeerCount implements Backend.
|
||||||
|
func (*mockBackend) PeerCount() int {
|
||||||
|
panic("unimplemented")
|
||||||
|
}
|
||||||
|
|
||||||
func NewMockBackend(bc *core.BlockChain, txPool *txpool.TxPool) *mockBackend {
|
func NewMockBackend(bc *core.BlockChain, txPool *txpool.TxPool) *mockBackend {
|
||||||
return &mockBackend{
|
return &mockBackend{
|
||||||
bc: bc,
|
bc: bc,
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ import (
|
||||||
type Backend interface {
|
type Backend interface {
|
||||||
BlockChain() *core.BlockChain
|
BlockChain() *core.BlockChain
|
||||||
TxPool() *txpool.TxPool
|
TxPool() *txpool.TxPool
|
||||||
|
PeerCount() int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config is the configuration parameters of mining.
|
// Config is the configuration parameters of mining.
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,11 @@ type testWorkerBackend struct {
|
||||||
uncleBlock *types.Block
|
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 {
|
func newTestWorkerBackend(t TensingObject, chainConfig *params.ChainConfig, engine consensus.Engine, db ethdb.Database, n int) *testWorkerBackend {
|
||||||
var gspec = core.Genesis{
|
var gspec = core.Genesis{
|
||||||
Config: chainConfig,
|
Config: chainConfig,
|
||||||
|
|
|
||||||
|
|
@ -657,8 +657,15 @@ func (w *worker) mainLoop(ctx context.Context) {
|
||||||
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 {
|
||||||
|
if w.eth.PeerCount() > 0 {
|
||||||
//nolint:contextcheck
|
//nolint:contextcheck
|
||||||
w.commitWork(req.ctx, req.interrupt, req.noempty, req.timestamp)
|
w.commitWork(req.ctx, req.interrupt, req.noempty, req.timestamp)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//nolint:contextcheck
|
||||||
|
w.commitWork(req.ctx, req.interrupt, req.noempty, req.timestamp)
|
||||||
|
}
|
||||||
|
|
||||||
case req := <-w.getWorkCh:
|
case req := <-w.getWorkCh:
|
||||||
block, fees, err := w.generateWork(req.ctx, req.params)
|
block, fees, err := w.generateWork(req.ctx, req.params)
|
||||||
|
|
|
||||||
|
|
@ -356,6 +356,10 @@ func (srv *Server) SetMaxPeers(maxPeers int) {
|
||||||
|
|
||||||
// PeerCount returns the number of connected peers.
|
// PeerCount returns the number of connected peers.
|
||||||
func (srv *Server) PeerCount() int {
|
func (srv *Server) PeerCount() int {
|
||||||
|
if !srv.running {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
var count int
|
var count int
|
||||||
|
|
||||||
srv.doPeerOp(func(ps map[enode.ID]*Peer) {
|
srv.doPeerOp(func(ps map[enode.ID]*Peer) {
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,7 @@ var (
|
||||||
|
|
||||||
// BorTestChainConfig contains the chain parameters to run a node on the Test network.
|
// BorTestChainConfig contains the chain parameters to run a node on the Test network.
|
||||||
BorTestChainConfig = &ChainConfig{
|
BorTestChainConfig = &ChainConfig{
|
||||||
ChainID: big.NewInt(80001),
|
ChainID: big.NewInt(80002),
|
||||||
HomesteadBlock: big.NewInt(0),
|
HomesteadBlock: big.NewInt(0),
|
||||||
DAOForkBlock: nil,
|
DAOForkBlock: nil,
|
||||||
DAOForkSupport: true,
|
DAOForkSupport: true,
|
||||||
|
|
@ -264,7 +264,7 @@ var (
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
BorUnittestChainConfig = &ChainConfig{
|
BorUnittestChainConfig = &ChainConfig{
|
||||||
ChainID: big.NewInt(80001),
|
ChainID: big.NewInt(80003),
|
||||||
HomesteadBlock: big.NewInt(0),
|
HomesteadBlock: big.NewInt(0),
|
||||||
DAOForkBlock: nil,
|
DAOForkBlock: nil,
|
||||||
DAOForkSupport: true,
|
DAOForkSupport: true,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue