Skip to content

Commit

Permalink
update from single-step
Browse files Browse the repository at this point in the history
  • Loading branch information
tubackkhoa committed Apr 19, 2023
2 parents 1f32fb4 + c41355a commit 978b7ef
Show file tree
Hide file tree
Showing 41 changed files with 1,373 additions and 520 deletions.
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ services:
# apk add make upx
# upx --best --lzma
working_dir: /workspace
restart: on-failure
tty: true
volumes:
- ./orchestrator:/orchestrator
- ./e2e/.gbt/:/root/.gbt
entrypoint: tail -f /dev/null
depends_on:
- gravity

orai:
container_name: orai_test
Expand Down
57 changes: 27 additions & 30 deletions module/app/app.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package app

import (
"fmt"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -31,7 +30,6 @@ import (
"github.com/cosmos/cosmos-sdk/server/config"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/simapp"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
Expand Down Expand Up @@ -114,7 +112,6 @@ import (
"github.com/Gravity-Bridge/Gravity-Bridge/module/app/ante"
gravityparams "github.com/Gravity-Bridge/Gravity-Bridge/module/app/params"
"github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades"
v2 "github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades/v2"
"github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity"
"github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/exported"
"github.com/Gravity-Bridge/Gravity-Bridge/module/x/gravity/keeper"
Expand Down Expand Up @@ -563,7 +560,7 @@ func NewGravityApp(

var skipGenesisInvariants = cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))

app.registerStoreLoaders()
// app.registerStoreLoaders()

mm := *module.NewManager(
genutil.NewAppModule(
Expand Down Expand Up @@ -974,29 +971,29 @@ func (app *Gravity) registerUpgradeHandlers() {
)
}

// Sets up the StoreLoader for new, deleted, or renamed modules
func (app *Gravity) registerStoreLoaders() {
// Read the upgrade height and name from previous execution
upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk()
if err != nil {
panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
}

// v1->v2 STORE LOADER SETUP
// Register the new v2 modules and the special StoreLoader to add them
if upgradeInfo.Name == v2.V1ToV2PlanName {
if !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) { // Recognized the plan, need to skip this one though
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{bech32ibctypes.ModuleName}, // We are adding these modules
// Check upgrade docs to see which type of store loader is necessary for deletes/renames
// Renamed: []storetypes.StoreRename{{"foo", "bar"}}, example foo to bar rename
// Deleted: []string{"bazmodule"}, example deleted bazmodule
Renamed: nil,
Deleted: nil,
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
}
// // Sets up the StoreLoader for new, deleted, or renamed modules
// func (app *Gravity) registerStoreLoaders() {
// // Read the upgrade height and name from previous execution
// upgradeInfo, err := app.upgradeKeeper.ReadUpgradeInfoFromDisk()
// if err != nil {
// panic(fmt.Sprintf("failed to read upgrade info from disk %s", err))
// }

// // v1->v2 STORE LOADER SETUP
// // Register the new v2 modules and the special StoreLoader to add them
// if upgradeInfo.Name == v2.V1ToV2PlanName {
// if !app.upgradeKeeper.IsSkipHeight(upgradeInfo.Height) { // Recognized the plan, need to skip this one though
// storeUpgrades := storetypes.StoreUpgrades{
// Added: []string{bech32ibctypes.ModuleName}, // We are adding these modules
// // Check upgrade docs to see which type of store loader is necessary for deletes/renames
// // Renamed: []storetypes.StoreRename{{"foo", "bar"}}, example foo to bar rename
// // Deleted: []string{"bazmodule"}, example deleted bazmodule
// Renamed: nil,
// Deleted: nil,
// }

// // configure store loader that checks if version == upgradeHeight and applies store upgrades
// app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
// }
// }
// }
19 changes: 14 additions & 5 deletions module/app/upgrades/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
ibctransferkeeper "github.com/cosmos/ibc-go/v3/modules/apps/transfer/keeper"

"github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades/pleiades"
"github.com/Gravity-Bridge/Gravity-Bridge/module/app/upgrades/singlestep"
)

// RegisterUpgradeHandlers registers handlers for all upgrades
Expand Down Expand Up @@ -52,14 +52,23 @@ func RegisterUpgradeHandlers(
// pleiades.GetPleiadesUpgradeHandler(mm, configurator, crisisKeeper, gravityKeeper, bech32IbcKeeper),
// )

upgradeKeeper.SetUpgradeHandler(
pleiades.PleiadesPart1ToPart2PlanName,
pleiades.GetPleiades2UpgradeHandler(mm, configurator, crisisKeeper),
)
// upgradeKeeper.SetUpgradeHandler(
// pleiades.PleiadesPart1ToPart2PlanName,
// pleiades.GetPleiades2UpgradeHandler(mm, configurator, crisisKeeper),
// )

// // Pleiades part 2 aka v3->v4 UPGRADE HANDLER SETUP
// upgradeKeeper.SetUpgradeHandler(
// pleiades.PleiadesPart1ToPart2PlanName,
// pleiades.GetPleiades2UpgradeHandler(mm, configurator, crisisKeeper),
// )

// upgradeKeeper.SetUpgradeHandler(
// tron.PlanName,
// tron.GetTronUpgradeHandler(mm, configurator, crisisKeeper),
// )
upgradeKeeper.SetUpgradeHandler(
singlestep.PlanName,
singlestep.GetUpgradeHandler(mm, configurator, crisisKeeper),
)
}
8 changes: 8 additions & 0 deletions module/app/upgrades/singlestep/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SingleStep UPGRADE

The _Single Step_ upgrade contains the following changes.

## Summary of Changes

- Add a remove evm chain msg which allows anyone to create an on-chain proposal to remove an evm chain
- Introduces a new CosmosReceiver string format to redirect OraiBridge tokens to appropriate source channels and destinations
3 changes: 3 additions & 0 deletions module/app/upgrades/singlestep/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package singlestep

var PlanName = "singlestep"
28 changes: 28 additions & 0 deletions module/app/upgrades/singlestep/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package singlestep

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func GetUpgradeHandler(
mm *module.Manager, configurator *module.Configurator, crisisKeeper *crisiskeeper.Keeper,
) func(
ctx sdk.Context, plan upgradetypes.Plan, vmap module.VersionMap,
) (module.VersionMap, error) {
if mm == nil {
panic("Nil argument to GetSingleStepUpgradeHandler")
}
return func(ctx sdk.Context, plan upgradetypes.Plan, vmap module.VersionMap) (module.VersionMap, error) {

ctx.Logger().Info("SingleStep Upgrade: Running any configured module migrations")
out, outErr := mm.RunMigrations(ctx, *configurator, vmap)

ctx.Logger().Info("Asserting invariants after upgrade")
crisisKeeper.AssertInvariants(ctx)

return out, outErr
}
}
7 changes: 7 additions & 0 deletions module/app/upgrades/tron/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# TRON UPGRADE

The *Tron* upgrade contains the following changes.

## Summary of Changes

* Disable filtering evm net version
3 changes: 3 additions & 0 deletions module/app/upgrades/tron/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package tron

var PlanName = "tron"
28 changes: 28 additions & 0 deletions module/app/upgrades/tron/handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package tron

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func GetTronUpgradeHandler(
mm *module.Manager, configurator *module.Configurator, crisisKeeper *crisiskeeper.Keeper,
) func(
ctx sdk.Context, plan upgradetypes.Plan, vmap module.VersionMap,
) (module.VersionMap, error) {
if mm == nil {
panic("Nil argument to GetTronUpgradeHandler")
}
return func(ctx sdk.Context, plan upgradetypes.Plan, vmap module.VersionMap) (module.VersionMap, error) {

ctx.Logger().Info("Tron Upgrade: Running any configured module migrations")
out, outErr := mm.RunMigrations(ctx, *configurator, vmap)

ctx.Logger().Info("Asserting invariants after upgrade")
crisisKeeper.AssertInvariants(ctx)

return out, outErr
}
}
30 changes: 24 additions & 6 deletions module/proto/gravity/v1/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,29 @@ message AddEvmChainProposal {
string bridge_ethereum_address = 7;
}

// PendingIbcAutoForward represents a SendToCosmos transaction with a foreign CosmosReceiver which will be added to the
// PendingIbcAutoForward queue in attestation_handler and sent over IBC on some submission of a MsgExecuteIbcAutoForwards
// RemoveEvmChainProposal
// this types allows users to remove an EVM chain through gov proposal
message RemoveEvmChainProposal {
option (gogoproto.equal) = true;
option (gogoproto.goproto_getters) = false;
option (gogoproto.goproto_stringer) = false;

string title = 1;
string description = 2;
string evm_chain_prefix = 3;
}

// PendingIbcAutoForward represents a SendToCosmos transaction with a foreign
// CosmosReceiver which will be added to the PendingIbcAutoForward queue in
// attestation_handler and sent over IBC on some submission of a
// MsgExecuteIbcAutoForwards
message PendingIbcAutoForward {
string foreign_receiver = 1; // the destination address. sdk.AccAddress does not preserve foreign prefixes
cosmos.base.v1beta1.Coin token = 2; // the token sent from ethereum to the ibc-enabled chain over `IbcChannel`
string ibc_channel = 3; // the IBC channel to send `Amount` over via ibc-transfer module
uint64 event_nonce = 4; // the EventNonce from the MsgSendToCosmosClaim, used for ordering the queue
string foreign_receiver = 1; // the destination address. sdk.AccAddress does
// not preserve foreign prefixes
cosmos.base.v1beta1.Coin token = 2; // the token sent from ethereum to the
// ibc-enabled chain over `IbcChannel`
string ibc_channel =
3; // the IBC channel to send `Amount` over via ibc-transfer module
uint64 event_nonce = 4; // the EventNonce from the MsgSendToCosmosClaim, used
// for ordering the queue
}
10 changes: 3 additions & 7 deletions module/x/gravity/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ func TestValsetSlashing_ValsetCreated_After_ValidatorBonded(t *testing.T) {
// ensure that the validator who is bonded before valset is created is slashed
// now validator will not be slashed, unless all evm chains are not updated
val := input.StakingKeeper.Validator(ctx, keeper.ValAddrs[0])
// require.True(t, val.IsJailed())
require.False(t, val.IsJailed())

// ensure that the validator who attested the valset is not slashed.
Expand Down Expand Up @@ -445,19 +444,16 @@ func TestBatchSlashing(t *testing.T) {

// ensure that the validator is jailed and slashed
val := input.StakingKeeper.Validator(ctx, keeper.ValAddrs[0])
// require.True(t, val.IsJailed())
require.False(t, val.IsJailed())

// ensure that the 2nd validator is not jailed and slashed
val2 := input.StakingKeeper.Validator(ctx, keeper.ValAddrs[1])
require.False(t, val2.IsJailed())

// Ensure that the last slashed valset nonce is set properly
// lastSlashedBatchBlock := input.GravityKeeper.GetLastSlashedBatchBlock(ctx, evmChain.EvmChainPrefix)
// assert.Equal(t, lastSlashedBatchBlock, batch.CosmosBlockCreated)

// assert.True(t, len(pk.GetUnSlashedBatches(ctx, evmChain.EvmChainPrefix, uint64(ctx.BlockHeight()))) == 0)
assert.False(t, len(pk.GetUnSlashedBatches(ctx, evmChain.EvmChainPrefix, uint64(ctx.BlockHeight()))) == 0)
lastSlashedBatchBlock := input.GravityKeeper.GetLastSlashedBatchBlock(ctx, evmChain.EvmChainPrefix)
assert.NotEqual(t, lastSlashedBatchBlock, batch.CosmosBlockCreated)
assert.True(t, len(pk.GetUnSlashedBatches(ctx, evmChain.EvmChainPrefix, uint64(ctx.BlockHeight()))) != 0)

}

Expand Down
48 changes: 48 additions & 0 deletions module/x/gravity/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func GetTxCmd(storeKey string) *cobra.Command {
CmdGovUnhaltBridgeProposal(),
CmdExecutePendingIbcAutoForwards(),
CmdAddEvmChainProposal(),
CmdRemoveEvmChainProposal(),
}...)

return gravityTxCmd
Expand Down Expand Up @@ -357,6 +358,53 @@ func CmdAddEvmChainProposal() *cobra.Command {
return cmd
}

// CmdRemoveEvmChainProposal enables users to create a proposal to add new EVM chains
func CmdRemoveEvmChainProposal() *cobra.Command {
cmd := &cobra.Command{
Use: "remove-evm-chain [evm-chain-prefix] [initial-deposit] [title] [description]",
Short: "Creates a governance proposal to remove an EVM chain on the network",
Args: cobra.ExactArgs(4),
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}
cosmosAddr := cliCtx.GetFromAddress()

initialDeposit, err := sdk.ParseCoinsNormalized(args[1])
if err != nil {
return sdkerrors.Wrap(err, "bad initial deposit amount")
}

if len(initialDeposit) != 1 {
return fmt.Errorf("unexpected coin amounts, expecting just 1 coin amount for initialDeposit")
}

evmChainPrefix := args[0]

proposal := &types.RemoveEvmChainProposal{EvmChainPrefix: evmChainPrefix, Title: args[2], Description: args[3]}
proposalAny, err := codectypes.NewAnyWithValue(proposal)
if err != nil {
return sdkerrors.Wrap(err, "invalid metadata or proposal details!")
}

// Make the message
msg := govtypes.MsgSubmitProposal{
Proposer: cosmosAddr.String(),
InitialDeposit: initialDeposit,
Content: proposalAny,
}
if err := msg.ValidateBasic(); err != nil {
return err
}
// Send it
return tx.GenerateOrBroadcastTxCLI(cliCtx, cmd.Flags(), &msg)
},
}
flags.AddTxFlagsToCmd(cmd)
return cmd
}

// CmdSendToEth sends tokens to Ethereum. Locks Cosmos-side tokens into the Transaction pool for batching.
func CmdSendToEth() *cobra.Command {
// nolint: exhaustruct
Expand Down
Loading

0 comments on commit 978b7ef

Please sign in to comment.