-
Notifications
You must be signed in to change notification settings - Fork 135
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!: compute partial set #1642
Changes from 10 commits
71ac8e3
61a4052
4bc4887
f5c3af1
de1ce67
8710bc2
a3e3d41
6fa64fa
20f9625
7a2b2d9
000760a
272b87b
2bff04a
5348f83
7144504
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 |
---|---|---|
|
@@ -1190,14 +1190,17 @@ func (k Keeper) SetOptedIn( | |
chainID string, | ||
providerAddr types.ProviderConsAddress, | ||
blockHeight uint64, | ||
power 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) | ||
powerBytes := make([]byte, 8) | ||
binary.BigEndian.PutUint64(powerBytes, power) | ||
|
||
store.Set(types.OptedInKey(chainID, providerAddr), append(blockHeightBytes, powerBytes...)) | ||
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. Store 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 the recommendation here to define it in proto to simplify our life later on when we implement queries that return opted-in validators? |
||
} | ||
|
||
func (k Keeper) DeleteOptedIn( | ||
|
@@ -1209,6 +1212,19 @@ func (k Keeper) DeleteOptedIn( | |
store.Delete(types.OptedInKey(chainID, providerAddr)) | ||
} | ||
|
||
func (k Keeper) DeleteAllOptedIn( | ||
insumity marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctx sdk.Context, | ||
chainID string) { | ||
store := ctx.KVStore(k.storeKey) | ||
key := types.ChainIdWithLenKey(types.OptedInBytePrefix, chainID) | ||
iterator := sdk.KVStorePrefixIterator(store, key) | ||
defer iterator.Close() | ||
|
||
for ; iterator.Valid(); iterator.Next() { | ||
store.Delete(iterator.Key()) | ||
insumity marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
func (k Keeper) IsOptedIn( | ||
ctx sdk.Context, | ||
chainID string, | ||
|
@@ -1229,7 +1245,8 @@ func (k Keeper) GetOptedIn( | |
for ; iterator.Valid(); iterator.Next() { | ||
optedInValidators = append(optedInValidators, OptedInValidator{ | ||
ProviderAddr: types.NewProviderConsAddress(iterator.Key()[len(key):]), | ||
BlockHeight: binary.BigEndian.Uint64(iterator.Value()), | ||
BlockHeight: binary.BigEndian.Uint64(iterator.Value()[0:8]), | ||
Power: binary.BigEndian.Uint64(iterator.Value()[8:]), | ||
}) | ||
} | ||
|
||
|
@@ -1254,6 +1271,19 @@ func (k Keeper) DeleteToBeOptedIn( | |
store.Delete(types.ToBeOptedInKey(chainID, providerAddr)) | ||
} | ||
|
||
func (k Keeper) DeleteAllToBeOptedIn( | ||
ctx sdk.Context, | ||
chainID string) { | ||
store := ctx.KVStore(k.storeKey) | ||
key := types.ChainIdWithLenKey(types.ToBeOptedInBytePrefix, chainID) | ||
iterator := sdk.KVStorePrefixIterator(store, key) | ||
defer iterator.Close() | ||
|
||
for ; iterator.Valid(); iterator.Next() { | ||
store.Delete(iterator.Key()) | ||
} | ||
} | ||
|
||
func (k Keeper) IsToBeOptedIn( | ||
ctx sdk.Context, | ||
chainID string, | ||
|
@@ -1298,6 +1328,19 @@ func (k Keeper) DeleteToBeOptedOut( | |
store.Delete(types.ToBeOptedOutKey(chainID, providerAddr)) | ||
} | ||
|
||
func (k Keeper) DeleteAllToBeOptedOut( | ||
ctx sdk.Context, | ||
chainID string) { | ||
store := ctx.KVStore(k.storeKey) | ||
key := types.ChainIdWithLenKey(types.ToBeOptedOutBytePrefix, chainID) | ||
iterator := sdk.KVStorePrefixIterator(store, key) | ||
defer iterator.Close() | ||
|
||
for ; iterator.Valid(); iterator.Next() { | ||
store.Delete(iterator.Key()) | ||
} | ||
} | ||
|
||
func (k Keeper) IsToBeOptedOut( | ||
ctx sdk.Context, | ||
chainID string, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,19 +139,30 @@ func (k msgServer) SubmitConsumerDoubleVoting(goCtx context.Context, msg *types. | |
func (k msgServer) OptIn(goCtx context.Context, msg *types.MsgOptIn) (*types.MsgOptInResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
valAddress, err := sdk.ConsAddressFromBech32(msg.ProviderAddr) | ||
providerValidatorAddr, err := sdk.ValAddressFromBech32(msg.ProviderAddr) | ||
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. Fixed this. Similarly to |
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// validator must already be registered | ||
validator, found := k.stakingKeeper.GetValidator(ctx, providerValidatorAddr) | ||
if !found { | ||
return nil, stakingtypes.ErrNoValidatorFound | ||
} | ||
|
||
consAddress, err := validator.GetConsAddr() | ||
if err != nil { | ||
return nil, err | ||
} | ||
providerAddr := types.NewProviderConsAddress(valAddress) | ||
providerConsAddr := types.NewProviderConsAddress(consAddress) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if msg.ConsumerKey != "" { | ||
err = k.Keeper.HandleOptIn(ctx, msg.ChainId, providerAddr, &msg.ConsumerKey) | ||
err = k.Keeper.HandleOptIn(ctx, msg.ChainId, providerConsAddr, &msg.ConsumerKey) | ||
} else { | ||
err = k.Keeper.HandleOptIn(ctx, msg.ChainId, providerAddr, nil) | ||
err = k.Keeper.HandleOptIn(ctx, msg.ChainId, providerConsAddr, nil) | ||
} | ||
|
||
if err != nil { | ||
|
@@ -172,16 +183,27 @@ func (k msgServer) OptIn(goCtx context.Context, msg *types.MsgOptIn) (*types.Msg | |
func (k msgServer) OptOut(goCtx context.Context, msg *types.MsgOptOut) (*types.MsgOptOutResponse, error) { | ||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
valAddress, err := sdk.ConsAddressFromBech32(msg.ProviderAddr) | ||
providerValidatorAddr, err := sdk.ValAddressFromBech32(msg.ProviderAddr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// validator must already be registered | ||
validator, found := k.stakingKeeper.GetValidator(ctx, providerValidatorAddr) | ||
if !found { | ||
return nil, stakingtypes.ErrNoValidatorFound | ||
} | ||
|
||
consAddress, err := validator.GetConsAddr() | ||
if err != nil { | ||
return nil, err | ||
} | ||
providerAddr := types.NewProviderConsAddress(valAddress) | ||
providerConsAddr := types.NewProviderConsAddress(consAddress) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
err = k.Keeper.HandleOptOut(ctx, msg.ChainId, providerAddr) | ||
err = k.Keeper.HandleOptOut(ctx, msg.ChainId, providerConsAddr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
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.
Introduce
power
in the opted-in state so we can see if we should send aValidatorUpdate
down to CometBFT based on whether the power changed since last time it was sent. Only makes sense in an epoch-based setting because in a non-epoch-based setting, we could use the validator updates from thestaking
module.