minor makeup

This commit is contained in:
Tuna 2018-10-23 11:08:51 +07:00
parent a7c149d76b
commit 6b43905a23
2 changed files with 17 additions and 14 deletions

View file

@ -215,10 +215,10 @@ type Posv struct {
signFn clique.SignerFn // Signer function to authorize hashes with signFn clique.SignerFn // Signer function to authorize hashes with
lock sync.RWMutex // Protects the signer fields lock sync.RWMutex // Protects the signer fields
HookReward func(chain consensus.ChainReader, state *state.StateDB, header *types.Header) error HookReward func(chain consensus.ChainReader, state *state.StateDB, header *types.Header) error
HookPenalty func(chain consensus.ChainReader, blockNumberEpoc uint64) ([]common.Address, error) HookPenalty func(chain consensus.ChainReader, blockNumberEpoc uint64) ([]common.Address, error)
HookPrepare func(header *types.Header, signers []common.Address) error HookValidator func(header *types.Header, signers []common.Address) error
VerifyValidators func(header *types.Header, signers []common.Address) error HookVerifyMNs func(header *types.Header, signers []common.Address) error
} }
// New creates a Posv proof-of-stake-voting consensus engine with the initial // New creates a Posv proof-of-stake-voting consensus engine with the initial
@ -394,8 +394,8 @@ func (c *Posv) verifyCascadingFields(chain consensus.ChainReader, header *types.
if !bytes.Equal(header.Extra[extraVanity:extraSuffix], byteMasterNodes) { if !bytes.Equal(header.Extra[extraVanity:extraSuffix], byteMasterNodes) {
return errInvalidCheckpointSigners return errInvalidCheckpointSigners
} }
if c.VerifyValidators != nil { if c.HookVerifyMNs != nil {
err := c.VerifyValidators(header, signers) err := c.HookVerifyMNs(header, signers)
if err != nil { if err != nil {
return err return err
} }
@ -705,8 +705,8 @@ func (c *Posv) Prepare(chain consensus.ChainReader, header *types.Header) error
if header.Time.Int64() < time.Now().Unix() { if header.Time.Int64() < time.Now().Unix() {
header.Time = big.NewInt(time.Now().Unix()) header.Time = big.NewInt(time.Now().Unix())
} }
if c.HookPrepare != nil { if c.HookValidator != nil {
c.HookPrepare(header, signers) c.HookValidator(header, signers)
if err != nil { if err != nil {
return err return err
} }

View file

@ -190,7 +190,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
if eth.chainConfig.Posv != nil { if eth.chainConfig.Posv != nil {
c := eth.engine.(*posv.Posv) c := eth.engine.(*posv.Posv)
// Inject hook for send tx sign to smartcontract after insert block into chain. // Hook sends tx sign to smartcontract after inserting block to chain.
importedHook := func(block *types.Block) { importedHook := func(block *types.Block) {
snap, err := c.GetSnapshot(eth.blockchain, block.Header()) snap, err := c.GetSnapshot(eth.blockchain, block.Header())
if err != nil { if err != nil {
@ -210,8 +210,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
} }
eth.protocolManager.fetcher.SetImportedHook(importedHook) eth.protocolManager.fetcher.SetImportedHook(importedHook)
// Hook will process when preparing block. // Hook prepares validators M2 for the current epoch
c.HookPrepare = func(header *types.Header, signers []common.Address) error { c.HookValidator = func(header *types.Header, signers []common.Address) error {
number := header.Number.Int64() number := header.Number.Int64()
if number > 0 && number%common.EpocBlockRandomize == 0 { if number > 0 && number%common.EpocBlockRandomize == 0 {
validators, err := GetValidators(eth.blockchain, signers) validators, err := GetValidators(eth.blockchain, signers)
@ -222,7 +222,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
} }
return nil return nil
} }
// Hook penalty.
// Hook scans for bad masternodes and decide to penalty them
c.HookPenalty = func(chain consensus.ChainReader, blockNumberEpoc uint64) ([]common.Address, error) { c.HookPenalty = func(chain consensus.ChainReader, blockNumberEpoc uint64) ([]common.Address, error) {
client, err := eth.blockchain.GetClient() client, err := eth.blockchain.GetClient()
if err != nil { if err != nil {
@ -263,7 +264,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
return []common.Address{}, nil return []common.Address{}, nil
} }
// Hook reward for posv validator. // Hook calculates reward for masternodes
c.HookReward = func(chain consensus.ChainReader, state *state.StateDB, header *types.Header) error { c.HookReward = func(chain consensus.ChainReader, state *state.StateDB, header *types.Header) error {
client, err := eth.blockchain.GetClient() client, err := eth.blockchain.GetClient()
if err != nil { if err != nil {
@ -308,7 +309,9 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
return nil return nil
} }
c.VerifyValidators = func(header *types.Header, signers []common.Address) error {
// Hook verifies masternodes set
c.HookVerifyMNs = func(header *types.Header, signers []common.Address) error {
number := header.Number.Int64() number := header.Number.Int64()
if number > 0 && number%common.EpocBlockRandomize == 0 { if number > 0 && number%common.EpocBlockRandomize == 0 {
validators, err := GetValidators(eth.blockchain, signers) validators, err := GetValidators(eth.blockchain, signers)