Skip to content

Commit

Permalink
Authorize Clique & Parlia even when wrapped into Serenity (#4354)
Browse files Browse the repository at this point in the history
* Print more info on ErrUnauthorizedSigner

* Authorize Clique even when wrapped into Serenity

* Revert "Print more info on ErrUnauthorizedSigner"

This reverts commit b0ab83f.

* Authorize Parlia even when wrapped into Serenity
  • Loading branch information
yperbasis authored Jun 3, 2022
1 parent f838268 commit 53b30e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
7 changes: 6 additions & 1 deletion consensus/serenity/serenity.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ func New(eth1Engine consensus.Engine) *Serenity {
return &Serenity{eth1Engine: eth1Engine}
}

// Type returns underlying consensus engine
// InnerEngine returns the embedded eth1 consensus engine.
func (s *Serenity) InnerEngine() consensus.Engine {
return s.eth1Engine
}

// Type returns the type of the underlying consensus engine.
func (s *Serenity) Type() params.ConsensusType {
return s.eth1Engine.Type()
}
Expand Down
23 changes: 21 additions & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import (
"github.com/ledgerwatch/erigon/consensus/clique"
"github.com/ledgerwatch/erigon/consensus/ethash"
"github.com/ledgerwatch/erigon/consensus/parlia"
"github.com/ledgerwatch/erigon/consensus/serenity"
"github.com/ledgerwatch/erigon/core"
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/types"
Expand Down Expand Up @@ -620,23 +621,41 @@ func (s *Ethereum) StartMining(ctx context.Context, db kv.RwDB, mining *stagedsy
log.Error("Cannot start mining without etherbase", "err", err)
return fmt.Errorf("etherbase missing: %w", err)
}

var clq *clique.Clique
if c, ok := s.engine.(*clique.Clique); ok {
clq = c
} else if cl, ok := s.engine.(*serenity.Serenity); ok {
if c, ok := cl.InnerEngine().(*clique.Clique); ok {
clq = c
}
}
if clq != nil {
if cfg.SigKey == nil {
log.Error("Etherbase account unavailable locally", "err", err)
return fmt.Errorf("signer missing: %w", err)
}

c.Authorize(eb, func(_ common.Address, mimeType string, message []byte) ([]byte, error) {
clq.Authorize(eb, func(_ common.Address, mimeType string, message []byte) ([]byte, error) {
return crypto.Sign(crypto.Keccak256(message), cfg.SigKey)
})
}

var prl *parlia.Parlia
if p, ok := s.engine.(*parlia.Parlia); ok {
prl = p
} else if cl, ok := s.engine.(*serenity.Serenity); ok {
if p, ok := cl.InnerEngine().(*parlia.Parlia); ok {
prl = p
}
}
if prl != nil {
if cfg.SigKey == nil {
log.Error("Etherbase account unavailable locally", "err", err)
return fmt.Errorf("signer missing: %w", err)
}

p.Authorize(eb, func(validator common.Address, payload []byte, chainId *big.Int) ([]byte, error) {
prl.Authorize(eb, func(validator common.Address, payload []byte, chainId *big.Int) ([]byte, error) {
return crypto.Sign(payload, cfg.SigKey)
})
}
Expand Down

0 comments on commit 53b30e9

Please sign in to comment.