diff --git a/x/ccv/provider/keeper/keymap.go b/x/ccv/provider/keeper/keymap.go index d07c754547..c10c472607 100644 --- a/x/ccv/provider/keeper/keymap.go +++ b/x/ccv/provider/keeper/keymap.go @@ -196,12 +196,11 @@ func (e *KeyMap) inner(vscid VSCID, providerUpdates map[ProviderPubKey]int64) ma // and where the assigned consumer key has changed e.Store.IterateCkToMemo(func(cca ConsumerConsAddr, m ccvtypes.LastUpdateMemo) bool { oldCk := m.Ck - if newCk, ok := e.Store.GetPkToCk(*m.Pk); ok { - str := DeterministicStringify(*m.Pk) + if newCk, ok := e.Store.GetPkToCk(*m.Pk); ok { // TODO: do away with ok, should always be ok // TODO: is !seen[str] needed? - if !oldCk.Equal(newCk) && 0 < m.Power { // TODO: comment why 0 < needed + if !oldCk.Equal(newCk) && 0 < m.Power { providerKeysToSendUpdateFor = append(providerKeysToSendUpdateFor, *m.Pk) - keyInProviderKeysToSendUpdateFor[str] = true + keyInProviderKeysToSendUpdateFor[DeterministicStringify(*m.Pk)] = true } } return false diff --git a/x/ccv/provider/keeper/keymap_test.go b/x/ccv/provider/keeper/keymap_test.go index f7b623f072..9549c19dbe 100644 --- a/x/ccv/provider/keeper/keymap_test.go +++ b/x/ccv/provider/keeper/keymap_test.go @@ -371,21 +371,12 @@ func (d *driver) externalInvariants() { expectQueryable[keeper.DeterministicStringify(u.PubKey)] = true } } - // If a consumer key is CURRENTLY mapped to by a provider key, it - // must be queryable. - d.km.Store.IteratePkToCk(func(_, ck keeper.ConsumerPubKey) bool { - expectQueryable[keeper.DeterministicStringify(ck)] = true - return false - }) // Simply check every consumer key for the correct queryable-ness. for ck := uint64(0); ck < NUM_CKS; ck++ { ck += 100 //TODO: fix with others - pk, actualQueryable := d.km.GetProviderPubKeyFromConsumerPubKey(key(ck)) cca := keeper.ConsumerPubKeyToConsumerConsAddr(key(ck)) - pkByConsAddr, actualQueryableByConsAddr := d.km.GetProviderPubKeyFromConsumerConsAddress(cca) - require.Equal(d.t, pk, pkByConsAddr) - require.Equal(d.t, actualQueryable, actualQueryableByConsAddr) + _, actualQueryable := d.km.GetProviderPubKeyFromConsumerConsAddress(cca) if expect, found := expectQueryable[keeper.DeterministicStringify(key(ck))]; found && expect { require.True(d.t, actualQueryable) } else { @@ -657,14 +648,15 @@ func TestKeyMapSetUseReplaceAndReverse(t *testing.T) { km.SetProviderPubKeyToConsumerPubKey(key(42), key(43)) updates := []abci.ValidatorUpdate{{PubKey: key(42), Power: 999}} km.ComputeUpdates(100, updates) - km.SetProviderPubKeyToConsumerPubKey(key(42), key(44)) // New consumer key - actual, _ := km.GetProviderPubKeyFromConsumerPubKey(key(43)) // Old is queryable + km.SetProviderPubKeyToConsumerPubKey(key(42), key(44)) // New consumer key + // actual, _ := km.GetProviderPubKeyFromConsumerPubKey(key(43)) // Old is queryable + actual, _ := km.GetProviderPubKeyFromConsumerConsAddress(keeper.ConsumerPubKeyToConsumerConsAddr(key(43))) require.Equal(t, key(42), actual) actual, _ = km.GetProviderPubKeyFromConsumerPubKey(key(44)) // New is queryable require.Equal(t, key(42), actual) - km.ComputeUpdates(101, updates) // Old is garbage collected on consumer - km.PruneUnusedKeys(102) // Old is garbage collected on provider - _, found := km.GetProviderPubKeyFromConsumerPubKey(key(43)) // Not queryable + km.ComputeUpdates(101, updates) // Old is no longer known to consumer + km.PruneUnusedKeys(102) // Old is garbage collected on provider + _, found := km.GetProviderPubKeyFromConsumerConsAddress(keeper.ConsumerPubKeyToConsumerConsAddr(key(43))) require.False(t, found) actual, _ = km.GetProviderPubKeyFromConsumerPubKey(key(44)) // New key is still queryable require.Equal(t, key(42), actual) @@ -676,12 +668,12 @@ func TestKeyMapSetUseReplaceAndPrune(t *testing.T) { updates := []abci.ValidatorUpdate{{PubKey: key(42), Power: 999}} km.ComputeUpdates(100, updates) km.SetProviderPubKeyToConsumerPubKey(key(42), key(44)) - actual, _ := km.GetProviderPubKeyFromConsumerPubKey(key(43)) // Queryable + actual, _ := km.GetProviderPubKeyFromConsumerConsAddress(keeper.ConsumerPubKeyToConsumerConsAddr(key(43))) require.Equal(t, key(42), actual) actual, _ = km.GetProviderPubKeyFromConsumerPubKey(key(44)) // Queryable require.Equal(t, key(42), actual) - km.PruneUnusedKeys(101) // Should not be pruned - _, found := km.GetProviderPubKeyFromConsumerPubKey(key(43)) // Still queryable + km.PruneUnusedKeys(101) // Should not be pruned + _, found := km.GetProviderPubKeyFromConsumerConsAddress(keeper.ConsumerPubKeyToConsumerConsAddr(key(43))) require.True(t, found) actual, _ = km.GetProviderPubKeyFromConsumerPubKey(key(44)) // New key is still queryable require.Equal(t, key(42), actual)