Skip to content

Commit

Permalink
Merge pull request ethereum#274 from ngtuna/sign-permission
Browse files Browse the repository at this point in the history
verify masternode permission for signing
  • Loading branch information
nguyenbatam authored Nov 10, 2018
2 parents 046ed99 + 151f6b5 commit ed9f363
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
8 changes: 4 additions & 4 deletions cmd/tomo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) {
if _, ok := ethereum.Engine().(*posv.Posv); ok {
go func() {
started := false
ok, err := ethereum.ValidateStaker()
ok, err := ethereum.ValidateMasternode()
if err != nil {
utils.Fatalf("Can't verify validator permission: %v", err)
utils.Fatalf("Can't verify masternode permission: %v", err)
}
if ok {
log.Info("Validator found. Enabling staking mode...")
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 {
Expand All @@ -314,7 +314,7 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) {
defer close(core.CheckpointCh)
for range core.CheckpointCh {
log.Info("Checkpoint!!! It's time to reconcile node's state...")
ok, err := ethereum.ValidateStaker()
ok, err := ethereum.ValidateMasternode()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
}
Expand Down
16 changes: 12 additions & 4 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
if eth.chainConfig.Posv != nil {
c := eth.engine.(*posv.Posv)
signHook := func(block *types.Block) error {
ok, err := eth.ValidateMasternode()
if err != nil {
return fmt.Errorf("Can't verify masternode permission: %v", err)
}
if !ok {
// silently return as this node doesn't have masternode permission to sign block
return nil
}
if err := contracts.CreateTransactionSign(chainConfig, eth.txPool, eth.accountManager, block, chainDb); err != nil {
return fmt.Errorf("Fail to create tx sign for importing block: %v", err)
}
Expand Down Expand Up @@ -497,8 +505,8 @@ func (self *Ethereum) SetEtherbase(etherbase common.Address) {
self.miner.SetEtherbase(etherbase)
}

// ValidateMiner checks if node's address is in set of validators
func (s *Ethereum) ValidateStaker() (bool, error) {
// ValidateMasternode checks if node's address is in set of masternodes
func (s *Ethereum) ValidateMasternode() (bool, error) {
eb, err := s.Etherbase()
if err != nil {
return false, err
Expand All @@ -508,14 +516,14 @@ func (s *Ethereum) ValidateStaker() (bool, error) {
c := s.engine.(*posv.Posv)
snap, err := c.GetSnapshot(s.blockchain, s.blockchain.CurrentHeader())
if err != nil {
return false, fmt.Errorf("Can't verify miner: %v", err)
return false, fmt.Errorf("Can't verify masternode permission: %v", err)
}
if _, authorized := snap.Signers[eb]; !authorized {
//This miner doesn't belong to set of validators
return false, nil
}
} else {
return false, fmt.Errorf("Only verify miners in Posv protocol")
return false, fmt.Errorf("Only verify masternode permission in PoSV protocol")
}
return true, nil
}
Expand Down

0 comments on commit ed9f363

Please sign in to comment.