Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorize Clique & Parlia even when wrapped into Serenity #4354

Merged
merged 4 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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