mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-20 05:41:35 +00:00
added MINER-VALIDATOR
This commit is contained in:
parent
0cb82cf94f
commit
2a089900f5
3 changed files with 22 additions and 9 deletions
|
|
@ -294,9 +294,10 @@ func startNode(ctx *cli.Context, stack *node.Node) {
|
|||
if ok, err := ethereum.ValidateMiner(); err != nil {
|
||||
utils.Fatalf("Can't verify validator permission: %v", err)
|
||||
} else if !ok {
|
||||
utils.Fatalf("Only validator can mine blocks")
|
||||
log.Info("Only validator can mine blocks. Cancel mining on this node")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// Use a reduced number of threads if requested
|
||||
if threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name); threads > 0 {
|
||||
type threaded interface {
|
||||
|
|
|
|||
|
|
@ -367,6 +367,16 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainReader, header *type
|
|||
return c.verifySeal(chain, header, parents)
|
||||
}
|
||||
|
||||
func (c *Clique) GetSnapshot(chain consensus.ChainReader, header *types.Header) (*Snapshot, error) {
|
||||
number := header.Number.Uint64()
|
||||
log.Trace("take snapshot", "number", number, "hash", header.Hash())
|
||||
snap, err := c.snapshot(chain, number, header.Hash(), nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return snap, nil
|
||||
}
|
||||
|
||||
// snapshot retrieves the authorization snapshot at a given point in time.
|
||||
func (c *Clique) snapshot(chain consensus.ChainReader, number uint64, hash common.Hash, parents []*types.Header) (*Snapshot, error) {
|
||||
// Search for a snapshot in memory or on disk for checkpoints
|
||||
|
|
@ -575,8 +585,8 @@ func (c *Clique) Finalize(chain consensus.ChainReader, header *types.Header, sta
|
|||
chainReward := new(big.Int).SetUint64(chain.Config().Clique.Reward * params.Ether)
|
||||
|
||||
reward := new(big.Int).Set(chainReward)
|
||||
state.AddBalance(header.Coinbase, reward)
|
||||
|
||||
state.AddBalance(header.Coinbase, reward)
|
||||
|
||||
// No block rewards in PoA, so the state remains as is and uncles are dropped
|
||||
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
||||
header.UncleHash = types.CalcUncleHash(nil)
|
||||
|
|
@ -689,4 +699,4 @@ func (c *Clique) APIs(chain consensus.ChainReader) []rpc.API {
|
|||
Service: &API{chain: chain, clique: c},
|
||||
Public: false,
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
|
@ -339,17 +339,19 @@ func (s *Ethereum) ValidateMiner() (bool, error) {
|
|||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if c, ok := s.engine.(*clique.Clique); !ok {
|
||||
return false, fmt.Errorf("Only verify miners in Clique protocol")
|
||||
} else {
|
||||
if s.chainConfig.Clique != nil {
|
||||
//check if miner's wallet is in set of validators
|
||||
c := s.engine.(*clique.Clique)
|
||||
snap, err := c.GetSnapshot(s.blockchain, s.blockchain.CurrentHeader())
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("Can't verify miner: %v", err)
|
||||
}
|
||||
if _, authorized := snap.Signers[eb]; !authorized {
|
||||
return false, fmt.Errorf("This miner doesn't belong to set of validators")
|
||||
//This miner doesn't belong to set of validators
|
||||
return false, nil
|
||||
}
|
||||
} else {
|
||||
return false, fmt.Errorf("Only verify miners in Clique protocol")
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue