Skip to content

Commit c6823c7

Browse files
karalabeholiman
authored andcommitted
consensus/clique, miner: remove clique -> accounts dependency (#30642)
Clique currently depends on the `accounts` package. This was a bit of a big cannon even in the past, just to pass a signer "account" to the Clique block producer. Either way, nowadays Geth does not support clique mining any more, so by removing that bit of functionality from our code, we can also break this dependency. Clique should ideally be further torn out, but this at least gets us one step closer to cleanups.
1 parent 26e1470 commit c6823c7

File tree

2 files changed

+3
-78
lines changed

2 files changed

+3
-78
lines changed

consensus/clique/clique.go

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727
"sync"
2828
"time"
2929

30-
"github.com/ethereum/go-ethereum/accounts"
3130
"github.com/ethereum/go-ethereum/common"
3231
"github.com/ethereum/go-ethereum/common/hexutil"
3332
"github.com/ethereum/go-ethereum/common/lru"
@@ -50,8 +49,6 @@ const (
5049
checkpointInterval = 1024 // Number of blocks after which to save the vote snapshot to the database
5150
inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory
5251
inmemorySignatures = 4096 // Number of recent block signatures to keep in memory
53-
54-
wiggleTime = 500 * time.Millisecond // Random delay (per signer) to allow concurrent signers
5552
)
5653

5754
// Clique proof-of-authority protocol constants.
@@ -140,9 +137,6 @@ var (
140137
errRecentlySigned = errors.New("recently signed")
141138
)
142139

143-
// SignerFn hashes and signs the data to be signed by a backing account.
144-
type SignerFn func(signer accounts.Account, mimeType string, message []byte) ([]byte, error)
145-
146140
// ecrecover extracts the Ethereum account address from a signed header.
147141
func ecrecover(header *types.Header, sigcache *sigLRU) (common.Address, error) {
148142
// If the signature's already cached, return that
@@ -180,7 +174,6 @@ type Clique struct {
180174
proposals map[common.Address]bool // Current list of proposals we are pushing
181175

182176
signer common.Address // Ethereum address of the signing key
183-
signFn SignerFn // Signer function to authorize hashes with
184177
lock sync.RWMutex // Protects the signer and proposals fields
185178

186179
// The fields below are for testing only
@@ -602,82 +595,17 @@ func (c *Clique) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *
602595

603596
// Authorize injects a private key into the consensus engine to mint new blocks
604597
// with.
605-
func (c *Clique) Authorize(signer common.Address, signFn SignerFn) {
598+
func (c *Clique) Authorize(signer common.Address) {
606599
c.lock.Lock()
607600
defer c.lock.Unlock()
608601

609602
c.signer = signer
610-
c.signFn = signFn
611603
}
612604

613605
// Seal implements consensus.Engine, attempting to create a sealed block using
614606
// the local signing credentials.
615607
func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error {
616-
header := block.Header()
617-
618-
// Sealing the genesis block is not supported
619-
number := header.Number.Uint64()
620-
if number == 0 {
621-
return errUnknownBlock
622-
}
623-
// For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing)
624-
if c.config.Period == 0 && len(block.Transactions()) == 0 {
625-
return errors.New("sealing paused while waiting for transactions")
626-
}
627-
// Don't hold the signer fields for the entire sealing procedure
628-
c.lock.RLock()
629-
signer, signFn := c.signer, c.signFn
630-
c.lock.RUnlock()
631-
632-
// Bail out if we're unauthorized to sign a block
633-
snap, err := c.snapshot(chain, number-1, header.ParentHash, nil)
634-
if err != nil {
635-
return err
636-
}
637-
if _, authorized := snap.Signers[signer]; !authorized {
638-
return errUnauthorizedSigner
639-
}
640-
// If we're amongst the recent signers, wait for the next block
641-
for seen, recent := range snap.Recents {
642-
if recent == signer {
643-
// Signer is among recents, only wait if the current block doesn't shift it out
644-
if limit := uint64(len(snap.Signers)/2 + 1); number < limit || seen > number-limit {
645-
return errors.New("signed recently, must wait for others")
646-
}
647-
}
648-
}
649-
// Sweet, the protocol permits us to sign the block, wait for our time
650-
delay := time.Unix(int64(header.Time), 0).Sub(time.Now()) // nolint: gosimple
651-
if header.Difficulty.Cmp(diffNoTurn) == 0 {
652-
// It's not our turn explicitly to sign, delay it a bit
653-
wiggle := time.Duration(len(snap.Signers)/2+1) * wiggleTime
654-
delay += time.Duration(rand.Int63n(int64(wiggle)))
655-
656-
log.Trace("Out-of-turn signing requested", "wiggle", common.PrettyDuration(wiggle))
657-
}
658-
// Sign all the things!
659-
sighash, err := signFn(accounts.Account{Address: signer}, accounts.MimetypeClique, CliqueRLP(header))
660-
if err != nil {
661-
return err
662-
}
663-
copy(header.Extra[len(header.Extra)-extraSeal:], sighash)
664-
// Wait until sealing is terminated or delay timeout.
665-
log.Trace("Waiting for slot to sign and propagate", "delay", common.PrettyDuration(delay))
666-
go func() {
667-
select {
668-
case <-stop:
669-
return
670-
case <-time.After(delay):
671-
}
672-
673-
select {
674-
case results <- block.WithSeal(header):
675-
default:
676-
log.Warn("Sealing result is not read by miner", "sealhash", SealHash(header))
677-
}
678-
}()
679-
680-
return nil
608+
panic("clique (poa) sealing not supported any more")
681609
}
682610

683611
// CalcDifficulty is the difficulty adjustment algorithm. It returns the difficulty

miner/payload_building_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"testing"
2323
"time"
2424

25-
"github.com/ethereum/go-ethereum/accounts"
2625
"github.com/ethereum/go-ethereum/beacon/engine"
2726
"github.com/ethereum/go-ethereum/common"
2827
"github.com/ethereum/go-ethereum/consensus"
@@ -114,9 +113,7 @@ func newTestWorkerBackend(t *testing.T, chainConfig *params.ChainConfig, engine
114113
case *clique.Clique:
115114
gspec.ExtraData = make([]byte, 32+common.AddressLength+crypto.SignatureLength)
116115
copy(gspec.ExtraData[32:32+common.AddressLength], testBankAddress.Bytes())
117-
e.Authorize(testBankAddress, func(account accounts.Account, s string, data []byte) ([]byte, error) {
118-
return crypto.Sign(crypto.Keccak256(data), testBankKey)
119-
})
116+
e.Authorize(testBankAddress)
120117
case *ethash.Ethash:
121118
default:
122119
t.Fatalf("unexpected consensus engine type: %T", engine)

0 commit comments

Comments
 (0)