Skip to content

Commit f9792ca

Browse files
authored
Merge pull request #1013 from bnb-chain/develop
feat: implement BEP-333(BNB Chain Fusion) (#1003)
2 parents 13bb81c + 1d1b11e commit f9792ca

File tree

32 files changed

+860
-195
lines changed

32 files changed

+860
-195
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## v0.10.17
4+
This is the release for the sunset of BNB Beacon Chain.
5+
6+
FEATURES
7+
* [\#977](https://github.com/bnb-chain/node/pull/1003) [BEP] feat: implement BEP-333(BNB Chain Fusion)
8+
9+
310
## v0.10.16
411
FEATURES
512
* [\#977](https://github.com/bnb-chain/node/pull/977) [BEP] asset: add bep255 upgrade height for mainnet

app/app.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ import (
5555
"github.com/bnb-chain/node/plugins/dex/list"
5656
"github.com/bnb-chain/node/plugins/dex/order"
5757
dextypes "github.com/bnb-chain/node/plugins/dex/types"
58+
migrate "github.com/bnb-chain/node/plugins/migrate"
59+
tokenRecover "github.com/bnb-chain/node/plugins/recover"
5860
"github.com/bnb-chain/node/plugins/tokens"
5961
"github.com/bnb-chain/node/plugins/tokens/issue"
6062
"github.com/bnb-chain/node/plugins/tokens/ownership"
6163
"github.com/bnb-chain/node/plugins/tokens/seturi"
6264
"github.com/bnb-chain/node/plugins/tokens/swap"
6365
"github.com/bnb-chain/node/plugins/tokens/timelock"
6466
"github.com/bnb-chain/node/wire"
67+
stakeMigration "github.com/cosmos/cosmos-sdk/x/stake/stake_migration"
6568
)
6669

6770
const (
@@ -359,6 +362,9 @@ func SetUpgradeConfig(upgradeConfig *config.UpgradeConfig) {
359362
upgrade.Mgr.AddUpgradeHeight(upgrade.FixDoubleSignChainId, upgradeConfig.FixDoubleSignChainIdHeight)
360363
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP126, upgradeConfig.BEP126Height)
361364
upgrade.Mgr.AddUpgradeHeight(upgrade.BEP255, upgradeConfig.BEP255Height)
365+
upgrade.Mgr.AddUpgradeHeight(upgrade.FirstSunset, upgradeConfig.FirstSunsetHeight)
366+
upgrade.Mgr.AddUpgradeHeight(upgrade.SecondSunset, upgradeConfig.SecondSunsetHeight)
367+
upgrade.Mgr.AddUpgradeHeight(upgrade.FinalSunset, upgradeConfig.FinalSunsetHeight)
362368

363369
// register store keys of upgrade
364370
upgrade.Mgr.RegisterStoreKeys(upgrade.BEP9, common.TimeLockStoreKey.Name())
@@ -619,6 +625,11 @@ func (app *BNBBeaconChain) initStaking() {
619625
newCtx := ctx.WithSideChainKeyPrefix(storePrefix)
620626
app.stakeKeeper.ClearUpSideVoteAddrs(newCtx)
621627
})
628+
upgrade.Mgr.RegisterBeginBlocker(sdk.FirstSunsetFork, func(ctx sdk.Context) {
629+
chainId := sdk.ChainID(ServerContext.BscIbcChainId)
630+
// enable channel but not send cross chain msg
631+
app.scKeeper.SetChannelSendPermission(ctx, chainId, sTypes.StakeMigrationChannelID, sdk.ChannelAllow)
632+
})
622633
app.stakeKeeper.SubscribeParamChange(app.ParamHub)
623634
app.stakeKeeper.SubscribeBCParamChange(app.ParamHub)
624635
app.stakeKeeper = app.stakeKeeper.WithHooks(app.slashKeeper.Hooks())
@@ -629,6 +640,13 @@ func (app *BNBBeaconChain) initStaking() {
629640
if err != nil {
630641
panic(err)
631642
}
643+
644+
// register stake migration channel
645+
stakeMigrationApp := stakeMigration.NewStakeMigrationApp(app.stakeKeeper)
646+
err = app.scKeeper.RegisterChannel(sTypes.StakeMigrationChannel, sTypes.StakeMigrationChannelID, stakeMigrationApp)
647+
if err != nil {
648+
panic(err)
649+
}
632650
}
633651

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

923942
app.DexKeeper.StoreTradePrices(ctx)
@@ -945,6 +964,9 @@ func (app *BNBBeaconChain) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock)
945964
} else if ctx.RouterCallRecord()["stake"] || sdk.IsUpgrade(upgrade.BEP128) {
946965
validatorUpdates, completedUbd = stake.EndBlocker(ctx, app.stakeKeeper)
947966
}
967+
968+
// That is no deep copy when New IBC Keeper. need to set it again.
969+
app.ibcKeeper.SetSideChainKeeper(app.scKeeper)
948970
ibc.EndBlocker(ctx, app.ibcKeeper)
949971
if len(validatorUpdates) != 0 {
950972
app.ValAddrCache.ClearCache()
@@ -1156,6 +1178,8 @@ func MakeCodec() *wire.Codec {
11561178
bridge.RegisterWire(cdc)
11571179
oracle.RegisterWire(cdc)
11581180
ibc.RegisterWire(cdc)
1181+
tokenRecover.RegisterWire(cdc)
1182+
migrate.RegisterWire(cdc)
11591183
return cdc
11601184
}
11611185

app/config/config.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ FixDoubleSignChainIdHeight = {{ .UpgradeConfig.FixDoubleSignChainIdHeight }}
103103
BEP126Height = {{ .UpgradeConfig.BEP126Height }}
104104
# Block height of BEP255 upgrade
105105
BEP255Height = {{ .UpgradeConfig.BEP255Height }}
106+
# Block height of FirstSunset upgrade
107+
FirstSunsetHeight = {{ .UpgradeConfig.FirstSunsetHeight }}
108+
# Block height of SecondSunset upgrade
109+
SecondSunsetHeight = {{ .UpgradeConfig.SecondSunsetHeight }}
110+
# Block height of FinalSunset upgrade
111+
FinalSunsetHeight = {{ .UpgradeConfig.FinalSunsetHeight }}
106112
107113
[query]
108114
# ABCI query interface black list, suggested value: ["custom/gov/proposals", "custom/timelock/timelocks", "custom/atomicSwap/swapcreator", "custom/atomicSwap/swaprecipient"]
@@ -552,6 +558,9 @@ type UpgradeConfig struct {
552558
FixDoubleSignChainIdHeight int64 `mapstructure:"FixDoubleSignChainIdHeight"`
553559
BEP126Height int64 `mapstructure:"BEP126Height"`
554560
BEP255Height int64 `mapstructure:"BEP255Height"`
561+
FirstSunsetHeight int64 `mapstructure:"FirstSunsetHeight"`
562+
SecondSunsetHeight int64 `mapstructure:"SecondSunsetHeight"`
563+
FinalSunsetHeight int64 `mapstructure:"FinalSunsetHeight"`
555564
}
556565

557566
func defaultUpgradeConfig() *UpgradeConfig {
@@ -586,7 +595,10 @@ func defaultUpgradeConfig() *UpgradeConfig {
586595
BEP171Height: math.MaxInt64,
587596
FixFailAckPackageHeight: math.MaxInt64,
588597
EnableAccountScriptsForCrossChainTransferHeight: math.MaxInt64,
589-
BEP255Height: math.MaxInt64,
598+
BEP255Height: math.MaxInt64,
599+
FirstSunsetHeight: math.MaxInt64,
600+
SecondSunsetHeight: math.MaxInt64,
601+
FinalSunsetHeight: math.MaxInt64,
590602
}
591603
}
592604

0 commit comments

Comments
 (0)