-
Notifications
You must be signed in to change notification settings - Fork 122
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
fix!: update consumer chain queries #2246
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ import ( | |
|
||
"github.com/cometbft/cometbft/proto/tendermint/crypto" | ||
|
||
sdkquery "github.com/cosmos/cosmos-sdk/types/query" | ||
cryptotestutil "github.com/cosmos/interchain-security/v6/testutil/crypto" | ||
testkeeper "github.com/cosmos/interchain-security/v6/testutil/keeper" | ||
"github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper" | ||
|
@@ -558,6 +559,7 @@ func TestQueryConsumerChain(t *testing.T) { | |
|
||
expRes := types.QueryConsumerChainResponse{ | ||
ChainId: chainId, | ||
ConsumerId: consumerId, | ||
OwnerAddress: providerKeeper.GetAuthority(), | ||
Metadata: types.ConsumerMetadata{Name: chainId}, | ||
Phase: types.CONSUMER_PHASE_REGISTERED.String(), | ||
|
@@ -663,7 +665,7 @@ func TestQueryConsumerChains(t *testing.T) { | |
name string | ||
setup func(ctx sdk.Context, pk keeper.Keeper) | ||
phase_filter types.ConsumerPhase | ||
limit int32 | ||
limit uint64 | ||
expConsumers []*types.Chain | ||
}{ | ||
{ | ||
|
@@ -675,7 +677,7 @@ func TestQueryConsumerChains(t *testing.T) { | |
name: "expect an amount of consumer equal to the limit", | ||
setup: func(ctx sdk.Context, pk keeper.Keeper) {}, | ||
expConsumers: consumers[:3], | ||
limit: int32(3), | ||
limit: 3, | ||
}, | ||
{ | ||
name: "expect registered consumers when phase filter is set to Registered", | ||
|
@@ -720,14 +722,19 @@ func TestQueryConsumerChains(t *testing.T) { | |
tc.setup(ctx, pk) | ||
req := types.QueryConsumerChainsRequest{ | ||
Phase: tc.phase_filter, | ||
Limit: tc.limit, | ||
Pagination: &sdkquery.PageRequest{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we test this, but would be nice to have a test that uses the |
||
Limit: tc.limit, | ||
}, | ||
} | ||
expectedResponse := types.QueryConsumerChainsResponse{ | ||
Chains: tc.expConsumers, | ||
} | ||
res, err := pk.QueryConsumerChains(ctx, &req) | ||
require.NoError(t, err) | ||
require.Equal(t, &expectedResponse, res, tc.name) | ||
require.Equal(t, expectedResponse.GetChains(), res.GetChains(), tc.name) | ||
if tc.limit != 0 { | ||
require.Len(t, res.GetChains(), int(tc.limit), tc.name) | ||
} | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -680,9 +680,14 @@ func ConsumerIdToPowerShapingParametersKey(consumerId string) []byte { | |
return StringIdWithLenKey(mustGetKeyPrefix(ConsumerIdToPowerShapingParameters), consumerId) | ||
} | ||
|
||
// ConsumerIdToPhaseKeyPrefix returns the key prefix used to iterate over all the consumer ids and their phases. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In line 685 (above) do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't get it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
func ConsumerIdToPhaseKeyPrefix() byte { | ||
return mustGetKeyPrefix(ConsumerIdToPhaseKeyName) | ||
} | ||
|
||
// ConsumerIdToPhaseKey returns the key used to store the phase that corresponds to this consumer id | ||
func ConsumerIdToPhaseKey(consumerId string) []byte { | ||
return StringIdWithLenKey(mustGetKeyPrefix(ConsumerIdToPhaseKeyName), consumerId) | ||
return StringIdWithLenKey(ConsumerIdToPhaseKeyPrefix(), consumerId) | ||
} | ||
|
||
// ConsumerIdToRemovalTimeKeyPrefix returns the key prefix for storing the removal times of consumer chains | ||
|
@@ -813,8 +818,8 @@ func StringIdWithLenKey(prefix byte, stringId string) []byte { | |
func ParseStringIdWithLenKey(prefix byte, bz []byte) (string, error) { | ||
expectedPrefix := []byte{prefix} | ||
prefixL := len(expectedPrefix) | ||
if prefix := bz[:prefixL]; !bytes.Equal(prefix, expectedPrefix) { | ||
return "", fmt.Errorf("invalid prefix; expected: %X, got: %X", expectedPrefix, prefix) | ||
if prefixBz := bz[:prefixL]; !bytes.Equal(prefixBz, expectedPrefix) { | ||
return "", fmt.Errorf("invalid prefix; expected: %X, got: %X, input %X -- len %d", expectedPrefix, prefixBz, prefix, prefixL) | ||
} | ||
stringIdL := sdk.BigEndianToUint64(bz[prefixL : prefixL+8]) | ||
stringId := string(bz[prefixL+8 : prefixL+8+int(stringIdL)]) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
consumer_id
seems to be part of theQueryConsumerChainRequest
. If so, what's the point of returning it as part the response?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So that we can validate on the FE that we got the chain_id for the consumer_id we requested. But, more importantly so that we don't have to keep extra context (e.g coming from URL params) about which chain we're dealing with.
E.g. previously we had to read the URL param for consumer_id for any operation we were doing:
So we had to "remember" the
123
. This way we look up an object and treat is as the source of truth and do all operations required by fetching the consumer_id from the returned object.Does that make sense?