Merge pull request #194 from ngtuna/signed-recently

adjust condition for `signed recently` check
This commit is contained in:
Tuna 2018-09-27 14:38:51 +07:00 committed by GitHub
commit 904ba5312a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 50 deletions

View file

@ -20,12 +20,12 @@ import (
"bufio" "bufio"
"errors" "errors"
"fmt" "fmt"
"gopkg.in/urfave/cli.v1"
"io" "io"
"os" "os"
"reflect" "reflect"
"unicode"
"strings" "strings"
"gopkg.in/urfave/cli.v1" "unicode"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/dashboard" "github.com/ethereum/go-ethereum/dashboard"
@ -151,7 +151,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) {
ctx.Set(utils.NATFlag.Name, cfg.NAT) ctx.Set(utils.NATFlag.Name, cfg.NAT)
} }
// read passwords from enviroment // read passwords from environment
passwords := []string{} passwords := []string{}
for _, env := range cfg.Account.Passwords { for _, env := range cfg.Account.Passwords {
if trimmed := strings.TrimSpace(env); trimmed != "" { if trimmed := strings.TrimSpace(env); trimmed != "" {

View file

@ -321,40 +321,37 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) {
log.Info("Enabled staking node!!!") log.Info("Enabled staking node!!!")
} }
defer close(core.CheckpointCh) defer close(core.CheckpointCh)
for { for range core.CheckpointCh {
select { log.Info("Checkpoint!!! It's time to reconcile node's state...")
case <-core.CheckpointCh: ok, err := ethereum.ValidateStaker()
log.Info("Checkpoint!!! It's time to reconcile node's state...") if err != nil {
ok, err := ethereum.ValidateStaker() utils.Fatalf("Can't verify masternode permission: %v", err)
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 { } else if !started {
if started { log.Info("Masternode found. Enabling staking mode...")
log.Info("Only masternode can propose and verify blocks. Cancelling staking on this node...") // Use a reduced number of threads if requested
ethereum.StopStaking() if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 {
started = false type threaded interface {
log.Info("Cancelled mining mode!!!") SetThreads(threads int)
} }
} 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 {
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)
}
started = true
log.Info("Enabled staking node!!!")
} }
} }
}() }()

View file

@ -575,13 +575,16 @@ func (c *Posv) verifySeal(chain consensus.ChainReader, header *types.Header, par
return errUnauthorized return errUnauthorized
} }
} }
for seen, recent := range snap.Recents { if len(masternodes) > 1 {
if recent == signer { for seen, recent := range snap.Recents {
// Signer is among recents, only fail if the current block doesn't shift it out if recent == signer {
if limit := uint64(len(masternodes)/2 + 1); seen > number-limit { // Signer is among recents, only fail if the current block doesn't shift it out
// Only take into account the non-epoch blocks // There is only case that we don't allow signer to create two continuous blocks.
if number%c.config.Epoch != 0 { if limit := uint64(2); seen > number-limit {
return errUnauthorized // Only take into account the non-epoch blocks
if number%c.config.Epoch != 0 {
return errUnauthorized
}
} }
} }
} }
@ -755,16 +758,20 @@ func (c *Posv) Seal(chain consensus.ChainReader, block *types.Block, stop <-chan
} }
} }
// If we're amongst the recent signers, wait for the next block // If we're amongst the recent signers, wait for the next block
for seen, recent := range snap.Recents { // only check recent signers if there are more than one signer.
if recent == signer { if len(masternodes) > 1 {
// Signer is among recents, only wait if the current block doesn't shift it out for seen, recent := range snap.Recents {
if limit := uint64(len(masternodes)/2 + 1); number < limit || seen > number-limit { if recent == signer {
// Only take into account the non-epoch blocks // Signer is among recents, only wait if the current block doesn't shift it out
if number%c.config.Epoch != 0 { // There is only case that we don't allow signer to create two continuous blocks.
log.Info("Debugging", "len(masternodes)", len(masternodes), "number", number, "limit", limit, "seen", seen, "recent", recent.String(), "snap.Recents", snap.Recents) if limit := uint64(2); number < limit || seen > number-limit {
log.Info("Signed recently, must wait for others") // Only take into account the non-epoch blocks
<-stop if number%c.config.Epoch != 0 {
return nil, nil log.Info("Debugging", "len(masternodes)", len(masternodes), "number", number, "limit", limit, "seen", seen, "recent", recent.String(), "snap.Recents", snap.Recents)
log.Info("Signed recently, must wait for others")
<-stop
return nil, nil
}
} }
} }
} }