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

Wb/fix testnet blockhash branching #630

Merged
merged 8 commits into from
Feb 16, 2023
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
8 changes: 8 additions & 0 deletions l2geth/consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const (
inmemorySignatures = 4096 // Number of recent block signatures to keep in memory

wiggleTime = 500 * time.Millisecond // Random delay (per signer) to allow concurrent signers

preUpgradedGaslimit = 15000000 //this params is only used for testnet
)

// Clique proof-of-authority protocol constants.
Expand Down Expand Up @@ -579,6 +581,12 @@ func (c *Clique) FinalizeAndAssemble(chain consensus.ChainReader, header *types.
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
header.UncleHash = types.CalcUncleHash(nil)

//this is only for testnet, if height< fixblockhash branch block height, set gaslimit = 15000000
//if height >= fixblockhash branch block height, use the config value
if !chain.Config().ISUpdateGaslimitBlock(header.Number) {
header.GasLimit = preUpgradedGaslimit
}

// Assemble and return the final block for sealing
return types.NewBlock(header, txs, nil, receipts), nil
}
Expand Down
45 changes: 29 additions & 16 deletions l2geth/params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,17 +215,15 @@ var (
//
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
AllEthashProtocolChanges = &ChainConfig{big.NewInt(108), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil}

AllEthashProtocolChanges = &ChainConfig{big.NewInt(108), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, big.NewInt(0), new(EthashConfig), nil}
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
// and accepted by the Ethereum core developers into the Clique consensus.
//
// This configuration is intentionally not using keyed fields to force anyone
// adding flags to the config to also have to set these fields.
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(420), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}}

TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, new(EthashConfig), nil}
TestRules = TestChainConfig.Rules(new(big.Int))
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(420), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, big.NewInt(0), nil, &CliqueConfig{Period: 0, Epoch: 30000}}
TestChainConfig = &ChainConfig{big.NewInt(1), big.NewInt(0), nil, false, big.NewInt(0), common.Hash{}, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, big.NewInt(0), new(EthashConfig), nil}
TestRules = TestChainConfig.Rules(new(big.Int))

// OpMainnetChainID is the ID of Mantle's mainnet chain.
OpMainnetChainID = big.NewInt(10)
Expand Down Expand Up @@ -311,6 +309,8 @@ type ChainConfig struct {

EWASMBlock *big.Int `json:"ewasmBlock,omitempty"` // EWASM switch block (nil = no fork, 0 = already activated)

UpdateGaslimitBlock *big.Int `json:"updateGaslimitBlock,omitempty"` // UpdateGaslimitBlock witch block (nil = no fork, 0 = already activated)

// Various consensus engines
Ethash *EthashConfig `json:"ethash,omitempty"`
Clique *CliqueConfig `json:"clique,omitempty"`
Expand Down Expand Up @@ -360,6 +360,7 @@ func (c *ChainConfig) String() string {
c.IstanbulBlock,
c.MuirGlacierBlock,
c.BerlinBlock,
c.UpdateGaslimitBlock,
engine,
)
}
Expand Down Expand Up @@ -426,6 +427,11 @@ func (c *ChainConfig) IsEWASM(num *big.Int) bool {
return isForked(c.EWASMBlock, num)
}

// ISUpdateGaslimitBlock returns whether num represents a block number after the UpdateGaslimitBlock fork
func (c *ChainConfig) ISUpdateGaslimitBlock(num *big.Int) bool {
return isForked(c.UpdateGaslimitBlock, num)
}

// IsSDUpdate returns whether num represents a block number after the SD update fork
func (c *ChainConfig) IsSDUpdate(num *big.Int) bool {
if c.ChainID.Cmp(OpMainnetChainID) == 0 {
Expand Down Expand Up @@ -474,6 +480,8 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
{"istanbulBlock", c.IstanbulBlock},
{"muirGlacierBlock", c.MuirGlacierBlock},
{name: "berlinBlock", block: c.BerlinBlock},
//we needn't to check config fork order for UpdateGaslimitBlock
//{name: "UpdateGaslimitBlock", block: c.UpdateGaslimitBlock},
} {
if lastFork.name != "" {
// Next one must be higher number
Expand Down Expand Up @@ -536,6 +544,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
if isForkIncompatible(c.EWASMBlock, newcfg.EWASMBlock, head) {
return newCompatError("ewasm fork block", c.EWASMBlock, newcfg.EWASMBlock)
}
if isForkIncompatible(c.UpdateGaslimitBlock, newcfg.UpdateGaslimitBlock, head) {
return newCompatError("UpdateGaslimitBlock fork block", c.UpdateGaslimitBlock, newcfg.UpdateGaslimitBlock)
}
return nil
}

Expand Down Expand Up @@ -604,6 +615,7 @@ type Rules struct {
IsHomestead, IsEIP150, IsEIP155, IsEIP158 bool
IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
IsBerlin bool
ISUpdateGaslimitBlock bool
}

// Rules ensures c's ChainID is not nil.
Expand All @@ -613,15 +625,16 @@ func (c *ChainConfig) Rules(num *big.Int) Rules {
chainID = new(big.Int)
}
return Rules{
ChainID: new(big.Int).Set(chainID),
IsHomestead: c.IsHomestead(num),
IsEIP150: c.IsEIP150(num),
IsEIP155: c.IsEIP155(num),
IsEIP158: c.IsEIP158(num),
IsByzantium: c.IsByzantium(num),
IsConstantinople: c.IsConstantinople(num),
IsPetersburg: c.IsPetersburg(num),
IsIstanbul: c.IsIstanbul(num),
IsBerlin: c.IsBerlin(num),
ChainID: new(big.Int).Set(chainID),
IsHomestead: c.IsHomestead(num),
IsEIP150: c.IsEIP150(num),
IsEIP155: c.IsEIP155(num),
IsEIP158: c.IsEIP158(num),
IsByzantium: c.IsByzantium(num),
IsConstantinople: c.IsConstantinople(num),
IsPetersburg: c.IsPetersburg(num),
IsIstanbul: c.IsIstanbul(num),
IsBerlin: c.IsBerlin(num),
ISUpdateGaslimitBlock: c.ISUpdateGaslimitBlock(num),
}
}
1 change: 1 addition & 0 deletions packages/contracts/deploy-config/goerli-qa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const config = {
l1BlockTimeSeconds: 15,
l2BlockGasLimit: 15_000_000,
l2ChainId: 1705003,
updateGaslimitBlock: 90000,
ctcL2GasDiscountDivisor: 32,
ctcEnqueueGasCost: 60_000,
sccFaultProofWindowSeconds: 0,
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/deploy-config/goerli-testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const config = {
l1BlockTimeSeconds: 15,
l2BlockGasLimit: 15_000_000,
l2ChainId: 5001,
updateGaslimitBlock: 222073,
ctcL2GasDiscountDivisor: 32,
ctcEnqueueGasCost: 60_000,
sccFaultProofWindowSeconds: 10,
Expand Down
1 change: 1 addition & 0 deletions packages/contracts/deploy-config/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const config = {
l1BlockTimeSeconds: 15,
l2BlockGasLimit: 15_000_000,
l2ChainId: 17,
updateGaslimitBlock: 10,
ctcL2GasDiscountDivisor: 32,
ctcEnqueueGasCost: 60_000,
sccFaultProofWindowSeconds: 0,
Expand Down
87 changes: 61 additions & 26 deletions packages/contracts/tasks/take-dump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,33 +162,68 @@ task('take-dump').setAction(async (args, hre) => {
commit = '0000000000000000000000000000000000000000'
}

const genesis = {
commit,
config: {
chainId: hre.deployConfig.l2ChainId,
homesteadBlock: 0,
eip150Block: 0,
eip155Block: 0,
eip158Block: 0,
byzantiumBlock: 0,
constantinopleBlock: 0,
petersburgBlock: 0,
istanbulBlock: 0,
muirGlacierBlock: 0,
berlinBlock: hre.deployConfig.hfBerlinBlock,
clique: {
period: 0,
epoch: 30000,
let genesis;
//if hre.deployConfig.l2ChainId === 5000, it is mainnet
//we needn't import it
if (hre.deployConfig.l2ChainId === 5000) {
genesis = {
commit,
config: {
chainId: hre.deployConfig.l2ChainId,
homesteadBlock: 0,
eip150Block: 0,
eip155Block: 0,
eip158Block: 0,
byzantiumBlock: 0,
constantinopleBlock: 0,
petersburgBlock: 0,
istanbulBlock: 0,
muirGlacierBlock: 0,
berlinBlock: hre.deployConfig.hfBerlinBlock,
clique: {
period: 0,
epoch: 30000,
},
},
},
difficulty: '1',
gasLimit: hre.deployConfig.l2BlockGasLimit.toString(10),
extradata:
'0x' +
'00'.repeat(32) +
remove0x(hre.deployConfig.bvmBlockSignerAddress) +
'00'.repeat(65),
alloc: dump,
difficulty: '1',
gasLimit: hre.deployConfig.l2BlockGasLimit.toString(10),
extradata:
'0x' +
'00'.repeat(32) +
remove0x(hre.deployConfig.bvmBlockSignerAddress) +
'00'.repeat(65),
alloc: dump,
}
}else{
genesis = {
commit,
config: {
chainId: hre.deployConfig.l2ChainId,
homesteadBlock: 0,
eip150Block: 0,
eip155Block: 0,
eip158Block: 0,
byzantiumBlock: 0,
constantinopleBlock: 0,
petersburgBlock: 0,
istanbulBlock: 0,
muirGlacierBlock: 0,
berlinBlock: hre.deployConfig.hfBerlinBlock,
updateGaslimitBlock: hre.deployConfig.updateGaslimitBlock,
clique: {
period: 0,
epoch: 30000,
},
},
difficulty: '1',
gasLimit: hre.deployConfig.l2BlockGasLimit.toString(10),
extradata:
'0x' +
'00'.repeat(32) +
remove0x(hre.deployConfig.bvmBlockSignerAddress) +
'00'.repeat(65),
alloc: dump,
}
}

// Make sure the output location exists
Expand Down