mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
fix unit tests
This commit is contained in:
parent
4a93b33256
commit
4ceb65f9a5
2 changed files with 65 additions and 62 deletions
125
cmd/tomo/main.go
125
cmd/tomo/main.go
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/accounts"
|
||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||
"github.com/ethereum/go-ethereum/consensus/posv"
|
||||
"github.com/ethereum/go-ethereum/console"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
"github.com/ethereum/go-ethereum/eth"
|
||||
|
|
@ -293,73 +294,75 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) {
|
|||
if err := stack.Service(ðereum); err != nil {
|
||||
utils.Fatalf("Ethereum service not running: %v", err)
|
||||
}
|
||||
go func() {
|
||||
started := false
|
||||
ok, err := ethereum.ValidateStaker()
|
||||
if err != nil {
|
||||
utils.Fatalf("Can't verify validator permission: %v", err)
|
||||
}
|
||||
if ok {
|
||||
log.Info("Validator found. Enabling staking mode...")
|
||||
// Use a reduced number of threads if requested
|
||||
if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 {
|
||||
type threaded interface {
|
||||
SetThreads(threads int)
|
||||
}
|
||||
if th, ok := ethereum.Engine().(threaded); ok {
|
||||
th.SetThreads(threads)
|
||||
}
|
||||
if _, ok := ethereum.Engine().(*posv.Posv); ok {
|
||||
go func() {
|
||||
started := false
|
||||
ok, err := ethereum.ValidateStaker()
|
||||
if err != nil {
|
||||
utils.Fatalf("Can't verify validator permission: %v", err)
|
||||
}
|
||||
// Set the gas price to the limits from the CLI and start mining
|
||||
ethereum.TxPool().SetGasPrice(cfg.Eth.GasPrice)
|
||||
if err := ethereum.StartStaking(true); err != nil {
|
||||
utils.Fatalf("Failed to start staking: %v", err)
|
||||
}
|
||||
started = true
|
||||
log.Info("Enabled staking node!!!")
|
||||
}
|
||||
defer close(core.CheckpointCh)
|
||||
defer close(core.M1Ch)
|
||||
for {
|
||||
select {
|
||||
case <-core.CheckpointCh:
|
||||
log.Info("Checkpoint!!! It's time to reconcile node's state...")
|
||||
ok, err := ethereum.ValidateStaker()
|
||||
if err != nil {
|
||||
utils.Fatalf("Can't verify masternode permission: %v", err)
|
||||
}
|
||||
if !ok {
|
||||
if started {
|
||||
log.Info("Only masternode can propose and verify blocks. Cancelling staking on this node...")
|
||||
ethereum.StopStaking()
|
||||
started = false
|
||||
log.Info("Cancelled mining mode!!!")
|
||||
if ok {
|
||||
log.Info("Validator found. Enabling staking mode...")
|
||||
// Use a reduced number of threads if requested
|
||||
if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 {
|
||||
type threaded interface {
|
||||
SetThreads(threads int)
|
||||
}
|
||||
} else if !started {
|
||||
log.Info("Masternode found. Enabling staking mode...")
|
||||
// Use a reduced number of threads if requested
|
||||
if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 {
|
||||
type threaded interface {
|
||||
SetThreads(threads int)
|
||||
if th, ok := ethereum.Engine().(threaded); ok {
|
||||
th.SetThreads(threads)
|
||||
}
|
||||
}
|
||||
// Set the gas price to the limits from the CLI and start mining
|
||||
ethereum.TxPool().SetGasPrice(cfg.Eth.GasPrice)
|
||||
if err := ethereum.StartStaking(true); err != nil {
|
||||
utils.Fatalf("Failed to start staking: %v", err)
|
||||
}
|
||||
started = true
|
||||
log.Info("Enabled staking node!!!")
|
||||
}
|
||||
defer close(core.CheckpointCh)
|
||||
defer close(core.M1Ch)
|
||||
for {
|
||||
select {
|
||||
case <-core.CheckpointCh:
|
||||
log.Info("Checkpoint!!! It's time to reconcile node's state...")
|
||||
ok, err := ethereum.ValidateStaker()
|
||||
if err != nil {
|
||||
utils.Fatalf("Can't verify masternode permission: %v", err)
|
||||
}
|
||||
if !ok {
|
||||
if started {
|
||||
log.Info("Only masternode can propose and verify blocks. Cancelling staking on this node...")
|
||||
ethereum.StopStaking()
|
||||
started = false
|
||||
log.Info("Cancelled mining mode!!!")
|
||||
}
|
||||
if th, ok := ethereum.Engine().(threaded); ok {
|
||||
th.SetThreads(threads)
|
||||
} else if !started {
|
||||
log.Info("Masternode found. Enabling staking mode...")
|
||||
// Use a reduced number of threads if requested
|
||||
if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 {
|
||||
type threaded interface {
|
||||
SetThreads(threads int)
|
||||
}
|
||||
if th, ok := ethereum.Engine().(threaded); ok {
|
||||
th.SetThreads(threads)
|
||||
}
|
||||
}
|
||||
// Set the gas price to the limits from the CLI and start mining
|
||||
ethereum.TxPool().SetGasPrice(cfg.Eth.GasPrice)
|
||||
if err := ethereum.StartStaking(true); err != nil {
|
||||
utils.Fatalf("Failed to start staking: %v", err)
|
||||
}
|
||||
started = true
|
||||
log.Info("Enabled staking node!!!")
|
||||
}
|
||||
// Set the gas price to the limits from the CLI and start mining
|
||||
ethereum.TxPool().SetGasPrice(cfg.Eth.GasPrice)
|
||||
if err := ethereum.StartStaking(true); err != nil {
|
||||
utils.Fatalf("Failed to start staking: %v", err)
|
||||
case <-core.M1Ch:
|
||||
err := ethereum.BlockChain().UpdateM1()
|
||||
if err != nil {
|
||||
log.Error("Error when update M1", err)
|
||||
}
|
||||
started = true
|
||||
log.Info("Enabled staking node!!!")
|
||||
}
|
||||
case <-core.M1Ch:
|
||||
err := ethereum.BlockChain().UpdateM1()
|
||||
if err != nil {
|
||||
log.Error("Error when update M1", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -698,7 +698,7 @@ func (bc *BlockChain) procFutureBlocks() {
|
|||
type WriteStatus byte
|
||||
|
||||
const (
|
||||
NonStatTy WriteStatus = iota
|
||||
NonStatTy WriteStatus = iota
|
||||
CanonStatTy
|
||||
SideStatTy
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue