-
Notifications
You must be signed in to change notification settings - Fork 143
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
Consumer panic cleanup #655
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8aca15b
panics in validators.go
mpoke 36da6f9
remove GetChangePubKeyAddress
mpoke a027cac
GetCurrentValidatorsAsABCIUpdates panics instead of ret err
mpoke 58f8b94
relay.go
mpoke 3e410de
keeper.go
mpoke 421028c
panic in SetHooks
mpoke 91fd348
GetCurrentValidatorsAsABCIUpdates -> MustGetCurrentValidatorsAsABCIUp…
mpoke 4ae49b7
Merge branch 'main' into marius/panic-consumer
mpoke e8c57cb
Merge branch 'main' into marius/panic-consumer
mpoke d5f370c
Merge branch 'main' into marius/panic-consumer
mpoke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ import ( | |
sdk "github.com/cosmos/cosmos-sdk/types" | ||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" | ||
"github.com/cosmos/interchain-security/x/ccv/consumer/types" | ||
"github.com/cosmos/interchain-security/x/ccv/utils" | ||
abci "github.com/tendermint/tendermint/abci/types" | ||
) | ||
|
||
|
@@ -17,7 +16,14 @@ import ( | |
func (k Keeper) ApplyCCValidatorChanges(ctx sdk.Context, changes []abci.ValidatorUpdate) []abci.ValidatorUpdate { | ||
ret := []abci.ValidatorUpdate{} | ||
for _, change := range changes { | ||
addr := utils.GetChangePubKeyAddress(change) | ||
// convert TM pubkey to SDK pubkey | ||
pubkey, err := cryptocodec.FromTmProtoPublicKey(change.GetPubKey()) | ||
if err != nil { | ||
// An error here would indicate that the validator updates | ||
// received from the provider are invalid. | ||
panic(err) | ||
} | ||
addr := pubkey.Address() | ||
Comment on lines
+19
to
+26
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. Moved here the logic from |
||
val, found := k.GetCCValidator(ctx, addr) | ||
|
||
if found { | ||
|
@@ -33,12 +39,10 @@ func (k Keeper) ApplyCCValidatorChanges(ctx sdk.Context, changes []abci.Validato | |
// create a new validator | ||
consAddr := sdk.ConsAddress(addr) | ||
|
||
pubkey, err := cryptocodec.FromTmProtoPublicKey(change.GetPubKey()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
ccVal, err := types.NewCCValidator(addr, change.Power, pubkey) | ||
if err != nil { | ||
// An error here would indicate that the validator updates | ||
// received from the provider are invalid. | ||
panic(err) | ||
} | ||
|
||
|
@@ -186,10 +190,14 @@ func (k Keeper) TrackHistoricalInfo(ctx sdk.Context) { | |
for _, v := range k.GetAllCCValidator(ctx) { | ||
pk, err := v.ConsPubKey() | ||
if err != nil { | ||
// This should never happen as the pubkey is assumed | ||
// to be stored correctly in ApplyCCValidatorChanges. | ||
panic(err) | ||
} | ||
val, err := stakingtypes.NewValidator(nil, pk, stakingtypes.Description{}) | ||
if err != nil { | ||
// This should never happen as the pubkey is assumed | ||
// to be stored correctly in ApplyCCValidatorChanges. | ||
panic(err) | ||
} | ||
|
||
|
@@ -207,20 +215,25 @@ func (k Keeper) TrackHistoricalInfo(ctx sdk.Context) { | |
k.SetHistoricalInfo(ctx, ctx.BlockHeight(), &historicalEntry) | ||
} | ||
|
||
// GetCurrentValidatorsAsABCIUpdates gets all cross-chain validators converted to the ABCI validator update type | ||
func (k Keeper) GetCurrentValidatorsAsABCIUpdates(ctx sdk.Context) ([]abci.ValidatorUpdate, error) { | ||
// MustGetCurrentValidatorsAsABCIUpdates gets all cross-chain validators converted | ||
// to the ABCI validator update type. It panics in case of failure. | ||
func (k Keeper) MustGetCurrentValidatorsAsABCIUpdates(ctx sdk.Context) []abci.ValidatorUpdate { | ||
vals := k.GetAllCCValidator(ctx) | ||
valUpdates := make([]abci.ValidatorUpdate, 0, len(vals)) | ||
for _, v := range vals { | ||
pk, err := v.ConsPubKey() | ||
if err != nil { | ||
return nil, err | ||
// This should never happen as the pubkey is assumed | ||
// to be stored correctly in ApplyCCValidatorChanges. | ||
panic(err) | ||
} | ||
tmPK, err := cryptocodec.ToTmProtoPublicKey(pk) | ||
if err != nil { | ||
return nil, err | ||
// This should never happen as the pubkey is assumed | ||
// to be stored correctly in ApplyCCValidatorChanges. | ||
panic(err) | ||
} | ||
valUpdates = append(valUpdates, abci.ValidatorUpdate{PubKey: tmPK, Power: v.Power}) | ||
} | ||
return valUpdates, nil | ||
return valUpdates | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,15 +44,6 @@ func AccumulateChanges(currentChanges, newChanges []abci.ValidatorUpdate) []abci | |
return out | ||
} | ||
|
||
func GetChangePubKeyAddress(change abci.ValidatorUpdate) (addr []byte) { | ||
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. Removed as it was called only from |
||
pk, err := cryptocodec.FromTmProtoPublicKey(change.PubKey) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return pk.Address() | ||
} | ||
|
||
// TMCryptoPublicKeyToConsAddr converts a TM public key to an SDK public key | ||
// and returns the associated consensus address | ||
func TMCryptoPublicKeyToConsAddr(k tmprotocrypto.PublicKey) (sdk.ConsAddress, error) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Removed. Redundant check.