-
Notifications
You must be signed in to change notification settings - Fork 136
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
feat!: introduce MsgOptIn and MsgOptOut #1620
Changes from 4 commits
4eac8bf
8f2269f
a32e882
b0d2337
32fed21
45bf863
78e12c8
656adc2
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 |
---|---|---|
|
@@ -1160,7 +1160,7 @@ func (k Keeper) DeleteTopN( | |
store.Delete(types.TopNKey(chainID)) | ||
} | ||
|
||
// GetTopN returns (N, true) if chain `chainID` has a top N associated, and (0, false) otherwise. | ||
// GetTopN returns (N, true) if chain `chainID` has a top N associated, and (0, false) otherwise. | ||
func (k Keeper) GetTopN( | ||
ctx sdk.Context, | ||
chainID string, | ||
|
@@ -1184,3 +1184,141 @@ func (k Keeper) IsOptIn(ctx sdk.Context, chainID string) bool { | |
topN, found := k.GetTopN(ctx, chainID) | ||
return !found || topN == 0 | ||
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. Is it possible to have a chain with TopN set to 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 think it exactly indicates opt in chains. 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.
Good point. It's not clear where |
||
} | ||
func (k Keeper) SetOptedIn( | ||
insumity marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctx sdk.Context, | ||
chainID string, | ||
providerAddr types.ProviderConsAddress, | ||
blockHeight uint64, | ||
) { | ||
store := ctx.KVStore(k.storeKey) | ||
|
||
// validator is considered opted in | ||
blockHeightBytes := make([]byte, 8) | ||
binary.BigEndian.PutUint64(blockHeightBytes, blockHeight) | ||
|
||
store.Set(types.OptedInKey(chainID, providerAddr), blockHeightBytes) | ||
} | ||
|
||
func (k Keeper) DeleteOptedIn( | ||
ctx sdk.Context, | ||
chainID string, | ||
providerAddr types.ProviderConsAddress, | ||
) { | ||
store := ctx.KVStore(k.storeKey) | ||
store.Delete(types.OptedInKey(chainID, providerAddr)) | ||
} | ||
|
||
func (k Keeper) IsOptedIn( | ||
ctx sdk.Context, | ||
chainID string, | ||
providerAddr types.ProviderConsAddress, | ||
) bool { | ||
store := ctx.KVStore(k.storeKey) | ||
return store.Get(types.OptedInKey(chainID, providerAddr)) != nil | ||
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. any reason to potentially check whether the block height is smaller than the current block height, instead for nil? 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. The block height would always be smaller or equal to the current block height. It would be equal to the current block height when we first opt in that validator, for instance at the end of an epoch. |
||
} | ||
|
||
func (k Keeper) GetOptedIn( | ||
ctx sdk.Context, | ||
chainID string) (optedInValidators []OptedInValidator) { | ||
store := ctx.KVStore(k.storeKey) | ||
key := types.ChainIdWithLenKey(types.OptedInBytePrefix, chainID) | ||
iterator := sdk.KVStorePrefixIterator(store, key) | ||
defer iterator.Close() | ||
|
||
for ; iterator.Valid(); iterator.Next() { | ||
optedInValidators = append(optedInValidators, OptedInValidator{ | ||
ProviderAddr: types.NewProviderConsAddress(iterator.Key()[len(key):]), | ||
BlockHeight: binary.BigEndian.Uint64(iterator.Value()), | ||
}) | ||
} | ||
|
||
return optedInValidators | ||
} | ||
|
||
func (k Keeper) SetToBeOptedIn( | ||
ctx sdk.Context, | ||
chainID string, | ||
providerAddr types.ProviderConsAddress, | ||
) { | ||
store := ctx.KVStore(k.storeKey) | ||
store.Set(types.ToBeOptedInKey(chainID, providerAddr), []byte{}) | ||
} | ||
|
||
func (k Keeper) DeleteToBeOptedIn( | ||
ctx sdk.Context, | ||
chainID string, | ||
providerAddr types.ProviderConsAddress, | ||
) { | ||
store := ctx.KVStore(k.storeKey) | ||
store.Delete(types.ToBeOptedInKey(chainID, providerAddr)) | ||
} | ||
|
||
func (k Keeper) IsToBeOptedIn( | ||
ctx sdk.Context, | ||
chainID string, | ||
providerAddr types.ProviderConsAddress, | ||
) bool { | ||
store := ctx.KVStore(k.storeKey) | ||
return store.Get(types.ToBeOptedInKey(chainID, providerAddr)) != nil | ||
} | ||
|
||
func (k Keeper) GetToBeOptedIn( | ||
ctx sdk.Context, | ||
chainID string) (addresses []types.ProviderConsAddress) { | ||
|
||
store := ctx.KVStore(k.storeKey) | ||
key := types.ChainIdWithLenKey(types.ToBeOptedInBytePrefix, chainID) | ||
iterator := sdk.KVStorePrefixIterator(store, key) | ||
defer iterator.Close() | ||
|
||
for ; iterator.Valid(); iterator.Next() { | ||
providerAddr := types.NewProviderConsAddress(iterator.Key()[len(key):]) | ||
addresses = append(addresses, providerAddr) | ||
} | ||
|
||
return addresses | ||
} | ||
|
||
func (k Keeper) SetToBeOptedOut( | ||
ctx sdk.Context, | ||
chainID string, | ||
providerAddr types.ProviderConsAddress, | ||
) { | ||
store := ctx.KVStore(k.storeKey) | ||
store.Set(types.ToBeOptedOutKey(chainID, providerAddr), []byte{}) | ||
} | ||
|
||
func (k Keeper) DeleteToBeOptedOut( | ||
ctx sdk.Context, | ||
chainID string, | ||
providerAddr types.ProviderConsAddress, | ||
) { | ||
store := ctx.KVStore(k.storeKey) | ||
store.Delete(types.ToBeOptedOutKey(chainID, providerAddr)) | ||
} | ||
|
||
func (k Keeper) IsToBeOptedOut( | ||
ctx sdk.Context, | ||
chainID string, | ||
providerAddr types.ProviderConsAddress, | ||
) bool { | ||
store := ctx.KVStore(k.storeKey) | ||
return store.Get(types.ToBeOptedOutKey(chainID, providerAddr)) != nil | ||
} | ||
|
||
func (k Keeper) GetToBeOptedOut( | ||
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. Might just be me, but the modifications in this file seem like tripley duplicated code, 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. That's true. At least the |
||
ctx sdk.Context, | ||
chainID string) (addresses []types.ProviderConsAddress) { | ||
|
||
store := ctx.KVStore(k.storeKey) | ||
key := types.ChainIdWithLenKey(types.ToBeOptedOutBytePrefix, chainID) | ||
iterator := sdk.KVStorePrefixIterator(store, key) | ||
defer iterator.Close() | ||
|
||
for ; iterator.Valid(); iterator.Next() { | ||
providerAddr := types.NewProviderConsAddress(iterator.Key()[len(key):]) | ||
addresses = append(addresses, providerAddr) | ||
} | ||
|
||
return addresses | ||
} |
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.
Could not set as
optional
field becausemake proto-gen
led to:I don't see
optional
used anywhere else in our.proto
files either.