Skip to content
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

node: Integrate Transfer Verifier into the Ethereum watcher #4233

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

johnsaigle
Copy link
Contributor

@johnsaigle johnsaigle commented Jan 22, 2025

  • Create a TxVerifier instance in the Run function of the EVM watcher
  • Wrap all instances where a message would be published to the broadcasting msg channel with a new function, * publishIfSafe
  • This new function calls TxVerifier. If TxVerifier returns true, only then will it publish the message
  • Special carve out for Ethereum only (not other EVM chains)
  • Modified the Transfer Verifier pkg API so that we can call the method with either an existing Receipt or a txHash

Copy link
Collaborator

@banescusebi banescusebi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of suggestions

@@ -88,7 +94,7 @@ type (
// VAA ChainID of the network we're connecting to.
chainID vaa.ChainID

// Channel to send new messages to.
// Channel to send new messages to. Should be wrapped be a call to `publishIfSafe()`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Channel to send new messages to. Should be wrapped be a call to `publishIfSafe()`
// Channel to send new messages to. Each message should be wrapped by a call to `publishIfSafe()`

Comment on lines +390 to +397
pubErr := w.publishIfSafe(msg, ctx, tx, receipt)
if pubErr != nil {
logger.Error("could not publish message: transfer verification failed",
zap.String("msgId", msg.MessageIDString()),
zap.String("txHash", msg.TxIDString()),
zap.Error(pubErr),
)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This chunk of code is used 4 more times below. Should we put it inside publishIfSafe and then have that function not return anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference is to maintain the return value so that the calling code has an idea of whether or not an error occurred. We could think about reducing code duplication by passing a *logger as an argument to that function and allowing it to print the error message, but then the calling code would need another log call if someone wants to log data that isn't visible to publishIfSafe, e.g. the blockNumber which exists for some instances in this file but not others.

input string,
) ([]vaa.ChainID, error) {
if len(input) == 0 {
return nil, errors.New("could not parse input to parseTxVerifierChains: input empty")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we wanted to disable transfer verification on all chains, wouldn't the empty input be a valid case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case we would just not pass in the flag at all, similar to how someone might omit the flag that enables the governor or sets a coingecko key. I think having a CLI interface where --txVerifierChains='' is a valid input is a bit messy.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably misunderstanding how these Go command line flags work, but if you don't provide the flag what does the value default to? My current understanding is it would default to the value you specify in the declaration, which is an empty string; am I greping that wrong?

Copy link
Contributor Author

@johnsaigle johnsaigle Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't gone deeply into it but basically the flags are parsed into specific variables that you define. In this case the type I used is *string (pointer to a string) so the default value when it's not provided would be nil, (I think) rather than a non-nil string of length 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some more testing and patched the code. The latest commit does the following:

  • if the CLI flag is an empty string, panic (via logger.Fatal)
  • if it's absent, txVerifier is disabled
  • if it contains a list of chain IDs, enable Tx Verifier for those chains

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants