Commit 4d66141b authored by Nicolas Lara's avatar Nicolas Lara
Browse files

Merge branch 'v15.x' into mergify/bp/v15.x/pr-4276

parents a16ce491 4062d2fc
Showing with 713 additions and 193 deletions
+713 -193
......@@ -52,6 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#4107](https://github.com/osmosis-labs/osmosis/pull/4107) Add superfluid unbond partial amount
* [#4207](https://github.com/osmosis-labs/osmosis/pull/4207) Add support for Async Interchain Queries
* [#4248](https://github.com/osmosis-labs/osmosis/pull/4248) Add panic recovery to `MultihopEstimateInGivenExactAmountOut`, `MultihopEstimateOutGivenExactAmountIn` and `RouteExactAmountOut`
* [#3911](https://github.com/osmosis-labs/osmosis/pull/3911) Add Packet Forward Middleware
## Misc Improvements
* [#4131](https://github.com/osmosis-labs/osmosis/pull/4141) Add GatherValuesFromStorePrefixWithKeyParser function to osmoutils.
......
......@@ -58,6 +58,10 @@ import (
ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types"
icqkeeper "github.com/strangelove-ventures/async-icq/v4/keeper"
packetforward "github.com/strangelove-ventures/packet-forward-middleware/v4/router"
packetforwardkeeper "github.com/strangelove-ventures/packet-forward-middleware/v4/router/keeper"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"
// IBC Transfer: Defines the "transfer" IBC port
transfer "github.com/cosmos/ibc-go/v4/modules/apps/transfer"
......@@ -145,6 +149,7 @@ type AppKeepers struct {
TransferStack *ibchooks.IBCMiddleware
Ics20WasmHooks *ibchooks.WasmHooks
HooksICS4Wrapper ibchooks.ICS4Middleware
PacketForwardKeeper *packetforwardkeeper.Keeper
// keys to access the substores
keys map[string]*sdk.KVStoreKey
......@@ -457,19 +462,24 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.GovKeeper = &govKeeper
}
// Create the IBC Transfer Stack from bottom to top:
// WireICS20PreWasmKeeper Create the IBC Transfer Stack from bottom to top:
//
// * SendPacket. Originates from the transferKeeper and and goes up the stack:
// * SendPacket. Originates from the transferKeeper and goes up the stack:
// transferKeeper.SendPacket -> ibc_rate_limit.SendPacket -> ibc_hooks.SendPacket -> channel.SendPacket
// * RecvPacket, message that originates from core IBC and goes down to app, the flow is the other way
// channel.RecvPacket -> ibc_hooks.OnRecvPacket -> ibc_rate_limit.OnRecvPacket -> transfer.OnRecvPacket
// channel.RecvPacket -> ibc_hooks.OnRecvPacket -> ibc_rate_limit.OnRecvPacket -> forward.OnRecvPacket -> transfer.OnRecvPacket
//
// Note that the forward middleware is only integrated on the "reveive" direction. It can be safely skipped when sending.
// Note also that the forward middleware is called "router", but we are using the name "forward" for clarity
// This may later be renamed upstream: https://github.com/strangelove-ventures/packet-forward-middleware/issues/10
//
// After this, the wasm keeper is required to be set on both
// appkeepers.WasmHooks AND appKeepers.RateLimitingICS4Wrapper
func (appKeepers *AppKeepers) WireICS20PreWasmKeeper(
appCodec codec.Codec,
bApp *baseapp.BaseApp,
hooksKeeper *ibchookskeeper.Keeper) {
hooksKeeper *ibchookskeeper.Keeper,
) {
// Setup the ICS4Wrapper used by the hooks middleware
osmoPrefix := sdk.GetConfig().GetBech32AccountAddrPrefix()
wasmHooks := ibchooks.NewWasmHooks(hooksKeeper, nil, osmoPrefix) // The contract keeper needs to be set later
......@@ -507,10 +517,31 @@ func (appKeepers *AppKeepers) WireICS20PreWasmKeeper(
)
appKeepers.TransferKeeper = &transferKeeper
appKeepers.RawIcs20TransferAppModule = transfer.NewAppModule(*appKeepers.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(*appKeepers.TransferKeeper)
// Packet Forward Middleware
// Initialize packet forward middleware router
appKeepers.PacketForwardKeeper = packetforwardkeeper.NewKeeper(
appCodec,
appKeepers.keys[packetforwardtypes.StoreKey],
appKeepers.GetSubspace(packetforwardtypes.ModuleName),
appKeepers.TransferKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.DistrKeeper,
appKeepers.BankKeeper,
// The ICS4Wrapper is replaced by the HooksICS4Wrapper instead of the channel so that sending can be overridden by the middleware
appKeepers.HooksICS4Wrapper,
)
packetForwardMiddleware := packetforward.NewIBCMiddleware(
transfer.NewIBCModule(*appKeepers.TransferKeeper),
appKeepers.PacketForwardKeeper,
0,
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp,
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)
// RateLimiting IBC Middleware
rateLimitingTransferModule := ibcratelimit.NewIBCModule(transferIBCModule, appKeepers.RateLimitingICS4Wrapper)
rateLimitingTransferModule := ibcratelimit.NewIBCModule(packetForwardMiddleware, appKeepers.RateLimitingICS4Wrapper)
// Hooks Middleware
hooksTransferModule := ibchooks.NewIBCMiddleware(&rateLimitingTransferModule, &appKeepers.HooksICS4Wrapper)
appKeepers.TransferStack = &hooksTransferModule
......@@ -586,6 +617,7 @@ func (appKeepers *AppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legac
paramsKeeper.Subspace(twaptypes.ModuleName)
paramsKeeper.Subspace(ibcratelimittypes.ModuleName)
paramsKeeper.Subspace(icqtypes.ModuleName)
paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
return paramsKeeper
}
......@@ -686,5 +718,6 @@ func KVStoreKeys() []string {
protorevtypes.StoreKey,
ibchookstypes.StoreKey,
icqtypes.StoreKey,
packetforwardtypes.StoreKey,
}
}
......@@ -6,6 +6,7 @@ import (
transfer "github.com/cosmos/ibc-go/v4/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v4/modules/core"
ibcclientclient "github.com/cosmos/ibc-go/v4/modules/core/02-client/client"
"github.com/strangelove-ventures/packet-forward-middleware/v4/router"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
......@@ -101,4 +102,5 @@ var AppModuleBasics = []module.AppModuleBasic{
ica.AppModuleBasic{},
ibc_hooks.AppModuleBasic{},
ibc_rate_limit.AppModuleBasic{},
router.AppModuleBasic{},
}
......@@ -2,6 +2,8 @@ package v15
import (
store "github.com/cosmos/cosmos-sdk/store/types"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"
"github.com/osmosis-labs/osmosis/v14/app/upgrades"
poolmanagertypes "github.com/osmosis-labs/osmosis/v14/x/poolmanager/types"
protorevtypes "github.com/osmosis-labs/osmosis/v14/x/protorev/types"
......@@ -16,7 +18,7 @@ var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{poolmanagertypes.StoreKey, valsetpreftypes.StoreKey, protorevtypes.StoreKey, icqtypes.StoreKey},
Added: []string{poolmanagertypes.StoreKey, valsetpreftypes.StoreKey, protorevtypes.StoreKey, icqtypes.StoreKey, packetforwardtypes.StoreKey},
Deleted: []string{},
},
}
......@@ -4,6 +4,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
......@@ -27,6 +28,7 @@ func CreateUpgradeHandler(
poolmanagerParams := poolmanagertypes.NewParams(keepers.GAMMKeeper.GetParams(ctx).PoolCreationFee)
keepers.PoolManagerKeeper.SetParams(ctx, poolmanagerParams)
keepers.PacketForwardKeeper.SetParams(ctx, packetforwardtypes.DefaultParams())
// N.B: pool id in gamm is to be deprecated in the future
// Instead,it is moved to poolmanager.
......
......@@ -5,7 +5,7 @@ go 1.19
require (
github.com/CosmWasm/wasmd v0.30.0
github.com/cosmos/cosmos-proto v1.0.0-alpha8
github.com/cosmos/cosmos-sdk v0.46.8
github.com/cosmos/cosmos-sdk v0.45.11
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/ibc-go/v4 v4.3.0
github.com/gogo/protobuf v1.3.3
......@@ -14,6 +14,7 @@ require (
github.com/golangci/golangci-lint v1.51.1
github.com/gorilla/mux v1.8.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/iancoleman/orderedmap v0.2.0
github.com/mattn/go-sqlite3 v1.14.16
github.com/ory/dockertest/v3 v3.9.1
github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3
......@@ -26,8 +27,8 @@ require (
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
// Async ICQ branch: ibc-v4
github.com/strangelove-ventures/async-icq/v4 v4.0.0-rc0
github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.3
github.com/stretchr/testify v1.8.1
github.com/tendermint/tendermint v0.34.24
github.com/tendermint/tm-db v0.6.8-0.20220506192307-f628bb5dc95b
......@@ -319,4 +320,5 @@ replace (
github.com/tendermint/tendermint => github.com/informalsystems/tendermint v0.34.24
// use grpc compatible with cosmos protobufs
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
......@@ -611,6 +611,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg=
github.com/huin/goupnp v1.0.0/go.mod h1:n9v9KO1tAxYH82qOn+UTIFQDmx5n1Zxd/ClZDMX7Bnc=
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
......@@ -1061,6 +1063,8 @@ github.com/steakknife/bloomfilter v0.0.0-20180922174646-6819c0d2a570/go.mod h1:8
github.com/steakknife/hamming v0.0.0-20180906055917-c99c65617cd3/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU=
github.com/strangelove-ventures/async-icq/v4 v4.0.0-rc0 h1:foE/5O2/XiqGsdTKx3R0BTfKgW9KnUYyQLZt0WFSesE=
github.com/strangelove-ventures/async-icq/v4 v4.0.0-rc0/go.mod h1:thzXHoaK1MgPDCjN7Rp9A/VcHA4cmjQpKCtVNt2O2xk=
github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.3 h1:3E7I9C+gM7n0+OkI7JmvWH5PGD6pZOIc1+mUUooh6dI=
github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.3/go.mod h1:AG8F5pdk3x1h7PlRvPoMem3623W+w8HJHrWYkVJ51kk=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,6 +3,9 @@ package e2e
import (
"encoding/json"
"fmt"
transfertypes "github.com/cosmos/ibc-go/v4/modules/apps/transfer/types"
"github.com/iancoleman/orderedmap"
"github.com/osmosis-labs/osmosis/v14/tests/e2e/configurer/chain"
"io"
"os"
"path/filepath"
......@@ -10,6 +13,8 @@ import (
"strings"
"time"
packetforwardingtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types"
ibchookskeeper "github.com/osmosis-labs/osmosis/x/ibc-hooks/keeper"
paramsutils "github.com/cosmos/cosmos-sdk/x/params/client/utils"
......@@ -25,6 +30,30 @@ import (
"github.com/osmosis-labs/osmosis/v14/tests/e2e/initialization"
)
// Reusable Checks
// CheckBalance Checks the balance of an address
func (s *IntegrationTestSuite) CheckBalance(node *chain.NodeConfig, addr, denom string, amount int64) {
// check the balance of the contract
s.Require().Eventually(func() bool {
balance, err := node.QueryBalances(addr)
s.Require().NoError(err)
if len(balance) == 0 {
return false
}
// check that the amount is in one of the balances inside the balance list
for _, b := range balance {
if b.Denom == denom && b.Amount.Int64() == amount {
return true
}
}
return false
},
1*time.Minute,
10*time.Millisecond,
)
}
// TestGeometricTwapMigration tests that the geometric twap record
// migration runs succesfully. It does so by attempting to execute
// the swap on the pool created pre-upgrade. When a pool is created
......@@ -273,37 +302,44 @@ func (s *IntegrationTestSuite) TestLargeWasmUpload() {
node.StoreWasmCode("bytecode/large.wasm", initialization.ValidatorWalletName)
}
func (s *IntegrationTestSuite) TestIBCWasmHooks() {
if s.skipIBC {
s.T().Skip("Skipping IBC tests")
}
chainA := s.configurer.GetChainConfig(0)
chainB := s.configurer.GetChainConfig(1)
nodeA, err := chainA.GetDefaultNode()
s.NoError(err)
nodeB, err := chainB.GetDefaultNode()
s.NoError(err)
// copy the contract from x/rate-limit/testdata/
func (s *IntegrationTestSuite) UploadAndInstantiateCounter(chain *chain.Config) string {
// copy the contract from tests/ibc-hooks/bytecode
wd, err := os.Getwd()
s.NoError(err)
// co up two levels
projectDir := filepath.Dir(filepath.Dir(wd))
err = copyFile(projectDir+"/tests/ibc-hooks/bytecode/counter.wasm", wd+"/scripts/counter.wasm")
s.NoError(err)
node, err := chain.GetDefaultNode()
s.NoError(err)
nodeA.StoreWasmCode("counter.wasm", initialization.ValidatorWalletName)
chainA.LatestCodeId = int(nodeA.QueryLatestWasmCodeID())
nodeA.InstantiateWasmContract(
strconv.Itoa(chainA.LatestCodeId),
node.StoreWasmCode("counter.wasm", initialization.ValidatorWalletName)
chain.LatestCodeId = int(node.QueryLatestWasmCodeID())
node.InstantiateWasmContract(
strconv.Itoa(chain.LatestCodeId),
`{"count": 0}`,
initialization.ValidatorWalletName)
contracts, err := nodeA.QueryContractsFromId(chainA.LatestCodeId)
contracts, err := node.QueryContractsFromId(chain.LatestCodeId)
s.NoError(err)
s.Require().Len(contracts, 1, "Wrong number of contracts for the counter")
contractAddr := contracts[0]
return contractAddr
}
func (s *IntegrationTestSuite) TestIBCWasmHooks() {
if s.skipIBC {
s.T().Skip("Skipping IBC tests")
}
chainA := s.configurer.GetChainConfig(0)
chainB := s.configurer.GetChainConfig(1)
nodeA, err := chainA.GetDefaultNode()
s.NoError(err)
nodeB, err := chainB.GetDefaultNode()
s.NoError(err)
contractAddr := s.UploadAndInstantiateCounter(chainA)
transferAmount := int64(10)
validatorAddr := nodeB.GetWallet(initialization.ValidatorWalletName)
......@@ -311,23 +347,15 @@ func (s *IntegrationTestSuite) TestIBCWasmHooks() {
fmt.Sprintf(`{"wasm":{"contract":"%s","msg": {"increment": {}} }}`, contractAddr))
// check the balance of the contract
s.Eventually(func() bool {
balance, err := nodeA.QueryBalances(contractAddr)
s.Require().NoError(err)
if len(balance) == 0 {
return false
}
return balance[0].Amount.Int64() == transferAmount
},
1*time.Minute,
10*time.Millisecond,
)
denomTrace := transfertypes.ParseDenomTrace(transfertypes.GetPrefixedDenom("transfer", "channel-0", "uosmo"))
ibcDenom := denomTrace.IBCDenom()
s.CheckBalance(nodeA, contractAddr, ibcDenom, transferAmount)
// sender wasm addr
senderBech32, err := ibchookskeeper.DeriveIntermediateSender("channel-0", validatorAddr, "osmo")
var response map[string]interface{}
s.Eventually(func() bool {
s.Require().Eventually(func() bool {
response, err = nodeA.QueryWasmSmart(contractAddr, fmt.Sprintf(`{"get_total_funds": {"addr": "%s"}}`, senderBech32))
totalFunds := response["total_funds"].([]interface{})[0]
amount := totalFunds.(map[string]interface{})["amount"].(string)
......@@ -340,6 +368,56 @@ func (s *IntegrationTestSuite) TestIBCWasmHooks() {
)
}
// TestPacketForwarding sends a packet from chainA to chainB, and forwards it
// back to chainA with a custom memo to execute the counter contract on chain A
func (s *IntegrationTestSuite) TestPacketForwarding() {
if s.skipIBC {
s.T().Skip("Skipping IBC tests")
}
chainA := s.configurer.GetChainConfig(0)
nodeA, err := chainA.GetDefaultNode()
s.NoError(err)
// Instantiate the counter contract on chain A
contractAddr := s.UploadAndInstantiateCounter(chainA)
transferAmount := int64(10)
validatorAddr := nodeA.GetWallet(initialization.ValidatorWalletName)
// Specify that the counter contract should be called on chain A when the packet is received
contractCallMemo := []byte(fmt.Sprintf(`{"wasm":{"contract":"%s","msg": {"increment": {}} }}`, contractAddr))
// Generate the forward metadata
forwardMetadata := packetforwardingtypes.ForwardMetadata{
Receiver: contractAddr,
Port: "transfer",
Channel: "channel-0",
Next: packetforwardingtypes.NewJSONObject(false, contractCallMemo, orderedmap.OrderedMap{}), // The packet sent to chainA will have this memo
}
memoData := packetforwardingtypes.PacketMetadata{Forward: &forwardMetadata}
forwardMemo, err := json.Marshal(memoData)
s.NoError(err)
// Send the transfer from chainA to chainB. ChainB will parse the memo and forward the packet back to chainA
nodeA.SendIBCTransfer(validatorAddr, validatorAddr, fmt.Sprintf("%duosmo", transferAmount), string(forwardMemo))
// check the balance of the contract
s.CheckBalance(nodeA, contractAddr, "uosmo", transferAmount)
// sender wasm addr
senderBech32, err := ibchookskeeper.DeriveIntermediateSender("channel-0", validatorAddr, "osmo")
var response map[string]interface{}
s.Require().Eventually(func() bool {
response, err = nodeA.QueryWasmSmart(contractAddr, fmt.Sprintf(`{"get_count": {"addr": "%s"}}`, senderBech32))
if err != nil {
return false
}
count := response["count"].(float64)
return err == nil && count == 0
},
15*time.Second,
10*time.Millisecond,
)
}
// TestAddToExistingLockPostUpgrade ensures addToExistingLock works for locks created preupgrade.
func (s *IntegrationTestSuite) TestAddToExistingLockPostUpgrade() {
if s.skipUpgrade {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment