Skip to content

Commit

Permalink
feat: ICS v6 + new metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Sep 25, 2024
1 parent dce4f73 commit 26f73ca
Show file tree
Hide file tree
Showing 21 changed files with 190 additions and 132 deletions.
2 changes: 1 addition & 1 deletion assets/config-valid.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ denoms = [
[[chains.consumers]]
name = "neutron"
lcd-endpoint = "https://api.neutron.quokkastake.io"
chain-id = "neutron-1"
consumer-id = "0"
base-denom = "untrn"
bech-wallet-prefix = "neutron"
bech-validator-prefix = "neutronvaloper"
Expand Down
4 changes: 3 additions & 1 deletion assets/consumer-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"validators_power_cap": 0,
"validator_set_cap": 0,
"allowlist": [],
"denylist": []
"denylist": [],
"consumer_id": "0",
"phase": "CONSUMER_PHASE_LAUNCHED"
}
]
}
2 changes: 1 addition & 1 deletion assets/validator-consumers.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"consumer_chain_ids":["neutron-1","stride-1"]}
{"consumer_ids":["0", "1"]}
4 changes: 2 additions & 2 deletions config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ node-info = true
name = "neutron"
# LCD endpoint of a consumer chain. Required.
lcd-endpoint = "https://api.neutron.quokkastake.io"
# Consumer chain's chain-id. Required.
chain-id = "neutron-1"
# Consumer chain's consumer-id. Required.
consumer-id = "0"
# Base denom, same as in provider config.
base-denom = "untrn"
# Bech32 prefix of a wallet on this consumer chain. Required for getting validators' wallet balance.
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/consumer_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type ConsumerChain struct {
LCDEndpoint string `toml:"lcd-endpoint"`
BaseDenom string `toml:"base-denom"`
Denoms DenomInfos `toml:"denoms"`
ChainID string `toml:"chain-id"`
ConsumerID string `toml:"consumer-id"`
BechWalletPrefix string `toml:"bech-wallet-prefix"`
BechValidatorPrefix string `toml:"bech-validator-prefix"`
BechConsensusPrefix string `toml:"bech-consensus-prefix"`
Expand Down Expand Up @@ -38,8 +38,8 @@ func (c *ConsumerChain) Validate() error {
return errors.New("no LCD endpoint provided")
}

if c.ChainID == "" {
return errors.New("no chain-id provided")
if c.ConsumerID == "" {
return errors.New("no consumer-id provided")
}

if c.BaseDenom == "" {
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/consumer_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestConsumerChainValidateNoChainId(t *testing.T) {
func TestConsumerChainValidateNoBaseDenom(t *testing.T) {
t.Parallel()

chain := ConsumerChain{Name: "test", LCDEndpoint: "test", ChainID: "test"}
chain := ConsumerChain{Name: "test", LCDEndpoint: "test", ConsumerID: "0"}
err := chain.Validate()
require.Error(t, err)
}
Expand All @@ -59,7 +59,7 @@ func TestConsumerChainValidateInvalidDenom(t *testing.T) {
chain := ConsumerChain{
Name: "test",
LCDEndpoint: "test",
ChainID: "test",
ConsumerID: "0",
BaseDenom: "denom",
Denoms: DenomInfos{{}},
}
Expand All @@ -73,7 +73,7 @@ func TestConsumerChainValidateValid(t *testing.T) {
chain := ConsumerChain{
Name: "test",
LCDEndpoint: "test",
ChainID: "test",
ConsumerID: "0",
BaseDenom: "denom",
Denoms: DenomInfos{{Denom: "ustake", DisplayDenom: "stake"}},
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/fetchers/consumer_commission.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (f *ConsumerCommissionFetcher) processChain(
) {
defer f.wg.Done()

commission, queryInfo, err := rpc.GetConsumerCommission(ctx, validator.ConsensusAddress, chain.ChainID)
commission, queryInfo, err := rpc.GetConsumerCommission(ctx, validator.ConsensusAddress, chain.ConsumerID)

f.mutex.Lock()
defer f.mutex.Unlock()
Expand Down
26 changes: 13 additions & 13 deletions pkg/fetchers/consumer_commission_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ func TestConsumerCommissionFetcherNoConsensusAddress(t *testing.T) {
}},
ConsumerChains: []*config.ConsumerChain{
{
Name: "consumer",
ChainID: "consumer",
Name: "consumer",
ConsumerID: "0",
},
},
}}
Expand Down Expand Up @@ -104,8 +104,8 @@ func TestConsumerCommissionFetcherQueryDisabled(t *testing.T) {
Queries: map[string]bool{"consumer-commission": false},
ConsumerChains: []*config.ConsumerChain{
{
Name: "consumer",
ChainID: "consumer",
Name: "consumer",
ConsumerID: "0",
},
},
}}
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestConsumerCommissionFetcherQueryError(t *testing.T) {

httpmock.RegisterResponder(
"GET",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_commission_rate/consumer/cosmosvalcons1rt4g447zhv6jcqwdl447y88guwm0eevnrelgzc",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_commission_rate/0/cosmosvalcons1rt4g447zhv6jcqwdl447y88guwm0eevnrelgzc",
httpmock.NewErrorResponder(errors.New("error")),
)

Expand All @@ -155,8 +155,8 @@ func TestConsumerCommissionFetcherQueryError(t *testing.T) {
}},
ConsumerChains: []*config.ConsumerChain{
{
Name: "consumer",
ChainID: "consumer",
Name: "consumer",
ConsumerID: "0",
},
},
}}
Expand Down Expand Up @@ -193,7 +193,7 @@ func TestConsumerCommissionFetcherNodeError(t *testing.T) {

httpmock.RegisterResponder(
"GET",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_commission_rate/consumer/cosmosvalcons1rt4g447zhv6jcqwdl447y88guwm0eevnrelgzc",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_commission_rate/0/cosmosvalcons1rt4g447zhv6jcqwdl447y88guwm0eevnrelgzc",
httpmock.NewBytesResponder(200, assets.GetBytesOrPanic("error.json")),
)

Expand All @@ -207,8 +207,8 @@ func TestConsumerCommissionFetcherNodeError(t *testing.T) {
}},
ConsumerChains: []*config.ConsumerChain{
{
Name: "consumer",
ChainID: "consumer",
Name: "consumer",
ConsumerID: "0",
},
},
}}
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestConsumerCommissionFetcherQuerySuccess(t *testing.T) {

httpmock.RegisterResponder(
"GET",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_commission_rate/consumer/cosmosvalcons1rt4g447zhv6jcqwdl447y88guwm0eevnrelgzc",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_commission_rate/0/cosmosvalcons1rt4g447zhv6jcqwdl447y88guwm0eevnrelgzc",
httpmock.NewBytesResponder(200, assets.GetBytesOrPanic("consumer-commission.json")),
)

Expand All @@ -259,8 +259,8 @@ func TestConsumerCommissionFetcherQuerySuccess(t *testing.T) {
}},
ConsumerChains: []*config.ConsumerChain{
{
Name: "consumer",
ChainID: "consumer",
Name: "consumer",
ConsumerID: "0",
},
},
}}
Expand Down
4 changes: 2 additions & 2 deletions pkg/fetchers/consumer_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (f *ConsumerInfoFetcher) processChain(
f.Logger.Error().
Err(err).
Str("chain", chain.Name).
Msg("Error querying consumer validators")
Msg("Error querying consumer info")
return
}

Expand All @@ -99,6 +99,6 @@ func (f *ConsumerInfoFetcher) processChain(
f.allInfos[chain.Name] = map[string]types.ConsumerChainInfo{}

for _, consumerInfo := range allInfosList.Chains {
f.allInfos[chain.Name][consumerInfo.ChainID] = consumerInfo
f.allInfos[chain.Name][consumerInfo.ConsumerID] = consumerInfo
}
}
8 changes: 4 additions & 4 deletions pkg/fetchers/consumer_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func TestConsumerInfoFetcherQueryError(t *testing.T) {

httpmock.RegisterResponder(
"GET",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_chains",
httpmock.NewErrorResponder(errors.New("error")),
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_chains/0",
httpmock.NewErrorResponder(errors.New("custom error")),
)

chains := []*config.Chain{{
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestConsumerInfoFetcherNodeError(t *testing.T) {

httpmock.RegisterResponder(
"GET",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_chains",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_chains/0",
httpmock.NewBytesResponder(200, assets.GetBytesOrPanic("error.json")),
)

Expand Down Expand Up @@ -203,7 +203,7 @@ func TestConsumerInfoFetcherQuerySuccess(t *testing.T) {

httpmock.RegisterResponder(
"GET",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_chains",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_chains/0",
httpmock.NewBytesResponder(200, assets.GetBytesOrPanic("consumer-info.json")),
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/fetchers/consumer_validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (f *ConsumerValidatorsFetcher) processChain(
) {
defer f.wg.Done()

allValidatorsList, queryInfo, err := rpc.GetConsumerValidators(ctx, chain.ChainID)
allValidatorsList, queryInfo, err := rpc.GetConsumerValidators(ctx, chain.ConsumerID)

f.mutex.Lock()
defer f.mutex.Unlock()
Expand Down
22 changes: 11 additions & 11 deletions pkg/fetchers/consumer_validators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func TestConsumerValidatorsFetcherQueryDisabled(t *testing.T) {
Queries: map[string]bool{"consumer-validators": false},
ConsumerChains: []*config.ConsumerChain{
{
Name: "consumer",
ChainID: "consumer",
Name: "consumer",
ConsumerID: "0",
},
},
}}
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestConsumerValidatorsFetcherQueryError(t *testing.T) {

httpmock.RegisterResponder(
"GET",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_validators/consumer",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_validators/0",
httpmock.NewErrorResponder(errors.New("error")),
)

Expand All @@ -107,8 +107,8 @@ func TestConsumerValidatorsFetcherQueryError(t *testing.T) {
Validators: []config.Validator{{Address: "cosmosvaloper1xqz9pemz5e5zycaa89kys5aw6m8rhgsvw4328e"}},
ConsumerChains: []*config.ConsumerChain{
{
Name: "consumer",
ChainID: "consumer",
Name: "consumer",
ConsumerID: "0",
},
},
}}
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestConsumerValidatorsFetcherNodeError(t *testing.T) {

httpmock.RegisterResponder(
"GET",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_validators/consumer",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_validators/0",
httpmock.NewBytesResponder(200, assets.GetBytesOrPanic("error.json")),
)

Expand All @@ -153,8 +153,8 @@ func TestConsumerValidatorsFetcherNodeError(t *testing.T) {
Validators: []config.Validator{{Address: "cosmosvaloper1xqz9pemz5e5zycaa89kys5aw6m8rhgsvw4328e"}},
ConsumerChains: []*config.ConsumerChain{
{
Name: "consumer",
ChainID: "consumer",
Name: "consumer",
ConsumerID: "0",
},
},
}}
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestConsumerValidatorsFetcherQuerySuccess(t *testing.T) {

httpmock.RegisterResponder(
"GET",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_validators/consumer",
"https://api.cosmos.quokkastake.io/interchain_security/ccv/provider/consumer_validators/0",
httpmock.NewBytesResponder(200, assets.GetBytesOrPanic("consumer-validators.json")),
)

Expand All @@ -199,8 +199,8 @@ func TestConsumerValidatorsFetcherQuerySuccess(t *testing.T) {
Validators: []config.Validator{{Address: "cosmosvaloper1xqz9pemz5e5zycaa89kys5aw6m8rhgsvw4328e"}},
ConsumerChains: []*config.ConsumerChain{
{
Name: "consumer",
ChainID: "consumer",
Name: "consumer",
ConsumerID: "0",
},
},
}}
Expand Down
4 changes: 2 additions & 2 deletions pkg/fetchers/has_to_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (q *ValidatorConsumersFetcher) processChain(
}

q.allValidatorsConsumers[chainName][validator.Address] = map[string]bool{}
for _, chainID := range validatorConsumers.ConsumerChainIds {
q.allValidatorsConsumers[chainName][validator.Address][chainID] = true
for _, consumerID := range validatorConsumers.ConsumerIds {
q.allValidatorsConsumers[chainName][validator.Address][consumerID] = true
}
}
2 changes: 1 addition & 1 deletion pkg/fetchers/signing_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (q *SigningInfoFetcher) processConsumerChain(
// 1. Fetching assigned key.
assignedKey, queryInfo, err := providerRPC.GetConsumerAssignedKey(
validator.ConsensusAddress,
chain.ChainID,
chain.ConsumerID,
ctx,
)

Expand Down
Loading

0 comments on commit 26f73ca

Please sign in to comment.