mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
fix Stake Enable = true & remove check last index when insert chain
This commit is contained in:
parent
7c55084785
commit
4a93b33256
4 changed files with 87 additions and 85 deletions
|
|
@ -123,10 +123,11 @@ func defaultNodeConfig() node.Config {
|
||||||
func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) {
|
func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) {
|
||||||
// Load defaults.
|
// Load defaults.
|
||||||
cfg := tomoConfig{
|
cfg := tomoConfig{
|
||||||
Eth: eth.DefaultConfig,
|
Eth: eth.DefaultConfig,
|
||||||
Shh: whisper.DefaultConfig,
|
Shh: whisper.DefaultConfig,
|
||||||
Node: defaultNodeConfig(),
|
Node: defaultNodeConfig(),
|
||||||
Dashboard: dashboard.DefaultConfig,
|
Dashboard: dashboard.DefaultConfig,
|
||||||
|
StakeEnable: true,
|
||||||
}
|
}
|
||||||
// Load config file.
|
// Load config file.
|
||||||
if file := ctx.GlobalString(configFileFlag.Name); file != "" {
|
if file := ctx.GlobalString(configFileFlag.Name); file != "" {
|
||||||
|
|
@ -134,7 +135,9 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) {
|
||||||
utils.Fatalf("%v", err)
|
utils.Fatalf("%v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ctx.GlobalIsSet(utils.StakingEnabledFlag.Name) {
|
||||||
|
cfg.StakeEnable = ctx.GlobalBool(utils.StakingEnabledFlag.Name)
|
||||||
|
}
|
||||||
// read passwords from enviroment
|
// read passwords from enviroment
|
||||||
passwords := []string{}
|
passwords := []string{}
|
||||||
for _, env := range cfg.Account.Passwords {
|
for _, env := range cfg.Account.Passwords {
|
||||||
|
|
|
||||||
155
cmd/tomo/main.go
155
cmd/tomo/main.go
|
|
@ -284,83 +284,82 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
// Start auxiliary services if enabled
|
// Start auxiliary services if enabled
|
||||||
if cfg.StakeEnable || ctx.GlobalBool(utils.DeveloperFlag.Name) {
|
|
||||||
// Mining only makes sense if a full Ethereum node is running
|
// Mining only makes sense if a full Ethereum node is running
|
||||||
if ctx.GlobalBool(utils.LightModeFlag.Name) || ctx.GlobalString(utils.SyncModeFlag.Name) == "light" {
|
if ctx.GlobalBool(utils.LightModeFlag.Name) || ctx.GlobalString(utils.SyncModeFlag.Name) == "light" {
|
||||||
utils.Fatalf("Light clients do not support staking")
|
utils.Fatalf("Light clients do not support staking")
|
||||||
}
|
|
||||||
var ethereum *eth.Ethereum
|
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 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!!!")
|
|
||||||
}
|
|
||||||
} 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!!!")
|
|
||||||
}
|
|
||||||
case <-core.M1Ch:
|
|
||||||
err := ethereum.BlockChain().UpdateM1()
|
|
||||||
if(err !=nil){
|
|
||||||
log.Error("Error when update M1",err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
|
var ethereum *eth.Ethereum
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 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!!!")
|
||||||
|
}
|
||||||
|
} 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!!!")
|
||||||
|
}
|
||||||
|
case <-core.M1Ch:
|
||||||
|
err := ethereum.BlockChain().UpdateM1()
|
||||||
|
if err != nil {
|
||||||
|
log.Error("Error when update M1", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1192,7 +1192,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty
|
||||||
stats.processed++
|
stats.processed++
|
||||||
stats.usedGas += usedGas
|
stats.usedGas += usedGas
|
||||||
stats.report(chain, i, bc.stateCache.TrieDB().Size())
|
stats.report(chain, i, bc.stateCache.TrieDB().Size())
|
||||||
if i == len(chain)-1 && bc.chainConfig.Posv != nil {
|
if bc.chainConfig.Posv != nil {
|
||||||
// epoch block
|
// epoch block
|
||||||
if (chain[i].NumberU64() % bc.chainConfig.Posv.Epoch) == 0 {
|
if (chain[i].NumberU64() % bc.chainConfig.Posv.Epoch) == 0 {
|
||||||
CheckpointCh <- 1
|
CheckpointCh <- 1
|
||||||
|
|
|
||||||
|
|
@ -1350,7 +1350,7 @@ func (d *Downloader) processFullSyncContent() error {
|
||||||
// prepare set of masternodes for the next epoch
|
// prepare set of masternodes for the next epoch
|
||||||
if (inserts[len(inserts)-1].Header.Number.Uint64() % epoch) == (epoch - gap) {
|
if (inserts[len(inserts)-1].Header.Number.Uint64() % epoch) == (epoch - gap) {
|
||||||
err := d.blockchain.UpdateM1()
|
err := d.blockchain.UpdateM1()
|
||||||
if (err != nil) {
|
if err != nil {
|
||||||
log.Error("Error when update M1", err)
|
log.Error("Error when update M1", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue