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

Problem: Tendermint and Cosmos client do not accept auth query #833

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 12 additions & 5 deletions bootstrap/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
73 changes: 30 additions & 43 deletions bootstrap/indexservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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),
},
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
},
Expand All @@ -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(
Expand All @@ -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,
},
Expand Down
21 changes: 13 additions & 8 deletions bootstrap/infomanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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{
Expand Down
70 changes: 40 additions & 30 deletions bootstrap/syncmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions infrastructure/cosmosapp/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -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)
}
Expand Down