diff --git a/bootstrap/config/config.go b/bootstrap/config/config.go index ede886161..45fc74ca0 100644 --- a/bootstrap/config/config.go +++ b/bootstrap/config/config.go @@ -51,14 +51,21 @@ type Debug struct { } type TendermintApp struct { - HTTPRPCUrl string `yaml:"http_rpc_url" toml:"http_rpc_url" xml:"http_rpc_url" json:"http_rpc_url,omitempty"` - Insecure bool `yaml:"insecure" toml:"insecure" xml:"insecure" json:"insecure,omitempty"` - StrictGenesisParsing bool `yaml:"strict_genesis_parsing" toml:"strict_genesis_parsing" xml:"strict_genesis_parsing" json:"strict_genesis_parsing,omitempty"` + HTTPRPCUrl string `yaml:"http_rpc_url" toml:"http_rpc_url" xml:"http_rpc_url" json:"http_rpc_url,omitempty"` + Insecure bool `yaml:"insecure" toml:"insecure" xml:"insecure" json:"insecure,omitempty"` + MaybeAuthQueryKV *AuthQueryKV `yaml:"auth_query_kv" toml:"auth_query_kv" xml:"auth_query_kv" json:"auth_query_kv,omitempty"` + StrictGenesisParsing bool `yaml:"strict_genesis_parsing" toml:"strict_genesis_parsing" xml:"strict_genesis_parsing" json:"strict_genesis_parsing,omitempty"` } type CosmosApp struct { - HTTPRPCUrl string `yaml:"http_rpc_url" toml:"http_rpc_url" xml:"http_rpc_url" json:"http_rpc_url,omitempty"` - Insecure bool `yaml:"insecure" toml:"insecure" xml:"insecure" json:"insecure,omitempty"` + HTTPRPCUrl string `yaml:"http_rpc_url" toml:"http_rpc_url" xml:"http_rpc_url" json:"http_rpc_url,omitempty"` + Insecure bool `yaml:"insecure" toml:"insecure" xml:"insecure" json:"insecure,omitempty"` + MaybeAuthQueryKV *AuthQueryKV `yaml:"auth_query_kv" toml:"auth_query_kv" xml:"auth_query_kv" json:"auth_query_kv,omitempty"` +} + +type AuthQueryKV struct { + Key string `yaml:"key" toml:"key" xml:"key" json:"key,omitempty"` + Value string `yaml:"value" toml:"value" xml:"value" json:"value,omitempty"` } type Postgres struct { diff --git a/bootstrap/indexservice.go b/bootstrap/indexservice.go index 1573eac7a..fd09b45e6 100644 --- a/bootstrap/indexservice.go +++ b/bootstrap/indexservice.go @@ -22,17 +22,15 @@ type IndexService struct { projections []projection_entity.Projection cronJobs []projection_entity.CronJob - mode string - accountAddressPrefix string - consNodeAddressPrefix string - bondingDenom string - windowSize int - tendermintHTTPRPCURL string - cosmosAppHTTPRPCURL string - insecureTendermintClient bool - insecureCosmosAppClient bool - strictGenesisParsing bool - startingBlockHeight int64 + mode string + accountAddressPrefix string + consNodeAddressPrefix string + bondingDenom string + windowSize int + tendermintApp config.TendermintApp + cosmosApp config.CosmosApp + + startingBlockHeight int64 cosmosVersionBlockHeight utils.CosmosVersionBlockHeight @@ -57,17 +55,14 @@ func NewIndexService( projections: projections, cronJobs: cronJobs, - mode: config.IndexService.Mode, - consNodeAddressPrefix: config.Blockchain.ConNodeAddressPrefix, - accountAddressPrefix: config.Blockchain.AccountAddressPrefix, - bondingDenom: config.Blockchain.BondingDenom, - windowSize: config.IndexService.WindowSize, - tendermintHTTPRPCURL: config.TendermintApp.HTTPRPCUrl, - cosmosAppHTTPRPCURL: config.CosmosApp.HTTPRPCUrl, - insecureTendermintClient: config.TendermintApp.Insecure, - insecureCosmosAppClient: config.CosmosApp.Insecure, - strictGenesisParsing: config.TendermintApp.StrictGenesisParsing, - startingBlockHeight: config.IndexService.StartingBlockHeight, + mode: config.IndexService.Mode, + consNodeAddressPrefix: config.Blockchain.ConNodeAddressPrefix, + accountAddressPrefix: config.Blockchain.AccountAddressPrefix, + bondingDenom: config.Blockchain.BondingDenom, + windowSize: config.IndexService.WindowSize, + tendermintApp: config.TendermintApp, + cosmosApp: config.CosmosApp, + startingBlockHeight: config.IndexService.StartingBlockHeight, cosmosVersionBlockHeight: utils.CosmosVersionBlockHeight{ V0_42_7: utils.ParserBlockHeight(config.IndexService.CosmosVersionEnabledHeight.V0_42_7), }, @@ -83,9 +78,7 @@ func (service *IndexService) Run() error { infoManager := NewInfoManager( service.logger, service.rdbConn, - service.tendermintHTTPRPCURL, - service.insecureTendermintClient, - service.strictGenesisParsing, + service.tendermintApp, ) switch service.mode { @@ -144,15 +137,12 @@ func (service *IndexService) RunEventStoreMode() error { Logger: service.logger, RDbConn: service.rdbConn, Config: SyncManagerConfig{ - WindowSize: service.windowSize, - TendermintRPCUrl: service.tendermintHTTPRPCURL, - CosmosAppHTTPRPCURL: service.cosmosAppHTTPRPCURL, - InsecureTendermintClient: service.insecureTendermintClient, - InsecureCosmosAppClient: service.insecureCosmosAppClient, - StrictGenesisParsing: service.strictGenesisParsing, - AccountAddressPrefix: service.accountAddressPrefix, - StakingDenom: service.bondingDenom, - StartingBlockHeight: service.startingBlockHeight, + WindowSize: service.windowSize, + TendermintApp: service.tendermintApp, + CosmosApp: service.cosmosApp, + AccountAddressPrefix: service.accountAddressPrefix, + StakingDenom: service.bondingDenom, + StartingBlockHeight: service.startingBlockHeight, }, TxDecoder: service.txDecoder, }, @@ -174,7 +164,6 @@ func (service *IndexService) RunEventStoreMode() error { } func (service *IndexService) RunTendermintDirectMode() error { - for i := range service.projections { go func(projection projection_entity.Projection) { syncManager := NewSyncManager( @@ -184,14 +173,12 @@ func (service *IndexService) RunTendermintDirectMode() error { }), RDbConn: service.rdbConn, Config: SyncManagerConfig{ - WindowSize: service.windowSize, - TendermintRPCUrl: service.tendermintHTTPRPCURL, - CosmosAppHTTPRPCURL: service.cosmosAppHTTPRPCURL, - InsecureTendermintClient: service.insecureTendermintClient, - InsecureCosmosAppClient: service.insecureCosmosAppClient, - AccountAddressPrefix: service.accountAddressPrefix, - StakingDenom: service.bondingDenom, - StartingBlockHeight: service.startingBlockHeight, + WindowSize: service.windowSize, + TendermintApp: service.tendermintApp, + CosmosApp: service.cosmosApp, + AccountAddressPrefix: service.accountAddressPrefix, + StakingDenom: service.bondingDenom, + StartingBlockHeight: service.startingBlockHeight, }, TxDecoder: service.txDecoder, }, diff --git a/bootstrap/infomanager.go b/bootstrap/infomanager.go index 39482c14b..4ba03cd74 100644 --- a/bootstrap/infomanager.go +++ b/bootstrap/infomanager.go @@ -5,6 +5,7 @@ import ( "github.com/crypto-com/chain-indexing/appinterface/polling" "github.com/crypto-com/chain-indexing/appinterface/rdb" + "github.com/crypto-com/chain-indexing/bootstrap/config" applogger "github.com/crypto-com/chain-indexing/external/logger" "github.com/crypto-com/chain-indexing/infrastructure/tendermint" ) @@ -23,22 +24,26 @@ type InfoManager struct { func NewInfoManager( logger applogger.Logger, rdbConn rdb.Conn, - tendermintRPCUrl string, - insecureTendermintClient bool, - strictGenesisParsing bool, + tendermintApp config.TendermintApp, ) *InfoManager { var tendermintClient *tendermint.HTTPClient - if insecureTendermintClient { + if tendermintApp.Insecure { tendermintClient = tendermint.NewInsecureHTTPClient( - tendermintRPCUrl, - strictGenesisParsing, + tendermintApp.HTTPRPCUrl, + tendermintApp.StrictGenesisParsing, ) } else { tendermintClient = tendermint.NewHTTPClient( - tendermintRPCUrl, - strictGenesisParsing, + tendermintApp.HTTPRPCUrl, + tendermintApp.StrictGenesisParsing, ) } + if tendermintApp.MaybeAuthQueryKV != nil { + tendermintClient.SetAuthQueryKV(tendermint.HTTPClientAuthKV{ + Key: tendermintApp.MaybeAuthQueryKV.Key, + Value: tendermintApp.MaybeAuthQueryKV.Value, + }) + } viewStatus := polling.NewStatus(rdbConn.ToHandle()) return &InfoManager{ diff --git a/bootstrap/syncmanager.go b/bootstrap/syncmanager.go index 2848e3b49..f8ab4e30f 100644 --- a/bootstrap/syncmanager.go +++ b/bootstrap/syncmanager.go @@ -7,6 +7,7 @@ import ( "github.com/cenkalti/backoff/v4" cosmosapp_interface "github.com/crypto-com/chain-indexing/appinterface/cosmosapp" eventhandler_interface "github.com/crypto-com/chain-indexing/appinterface/eventhandler" + "github.com/crypto-com/chain-indexing/bootstrap/config" "github.com/crypto-com/chain-indexing/external/txdecoder" cosmosapp_infrastructure "github.com/crypto-com/chain-indexing/infrastructure/cosmosapp" "github.com/crypto-com/chain-indexing/usecase/model" @@ -29,14 +30,13 @@ const DEFAULT_MAX_RETRY_INTERVAL = 15 * time.Minute const DEFAULT_MAX_RETRY_TIME = MAX_RETRY_TIME_ALWAYS_RETRY type SyncManager struct { - rdbConn rdb.Conn - tendermintClient *tendermint.HTTPClient - cosmosClient cosmosapp_interface.Client - logger applogger.Logger - pollingInterval time.Duration - maxRetryInterval time.Duration - maxRetryTime time.Duration - strictGenesisParsing bool + rdbConn rdb.Conn + tendermintClient *tendermint.HTTPClient + cosmosClient cosmosapp_interface.Client + logger applogger.Logger + pollingInterval time.Duration + maxRetryInterval time.Duration + maxRetryTime time.Duration accountAddressPrefix string stakingDenom string @@ -65,15 +65,12 @@ type SyncManagerParams struct { } type SyncManagerConfig struct { - WindowSize int - TendermintRPCUrl string - CosmosAppHTTPRPCURL string - InsecureTendermintClient bool - InsecureCosmosAppClient bool - StrictGenesisParsing bool - AccountAddressPrefix string - StakingDenom string - StartingBlockHeight int64 + WindowSize int + TendermintApp config.TendermintApp + CosmosApp config.CosmosApp + AccountAddressPrefix string + StakingDenom string + StartingBlockHeight int64 } // NewSyncManager creates a new feed with polling for latest block starts at a specific height @@ -83,28 +80,42 @@ func NewSyncManager( eventHandler eventhandler_interface.Handler, ) *SyncManager { var tendermintClient *tendermint.HTTPClient - if params.Config.InsecureTendermintClient { + if params.Config.TendermintApp.Insecure { tendermintClient = tendermint.NewInsecureHTTPClient( - params.Config.TendermintRPCUrl, - params.Config.StrictGenesisParsing, + params.Config.TendermintApp.HTTPRPCUrl, + params.Config.TendermintApp.StrictGenesisParsing, ) } else { tendermintClient = tendermint.NewHTTPClient( - params.Config.TendermintRPCUrl, - params.Config.StrictGenesisParsing, + params.Config.TendermintApp.HTTPRPCUrl, + params.Config.TendermintApp.StrictGenesisParsing, ) } + if params.Config.TendermintApp.MaybeAuthQueryKV != nil { + tendermintClient.SetAuthQueryKV(tendermint.HTTPClientAuthKV{ + Key: params.Config.TendermintApp.MaybeAuthQueryKV.Key, + Value: params.Config.TendermintApp.MaybeAuthQueryKV.Value, + }) + } - var cosmosClient cosmosapp_interface.Client - if params.Config.InsecureCosmosAppClient { + var cosmosClient *cosmosapp_infrastructure.HTTPClient + if params.Config.CosmosApp.Insecure { cosmosClient = cosmosapp_infrastructure.NewInsecureHTTPClient( - params.Config.CosmosAppHTTPRPCURL, params.Config.StakingDenom, + params.Config.CosmosApp.HTTPRPCUrl, + params.Config.StakingDenom, ) } else { cosmosClient = cosmosapp_infrastructure.NewHTTPClient( - params.Config.CosmosAppHTTPRPCURL, params.Config.StakingDenom, + params.Config.CosmosApp.HTTPRPCUrl, + params.Config.StakingDenom, ) } + if params.Config.CosmosApp.MaybeAuthQueryKV != nil { + cosmosClient.SetAuthQueryKV(cosmosapp_infrastructure.HTTPClientAuthKV{ + Key: params.Config.CosmosApp.MaybeAuthQueryKV.Key, + Value: params.Config.CosmosApp.MaybeAuthQueryKV.Value, + }) + } return &SyncManager{ rdbConn: params.RDbConn, @@ -113,10 +124,9 @@ func NewSyncManager( logger: params.Logger.WithFields(applogger.LogFields{ "module": "SyncManager", }), - pollingInterval: DEFAULT_POLLING_INTERVAL, - maxRetryInterval: DEFAULT_MAX_RETRY_INTERVAL, - maxRetryTime: DEFAULT_MAX_RETRY_TIME, - strictGenesisParsing: params.Config.StrictGenesisParsing, + pollingInterval: DEFAULT_POLLING_INTERVAL, + maxRetryInterval: DEFAULT_MAX_RETRY_INTERVAL, + maxRetryTime: DEFAULT_MAX_RETRY_TIME, accountAddressPrefix: params.Config.AccountAddressPrefix, stakingDenom: params.Config.StakingDenom, diff --git a/infrastructure/cosmosapp/httpclient.go b/infrastructure/cosmosapp/httpclient.go index 66b992f92..214e10502 100644 --- a/infrastructure/cosmosapp/httpclient.go +++ b/infrastructure/cosmosapp/httpclient.go @@ -6,7 +6,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "net/http" "net/url" "strconv" @@ -790,7 +789,7 @@ func (client *HTTPClient) request(method string, queryKVs ...queryKV) (io.ReadCl defer rawResp.Body.Close() var rawRespBody []byte - rawRespBody, err = ioutil.ReadAll(rawResp.Body) + rawRespBody, err = io.ReadAll(rawResp.Body) if err != nil { return nil, fmt.Errorf("error reading Body : %w", err) }