Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch/Make osmosis asset list a config, use default value of chain registry… #559

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func setupIndexer() *Indexer {
}

// Some chains do not have the denom metadata URL available on chain, so we do chain specific downloads instead.
tasks.DoChainSpecificUpsertDenoms(indexer.db, indexer.cfg.Lens.ChainID, indexer.cfg.Base.RequestRetryAttempts, indexer.cfg.Base.RequestRetryMaxWait)
tasks.DoChainSpecificUpsertDenoms(indexer.db, indexer.cfg.Lens.ChainID, indexer.cfg.Base.RequestRetryAttempts, indexer.cfg.Base.RequestRetryMaxWait, indexer.cfg.AssetList)
indexer.cl = config.GetLensClient(indexer.cfg.Lens)

core.ChainSpecificMessageTypeHandlerBootstrap(indexer.cfg.Lens.ChainID, indexer.cl)
Expand Down
4 changes: 2 additions & 2 deletions cmd/update_denoms.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ func updateDenoms(cmd *cobra.Command, args []string) {
config.Log.Infof("Running denom update task for all supported chains")
for chainID, function := range tasks.ChainSpecificDenomUpsertFunctions {
config.Log.Infof("Running denom update task for chain %s", chainID)
function(db, cfg.Base.RequestRetryAttempts, cfg.Base.RequestRetryMaxWait)
function(db, cfg.Base.RequestRetryAttempts, cfg.Base.RequestRetryMaxWait, cfg.AssetList)
}
case cfg.Lens.ChainID != "":
function, ok := tasks.ChainSpecificDenomUpsertFunctions[cfg.Lens.ChainID]
if ok {
config.Log.Infof("Running denom update task for chain %s found in config", cfg.Lens.ChainID)
function(db, cfg.Base.RequestRetryAttempts, cfg.Base.RequestRetryMaxWait)
function(db, cfg.Base.RequestRetryAttempts, cfg.Base.RequestRetryMaxWait, cfg.AssetList)
config.Log.Info("Done")
} else {
config.Log.Fatalf("No denom update functionality for chain-id %s", cfg.Lens.ChainID)
Expand Down
5 changes: 5 additions & 0 deletions config/assetlist_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package config

type AssetList struct {
OsmosisAssetListURL string
}
4 changes: 4 additions & 0 deletions config/index_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type IndexConfig struct {
Log log
Lens lens
Client client
AssetList AssetList
}

type indexBase struct {
Expand Down Expand Up @@ -72,6 +73,9 @@ func SetupIndexSpecificFlags(conf *IndexConfig, cmd *cobra.Command) {
cmd.PersistentFlags().BoolVar(&conf.Base.ExitWhenCaughtUp, "base.exit-when-caught-up", false, "mainly used for Osmosis rewards indexing")
cmd.PersistentFlags().Int64Var(&conf.Base.RequestRetryAttempts, "base.request-retry-attempts", 0, "number of RPC query retries to make")
cmd.PersistentFlags().Uint64Var(&conf.Base.RequestRetryMaxWait, "base.request-retry-max-wait", 30, "max retry incremental backoff wait time in seconds")

// mainnet chain configs
cmd.PersistentFlags().StringVar(&conf.AssetList.OsmosisAssetListURL, "asset-list.osmosis-asset-list-url", "https://raw.githubusercontent.com/cosmos/chain-registry/9df81ac3e93a040e678d3fa99b9799d7061377c9/osmosis/assetlist.json", "osmosis asset list url, must fit the asset list schema")
}

func (conf *IndexConfig) Validate() error {
Expand Down
12 changes: 8 additions & 4 deletions config/update_denoms_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package config
import "github.com/spf13/cobra"

type UpdateDenomsConfig struct {
Database Database
Lens lens
Log log
Base updateDenomsBase
Database Database
Lens lens
Log log
Base updateDenomsBase
AssetList AssetList
}

type updateDenomsBase struct {
Expand All @@ -18,6 +19,9 @@ func SetupUpdateDenomsSpecificFlags(conf *UpdateDenomsConfig, cmd *cobra.Command
cmd.Flags().BoolVar(&conf.Base.UpdateAll, "base.update-all", false, "If provided, the update script will ignore the config chain-id and update all denoms by reaching out to all assetlists supported.")
cmd.PersistentFlags().Int64Var(&conf.Base.RequestRetryAttempts, "base.request-retry-attempts", 0, "number of RPC query retries to make")
cmd.PersistentFlags().Uint64Var(&conf.Base.RequestRetryMaxWait, "base.request-retry-max-wait", 30, "max retry incremental backoff wait time in seconds")

// mainnet chain configs
cmd.PersistentFlags().StringVar(&conf.AssetList.OsmosisAssetListURL, "asset-list.osmosis-asset-list-url", "https://raw.githubusercontent.com/cosmos/chain-registry/9df81ac3e93a040e678d3fa99b9799d7061377c9/osmosis/assetlist.json", "osmosis asset list url, must fit the asset list schema")
}

func (conf *UpdateDenomsConfig) Validate() error {
Expand Down
19 changes: 12 additions & 7 deletions tasks/denoms.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ type DenomUnit struct {
Aliases []string
}

var ChainSpecificDenomUpsertFunctions = map[string]func(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSeconds uint64){
var ChainSpecificDenomUpsertFunctions = map[string]func(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSeconds uint64, conf config.AssetList){
osmosis.ChainID: UpsertOsmosisDenoms,
juno.ChainID: UpsertJunoDenoms,
}

func DoChainSpecificUpsertDenoms(db *gorm.DB, chain string, retryMaxAttempts int64, retryMaxWaitSeconds uint64) {
func DoChainSpecificUpsertDenoms(db *gorm.DB, chain string, retryMaxAttempts int64, retryMaxWaitSeconds uint64, conf config.AssetList) {
if chain == osmosis.ChainID {
UpsertOsmosisDenoms(db, retryMaxAttempts, retryMaxWaitSeconds)
UpsertOsmosisDenoms(db, retryMaxAttempts, retryMaxWaitSeconds, conf)
}

if chain == juno.ChainID {
UpsertJunoDenoms(db, retryMaxAttempts, retryMaxWaitSeconds)
UpsertJunoDenoms(db, retryMaxAttempts, retryMaxWaitSeconds, conf)
}
// may want to move this elsewhere, or eliminate entirely
// I would prefer we just grab the denoms when needed always
Expand All @@ -53,9 +53,13 @@ func DoChainSpecificUpsertDenoms(db *gorm.DB, chain string, retryMaxAttempts int
dbTypes.CacheIBCDenoms(db)
}

func UpsertOsmosisDenoms(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSeconds uint64) {
func UpsertOsmosisDenoms(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSeconds uint64, conf config.AssetList) {
config.Log.Info("Updating Omsosis specific denoms")
url := "https://raw.githubusercontent.com/osmosis-labs/assetlists/main/osmosis-1/osmosis-1.assetlist.json"
url := conf.OsmosisAssetListURL

if url == "" {
config.Log.Fatal("No assetlist URL provided for Osmosis Denom Metadata")
}

denomAssets, err := getAssetsListWithRetry(url, retryMaxAttempts, retryMaxWaitSeconds)
if err != nil {
Expand All @@ -67,9 +71,10 @@ func UpsertOsmosisDenoms(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSecond
config.Log.Fatal("Upsert Osmosis Denom Metadata", err)
}
}
config.Log.Info("Finished updating Omsosis specific denoms")
}

func UpsertJunoDenoms(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSeconds uint64) {
func UpsertJunoDenoms(db *gorm.DB, retryMaxAttempts int64, retryMaxWaitSeconds uint64, conf config.AssetList) {
config.Log.Info("Updating Juno specific denoms")
url := "https://raw.githubusercontent.com/cosmos/chain-registry/master/juno/assetlist.json"

Expand Down
Loading