added MINER-VALIDATOR

This commit is contained in:
AnilChinchawale 2018-06-18 10:46:57 +05:30
parent 0cb82cf94f
commit 2a089900f5
3 changed files with 22 additions and 9 deletions

View file

@ -294,7 +294,8 @@ func startNode(ctx *cli.Context, stack *node.Node) {
if ok, err := ethereum.ValidateMiner(); err != nil { if ok, err := ethereum.ValidateMiner(); err != nil {
utils.Fatalf("Can't verify validator permission: %v", err) utils.Fatalf("Can't verify validator permission: %v", err)
} else if !ok { } 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 // Use a reduced number of threads if requested

View file

@ -367,6 +367,16 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainReader, header *type
return c.verifySeal(chain, header, parents) 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. // 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) { 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 // Search for a snapshot in memory or on disk for checkpoints

View file

@ -339,17 +339,19 @@ func (s *Ethereum) ValidateMiner() (bool, error) {
if err != nil { if err != nil {
return false, err return false, err
} }
if c, ok := s.engine.(*clique.Clique); !ok { if s.chainConfig.Clique != nil {
return false, fmt.Errorf("Only verify miners in Clique protocol")
} else {
//check if miner's wallet is in set of validators //check if miner's wallet is in set of validators
c := s.engine.(*clique.Clique)
snap, err := c.GetSnapshot(s.blockchain, s.blockchain.CurrentHeader()) snap, err := c.GetSnapshot(s.blockchain, s.blockchain.CurrentHeader())
if err != nil { if err != nil {
return false, fmt.Errorf("Can't verify miner: %v", err) return false, fmt.Errorf("Can't verify miner: %v", err)
} }
if _, authorized := snap.Signers[eb]; !authorized { 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 return true, nil
} }