mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-11 06:23:47 +00:00
Period -> PeriodMs
This commit is contained in:
parent
3f907d6a6f
commit
9c1e5852f6
7 changed files with 21 additions and 19 deletions
|
|
@ -329,7 +329,7 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header
|
||||||
if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash {
|
if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash {
|
||||||
return consensus.ErrUnknownAncestor
|
return consensus.ErrUnknownAncestor
|
||||||
}
|
}
|
||||||
if parent.Time+c.config.Period > header.Time {
|
if parent.Time+c.config.PeriodMs/1000 > header.Time {
|
||||||
return errInvalidTimestamp
|
return errInvalidTimestamp
|
||||||
}
|
}
|
||||||
// Verify that the gasUsed is <= gasLimit
|
// Verify that the gasUsed is <= gasLimit
|
||||||
|
|
@ -558,7 +558,9 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header
|
||||||
if parent == nil {
|
if parent == nil {
|
||||||
return consensus.ErrUnknownAncestor
|
return consensus.ErrUnknownAncestor
|
||||||
}
|
}
|
||||||
header.Time = parent.Time + c.config.Period
|
// TODO: Need to handle that sub 1 second periods will never increment header.Time.
|
||||||
|
// Or maybe next line handles that?
|
||||||
|
header.Time = parent.Time + c.config.PeriodMs/1000
|
||||||
if header.Time < uint64(time.Now().Unix()) {
|
if header.Time < uint64(time.Now().Unix()) {
|
||||||
header.Time = uint64(time.Now().Unix())
|
header.Time = uint64(time.Now().Unix())
|
||||||
}
|
}
|
||||||
|
|
@ -608,7 +610,7 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
|
||||||
return errUnknownBlock
|
return errUnknownBlock
|
||||||
}
|
}
|
||||||
// For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing)
|
// For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing)
|
||||||
if c.config.Period == 0 && len(block.Transactions()) == 0 {
|
if c.config.PeriodMs == 0 && len(block.Transactions()) == 0 {
|
||||||
return errors.New("sealing paused while waiting for transactions")
|
return errors.New("sealing paused while waiting for transactions")
|
||||||
}
|
}
|
||||||
// Don't hold the signer fields for the entire sealing procedure
|
// Don't hold the signer fields for the entire sealing procedure
|
||||||
|
|
|
||||||
|
|
@ -414,8 +414,8 @@ func (tt *cliqueTest) run(t *testing.T) {
|
||||||
// Assemble a chain of headers from the cast votes
|
// Assemble a chain of headers from the cast votes
|
||||||
config := *params.TestChainConfig
|
config := *params.TestChainConfig
|
||||||
config.Clique = ¶ms.CliqueConfig{
|
config.Clique = ¶ms.CliqueConfig{
|
||||||
Period: 1,
|
PeriodMs: 1000,
|
||||||
Epoch: tt.epoch,
|
Epoch: tt.epoch,
|
||||||
}
|
}
|
||||||
genesis.Config = &config
|
genesis.Config = &config
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -261,8 +261,8 @@ func waitForMiningState(t *testing.T, m *Miner, mining bool) {
|
||||||
func minerTestGenesisBlock(period uint64, gasLimit uint64, faucet common.Address) *core.Genesis {
|
func minerTestGenesisBlock(period uint64, gasLimit uint64, faucet common.Address) *core.Genesis {
|
||||||
config := *params.AllCliqueProtocolChanges
|
config := *params.AllCliqueProtocolChanges
|
||||||
config.Clique = ¶ms.CliqueConfig{
|
config.Clique = ¶ms.CliqueConfig{
|
||||||
Period: period,
|
PeriodMs: period,
|
||||||
Epoch: config.Clique.Epoch,
|
Epoch: config.Clique.Epoch,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assemble and return the genesis with the precompiles and faucet pre-funded
|
// Assemble and return the genesis with the precompiles and faucet pre-funded
|
||||||
|
|
@ -294,7 +294,7 @@ func createMiner(t *testing.T) (*Miner, *event.TypeMux, func(skipMiner bool)) {
|
||||||
// Create chainConfig
|
// Create chainConfig
|
||||||
chainDB := rawdb.NewMemoryDatabase()
|
chainDB := rawdb.NewMemoryDatabase()
|
||||||
triedb := trie.NewDatabase(chainDB, nil)
|
triedb := trie.NewDatabase(chainDB, nil)
|
||||||
genesis := minerTestGenesisBlock(15, 11_500_000, common.HexToAddress("12345"))
|
genesis := minerTestGenesisBlock(15000, 11_500_000, common.HexToAddress("12345"))
|
||||||
chainConfig, _, err := core.SetupGenesisBlock(chainDB, triedb, genesis)
|
chainConfig, _, err := core.SetupGenesisBlock(chainDB, triedb, genesis)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("can't create new chain config: %v", err)
|
t.Fatalf("can't create new chain config: %v", err)
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey, sealers []*ecdsa.PrivateKey) *core
|
||||||
genesis.GasLimit = 25000000
|
genesis.GasLimit = 25000000
|
||||||
|
|
||||||
genesis.Config.ChainID = big.NewInt(18)
|
genesis.Config.ChainID = big.NewInt(18)
|
||||||
genesis.Config.Clique.Period = 1
|
genesis.Config.Clique.PeriodMs = 1000
|
||||||
|
|
||||||
genesis.Alloc = core.GenesisAlloc{}
|
genesis.Alloc = core.GenesisAlloc{}
|
||||||
for _, faucet := range faucets {
|
for _, faucet := range faucets {
|
||||||
|
|
|
||||||
|
|
@ -461,7 +461,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
// If sealing is running resubmit a new work cycle periodically to pull in
|
// If sealing is running resubmit a new work cycle periodically to pull in
|
||||||
// higher priced transactions. Disable this overhead for pending blocks.
|
// higher priced transactions. Disable this overhead for pending blocks.
|
||||||
if w.isRunning() && (w.chainConfig.Clique == nil || w.chainConfig.Clique.Period > 0) {
|
if w.isRunning() && (w.chainConfig.Clique == nil || w.chainConfig.Clique.PeriodMs > 0) {
|
||||||
// Short circuit if no new transaction arrives.
|
// Short circuit if no new transaction arrives.
|
||||||
if w.newTxs.Load() == 0 {
|
if w.newTxs.Load() == 0 {
|
||||||
timer.Reset(recommit)
|
timer.Reset(recommit)
|
||||||
|
|
@ -565,7 +565,7 @@ func (w *worker) mainLoop() {
|
||||||
// Special case, if the consensus engine is 0 period clique(dev mode),
|
// Special case, if the consensus engine is 0 period clique(dev mode),
|
||||||
// submit sealing work here since all empty submission will be rejected
|
// submit sealing work here since all empty submission will be rejected
|
||||||
// by clique. Of course the advance sealing(empty submission) is disabled.
|
// by clique. Of course the advance sealing(empty submission) is disabled.
|
||||||
if w.chainConfig.Clique != nil && w.chainConfig.Clique.Period == 0 {
|
if w.chainConfig.Clique != nil && w.chainConfig.Clique.PeriodMs == 0 {
|
||||||
w.commitWork(nil, time.Now().Unix())
|
w.commitWork(nil, time.Now().Unix())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,8 +80,8 @@ func init() {
|
||||||
cliqueChainConfig = new(params.ChainConfig)
|
cliqueChainConfig = new(params.ChainConfig)
|
||||||
*cliqueChainConfig = *params.TestChainConfig
|
*cliqueChainConfig = *params.TestChainConfig
|
||||||
cliqueChainConfig.Clique = ¶ms.CliqueConfig{
|
cliqueChainConfig.Clique = ¶ms.CliqueConfig{
|
||||||
Period: 10,
|
PeriodMs: 10000,
|
||||||
Epoch: 30000,
|
Epoch: 30000,
|
||||||
}
|
}
|
||||||
|
|
||||||
signer := types.LatestSigner(params.TestChainConfig)
|
signer := types.LatestSigner(params.TestChainConfig)
|
||||||
|
|
@ -171,7 +171,7 @@ func TestGenerateAndImportBlock(t *testing.T) {
|
||||||
db = rawdb.NewMemoryDatabase()
|
db = rawdb.NewMemoryDatabase()
|
||||||
config = *params.AllCliqueProtocolChanges
|
config = *params.AllCliqueProtocolChanges
|
||||||
)
|
)
|
||||||
config.Clique = ¶ms.CliqueConfig{Period: 1, Epoch: 30000}
|
config.Clique = ¶ms.CliqueConfig{PeriodMs: 1000, Epoch: 30000}
|
||||||
engine := clique.New(config.Clique, db)
|
engine := clique.New(config.Clique, db)
|
||||||
|
|
||||||
w, b := newTestWorker(t, &config, engine, db, 0)
|
w, b := newTestWorker(t, &config, engine, db, 0)
|
||||||
|
|
|
||||||
|
|
@ -128,8 +128,8 @@ var (
|
||||||
TerminalTotalDifficultyPassed: true,
|
TerminalTotalDifficultyPassed: true,
|
||||||
ShanghaiTime: newUint64(1678832736),
|
ShanghaiTime: newUint64(1678832736),
|
||||||
Clique: &CliqueConfig{
|
Clique: &CliqueConfig{
|
||||||
Period: 15,
|
PeriodMs: 15000,
|
||||||
Epoch: 30000,
|
Epoch: 30000,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
// AllEthashProtocolChanges contains every protocol change (EIPs) introduced
|
// AllEthashProtocolChanges contains every protocol change (EIPs) introduced
|
||||||
|
|
@ -210,7 +210,7 @@ var (
|
||||||
TerminalTotalDifficulty: nil,
|
TerminalTotalDifficulty: nil,
|
||||||
TerminalTotalDifficultyPassed: false,
|
TerminalTotalDifficultyPassed: false,
|
||||||
Ethash: nil,
|
Ethash: nil,
|
||||||
Clique: &CliqueConfig{Period: 0, Epoch: 30000},
|
Clique: &CliqueConfig{PeriodMs: 0, Epoch: 30000},
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestChainConfig contains every protocol change (EIPs) introduced
|
// TestChainConfig contains every protocol change (EIPs) introduced
|
||||||
|
|
@ -344,8 +344,8 @@ func (c *EthashConfig) String() string {
|
||||||
|
|
||||||
// CliqueConfig is the consensus engine configs for proof-of-authority based sealing.
|
// CliqueConfig is the consensus engine configs for proof-of-authority based sealing.
|
||||||
type CliqueConfig struct {
|
type CliqueConfig struct {
|
||||||
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
|
PeriodMs uint64 `json:"period"` // Number of ms between blocks to enforce
|
||||||
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
|
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements the stringer interface, returning the consensus engine details.
|
// String implements the stringer interface, returning the consensus engine details.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue