Skip to content

Commit e09e48a

Browse files
author
HaoyangLiu
authored
R4R: apply mirror sync upgrade (bnb-chain#56)
* apply mirror sync upgrade remove 0x update rialto genesis hash update tokenhub code * update tokenhub code * update relayer incentive contract code * update upgrade height and remove mainnet upgrade
1 parent b605f1f commit e09e48a

File tree

4 files changed

+104
-6
lines changed

4 files changed

+104
-6
lines changed

cmd/geth/retesteth.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ type CParamsParams struct {
135135
ConstantinopleFixForkBlock *math.HexOrDecimal64 `json:"constantinopleFixForkBlock"`
136136
IstanbulBlock *math.HexOrDecimal64 `json:"istanbulForkBlock"`
137137
RamanujanForkBlock *math.HexOrDecimal64 `json:"ramanujanForkBlock"`
138+
MirrorSyncForkBlock *math.HexOrDecimal64 `json:"mirrorSyncForkBlock"`
138139
ChainID *math.HexOrDecimal256 `json:"chainID"`
139140
MaximumExtraDataSize math.HexOrDecimal64 `json:"maximumExtraDataSize"`
140141
TieBreakingGas bool `json:"tieBreakingGas"`
@@ -325,6 +326,7 @@ func (api *RetestethAPI) SetChainParams(ctx context.Context, chainParams ChainPa
325326
petersburgBlock *big.Int
326327
istanbulBlock *big.Int
327328
ramanujanBlock *big.Int
329+
mirrorSyncBlock *big.Int
328330
)
329331
if chainParams.Params.HomesteadForkBlock != nil {
330332
homesteadBlock = big.NewInt(int64(*chainParams.Params.HomesteadForkBlock))
@@ -357,6 +359,9 @@ func (api *RetestethAPI) SetChainParams(ctx context.Context, chainParams ChainPa
357359
if chainParams.Params.RamanujanForkBlock != nil {
358360
ramanujanBlock = big.NewInt(int64(*chainParams.Params.RamanujanForkBlock))
359361
}
362+
if chainParams.Params.MirrorSyncForkBlock != nil {
363+
mirrorSyncBlock = big.NewInt(int64(*chainParams.Params.MirrorSyncForkBlock))
364+
}
360365

361366
genesis := &core.Genesis{
362367
Config: &params.ChainConfig{
@@ -372,6 +377,7 @@ func (api *RetestethAPI) SetChainParams(ctx context.Context, chainParams ChainPa
372377
PetersburgBlock: petersburgBlock,
373378
IstanbulBlock: istanbulBlock,
374379
RamanujanBlock: ramanujanBlock,
380+
MirrorSyncBlock: mirrorSyncBlock,
375381
},
376382
Nonce: uint64(chainParams.Genesis.Nonce),
377383
Timestamp: uint64(chainParams.Genesis.Timestamp),

core/genesis.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
256256
return params.RinkebyChainConfig
257257
case ghash == params.GoerliGenesisHash:
258258
return params.GoerliChainConfig
259+
case ghash == params.BSCGenesisHash:
260+
return params.BSCChainConfig
259261
case ghash == params.ChapelGenesisHash:
260262
return params.ChapelChainConfig
261263
case ghash == params.RialtoGenesisHash:

core/systemcontracts/upgrade.go

Lines changed: 51 additions & 1 deletion
Large diffs are not rendered by default.

params/config.go

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ var (
3232
RinkebyGenesisHash = common.HexToHash("0x6341fd3daf94b748c72ced5a5b26028f2474f5f00d824504e4fa37a75767e177")
3333
GoerliGenesisHash = common.HexToHash("0xbf7e331f7f7c1dd2e05159666b3bf8bc7a8a3a9eb1d518969eab529dd9b88c1a")
3434

35+
BSCGenesisHash = common.HexToHash("0x0d21840abff46b96c84b2ac9e10e4f5cdaeb5693cb665db62a2f3b02d2d57b5b")
3536
ChapelGenesisHash = common.HexToHash("0x6d3c66c5357ec91d5c43af47e234a939b22557cbb552dc45bebbceeed90fbe34")
36-
RialtoGenesisHash = common.HexToHash("0xaa1c1e0af675e846942719466ab72822eff51ebf8462ead0897ae1240e3c0da1")
37+
RialtoGenesisHash = common.HexToHash("0x005dc005bddd1967de6187c1c23be801eb7abdd80cebcc24f341b727b70311d6")
3738
)
3839

3940
// TrustedCheckpoints associates each known checkpoint with the genesis hash of
@@ -213,6 +214,26 @@ var (
213214
Threshold: 2,
214215
}
215216

217+
BSCChainConfig = &ChainConfig{
218+
ChainID: big.NewInt(56),
219+
HomesteadBlock: big.NewInt(0),
220+
EIP150Block: big.NewInt(0),
221+
EIP155Block: big.NewInt(0),
222+
EIP158Block: big.NewInt(0),
223+
ByzantiumBlock: big.NewInt(0),
224+
ConstantinopleBlock: big.NewInt(0),
225+
PetersburgBlock: big.NewInt(0),
226+
IstanbulBlock: big.NewInt(0),
227+
MuirGlacierBlock: big.NewInt(0),
228+
RamanujanBlock: big.NewInt(0),
229+
NielsBlock: big.NewInt(0),
230+
MirrorSyncBlock: big.NewInt(0),
231+
Parlia: &ParliaConfig{
232+
Period: 3,
233+
Epoch: 200,
234+
},
235+
}
236+
216237
ChapelChainConfig = &ChainConfig{
217238
ChainID: big.NewInt(97),
218239
HomesteadBlock: big.NewInt(0),
@@ -226,6 +247,7 @@ var (
226247
MuirGlacierBlock: big.NewInt(0),
227248
RamanujanBlock: big.NewInt(1010000),
228249
NielsBlock: big.NewInt(1014369),
250+
MirrorSyncBlock: big.NewInt(5582500),
229251
Parlia: &ParliaConfig{
230252
Period: 3,
231253
Epoch: 200,
@@ -245,6 +267,7 @@ var (
245267
MuirGlacierBlock: big.NewInt(0),
246268
RamanujanBlock: big.NewInt(400),
247269
NielsBlock: big.NewInt(0),
270+
MirrorSyncBlock: big.NewInt(400),
248271
Parlia: &ParliaConfig{
249272
Period: 3,
250273
Epoch: 200,
@@ -256,16 +279,16 @@ var (
256279
//
257280
// This configuration is intentionally not using keyed fields to force anyone
258281
// adding flags to the config to also have to set these fields.
259-
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), 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), nil, nil, nil, nil, new(EthashConfig), nil, nil}
282+
AllEthashProtocolChanges = &ChainConfig{big.NewInt(1337), 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), nil, nil, nil, nil, nil, new(EthashConfig), nil, nil}
260283

261284
// AllCliqueProtocolChanges contains every protocol change (EIPs) introduced
262285
// and accepted by the Ethereum core developers into the Clique consensus.
263286
//
264287
// This configuration is intentionally not using keyed fields to force anyone
265288
// adding flags to the config to also have to set these fields.
266-
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), 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), nil, nil, nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
289+
AllCliqueProtocolChanges = &ChainConfig{big.NewInt(1337), 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), nil, nil, nil, nil, nil, nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
267290

268-
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), nil, nil, nil, nil, new(EthashConfig), nil, nil}
291+
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), nil, nil, nil, nil, nil, new(EthashConfig), nil, nil}
269292
TestRules = TestChainConfig.Rules(new(big.Int))
270293
)
271294

@@ -339,6 +362,7 @@ type ChainConfig struct {
339362
EWASMBlock *big.Int `json:"ewasmBlock,omitempty" toml:",omitempty"` // EWASM switch block (nil = no fork, 0 = already activated)
340363
RamanujanBlock *big.Int `json:"ramanujanBlock,omitempty" toml:",omitempty"` // ramanujanBlock switch block (nil = no fork, 0 = already activated)
341364
NielsBlock *big.Int `json:"nielsBlock,omitempty" toml:",omitempty"` // nielsBlock switch block (nil = no fork, 0 = already activated)
365+
MirrorSyncBlock *big.Int `json:"mirrorSyncBlock,omitempty" toml:",omitempty"` // mirrorSyncBlock switch block (nil = no fork, 0 = already activated)
342366

343367
// Various consensus engines
344368
Ethash *EthashConfig `json:"ethash,omitempty" toml:",omitempty"`
@@ -389,7 +413,7 @@ func (c *ChainConfig) String() string {
389413
default:
390414
engine = "unknown"
391415
}
392-
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, Engine: %v}",
416+
return fmt.Sprintf("{ChainID: %v Homestead: %v DAO: %v DAOSupport: %v EIP150: %v EIP155: %v EIP158: %v Byzantium: %v Constantinople: %v Petersburg: %v Istanbul: %v, Muir Glacier: %v, Ramanujan: %v, Niels: %v, MirrorSync: %v, Engine: %v}",
393417
c.ChainID,
394418
c.HomesteadBlock,
395419
c.DAOForkBlock,
@@ -404,6 +428,7 @@ func (c *ChainConfig) String() string {
404428
c.MuirGlacierBlock,
405429
c.RamanujanBlock,
406430
c.NielsBlock,
431+
c.MirrorSyncBlock,
407432
engine,
408433
)
409434
}
@@ -463,6 +488,17 @@ func (c *ChainConfig) IsOnNiels(num *big.Int) bool {
463488
return configNumEqual(c.NielsBlock, num)
464489
}
465490

491+
// IsMirrorSync returns whether num is either equal to the MirrorSync fork block or greater.
492+
func (c *ChainConfig) IsMirrorSync(num *big.Int) bool {
493+
return isForked(c.MirrorSyncBlock, num)
494+
}
495+
496+
// IsOnMirrorSync returns whether num is equal to the MirrorSync fork block
497+
func (c *ChainConfig) IsOnMirrorSync(num *big.Int) bool {
498+
return configNumEqual(c.MirrorSyncBlock, num)
499+
}
500+
501+
466502
// IsMuirGlacier returns whether num is either equal to the Muir Glacier (EIP-2384) fork block or greater.
467503
func (c *ChainConfig) IsMuirGlacier(num *big.Int) bool {
468504
return isForked(c.MuirGlacierBlock, num)
@@ -522,6 +558,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
522558
{"istanbulBlock", c.IstanbulBlock},
523559
{"muirGlacierBlock", c.MuirGlacierBlock},
524560
{"ramanujanBlock", c.RamanujanBlock},
561+
{"mirrorSyncBlock", c.MirrorSyncBlock},
525562
} {
526563
if lastFork.name != "" {
527564
// Next one must be higher number
@@ -584,6 +621,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
584621
if isForkIncompatible(c.RamanujanBlock, newcfg.RamanujanBlock, head) {
585622
return newCompatError("ramanujan fork block", c.RamanujanBlock, newcfg.RamanujanBlock)
586623
}
624+
if isForkIncompatible(c.MirrorSyncBlock, newcfg.MirrorSyncBlock, head) {
625+
return newCompatError("mirrorSync fork block", c.MirrorSyncBlock, newcfg.MirrorSyncBlock)
626+
}
587627
return nil
588628
}
589629

0 commit comments

Comments
 (0)