Skip to content

Commit

Permalink
feat: add a hardfork for the link to opBNB (#504)
Browse files Browse the repository at this point in the history
* feat: add hardfork for link to opBNB

* fix localup script

* fix go.mod

* open the cross chain channels for opbnb

* fix comment

* fix imports
  • Loading branch information
yutianwu authored Oct 18, 2023
1 parent 10962ec commit acc5aa3
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ type CrossChainConfig struct {
SrcChainId uint32 `mapstructure:"src-chain-id"`

DestBscChainId uint32 `mapstructure:"dest-bsc-chain-id"`

DestOpChainId uint32 `mapstructure:"dest-op-chain-id"`
}

var CustomAppTemplate = serverconfig.DefaultConfigTemplate + `
Expand All @@ -25,6 +27,8 @@ var CustomAppTemplate = serverconfig.DefaultConfigTemplate + `
src-chain-id = {{ .CrossChain.SrcChainId }}
# chain-id for bsc destination chain
dest-bsc-chain-id = {{ .CrossChain.DestBscChainId }}
# chain-id for op bnb destination chain
dest-op-chain-id = {{ .CrossChain.DestOpChainId }}
`

func NewDefaultAppConfig() *AppConfig {
Expand All @@ -48,6 +52,7 @@ func NewDefaultAppConfig() *AppConfig {
CrossChain: CrossChainConfig{
SrcChainId: 1,
DestBscChainId: 2,
DestOpChainId: 3,
},
}
}
27 changes: 27 additions & 0 deletions app/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

bridgemoduletypes "github.com/bnb-chain/greenfield/x/bridge/types"
paymentmodule "github.com/bnb-chain/greenfield/x/payment"
paymenttypes "github.com/bnb-chain/greenfield/x/payment/types"
storagemoduletypes "github.com/bnb-chain/greenfield/x/storage/types"
)

func (app *App) RegisterUpgradeHandlers(chainID string, serverCfg *serverconfig.Config) error {
Expand All @@ -19,6 +21,7 @@ func (app *App) RegisterUpgradeHandlers(chainID string, serverCfg *serverconfig.

// Register the upgrade handlers here
app.registerNagquUpgradeHandler()
app.registerPampasUpgradeHandler()
// app.register...()
// ...
return nil
Expand Down Expand Up @@ -61,6 +64,30 @@ func (app *App) registerNagquUpgradeHandler() {
}
mm.SetConsensusVersion(2)
return nil
})
}

func (app *App) registerPampasUpgradeHandler() {
// Register the upgrade handler
app.UpgradeKeeper.SetUpgradeHandler(upgradetypes.Pampas,
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
app.Logger().Info("upgrade to ", plan.Name)

// open resource channels for opbnb
app.CrossChainKeeper.SetChannelSendPermission(ctx, sdk.ChainID(app.appConfig.CrossChain.DestOpChainId), bridgemoduletypes.SyncParamsChannelID, sdk.ChannelAllow)
app.CrossChainKeeper.SetChannelSendPermission(ctx, sdk.ChainID(app.appConfig.CrossChain.DestOpChainId), storagemoduletypes.BucketChannelId, sdk.ChannelAllow)
app.CrossChainKeeper.SetChannelSendPermission(ctx, sdk.ChainID(app.appConfig.CrossChain.DestOpChainId), storagemoduletypes.ObjectChannelId, sdk.ChannelAllow)
app.CrossChainKeeper.SetChannelSendPermission(ctx, sdk.ChainID(app.appConfig.CrossChain.DestOpChainId), storagemoduletypes.GroupChannelId, sdk.ChannelAllow)

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

// Register the upgrade initializer
app.UpgradeKeeper.SetUpgradeInitializer(upgradetypes.Pampas,
func() error {
app.Logger().Info("Init Pampas upgrade")
// enable chain id for opbnb
app.CrossChainKeeper.SetDestOpChainID(sdk.ChainID(app.appConfig.CrossChain.DestOpChainId))
return nil
})
}
1 change: 1 addition & 0 deletions deployment/localup/.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SP_MIN_DEPOSIT_AMOUNT=10000000000000000000000000
## CROSS CHAIN
SRC_CHAIN_ID=18
DEST_CHAIN_ID=714
DEST_OP_CHAIN_ID=2320

## Proposal
PROPOSAL_ID_START=1
Expand Down
2 changes: 2 additions & 0 deletions deployment/localup/localup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function generate_genesis() {
sed -i -e "s/snapshot-interval = 0/snapshot-interval = ${SNAPSHOT_INTERVAL}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/src-chain-id = 1/src-chain-id = ${SRC_CHAIN_ID}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/dest-bsc-chain-id = 2/dest-bsc-chain-id = ${DEST_CHAIN_ID}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/dest-op-chain-id = 3/dest-op-chain-id = ${DEST_OP_CHAIN_ID}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/snapshot-keep-recent = 2/snapshot-keep-recent = ${SNAPSHOT_KEEP_RECENT}/g" ${workspace}/.local/validator${i}/config/app.toml
sed -i -e "s/\"reserve_time\": \"15552000\"/\"reserve_time\": \"60\"/g" ${workspace}/.local/validator${i}/config/genesis.json
sed -i -e "s/\"forced_settle_time\": \"86400\"/\"forced_settle_time\": \"30\"/g" ${workspace}/.local/validator${i}/config/genesis.json
Expand All @@ -171,6 +172,7 @@ function generate_genesis() {
#sed -i -e "s/\"community_tax\": \"0.020000000000000000\"/\"community_tax\": \"0\"/g" ${workspace}/.local/validator${i}/config/genesis.json
sed -i -e "s/log_level = \"info\"/\log_level= \"debug\"/g" ${workspace}/.local/validator${i}/config/config.toml
echo -e '[[upgrade]]\nname = "Nagqu"\nheight = 20\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
echo -e '[[upgrade]]\nname = "Pampas"\nheight = 20\ninfo = ""' >> ${workspace}/.local/validator${i}/config/app.toml
done

# enable swagger API for validator0
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ replace (
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-cometbft v1.0.0
github.com/cometbft/cometbft-db => github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v1.0.1
github.com/cosmos/cosmos-sdk => github.com/bnb-chain/greenfield-cosmos-sdk v0.2.3-alpha.3.0.20231017121821-7b897e5a86e1
github.com/cosmos/iavl => github.com/bnb-chain/greenfield-iavl v0.20.1
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/wercker/journalhook => github.com/wercker/journalhook v0.0.0-20230927020745-64542ffa4117
)
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ github.com/bnb-chain/greenfield-cometbft v1.0.0 h1:0r6hOJWD/+es0gxP/exKuN/krgXAr
github.com/bnb-chain/greenfield-cometbft v1.0.0/go.mod h1:f35mk/r5ab6yvzlqEWZt68LfUje68sYgMpVlt2CUYMk=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1 h1:XcWulGacHVRiSCx90Q8Y//ajOrLNBQWR/KDB89dy3cU=
github.com/bnb-chain/greenfield-cometbft-db v0.8.1-alpha.1/go.mod h1:ey1CiK4bYo1RBNJLRiVbYr5CMdSxci9S/AZRINLtppI=
github.com/bnb-chain/greenfield-cosmos-sdk v1.0.1 h1:8RZRfFyY9JdRLApcz+KADXO1Qd2sps6wXT74UAmaMmM=
github.com/bnb-chain/greenfield-cosmos-sdk v1.0.1/go.mod h1:y3hDhQhil5hMIhwBTpu07RZBF30ZITkoE+GHhVZChtY=
github.com/bnb-chain/greenfield-cosmos-sdk v0.2.3-alpha.3.0.20231017121821-7b897e5a86e1 h1:Wef+0FD76aE9l3DjE4tGqeRKvEw98z1YkjJ5rHPL6G4=
github.com/bnb-chain/greenfield-cosmos-sdk v0.2.3-alpha.3.0.20231017121821-7b897e5a86e1/go.mod h1:BGVMW9gRFKGzCwK/8CmDGe3sK9r9QujL1Uz2FMMM+/s=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210 h1:GHPbV2bC+gmuO6/sG0Tm8oGal3KKSRlyE+zPscDjlA8=
github.com/bnb-chain/greenfield-cosmos-sdk/api v0.0.0-20230816082903-b48770f5e210/go.mod h1:vhsZxXE9tYJeYB5JR4hPhd6Pc/uPf7j1T8IJ7p9FdeM=
github.com/bnb-chain/greenfield-cosmos-sdk/math v0.0.0-20230816082903-b48770f5e210 h1:FLVOn4+OVbsKi2+YJX5kmD27/4dRu4FW7xCXFhzDO5s=
Expand Down Expand Up @@ -1414,7 +1414,7 @@ github.com/wealdtech/go-eth2-util v1.6.3 h1:2INPeOR35x5LdFFpSzyw954WzTD+DFyHe3yK
github.com/wealdtech/go-eth2-util v1.6.3/go.mod h1:0hFMj/qtio288oZFHmAbCnPQ9OB3c4WFzs5NVPKTY4k=
github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4 v1.1.3/go.mod h1:qiIimacW5NhVRy8o+YxWo9YrecXqDAKKbL0+sOa0SJ4=
github.com/wealdtech/go-eth2-wallet-types/v2 v2.8.2/go.mod h1:k6kmiKWSWBTd4OxFifTEkPaBLhZspnO2KFD5XJY9nqg=
github.com/wercker/journalhook v0.0.0-20180428041537-5d0a5ae867b3/go.mod h1:XCsSkdKK4gwBMNrOCZWww0pX6AOt+2gYc5Z6jBRrNVg=
github.com/wercker/journalhook v0.0.0-20230927020745-64542ffa4117/go.mod h1:XCsSkdKK4gwBMNrOCZWww0pX6AOt+2gYc5Z6jBRrNVg=
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1/go.mod h1:8UvriyWtv5Q5EOgjHaSseUEdkQfvwFv1I/In/O2M9gc=
github.com/whyrusleeping/go-logging v0.0.0-20170515211332-0457bb6b88fc/go.mod h1:bopw91TMyo8J3tvftk8xmU2kPmlrt4nScJQZU2hE5EM=
github.com/whyrusleeping/mdns v0.0.0-20190826153040-b9b60ed33aa9/go.mod h1:j4l84WPFclQPj320J9gp0XwNKBb3U0zt5CBqjPp22G4=
Expand Down
6 changes: 3 additions & 3 deletions x/storage/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ func (k msgServer) MirrorObject(goCtx context.Context, msg *types.MsgMirrorObjec
relayerFee := k.Keeper.MirrorObjectRelayerFee(ctx, destChainId)
ackRelayerFee := k.Keeper.MirrorObjectAckRelayerFee(ctx, destChainId)

_, err = k.crossChainKeeper.CreateRawIBCPackageWithFee(ctx, k.crossChainKeeper.GetDestBscChainID(),
_, err = k.crossChainKeeper.CreateRawIBCPackageWithFee(ctx, destChainId,
types.ObjectChannelId, sdk.SynCrossChainPackageType, encodedWrapPackage, relayerFee, ackRelayerFee)
if err != nil {
return nil, err
Expand Down Expand Up @@ -540,7 +540,7 @@ func (k msgServer) MirrorBucket(goCtx context.Context, msg *types.MsgMirrorBucke
relayerFee := k.Keeper.MirrorBucketRelayerFee(ctx, destChainId)
ackRelayerFee := k.Keeper.MirrorBucketAckRelayerFee(ctx, destChainId)

_, err = k.crossChainKeeper.CreateRawIBCPackageWithFee(ctx, k.crossChainKeeper.GetDestBscChainID(),
_, err = k.crossChainKeeper.CreateRawIBCPackageWithFee(ctx, destChainId,
types.BucketChannelId, sdk.SynCrossChainPackageType, encodedWrapPackage, relayerFee, ackRelayerFee)
if err != nil {
return nil, err
Expand Down Expand Up @@ -610,7 +610,7 @@ func (k msgServer) MirrorGroup(goCtx context.Context, msg *types.MsgMirrorGroup)
relayerFee := k.Keeper.MirrorGroupRelayerFee(ctx, destChainId)
ackRelayerFee := k.Keeper.MirrorGroupAckRelayerFee(ctx, destChainId)

_, err = k.crossChainKeeper.CreateRawIBCPackageWithFee(ctx, k.crossChainKeeper.GetDestBscChainID(),
_, err = k.crossChainKeeper.CreateRawIBCPackageWithFee(ctx, destChainId,
types.GroupChannelId, sdk.SynCrossChainPackageType, encodedWrapPackage, relayerFee, ackRelayerFee)
if err != nil {
return nil, err
Expand Down

0 comments on commit acc5aa3

Please sign in to comment.