Skip to content

Commit

Permalink
Merge branch 'main' into zaki/interval-auctions
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBolten authored Dec 14, 2023
2 parents fd6c8c6 + a42cede commit 5e7e23a
Show file tree
Hide file tree
Showing 19 changed files with 362 additions and 90 deletions.
4 changes: 3 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ func NewSommelierApp(
keys[axelarcorktypes.StoreKey],
app.GetSubspace(axelarcorktypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
app.TransferKeeper,
app.DistrKeeper,
Expand Down Expand Up @@ -974,7 +975,7 @@ func (app *SommelierApp) setupUpgradeStoreLoaders() {

if upgradeInfo.Name == v7.UpgradeName {
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{auctiontypes.ModuleName, pubsubtypes.ModuleName},
Added: []string{auctiontypes.ModuleName, axelarcorktypes.ModuleName, pubsubtypes.ModuleName},
}
}

Expand Down Expand Up @@ -1017,6 +1018,7 @@ func (app *SommelierApp) setupUpgradeHandlers() {
app.mm,
app.configurator,
app.AuctionKeeper,
app.AxelarCorkKeeper,
app.CellarFeesKeeper,
app.ICAHostKeeper,
app.PubsubKeeper,
Expand Down
63 changes: 60 additions & 3 deletions app/upgrades/v7/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package v7

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
icahostkeeper "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/host/types"
ibctransfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
auctionkeeper "github.com/peggyjv/sommelier/v7/x/auction/keeper"
auctiontypes "github.com/peggyjv/sommelier/v7/x/auction/types"
axelarcorkkeeper "github.com/peggyjv/sommelier/v7/x/axelarcork/keeper"
axelarcorktypes "github.com/peggyjv/sommelier/v7/x/axelarcork/types"
cellarfeeskeeper "github.com/peggyjv/sommelier/v7/x/cellarfees/keeper"
cellarfeestypes "github.com/peggyjv/sommelier/v7/x/cellarfees/types"
pubsubkeeper "github.com/peggyjv/sommelier/v7/x/pubsub/keeper"
Expand All @@ -18,14 +23,14 @@ func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
auctionKeeper auctionkeeper.Keeper,
axelarcorkKeeper axelarcorkkeeper.Keeper,
cellarfeesKeeper cellarfeeskeeper.Keeper,
icaHostKeeper icahostkeeper.Keeper,
pubsubKeeper pubsubkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("v7 upgrade: entering handler")

// TODO(bolten): get a sanity check on this
// Now that we're on IBC V6, we can update the ICA host module to allow all message types rather than
// the list we specified in the v6 upgrade -- a default of HostEnabled: true and the string "*" for messages
icaParams := icahosttypes.DefaultParams()
Expand All @@ -35,6 +40,7 @@ func CreateUpgradeHandler(
// during the upgrade process. RunMigrations will migrate to the new cork version. Setting the consensus
// version to 1 prevents RunMigrations from running InitGenesis itself.
fromVM[auctiontypes.ModuleName] = mm.Modules[auctiontypes.ModuleName].ConsensusVersion()
fromVM[axelarcorktypes.ModuleName] = mm.Modules[axelarcorktypes.ModuleName].ConsensusVersion()
fromVM[pubsubtypes.ModuleName] = mm.Modules[pubsubtypes.ModuleName].ConsensusVersion()

// Params values were introduced in this upgrade but no migration was necessary, so we initialize the
Expand All @@ -46,11 +52,12 @@ func CreateUpgradeHandler(
ctx.Logger().Info("v7 upgrade: initializing auction genesis state")
auctionInitGenesis(ctx, auctionKeeper)

ctx.Logger().Info("v7 upgrade: intializing axelarcork genesis state")
axelarcorkInitGenesis(ctx, axelarcorkKeeper)

ctx.Logger().Info("v7 upgrade: initializing pubsub genesis state")
pubsubInitGenesis(ctx, pubsubKeeper)

//TODO(bolten): axelarcork module initialization

ctx.Logger().Info("v7 upgrade: running migrations and exiting handler")
return mm.RunMigrations(ctx, configurator, fromVM)
}
Expand Down Expand Up @@ -132,6 +139,56 @@ func auctionInitGenesis(ctx sdk.Context, auctionKeeper auctionkeeper.Keeper) {
auctionkeeper.InitGenesis(ctx, auctionKeeper, genesisState)
}

// Initialize the Axelar cork module with the correct parameters.
func axelarcorkInitGenesis(ctx sdk.Context, axelarcorkKeeper axelarcorkkeeper.Keeper) {
genesisState := axelarcorktypes.DefaultGenesisState()

genesisState.Params.Enabled = true
genesisState.Params.TimeoutDuration = uint64(6 * time.Hour)
genesisState.Params.IbcChannel = "channel-5"
genesisState.Params.IbcPort = ibctransfertypes.PortID
genesisState.Params.GmpAccount = "axelar1dv4u5k73pzqrxlzujxg3qp8kvc3pje7jtdvu72npnt5zhq05ejcsn5qme5s"
genesisState.Params.ExecutorAccount = "axelar1aythygn6z5thymj6tmzfwekzh05ewg3l7d6y89"
genesisState.Params.CorkTimeoutBlocks = 5000

genesisState.ChainConfigurations = axelarcorktypes.ChainConfigurations{
Configurations: []*axelarcorktypes.ChainConfiguration{
{
Name: "arbitrum",
Id: 42161,
ProxyAddress: "0xEe75bA2C81C04DcA4b0ED6d1B7077c188FEde4d2",
},
{
Name: "Avalanche",
Id: 43114,
ProxyAddress: "0xEe75bA2C81C04DcA4b0ED6d1B7077c188FEde4d2",
},
{
Name: "base",
Id: 8453,
ProxyAddress: "0xEe75bA2C81C04DcA4b0ED6d1B7077c188FEde4d2",
},
{
Name: "binance",
Id: 56,
ProxyAddress: "0xEe75bA2C81C04DcA4b0ED6d1B7077c188FEde4d2",
},
{
Name: "optimism",
Id: 10,
ProxyAddress: "0xEe75bA2C81C04DcA4b0ED6d1B7077c188FEde4d2",
},
{
Name: "Polygon",
Id: 137,
ProxyAddress: "0xEe75bA2C81C04DcA4b0ED6d1B7077c188FEde4d2",
},
},
}

axelarcorkkeeper.InitGenesis(ctx, axelarcorkKeeper, genesisState)
}

// Set up the initial pubsub state to mirror what is currently used in practice already, with 7seas as the
// first publisher using its existing CA certificate, its default subscriptions as the already launched cellars,
// and the subscribers as reflected in the steward-registry repo.
Expand Down
8 changes: 6 additions & 2 deletions x/axelarcork/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ func (k Keeper) EndBlocker(ctx sdk.Context) {
k.Logger(ctx).Info("tallying scheduled cork votes",
"height", fmt.Sprintf("%d", ctx.BlockHeight()),
"chain id", config.Id)
// TODO(bolten): might not be a necessary fix, but GetApprovedScheduledAxelarCorks is kind of
// unexpectedly destructive -- it deletes all of the validator submitted entries for scheduled
// corks and returns a list of the winning ones, which are then set using SetWinningAxelarCork
// here, but it seems like an odd side effect of a Get function to delete stuff
winningScheduledVotes := k.GetApprovedScheduledAxelarCorks(ctx, config.Id)
if len(winningScheduledVotes) > 0 {
k.Logger(ctx).Info("marking all winning scheduled cork votes as relayable",
"winning votes", winningScheduledVotes,
"chain id", config.Id)
for _, c := range winningScheduledVotes {
k.SetWinningAxelarCork(ctx, config.Id, uint64(ctx.BlockHeight()), c.Deadline, c)
k.SetWinningAxelarCork(ctx, config.Id, uint64(ctx.BlockHeight()), c)
}
}

Expand All @@ -39,7 +43,7 @@ func (k Keeper) EndBlocker(ctx sdk.Context) {
"chain id", config.Id)

timeoutHeight := uint64(ctx.BlockHeight()) - k.GetParamSet(ctx).CorkTimeoutBlocks
k.IterateWinningAxelarCorks(ctx, config.Id, func(_ common.Address, blockHeight uint64, deadline uint64, cork types.AxelarCork) (stop bool) {
k.IterateWinningAxelarCorks(ctx, config.Id, func(_ common.Address, blockHeight uint64, cork types.AxelarCork) (stop bool) {
if blockHeight >= timeoutHeight {
k.Logger(ctx).Info("deleting expired approved scheduled axelar cork",
"scheduled height", fmt.Sprintf("%d", blockHeight),
Expand Down
3 changes: 2 additions & 1 deletion x/axelarcork/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ func InitGenesis(ctx sdk.Context, k Keeper, gs types.GenesisState) {
if senderAccount == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}

k.accountKeeper.SetModuleAccount(ctx, senderAccount)

for i, config := range gs.ChainConfigurations.Configurations {
Expand All @@ -43,6 +42,8 @@ func InitGenesis(ctx sdk.Context, k Keeper, gs types.GenesisState) {
k.SetScheduledAxelarCork(ctx, scheduledCork.Cork.ChainId, scheduledCork.BlockHeight, valAddr, *scheduledCork.Cork)
}

// TODO(bolten): not a huge risk since they can be re-sent, but the genesis state is missing WinningAxelarCorks

for _, n := range gs.AxelarContractCallNonces {
if _, found := k.GetChainConfigurationByID(ctx, n.ChainId); !found {
panic(fmt.Sprintf("chain configuration %d not found", n.ChainId))
Expand Down
Loading

0 comments on commit 5e7e23a

Please sign in to comment.