-
Notifications
You must be signed in to change notification settings - Fork 62
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(solver): check target before accept #2478
Merged
Merged
Changes from all commits
Commits
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//nolint:unused // Some functions are unused but are kept for future use | ||
package app | ||
|
||
import ( | ||
"github.com/omni-network/omni/contracts/bindings" | ||
"github.com/omni-network/omni/e2e/solve/devapp" | ||
"github.com/omni-network/omni/lib/errors" | ||
"github.com/omni-network/omni/lib/netconf" | ||
"github.com/omni-network/omni/solver/types" | ||
) | ||
|
||
var ( | ||
targets map[netconf.ID]types.Targets = map[netconf.ID]types.Targets{ | ||
netconf.Devnet: {devapp.GetApp()}, | ||
} | ||
) | ||
|
||
func targetFor(network netconf.ID, call bindings.SolveCall) (types.Target, error) { | ||
t, ok := targets[network] | ||
if !ok { | ||
return nil, errors.New("no targets for network", "network", network) | ||
} | ||
|
||
return t.ForCall(call) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package types | ||
|
||
import ( | ||
"github.com/omni-network/omni/contracts/bindings" | ||
"github.com/omni-network/omni/lib/errors" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
// Target is the interface for a target contract the solver can interact with. | ||
type Target interface { | ||
// ChainID returns the chain ID of the target contract. | ||
ChainID() uint64 | ||
|
||
// Address returns the address of the target contract. | ||
Address() common.Address | ||
|
||
// IsAllowedCall returns true if the call is allowed. | ||
IsAllowedCall(call bindings.SolveCall) bool | ||
|
||
// TokenPrereqs returns the token prerequisites required for the call. | ||
TokenPrereqs(call bindings.SolveCall) ([]bindings.SolveTokenPrereq, error) | ||
|
||
// Verify returns an error if the call should not be fulfilled. | ||
Verify(srcChainID uint64, call bindings.SolveCall, deposits []bindings.SolveDeposit) error | ||
} | ||
|
||
type Targets []Target | ||
|
||
func (t Targets) ForCall(call bindings.SolveCall) (Target, error) { | ||
var match Target | ||
var matched bool | ||
|
||
for _, target := range t { | ||
if target.IsAllowedCall(call) { | ||
if matched { | ||
return nil, errors.New("multiple targets found") | ||
} | ||
|
||
match = target | ||
matched = true | ||
} | ||
} | ||
|
||
if !matched { | ||
return nil, errors.New("no target found") | ||
} | ||
|
||
return match, nil | ||
} |
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.
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.
I think we should error if multiple targets are matched?
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.
mmm, should we use the inbox or outbox contract address to identify the target? Picking any target that matches feels a bit loose?
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.
non matching calls will also be hard to debug since we can't see what rules are expected and why they are failing
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.
Yeah would help us catch bugs / bad target config.
We will still be executing through the outbox. And there is a difference between outbox allowing or not allowing a call (which it does). And a target saying "yes this is an allowed call".
We can also add an outbox check.
Yeah good point we do need to consider debugging.
"is this call one we support?" (
target.IsAllowedCall
)Here we filter out chains / contracts / functions selectors we don't support. Here I think we can
then "should I make this supported call?" (
target.Verify
)Here we can log the error returned by verify