mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32: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"
|
||||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"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/console"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"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 {
|
if err := stack.Service(ðereum); err != nil {
|
||||||
utils.Fatalf("Ethereum service not running: %v", err)
|
utils.Fatalf("Ethereum service not running: %v", err)
|
||||||
}
|
}
|
||||||
go func() {
|
if _, ok := ethereum.Engine().(*posv.Posv); ok {
|
||||||
started := false
|
go func() {
|
||||||
ok, err := ethereum.ValidateStaker()
|
started := false
|
||||||
if err != nil {
|
ok, err := ethereum.ValidateStaker()
|
||||||
utils.Fatalf("Can't verify validator permission: %v", err)
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// Set the gas price to the limits from the CLI and start mining
|
if ok {
|
||||||
ethereum.TxPool().SetGasPrice(cfg.Eth.GasPrice)
|
log.Info("Validator found. Enabling staking mode...")
|
||||||
if err := ethereum.StartStaking(true); err != nil {
|
// Use a reduced number of threads if requested
|
||||||
utils.Fatalf("Failed to start staking: %v", err)
|
if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 {
|
||||||
}
|
type threaded interface {
|
||||||
started = true
|
SetThreads(threads int)
|
||||||
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!!!")
|
|
||||||
}
|
}
|
||||||
} else if !started {
|
if th, ok := ethereum.Engine().(threaded); ok {
|
||||||
log.Info("Masternode found. Enabling staking mode...")
|
th.SetThreads(threads)
|
||||||
// Use a reduced number of threads if requested
|
}
|
||||||
if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 {
|
}
|
||||||
type threaded interface {
|
// Set the gas price to the limits from the CLI and start mining
|
||||||
SetThreads(threads int)
|
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 {
|
} else if !started {
|
||||||
th.SetThreads(threads)
|
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
|
case <-core.M1Ch:
|
||||||
ethereum.TxPool().SetGasPrice(cfg.Eth.GasPrice)
|
err := ethereum.BlockChain().UpdateM1()
|
||||||
if err := ethereum.StartStaking(true); err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("Failed to start staking: %v", err)
|
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
|
type WriteStatus byte
|
||||||
|
|
||||||
const (
|
const (
|
||||||
NonStatTy WriteStatus = iota
|
NonStatTy WriteStatus = iota
|
||||||
CanonStatTy
|
CanonStatTy
|
||||||
SideStatTy
|
SideStatTy
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue