Skip to content

Commit

Permalink
refactor: sqs out-of-process (backport #7242) (#7271)
Browse files Browse the repository at this point in the history
* refactor: sqs out-of-process (#7242)

* refactor: sqs out-of-process

* spell

* godocs

* go 1.20

* go work

* updaets

* updates

* sqs deps

* updates

* latest

* updates

* updates

* updates

(cherry picked from commit ff62dbd)

# Conflicts:
#	go.mod
#	go.sum
#	ingest/sqs/README.md
#	ingest/sqs/router/delivery/http/router_handler.go
#	ingest/sqs/router/usecase/candidate_routes.go
#	ingest/sqs/router/usecase/pools/routable_transmuter_pool.go
#	ingest/sqs/router/usecase/router_test.go
#	ingest/sqs/router/usecase/router_usecase_test.go
#	ingest/sqs/router/usecase/routertesting/parsing/mainnet_pools_test.go
#	ingest/sqs/scripts/healthcheck.sh
#	ingest/sqs/scripts/validate_cl_state.sh
#	osmomath/go.sum

* fix conflicts

* Auto: update go.mod after push to mergify/bp/v21.x/pr-7242 that modified dependencies locally

* fix script

* open go mods

---------

Co-authored-by: Roman <[email protected]>
Co-authored-by: Adam Tucker <[email protected]>
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
4 people authored Jan 9, 2024
1 parent e5fc875 commit 1a29dd0
Show file tree
Hide file tree
Showing 103 changed files with 804 additions and 11,363 deletions.
9 changes: 4 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ import (
"github.com/cosmos/ibc-go/v7/modules/apps/transfer"
ibc "github.com/cosmos/ibc-go/v7/modules/core"

"github.com/osmosis-labs/osmosis/v21/ingest/sqs"
"github.com/osmosis-labs/osmosis/v21/ingest/sqs/domain"

"github.com/osmosis-labs/osmosis/osmoutils"

nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
Expand Down Expand Up @@ -95,10 +98,6 @@ import (
_ "github.com/osmosis-labs/osmosis/v21/client/docs/statik"
"github.com/osmosis-labs/osmosis/v21/ingest"
"github.com/osmosis-labs/osmosis/v21/x/mint"

"github.com/osmosis-labs/osmosis/v21/ingest/sqs"

"github.com/osmosis-labs/osmosis/v21/ingest/sqs/pools/common"
)

const appName = "OsmosisApp"
Expand Down Expand Up @@ -259,7 +258,7 @@ func NewOsmosisApp(

// Initialize the SQS ingester if it is enabled.
if sqsConfig.IsEnabled {
sqsKeepers := common.SQSIngestKeepers{
sqsKeepers := domain.SQSIngestKeepers{
GammKeeper: app.GAMMKeeper,
CosmWasmPoolKeeper: app.CosmwasmPoolKeeper,
BankKeeper: app.BankKeeper,
Expand Down
35 changes: 29 additions & 6 deletions app/apptesting/cosmwasmpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package apptesting

import (
"encoding/json"
"fmt"
"os"
"strings"

Expand All @@ -22,20 +23,31 @@ const (
TransmuterContractName = "transmuter"
TransmuterMigrateContractName = "transmuter_migrate"
DefaultCodeId = 1

osmosisRepository = "osmosis"
osmosisRepoTransmuterPath = "x/cosmwasmpool/bytecode"
)

// PrepareCosmWasmPool sets up a cosmwasm pool with the default parameters.
func (s *KeeperTestHelper) PrepareCosmWasmPool() cosmwasmpooltypes.CosmWasmExtension {
return s.PrepareCustomTransmuterPool(s.TestAccs[0], []string{DefaultTransmuterDenomA, DefaultTransmuterDenomB})
}

// PrepareCustomTransmuterPool sets up a transmuter pool with the custom parameters.
// PrepareCustomTransmuterPool sets up a transmuter pool with the default parameters assuming that
// the transmuter contract is stored under x/cosmwasmpool/bytecode in the Osmosis repository.
func (s *KeeperTestHelper) PrepareCustomTransmuterPool(owner sdk.AccAddress, denoms []string) cosmwasmpooltypes.CosmWasmExtension {
return s.PrepareCustomTransmuterPoolCustomProject(owner, denoms, osmosisRepository, osmosisRepoTransmuterPath)
}

// PrepareCustomTransmuterPoolCustomProject sets up a transmuter pool with the custom parameters.
// Gives flexibility for the helper to be reused outside of the Osmosis repository by providing custom
// project name and bytecode path.
func (s *KeeperTestHelper) PrepareCustomTransmuterPoolCustomProject(owner sdk.AccAddress, denoms []string, projectName, byteCodePath string) cosmwasmpooltypes.CosmWasmExtension {
// Mint some assets to the account.
s.FundAcc(s.TestAccs[0], DefaultAcctFunds)

// Upload contract code and get the code id.
codeId := s.StoreCosmWasmPoolContractCode(TransmuterContractName)
codeId := s.StoreCosmWasmPoolContractCodeCustomProject(TransmuterContractName, projectName, byteCodePath)

// Add code id to the whitelist.
s.App.CosmwasmPoolKeeper.WhitelistCodeId(s.Ctx, codeId)
Expand Down Expand Up @@ -79,6 +91,13 @@ func (s *KeeperTestHelper) GetTransmuterInstantiateMsgBytes(poolAssetDenoms []st
// StoreCosmWasmPoolContractCode stores the cosmwasm pool contract code in the wasm keeper and returns the code id.
// contractName is the name of the contract file in the x/cosmwasmpool/bytecode directory without the .wasm extension.
func (s *KeeperTestHelper) StoreCosmWasmPoolContractCode(contractName string) uint64 {
return s.StoreCosmWasmPoolContractCodeCustomProject(contractName, osmosisRepository, osmosisRepoTransmuterPath)
}

// StoreCosmWasmPoolContractCodeCustomProject stores the cosmwasm pool contract code in the wasm keeper and returns the code id.
// contractName is the name of the contract file in the x/cosmwasmpool/bytecode directory without the .wasm extension.
// It has the flexibility of being used from outside the Osmosis repository by providing custom project name and bytecode path.
func (s *KeeperTestHelper) StoreCosmWasmPoolContractCodeCustomProject(contractName, projectName, byteCodePath string) uint64 {
cosmwasmpoolModuleAddr := s.App.AccountKeeper.GetModuleAddress(cosmwasmpooltypes.ModuleName)
s.Require().NotNil(cosmwasmpoolModuleAddr)

Expand All @@ -93,7 +112,7 @@ func (s *KeeperTestHelper) StoreCosmWasmPoolContractCode(contractName string) ui
})
s.Require().NoError(err)

code := s.GetContractCode(contractName)
code := s.GetContractCodeCustomProject(contractName, projectName, byteCodePath)

instantiateConfig := wasmtypes.AccessConfig{Permission: wasmtypes.AccessTypeAnyOfAddresses, Addresses: []string{cosmwasmpoolModuleAddr.String()}}
codeID, _, err := s.App.ContractKeeper.Create(s.Ctx, cosmwasmpoolModuleAddr, code, &instantiateConfig)
Expand All @@ -102,16 +121,20 @@ func (s *KeeperTestHelper) StoreCosmWasmPoolContractCode(contractName string) ui
return codeID
}

func (s *KeeperTestHelper) GetContractCode(contractName string) []byte {
return s.GetContractCodeCustomProject(contractName, "osmosis", "x/cosmwasmpool/bytecode")
}

// GetContractCode returns the contract code for the given contract name.
// Assumes that the contract code is stored under x/cosmwasmpool/bytecode.
func (s *KeeperTestHelper) GetContractCode(contractName string) []byte {
func (s *KeeperTestHelper) GetContractCodeCustomProject(contractName string, projectName string, path string) []byte {
workingDir, err := os.Getwd()
s.Require().NoError(err)

projectRootPath := "/osmosis/"
projectRootPath := fmt.Sprintf("/%s/", projectName)
projectRootIndex := strings.LastIndex(workingDir, projectRootPath) + len(projectRootPath)
workingDir = workingDir[:projectRootIndex]
code, err := os.ReadFile(workingDir + "x/cosmwasmpool/bytecode/" + contractName + ".wasm")
code, err := os.ReadFile(workingDir + path + "/" + contractName + ".wasm")
s.Require().NoError(err)

return code
Expand Down
9 changes: 8 additions & 1 deletion app/apptesting/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ func (s *KeeperTestHelper) SetupWithCustomChainId(chainId string) {
// PrepareAllSupportedPools creates all supported pools and returns their IDs.
// Additionally, attaches an internal gauge ID for each pool.
func (s *KeeperTestHelper) PrepareAllSupportedPools() SupportedPoolAndGaugeInfo {
return s.PrepareAllSupportedPoolsCustomProject(osmosisRepository, osmosisRepoTransmuterPath)
}

// PrepareAllSupportedPoolsCustomProject creates all supported pools and returns their IDs.
// Additionally, attaches an internal gauge ID for each pool.
// Allows the flexibility of being used from outside the Osmosis repository by providing custom project name and transmuter bytecode path.
func (s *KeeperTestHelper) PrepareAllSupportedPoolsCustomProject(projectName, transmuterPath string) SupportedPoolAndGaugeInfo {
// This is the ID of the first gauge created next (concentrated).
nextGaugeID := s.App.IncentivesKeeper.GetLastGaugeID(s.Ctx) + 1

Expand All @@ -156,7 +163,7 @@ func (s *KeeperTestHelper) PrepareAllSupportedPools() SupportedPoolAndGaugeInfo
concentratedPoolID = concentratedPool.GetId()
balancerPoolID = s.PrepareBalancerPool()
stableswapPoolID = s.PrepareBasicStableswapPool()
cosmWasmPool = s.PrepareCosmWasmPool()
cosmWasmPool = s.PrepareCustomTransmuterPoolCustomProject(s.TestAccs[0], []string{DefaultTransmuterDenomA, DefaultTransmuterDenomB}, projectName, transmuterPath)
cosmWasmPoolID = cosmWasmPool.GetId()
)
return SupportedPoolAndGaugeInfo{
Expand Down
43 changes: 0 additions & 43 deletions cmd/osmosisd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,49 +559,6 @@ is-enabled = "false"
db-host = "{{ .SidecarQueryServerConfig.StorageHost }}"
db-port = "{{ .SidecarQueryServerConfig.StoragePort }}"
# Defines the web server configuration.
server-address = "{{ .SidecarQueryServerConfig.ServerAddress }}"
timeout-duration-secs = "{{ .SidecarQueryServerConfig.ServerTimeoutDurationSecs }}"
# Defines the logger configuration.
logger-filename = "{{ .SidecarQueryServerConfig.LoggerFilename }}"
logger-is-production = "{{ .SidecarQueryServerConfig.LoggerIsProduction }}"
logger-level = "{{ .SidecarQueryServerConfig.LoggerLevel }}"
# Defines the gRPC gateway endpoint of the chain.
grpc-gateway-endpoint = "{{ .SidecarQueryServerConfig.ChainGRPCGatewayEndpoint }}"
# The list of preferred poold IDs in the router.
# These pools will be prioritized in the candidate route selection, ignoring all other
# heuristics such as TVL.
preferred-pool-ids = "{{ .SidecarQueryServerConfig.Router.PreferredPoolIDs }}"
# The maximum number of pools to be included in a single route.
max-pools-per-route = "{{ .SidecarQueryServerConfig.Router.MaxPoolsPerRoute }}"
# The maximum number of routes to be returned in candidate route search.
max-routes = "{{ .SidecarQueryServerConfig.Router.MaxRoutes }}"
# The maximum number of routes to be split across. Must be smaller than or
# equal to max-routes.
max-split-routes = "{{ .SidecarQueryServerConfig.Router.MaxSplitRoutes }}"
# The maximum number of iterations to split a route across.
max-split-iterations = "{{ .SidecarQueryServerConfig.Router.MaxSplitIterations }}"
# The minimum liquidity of a pool to be included in a route.
min-osmo-liquidity = "{{ .SidecarQueryServerConfig.Router.MinOSMOLiquidity }}"
# The height interval at which the candidate routes are recomputed and updated in
# Redis
route-update-height-interval = "{{ .SidecarQueryServerConfig.Router.RouteUpdateHeightInterval }}"
# Whether to enable candidate route caching in Redis.
route-cache-enabled = "{{ .SidecarQueryServerConfig.Router.RouteCacheEnabled }}"
# The number of seconds to cache routes for before expiry.
route-cache-expiry-seconds = "{{ .SidecarQueryServerConfig.Router.RouteCacheExpirySeconds }}"
###############################################################################
### Wasm Configuration ###
###############################################################################
Expand Down
Loading

0 comments on commit 1a29dd0

Please sign in to comment.