Skip to content

Commit

Permalink
bep153: Native Staking on BSC (bnb-chain#1051)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythonberg1997 committed Aug 18, 2022
1 parent ddbe6c4 commit 11d2bae
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
1 change: 1 addition & 0 deletions core/state_processor_test.go
Expand Up @@ -58,6 +58,7 @@ func TestStateProcessorErrors(t *testing.T) {
EulerBlock: big.NewInt(0),
BerlinBlock: big.NewInt(0),
LondonBlock: big.NewInt(0),
GibbsBlock: big.NewInt(0),
Ethash: new(params.EthashConfig),
}
signer = types.LatestSigner(config)
Expand Down
1 change: 1 addition & 0 deletions core/systemcontracts/const.go
Expand Up @@ -12,4 +12,5 @@ const (
GovHubContract = "0x0000000000000000000000000000000000001007"
TokenManagerContract = "0x0000000000000000000000000000000000001008"
CrossChainContract = "0x0000000000000000000000000000000000002000"
StakingContract = "0x0000000000000000000000000000000000002001"
)
37 changes: 37 additions & 0 deletions core/systemcontracts/upgrade.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions eth/gasprice/gasprice_test.go
Expand Up @@ -108,6 +108,7 @@ func newTestBackend(t *testing.T, londonBlock *big.Int, pending bool) *testBacke
)
config.LondonBlock = londonBlock
config.ArrowGlacierBlock = londonBlock
config.GibbsBlock = nil
engine := ethash.NewFaker()
db := rawdb.NewMemoryDatabase()
genesis, err := gspec.Commit(db)
Expand Down
35 changes: 30 additions & 5 deletions params/config.go
Expand Up @@ -279,6 +279,7 @@ var (
},
Threshold: 2,
}

BSCChainConfig = &ChainConfig{
ChainID: big.NewInt(56),
HomesteadBlock: big.NewInt(0),
Expand All @@ -296,6 +297,9 @@ var (
BrunoBlock: big.NewInt(13082000),
EulerBlock: big.NewInt(18907621),

//TODO
GibbsBlock: nil,

Parlia: &ParliaConfig{
Period: 3,
Epoch: 200,
Expand All @@ -319,6 +323,9 @@ var (
BrunoBlock: big.NewInt(13837000),
EulerBlock: big.NewInt(19203503),

//TODO
GibbsBlock: nil,

Parlia: &ParliaConfig{
Period: 3,
Epoch: 200,
Expand All @@ -340,7 +347,8 @@ var (
NielsBlock: big.NewInt(0),
MirrorSyncBlock: big.NewInt(400),
BrunoBlock: big.NewInt(400),
EulerBlock: nil,
EulerBlock: big.NewInt(400),
GibbsBlock: big.NewInt(400),

Parlia: &ParliaConfig{
Period: 3,
Expand All @@ -366,6 +374,7 @@ var (
MirrorSyncBlock: big.NewInt(0),
BrunoBlock: big.NewInt(0),
EulerBlock: big.NewInt(0),
GibbsBlock: big.NewInt(0),
MuirGlacierBlock: nil,
BerlinBlock: nil, // Don't enable Berlin directly, we're YOLOing it
YoloV3Block: big.NewInt(0),
Expand All @@ -380,16 +389,16 @@ 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(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), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), new(EthashConfig), nil, nil}
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), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), new(EthashConfig), nil, 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(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), big.NewInt(0), big.NewInt(0), nil, nil, big.NewInt(0), nil, nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}
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), big.NewInt(0), big.NewInt(0), nil, nil, big.NewInt(0), nil, nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, &CliqueConfig{Period: 0, Epoch: 30000}, nil}

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), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), new(EthashConfig), nil, nil}
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), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), nil, nil, big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), big.NewInt(0), new(EthashConfig), nil, nil}
TestRules = TestChainConfig.Rules(new(big.Int), false)
)

Expand Down Expand Up @@ -482,6 +491,7 @@ type ChainConfig struct {
MirrorSyncBlock *big.Int `json:"mirrorSyncBlock,omitempty" toml:",omitempty"` // mirrorSyncBlock switch block (nil = no fork, 0 = already activated)
BrunoBlock *big.Int `json:"brunoBlock,omitempty" toml:",omitempty"` // brunoBlock switch block (nil = no fork, 0 = already activated)
EulerBlock *big.Int `json:"eulerBlock,omitempty" toml:",omitempty"` // eulerBlock switch block (nil = no fork, 0 = already activated)
GibbsBlock *big.Int `json:"gibbsBlock,omitempty" toml:",omitempty"` // gibbsBlock switch block (nil = no fork, 0 = already activated)

// Various consensus engines
Ethash *EthashConfig `json:"ethash,omitempty" toml:",omitempty"`
Expand Down Expand Up @@ -532,7 +542,7 @@ func (c *ChainConfig) String() string {
default:
engine = "unknown"
}
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, Bruno: %v, Berlin: %v, YOLO v3: %v, CatalystBlock: %v, London: %v, ArrowGlacier: %v, MergeFork:%v, Euler: %v, Engine: %v}",
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, Bruno: %v, Berlin: %v, YOLO v3: %v, CatalystBlock: %v, London: %v, ArrowGlacier: %v, MergeFork:%v, Euler: %v, Gibbs: %v, Engine: %v}",
c.ChainID,
c.HomesteadBlock,
c.DAOForkBlock,
Expand All @@ -556,6 +566,7 @@ func (c *ChainConfig) String() string {
c.ArrowGlacierBlock,
c.MergeForkBlock,
c.EulerBlock,
c.GibbsBlock,
engine,
)
}
Expand Down Expand Up @@ -685,6 +696,16 @@ func (c *ChainConfig) IsTerminalPoWBlock(parentTotalDiff *big.Int, totalDiff *bi
return parentTotalDiff.Cmp(c.TerminalTotalDifficulty) < 0 && totalDiff.Cmp(c.TerminalTotalDifficulty) >= 0
}

// IsGibbs returns whether num is either equal to the gibbs fork block or greater.
func (c *ChainConfig) IsGibbs(num *big.Int) bool {
return isForked(c.GibbsBlock, num)
}

// IsOnGibbs returns whether num is equal to the gibbs fork block
func (c *ChainConfig) IsOnGibbs(num *big.Int) bool {
return configNumEqual(c.GibbsBlock, num)
}

// CheckCompatible checks whether scheduled fork transitions have been imported
// with a mismatching chain configuration.
func (c *ChainConfig) CheckCompatible(newcfg *ChainConfig, height uint64) *ConfigCompatError {
Expand Down Expand Up @@ -719,6 +740,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
{name: "berlinBlock", block: c.BerlinBlock},
{name: "londonBlock", block: c.LondonBlock},
{name: "arrowGlacierBlock", block: c.ArrowGlacierBlock, optional: true},
{name: "gibbsBlock", block: c.GibbsBlock},
{name: "mergeStartBlock", block: c.MergeForkBlock, optional: true},
} {
if lastFork.name != "" {
Expand Down Expand Up @@ -807,6 +829,9 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, head *big.Int) *Confi
if isForkIncompatible(c.EulerBlock, newcfg.EulerBlock, head) {
return newCompatError("euler fork block", c.EulerBlock, newcfg.EulerBlock)
}
if isForkIncompatible(c.GibbsBlock, newcfg.GibbsBlock, head) {
return newCompatError("gibbs fork block", c.GibbsBlock, newcfg.GibbsBlock)
}
return nil
}

Expand Down

0 comments on commit 11d2bae

Please sign in to comment.