Skip to content

Commit

Permalink
Merge pull request #1013 from bnb-chain/develop
Browse files Browse the repository at this point in the history
feat: implement BEP-333(BNB Chain Fusion) (#1003)
  • Loading branch information
unclezoro authored Feb 28, 2024
2 parents 13bb81c + 1d1b11e commit f9792ca
Show file tree
Hide file tree
Showing 32 changed files with 860 additions and 195 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## v0.10.17
This is the release for the sunset of BNB Beacon Chain.

FEATURES
* [\#977](https://github.com/bnb-chain/node/pull/1003) [BEP] feat: implement BEP-333(BNB Chain Fusion)


## v0.10.16
FEATURES
* [\#977](https://github.com/bnb-chain/node/pull/977) [BEP] asset: add bep255 upgrade height for mainnet
Expand Down
26 changes: 25 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ import (
"github.com/bnb-chain/node/plugins/dex/list"
"github.com/bnb-chain/node/plugins/dex/order"
dextypes "github.com/bnb-chain/node/plugins/dex/types"
migrate "github.com/bnb-chain/node/plugins/migrate"
tokenRecover "github.com/bnb-chain/node/plugins/recover"
"github.com/bnb-chain/node/plugins/tokens"
"github.com/bnb-chain/node/plugins/tokens/issue"
"github.com/bnb-chain/node/plugins/tokens/ownership"
"github.com/bnb-chain/node/plugins/tokens/seturi"
"github.com/bnb-chain/node/plugins/tokens/swap"
"github.com/bnb-chain/node/plugins/tokens/timelock"
"github.com/bnb-chain/node/wire"
stakeMigration "github.com/cosmos/cosmos-sdk/x/stake/stake_migration"
)

const (
Expand Down Expand Up @@ -359,6 +362,9 @@ func SetUpgradeConfig(upgradeConfig *config.UpgradeConfig) {
upgrade.Mgr.AddUpgradeHeight(upgrade.FixDoubleSignChainId, upgradeConfig.FixDoubleSignChainIdHeight)
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP126, upgradeConfig.BEP126Height)
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP255, upgradeConfig.BEP255Height)
upgrade.Mgr.AddUpgradeHeight(upgrade.FirstSunset, upgradeConfig.FirstSunsetHeight)
upgrade.Mgr.AddUpgradeHeight(upgrade.SecondSunset, upgradeConfig.SecondSunsetHeight)
upgrade.Mgr.AddUpgradeHeight(upgrade.FinalSunset, upgradeConfig.FinalSunsetHeight)

// register store keys of upgrade
upgrade.Mgr.RegisterStoreKeys(upgrade.BEP9, common.TimeLockStoreKey.Name())
Expand Down Expand Up @@ -619,6 +625,11 @@ func (app *BNBBeaconChain) initStaking() {
newCtx := ctx.WithSideChainKeyPrefix(storePrefix)
app.stakeKeeper.ClearUpSideVoteAddrs(newCtx)
})
upgrade.Mgr.RegisterBeginBlocker(sdk.FirstSunsetFork, func(ctx sdk.Context) {
chainId := sdk.ChainID(ServerContext.BscIbcChainId)
// enable channel but not send cross chain msg
app.scKeeper.SetChannelSendPermission(ctx, chainId, sTypes.StakeMigrationChannelID, sdk.ChannelAllow)
})
app.stakeKeeper.SubscribeParamChange(app.ParamHub)
app.stakeKeeper.SubscribeBCParamChange(app.ParamHub)
app.stakeKeeper = app.stakeKeeper.WithHooks(app.slashKeeper.Hooks())
Expand All @@ -629,6 +640,13 @@ func (app *BNBBeaconChain) initStaking() {
if err != nil {
panic(err)
}

// register stake migration channel
stakeMigrationApp := stakeMigration.NewStakeMigrationApp(app.stakeKeeper)
err = app.scKeeper.RegisterChannel(sTypes.StakeMigrationChannel, sTypes.StakeMigrationChannelID, stakeMigrationApp)
if err != nil {
panic(err)
}
}

func (app *BNBBeaconChain) initGov() {
Expand Down Expand Up @@ -880,7 +898,7 @@ func (app *BNBBeaconChain) isBreatheBlock(height int64, lastBlockTime time.Time,
// lastBlockTime is zero if this blockTime is for the first block (first block doesn't mean height = 1, because after
// state sync from breathe block, the height is breathe block + 1)
if app.baseConfig.BreatheBlockInterval > 0 {
return height%int64(app.baseConfig.BreatheBlockInterval) == 0
return !lastBlockTime.IsZero() && !utils.SamePeriodInUTC(lastBlockTime, blockTime, int64(app.baseConfig.BreatheBlockInterval))
} else {
return !lastBlockTime.IsZero() && !utils.SameDayInUTC(lastBlockTime, blockTime)
}
Expand Down Expand Up @@ -918,6 +936,7 @@ func (app *BNBBeaconChain) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock)
tokens.EndBreatheBlock(ctx, app.swapKeeper)
} else {
app.Logger.Debug("normal block", "height", height)
tokens.EndBlocker(ctx, app.timeLockKeeper, app.swapKeeper)
}

app.DexKeeper.StoreTradePrices(ctx)
Expand Down Expand Up @@ -945,6 +964,9 @@ func (app *BNBBeaconChain) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock)
} else if ctx.RouterCallRecord()["stake"] || sdk.IsUpgrade(upgrade.BEP128) {
validatorUpdates, completedUbd = stake.EndBlocker(ctx, app.stakeKeeper)
}

