Merge pull request #1 from shaspitz/shawn/period-ms

feat: 200ms blocktimes
This commit is contained in:
kant777 2023-11-15 12:19:42 -08:00 committed by GitHub
commit f481d9ca0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 24 additions and 19 deletions

View file

@ -329,7 +329,7 @@ func (c *Clique) verifyCascadingFields(chain consensus.ChainHeaderReader, header
if parent == nil || parent.Number.Uint64() != number-1 || parent.Hash() != header.ParentHash {
return consensus.ErrUnknownAncestor
}
if parent.Time+c.config.Period > header.Time {
if parent.Time+c.config.PeriodMs/1000 > header.Time {
return errInvalidTimestamp
}
// Verify that the gasUsed is <= gasLimit
@ -558,7 +558,7 @@ func (c *Clique) Prepare(chain consensus.ChainHeaderReader, header *types.Header
if parent == nil {
return consensus.ErrUnknownAncestor
}
header.Time = parent.Time + c.config.Period
header.Time = parent.Time + c.config.PeriodMs/1000
if header.Time < uint64(time.Now().Unix()) {
header.Time = uint64(time.Now().Unix())
}
@ -608,7 +608,7 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
return errUnknownBlock
}
// 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")
}
// Don't hold the signer fields for the entire sealing procedure
@ -648,6 +648,11 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
return err
}
copy(header.Extra[len(header.Extra)-extraSeal:], sighash)
// For now, hard code delay to 20ms less than block period.
// This may cause deadlocks with certain numbers of nodes, more testing is needed.
delay = time.Millisecond * (time.Duration(c.config.PeriodMs - 20))
// Wait until sealing is terminated or delay timeout.
log.Trace("Waiting for slot to sign and propagate", "delay", common.PrettyDuration(delay))
go func() {

View file

@ -414,8 +414,8 @@ func (tt *cliqueTest) run(t *testing.T) {
// Assemble a chain of headers from the cast votes
config := *params.TestChainConfig
config.Clique = &params.CliqueConfig{
Period: 1,
Epoch: tt.epoch,
PeriodMs: 1000,
Epoch: tt.epoch,
}
genesis.Config = &config

View file

@ -268,8 +268,8 @@ func waitForMiningState(t *testing.T, m *Miner, mining bool) {
func minerTestGenesisBlock(period uint64, gasLimit uint64, faucet common.Address) *core.Genesis {
config := *params.AllCliqueProtocolChanges
config.Clique = &params.CliqueConfig{
Period: period,
Epoch: config.Clique.Epoch,
PeriodMs: period,
Epoch: config.Clique.Epoch,
}
// Assemble and return the genesis with the precompiles and faucet pre-funded
@ -301,7 +301,7 @@ func createMiner(t *testing.T) (*Miner, *event.TypeMux, func(skipMiner bool)) {
// Create chainConfig
chainDB := rawdb.NewMemoryDatabase()
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)
if err != nil {
t.Fatalf("can't create new chain config: %v", err)

View file

@ -152,7 +152,7 @@ func makeGenesis(faucets []*ecdsa.PrivateKey, sealers []*ecdsa.PrivateKey) *core
genesis.GasLimit = 25000000
genesis.Config.ChainID = big.NewInt(18)
genesis.Config.Clique.Period = 1
genesis.Config.Clique.PeriodMs = 1000
genesis.Alloc = core.GenesisAlloc{}
for _, faucet := range faucets {

View file

@ -461,7 +461,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
case <-timer.C:
// If sealing is running resubmit a new work cycle periodically to pull in
// 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.
if w.newTxs.Load() == 0 {
timer.Reset(recommit)
@ -565,7 +565,7 @@ func (w *worker) mainLoop() {
// Special case, if the consensus engine is 0 period clique(dev mode),
// submit sealing work here since all empty submission will be rejected
// 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())
}
}

View file

@ -80,8 +80,8 @@ func init() {
cliqueChainConfig = new(params.ChainConfig)
*cliqueChainConfig = *params.TestChainConfig
cliqueChainConfig.Clique = &params.CliqueConfig{
Period: 10,
Epoch: 30000,
PeriodMs: 10000,
Epoch: 30000,
}
signer := types.LatestSigner(params.TestChainConfig)
@ -172,7 +172,7 @@ func TestGenerateAndImportBlock(t *testing.T) {
db = rawdb.NewMemoryDatabase()
config = *params.AllCliqueProtocolChanges
)
config.Clique = &params.CliqueConfig{Period: 1, Epoch: 30000}
config.Clique = &params.CliqueConfig{PeriodMs: 1000, Epoch: 30000}
engine := clique.New(config.Clique, db)
w, b := newTestWorker(t, &config, engine, db, 0)

View file

@ -128,8 +128,8 @@ var (
TerminalTotalDifficultyPassed: true,
ShanghaiTime: newUint64(1678832736),
Clique: &CliqueConfig{
Period: 15,
Epoch: 30000,
PeriodMs: 15000,
Epoch: 30000,
},
}
// AllEthashProtocolChanges contains every protocol change (EIPs) introduced
@ -210,7 +210,7 @@ var (
TerminalTotalDifficulty: nil,
TerminalTotalDifficultyPassed: false,
Ethash: nil,
Clique: &CliqueConfig{Period: 0, Epoch: 30000},
Clique: &CliqueConfig{PeriodMs: 0, Epoch: 30000},
}
// 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.
type CliqueConfig struct {
Period uint64 `json:"period"` // Number of seconds between blocks to enforce
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
PeriodMs uint64 `json:"period"` // Number of ms between blocks to enforce
Epoch uint64 `json:"epoch"` // Epoch length to reset votes and checkpoint
}
// String implements the stringer interface, returning the consensus engine details.