-
Notifications
You must be signed in to change notification settings - Fork 21
feat: Add AggregationISM to hyperlane-cosmos #152
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
Open
jonas089
wants to merge
6
commits into
bcp-innovations:main
Choose a base branch
from
jonas089:jonas/aggregation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
85798bf
aggregation ISM
jonas089 0710426
celestia-engineering review
jonas089 1a81626
wip
jonas089 d7363a4
Merge branch 'main' into jonas/aggregation
jonas089 a6e122f
wip: CI
jonas089 d066a50
Merge branch 'main' into jonas/aggregation
jonas089 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
70 changes: 70 additions & 0 deletions
70
x/core/01_interchain_security/keeper/aggregation_ism_handler.go
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| package keeper | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "cosmossdk.io/errors" | ||
| "github.com/bcp-innovations/hyperlane-cosmos/util" | ||
| "github.com/bcp-innovations/hyperlane-cosmos/x/core/01_interchain_security/types" | ||
| ) | ||
|
|
||
| // AggregationISMHandler | ||
| // The AggregationISM is a special ISM that aggregates verification from multiple ISMs. | ||
| // It requires a threshold number of ISMs to pass verification for the aggregation to succeed. | ||
| type AggregationISMHandler struct { | ||
| keeper *Keeper // The ism keeper | ||
| } | ||
|
|
||
| // Verify implements HyperlaneInterchainSecurityModule | ||
| // Verifies the message against all configured ISMs and returns true if threshold is met. | ||
| func (m *AggregationISMHandler) Verify(ctx context.Context, ismId util.HexAddress, metadata []byte, message util.HyperlaneMessage) (bool, error) { | ||
| ism, err := m.keeper.isms.Get(ctx, ismId.GetInternalId()) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
|
|
||
| // check if the ism is an aggregation ism | ||
| aggregationIsm, ok := ism.(*types.AggregationISM) | ||
| if !ok { | ||
| return false, errors.Wrapf(types.ErrInvalidISMType, "ISM %s is not an aggregation ISM", ismId.String()) | ||
| } | ||
|
|
||
| // count how many ISMs pass verification | ||
| passCount := uint32(0) | ||
| var verificationErrors []error | ||
|
|
||
| for _, moduleId := range aggregationIsm.Modules { | ||
| // call the top level Verify method on the core module | ||
| // this method will then recursively invoke the Verify method on all the sub ISMs | ||
| verified, err := m.keeper.coreKeeper.Verify(ctx, moduleId, metadata, message) | ||
| if err != nil { | ||
| // Track errors for diagnostic purposes | ||
| verificationErrors = append(verificationErrors, errors.Wrapf(err, "ISM %s verification error", moduleId.String())) | ||
| continue | ||
| } | ||
|
|
||
| if verified { | ||
| passCount++ | ||
| // Early exit if we've already met the threshold | ||
| if passCount >= aggregationIsm.Threshold { | ||
| return true, nil | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Build detailed error message with verification failures | ||
| errMsg := errors.Wrapf(types.ErrInsufficientVerifications, | ||
| "insufficient verifications: %d/%d (threshold: %d)", | ||
| passCount, len(aggregationIsm.Modules), aggregationIsm.Threshold) | ||
|
|
||
| // Append individual verification errors for debugging | ||
| for _, verErr := range verificationErrors { | ||
| errMsg = errors.Wrap(errMsg, verErr.Error()) | ||
| } | ||
|
|
||
| return false, errMsg | ||
| } | ||
|
|
||
| func (m *AggregationISMHandler) Exists(ctx context.Context, ismId util.HexAddress) (bool, error) { | ||
| return m.keeper.isms.Has(ctx, ismId.GetInternalId()) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.