// That is no deep copy when New IBC Keeper. need to set it again.
app.ibcKeeper.SetSideChainKeeper(app.scKeeper)
ibc.EndBlocker(ctx, app.ibcKeeper)
if len(validatorUpdates) != 0 {
app.ValAddrCache.ClearCache()
Expand Down Expand Up @@ -1156,6 +1178,8 @@ func MakeCodec() *wire.Codec {
bridge.RegisterWire(cdc)
oracle.RegisterWire(cdc)
ibc.RegisterWire(cdc)
tokenRecover.RegisterWire(cdc)
migrate.RegisterWire(cdc)
return cdc
}

Expand Down
14 changes: 13 additions & 1 deletion app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ FixDoubleSignChainIdHeight = {{ .UpgradeConfig.FixDoubleSignChainIdHeight }}
BEP126Height = {{ .UpgradeConfig.BEP126Height }}
# Block height of BEP255 upgrade
BEP255Height = {{ .UpgradeConfig.BEP255Height }}
# Block height of FirstSunset upgrade
FirstSunsetHeight = {{ .UpgradeConfig.FirstSunsetHeight }}
# Block height of SecondSunset upgrade
SecondSunsetHeight = {{ .UpgradeConfig.SecondSunsetHeight }}
# Block height of FinalSunset upgrade
FinalSunsetHeight = {{ .UpgradeConfig.FinalSunsetHeight }}
[query]
# ABCI query interface black list, suggested value: ["custom/gov/proposals", "custom/timelock/timelocks", "custom/atomicSwap/swapcreator", "custom/atomicSwap/swaprecipient"]
Expand Down Expand Up @@ -552,6 +558,9 @@ type UpgradeConfig struct {
FixDoubleSignChainIdHeight int64 `mapstructure:"FixDoubleSignChainIdHeight"`
BEP126Height int64 `mapstructure:"BEP126Height"`
BEP255Height int64 `mapstructure:"BEP255Height"`
FirstSunsetHeight int64 `mapstructure:"FirstSunsetHeight"`
SecondSunsetHeight int64 `mapstructure:"SecondSunsetHeight"`
FinalSunsetHeight int64 `mapstructure:"FinalSunsetHeight"`
}

func defaultUpgradeConfig() *UpgradeConfig {
Expand Down Expand Up @@ -586,7 +595,10 @@ func defaultUpgradeConfig() *UpgradeConfig {
BEP171Height: math.MaxInt64,
FixFailAckPackageHeight: math.MaxInt64,
EnableAccountScriptsForCrossChainTransferHeight: math.MaxInt64,
BEP255Height: math.MaxInt64,
BEP255Height: math.MaxInt64,
FirstSunsetHeight: math.MaxInt64,
SecondSunsetHeight: math.MaxInt64,
FinalSunsetHeight: math.MaxInt64,
}
}

Expand Down
Loading

0 comments on commit f9792ca

Please sign in to comment.