Skip to content

Commit

Permalink
Merge branch 'v17-upgrade-handler' into dynamic-unbonding-rr-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sampocs committed Jan 11, 2024
2 parents 5e4d667 + ba8e948 commit b08635f
Show file tree
Hide file tree
Showing 40 changed files with 1,748 additions and 610 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.21
env:
GOOS: ${{ matrix.targetos }}
GOARCH: ${{ matrix.arch }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: 1.19
go-version: 1.21
- uses: golangci/golangci-lint-action@v3.2.0
with:
version: latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Setup Golang
uses: actions/setup-go@v2.1.4
with:
go-version: 1.19
go-version: 1.21
# - name: Get data from build cache
# uses: actions/cache@v2
# with:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax = docker/dockerfile:1

ARG GO_VERSION="1.19"
ARG GO_VERSION="1.21"
ARG RUNNER_IMAGE="alpine:3.16"

FROM golang:${GO_VERSION}-alpine as builder
Expand Down
56 changes: 49 additions & 7 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ import (
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
ibchost "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"
ccvstaking "github.com/cosmos/interchain-security/v3/x/ccv/democracy/staking"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
ibctestingtypes "github.com/cosmos/ibc-go/v7/testing/types"
"github.com/spf13/cast"

ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
Expand Down Expand Up @@ -154,9 +154,12 @@ import (
ccvconsumer "github.com/cosmos/interchain-security/v3/x/ccv/consumer"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v3/x/ccv/consumer/keeper"
ccvconsumertypes "github.com/cosmos/interchain-security/v3/x/ccv/consumer/types"
ccvstaking "github.com/cosmos/interchain-security/v3/x/ccv/democracy/staking"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/interchain-security/v3/legacy_ibc_testing/core"
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward"
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/keeper"
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
)

const (
Expand Down Expand Up @@ -225,6 +228,7 @@ var (
autopilot.AppModuleBasic{},
icaoracle.AppModuleBasic{},
tendermint.AppModuleBasic{},
packetforward.AppModuleBasic{},
evmosvesting.AppModuleBasic{},
)

Expand Down Expand Up @@ -302,6 +306,7 @@ type StrideApp struct {
ICAHostKeeper icahostkeeper.Keeper
ConsumerKeeper ccvconsumerkeeper.Keeper
AutopilotKeeper autopilotkeeper.Keeper
PacketForwardKeeper *packetforwardkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -369,6 +374,7 @@ func NewStrideApp(
ccvconsumertypes.StoreKey,
crisistypes.StoreKey,
consensusparamtypes.StoreKey,
packetforwardtypes.StoreKey,
evmosvestingtypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -473,22 +479,38 @@ func NewStrideApp(
app.GetSubspace(ratelimitmoduletypes.ModuleName),
app.BankKeeper,
app.IBCKeeper.ChannelKeeper,
// TODO: Implement ICS4Wrapper in Records and pass records keeper here
app.IBCKeeper.ChannelKeeper, // ICS4Wrapper
)
ratelimitModule := ratelimitmodule.NewAppModule(appCodec, app.RatelimitKeeper)

// Initialize the packet forward middleware Keeper
// It's important to note that the PFM Keeper must be initialized before the Transfer Keeper
app.PacketForwardKeeper = packetforwardkeeper.NewKeeper(
appCodec,
keys[packetforwardtypes.StoreKey],
nil, // will be zero-value here, reference is set later on with SetTransferKeeper.
app.IBCKeeper.ChannelKeeper,
app.DistrKeeper,
app.BankKeeper,
app.RatelimitKeeper, // ICS4Wrapper
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey],
app.GetSubspace(ibctransfertypes.ModuleName),
app.RatelimitKeeper, // ICS4Wrapper
app.PacketForwardKeeper, // ICS4Wrapper
app.IBCKeeper.ChannelKeeper,
&app.IBCKeeper.PortKeeper,
app.AccountKeeper,
app.BankKeeper,
scopedTransferKeeper,
)

// Set the TransferKeeper reference in the PacketForwardKeeper
app.PacketForwardKeeper.SetTransferKeeper(app.TransferKeeper)

transferModule := transfer.NewAppModule(app.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(app.TransferKeeper)

Expand Down Expand Up @@ -613,6 +635,7 @@ func NewStrideApp(
appCodec,
keys[autopilottypes.StoreKey],
app.GetSubspace(autopilottypes.ModuleName),
app.BankKeeper,
app.StakeibcKeeper,
app.ClaimKeeper,
app.TransferKeeper,
Expand Down Expand Up @@ -702,14 +725,27 @@ func NewStrideApp(
icacallbacksStack = icaoracle.NewIBCMiddleware(icacallbacksStack, app.ICAOracleKeeper)
icacallbacksStack = icacontroller.NewIBCMiddleware(icacallbacksStack, app.ICAControllerKeeper)

// SendPacket originates from the base app and work up the stack to core IBC
// RecvPacket originates from core IBC and goes down the stack

// Stack three contains
// - IBC
// - core ibc
// - autopilot
// - records
// - ratelimit
// - pfm
// - transfer
// - base app
// Note: Traffic up the stack does not pass through records or autopilot,
// as defined via the ICS4Wrappers of each keeper
var transferStack porttypes.IBCModule = transferIBCModule
transferStack = packetforward.NewIBCMiddleware(
transferStack,
app.PacketForwardKeeper,
0, // retries on timeout
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, // forward timeout
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, // refund timeout
)
transferStack = ratelimitmodule.NewIBCMiddleware(app.RatelimitKeeper, transferStack)
transferStack = recordsmodule.NewIBCModule(app.RecordsKeeper, transferStack)
transferStack = autopilot.NewIBCModule(app.AutopilotKeeper, transferStack)
Expand Down Expand Up @@ -761,6 +797,8 @@ func NewStrideApp(
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
claim.NewAppModule(appCodec, app.ClaimKeeper),
// technically, app.GetSubspace(packetforwardtypes.ModuleName) will never be run https://github.com/cosmos/ibc-apps/issues/146#issuecomment-1839242144
packetforward.NewAppModule(app.PacketForwardKeeper, app.GetSubspace(packetforwardtypes.ModuleName)),
transferModule,
// monitoringModule,
stakeibcModule,
Expand Down Expand Up @@ -812,6 +850,7 @@ func NewStrideApp(
autopilottypes.ModuleName,
icaoracletypes.ModuleName,
consensusparamtypes.ModuleName,
packetforwardtypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand Down Expand Up @@ -847,6 +886,7 @@ func NewStrideApp(
autopilottypes.ModuleName,
icaoracletypes.ModuleName,
consensusparamtypes.ModuleName,
packetforwardtypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -887,6 +927,7 @@ func NewStrideApp(
autopilottypes.ModuleName,
icaoracletypes.ModuleName,
consensusparamtypes.ModuleName,
packetforwardtypes.ModuleName,
)

app.mm.RegisterInvariants(app.CrisisKeeper)
Expand Down Expand Up @@ -970,7 +1011,7 @@ func (app *StrideApp) Name() string { return app.BaseApp.Name() }
func (app *StrideApp) GetBaseApp() *baseapp.BaseApp { return app.BaseApp }

// GetStakingKeeper implements the TestingApp interface.
func (app *StrideApp) GetStakingKeeper() core.StakingKeeper {
func (app *StrideApp) GetStakingKeeper() ibctestingtypes.StakingKeeper {
return app.StakingKeeper
}

Expand Down Expand Up @@ -1159,6 +1200,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(icacallbacksmoduletypes.ModuleName)
paramsKeeper.Subspace(ccvconsumertypes.ModuleName)
paramsKeeper.Subspace(autopilottypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
paramsKeeper.Subspace(icaoracletypes.ModuleName)
paramsKeeper.Subspace(claimtypes.ModuleName)
return paramsKeeper
Expand Down
108 changes: 58 additions & 50 deletions app/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/ed25519"
tmencoding "github.com/cometbft/cometbft/crypto/encoding"
tmtypesproto "github.com/cometbft/cometbft/proto/tendermint/types"
tmtypes "github.com/cometbft/cometbft/types"
"github.com/cosmos/cosmos-sdk/baseapp"
Expand All @@ -18,18 +19,17 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/gogoproto/proto"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
tendermint "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
"github.com/cosmos/ibc-go/v7/testing/simapp"
appProvider "github.com/cosmos/interchain-security/v3/app/provider"
ibctesting "github.com/cosmos/interchain-security/v3/legacy_ibc_testing/testing"
icstestingutils "github.com/cosmos/interchain-security/v3/testutil/ibc_testing"
e2e "github.com/cosmos/interchain-security/v3/testutil/integration"
ccvprovidertypes "github.com/cosmos/interchain-security/v3/x/ccv/provider/types"
testkeeper "github.com/cosmos/interchain-security/v3/testutil/keeper"
ccvtypes "github.com/cosmos/interchain-security/v3/x/ccv/types"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
Expand Down Expand Up @@ -139,67 +139,75 @@ func (s *AppTestHelper) SetupIBCChains(hostChainID string) {
s.Coordinator = ibctesting.NewCoordinator(s.T(), 0)

// Initialize a provider testing app
s.ProviderChain = ibctesting.NewTestChain(s.T(), s.Coordinator, icstestingutils.ProviderAppIniter, ProviderChainID)
ibctesting.DefaultTestingAppInit = icstestingutils.ProviderAppIniter
s.ProviderChain = ibctesting.NewTestChain(s.T(), s.Coordinator, ProviderChainID)
s.ProviderApp = s.ProviderChain.App.(*appProvider.App)

// Initialize a stride testing app by casting a StrideApp -> TestingApp
s.StrideChain = ibctesting.NewTestChainWithValSet(s.T(), s.Coordinator, app.InitStrideIBCTestingApp, StrideChainID,
s.ProviderChain.Vals, s.ProviderChain.Signers)

// Initialize a host testing app using SimApp -> TestingApp
s.HostChain = ibctesting.NewTestChain(s.T(), s.Coordinator, ibctesting.SetupTestingApp, hostChainID)

// Update coordinator
s.Coordinator.Chains = map[string]*ibctesting.TestChain{
StrideChainID: s.StrideChain,
hostChainID: s.HostChain,
ProviderChainID: s.ProviderChain,
}
s.IbcEnabled = true

// valsets must match
providerValUpdates := tmtypes.TM2PB.ValidatorUpdates(s.ProviderChain.Vals)
strideValUpdates := tmtypes.TM2PB.ValidatorUpdates(s.StrideChain.Vals)
s.Require().True(len(providerValUpdates) == len(strideValUpdates), "initial valset not matching")

// for i := 0; i < len(providerValUpdates); i++ {
// addr1 := ccvutils.GetChangePubKeyAddress(providerValUpdates[i])
// addr2 := ccvutils.GetChangePubKeyAddress(strideValUpdates[i])
// s.Require().True(bytes.Equal(addr1, addr2), "validator mismatch")
// }

// move chains to the next block
s.ProviderChain.NextBlock()
s.StrideChain.NextBlock()
s.HostChain.NextBlock()

ibctesting.DefaultTestingAppInit = ibctesting.SetupTestingApp
s.HostChain = ibctesting.NewTestChain(s.T(), s.Coordinator, hostChainID)

// create a consumer addition prop
// NOTE: the initial height passed to CreateConsumerClient
// must be the height on the consumer when InitGenesis is called
prop := testkeeper.GetTestConsumerAdditionProp()
prop.ChainId = StrideChainID
prop.UnbondingPeriod = s.ProviderApp.GetTestStakingKeeper().UnbondingTime(s.ProviderChain.GetContext())
prop.InitialHeight = clienttypes.Height{RevisionNumber: 0, RevisionHeight: 3}

// create a consumer client on the provider chain
providerKeeper := s.ProviderApp.GetProviderKeeper()
// create consumer client on provider chain and set as consumer client for consumer chainID in provider keeper.
err := providerKeeper.CreateConsumerClient(
s.ProviderChain.GetContext(),
&ccvprovidertypes.ConsumerAdditionProposal{
ChainId: s.StrideChain.ChainID,
InitialHeight: s.StrideChain.LastHeader.GetHeight().(clienttypes.Height),
BlocksPerDistributionTransmission: 50,
CcvTimeoutPeriod: time.Hour,
TransferTimeoutPeriod: time.Hour,
UnbondingPeriod: time.Hour * 504,
ConsumerRedistributionFraction: "0.75",
HistoricalEntries: 10000,
},
prop,
)
s.Require().NoError(err)

// move provider to next block to commit the state
s.ProviderChain.NextBlock()
// move provider and host chain to next block
s.Coordinator.CommitBlock(s.ProviderChain)
s.Coordinator.CommitBlock(s.HostChain)

// initialize the consumer chain with the genesis state stored on the provider
strideConsumerGenesis, found := providerKeeper.GetConsumerGenesis(
s.ProviderChain.GetContext(),
s.StrideChain.ChainID,
StrideChainID,
)
s.Require().True(found, "consumer genesis not found")

// use the initial validator set from the consumer genesis as the stride chain's initial set
var strideValSet []*tmtypes.Validator
for _, update := range strideConsumerGenesis.InitialValSet {
tmPubKey, err := tmencoding.PubKeyFromProto(update.PubKey)
s.Require().NoError(err)
strideValSet = append(strideValSet, &tmtypes.Validator{
PubKey: tmPubKey,
VotingPower: update.Power,
Address: tmPubKey.Address(),
ProposerPriority: 0,
})
}

// Initialize the stride consumer chain, casted as a TestingApp
ibctesting.DefaultTestingAppInit = app.InitStrideIBCTestingApp(strideConsumerGenesis.InitialValSet)
s.StrideChain = ibctesting.NewTestChainWithValSet(
s.T(),
s.Coordinator,
StrideChainID,
tmtypes.NewValidatorSet(strideValSet),
s.ProviderChain.Signers,
)

// Call InitGenesis on the consumer
s.StrideChain.App.(*app.StrideApp).GetConsumerKeeper().InitGenesis(s.StrideChain.GetContext(), &strideConsumerGenesis)
s.StrideChain.NextBlock()

// Update coordinator
s.Coordinator.Chains = map[string]*ibctesting.TestChain{
StrideChainID: s.StrideChain,
hostChainID: s.HostChain,
ProviderChainID: s.ProviderChain,
}
s.IbcEnabled = true
}

// Creates clients, connections, and a transfer channel between stride and a host chain
Expand All @@ -217,7 +225,7 @@ func (s *AppTestHelper) CreateTransferChannel(hostChainID string) {

// Replace stride and host apps with those from TestingApp
s.App = s.StrideChain.App.(*app.StrideApp)
// s.HostApp = s.HostChain.GetSimApp()
s.HostApp = s.HostChain.GetSimApp()
s.Ctx = s.StrideChain.GetContext()

// Finally confirm the channel was setup properly
Expand Down Expand Up @@ -461,7 +469,7 @@ func (s *AppTestHelper) CreateAndStoreIBCDenom(baseDenom string) (ibcDenom strin
}

func (s *AppTestHelper) MarshalledICS20PacketData() sdk.AccAddress {
data := ibctransfertypes.FungibleTokenPacketData{}
data := transfertypes.FungibleTokenPacketData{}
return data.GetBytes()
}

Expand Down
Loading

0 comments on commit b08635f

Please sign in to comment.