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

Move relayer to subfolder #411

Merged
merged 20 commits into from
Aug 16, 2024
Merged

Move relayer to subfolder #411

merged 20 commits into from
Aug 16, 2024

Conversation

iansuvak
Copy link
Contributor

@iansuvak iansuvak commented Aug 5, 2024

Why this should be merged

Partially fixes #409. This would also enable us to rename this repo into something more general. icm-offchain-services ?

How this works

Moved

  • main to relayer/main
  • relayer specific configs to relayer/config
  • relayer specific network initialization code from peers.AppRequestNetwork to it's own main.go
  • Updates Readme and creates a stub top level README that links to individual applications

Kept at top level

  • E2E testing
  • scripts folder
  • build folder (binaries are distinguished by name but output to the same folder)

Not moved

  • database
  • messages

The folders above are relayer specific right now but I haven't moved them yet. Should we? They seem auxillary to the core function and could be feasibly generalized in the future.

How this was tested

  • CI

How is this documented

Updated READMEs

@iansuvak iansuvak added the Warp Signature API API service for serving arbitrary Warp signatures from any VM label Aug 5, 2024
@iansuvak iansuvak self-assigned this Aug 5, 2024
Base automatically changed from signature-aggregation-api to main August 8, 2024 20:04
@iansuvak iansuvak changed the title [WIP] Move relayer to subfolder along with docs update Move relayer to subfolder along with docs update Aug 13, 2024
@iansuvak iansuvak marked this pull request as ready for review August 13, 2024 15:07
@iansuvak iansuvak requested a review from a team as a code owner August 13, 2024 15:07
Copy link
Contributor

@geoff-vball geoff-vball left a comment

Choose a reason for hiding this comment

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

One nit otherwise LGTM

scripts/build_relayer.sh Outdated Show resolved Hide resolved
@iansuvak iansuvak changed the title Move relayer to subfolder along with docs update Move relayer to subfolder Aug 13, 2024
geoff-vball
geoff-vball previously approved these changes Aug 13, 2024
Copy link
Collaborator

@michaelkaplan13 michaelkaplan13 left a comment

Choose a reason for hiding this comment

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

👍 I this structure will much better suit us going forward.

README.md Outdated Show resolved Hide resolved
```bash
go generate ./...
```
1. [AWM Relayer](relayer/README.md)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be ICM relayer now?

May also be helpful to include a 1 sentence description of each service at the top level here.

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'll include descriptions but do we want to hold off on changing the name here until we change the name of the build binary / rest of the documentation / and the whole repo?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah yeah good call

@@ -534,3 +535,125 @@ func initializeMetrics() (prometheus.Gatherer, prometheus.Registerer, error) {
}
return gatherer, registry, nil
}

func initializeConnectionsAndCheckStake(
Copy link
Collaborator

Choose a reason for hiding this comment

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

initializeConnectionsAndCheckStake, connectToNonPrimaryNetworkPeers, and connectToPrimaryNetworkPeers may make more sense to live in a non-main package specific to the relayer, but not a huge deal either way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I thought about it originally, but they are only called as part of initialization at app startup. I am happy to move them but any idea on the naming? I don't think we need a new package for it since it would define no structs, methods or interfaces.

Maybe network_utils.go in the relayer package?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good to me 👍

iansuvak and others added 2 commits August 15, 2024 11:56
Co-authored-by: Michael Kaplan <55204436+michaelkaplan13@users.noreply.github.com>
Signed-off-by: Ian Suvak <ian.suvak@avalabs.org>
Comment on lines 103 to 114
if ok, quorum, err := checkForSufficientConnectedStake(logger, cfg, connectedValidators, blockchainID); !ok {
logger.Error(
"Failed to connect to a threshold of stake",
zap.String("destinationBlockchainID", blockchainID.String()),
zap.Uint64("connectedWeight", connectedValidators.ConnectedWeight),
zap.Uint64("totalValidatorWeight", connectedValidators.TotalValidatorWeight),
zap.Any("warpQuorum", quorum),
)
return err
}
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

In the case that we don't connect to a threshold of stake, we log an error here and then return nil, is that's what is intended?

I think the intended flow here should be to check for an error first, return the error if present, then check ok, which should maybe return a new error if we haven't connected to enough stake.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for finding this. It indeed seems like a bug in the existing implementation, but this whole initialization step is not really necessary I only kept it for now to maintain existing behavior.

For now I updated the comment to indicate actual behavior, since I do think that the existing bug i.e. more permissive behavior is actually what we want but if we align on another approach I'm happy to implement it.

Comment on lines +117 to +139
// Fetch the warp quorum from the config and check if the connected stake exceeds the threshold
func checkForSufficientConnectedStake(
logger logging.Logger,
cfg *config.Config,
connectedValidators *peers.ConnectedCanonicalValidators,
destinationBlockchainID ids.ID,
) (bool, *config.WarpQuorum, error) {
quorum, err := cfg.GetWarpQuorum(destinationBlockchainID)
if err != nil {
logger.Error(
"Failed to get warp quorum from config",
zap.String("destinationBlockchainID", destinationBlockchainID.String()),
zap.Error(err),
)
return false, nil, err
}
return utils.CheckStakeWeightExceedsThreshold(
big.NewInt(0).SetUint64(connectedValidators.ConnectedWeight),
connectedValidators.TotalValidatorWeight,
quorum.QuorumNumerator,
quorum.QuorumDenominator,
), &quorum, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Going along with my above comment - I think this would actually be better served not being a function - the tri-state return is kind of confusing. I think we should just inline this in the calling function.

If we wanted, we could make a helper that takes connectedValidators and a quorum and returns a bool to do the calculation on lines 133-138

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the suggestion to break up the quorum check and the stake weight check into separate functions.

@geoff-vball geoff-vball dismissed their stale review August 15, 2024 19:45

Questions on checking sufficient stake

cam-schultz
cam-schultz previously approved these changes Aug 16, 2024
Copy link
Collaborator

@cam-schultz cam-schultz left a comment

Choose a reason for hiding this comment

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

LGTM. I left once comment about the level of one of the logs, but don't feel strongly either way.

relayer/network_utils.go Outdated Show resolved Hide resolved
Copy link
Contributor

@bernard-avalabs bernard-avalabs left a comment

Choose a reason for hiding this comment

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

Generally looks good to me. Just left some minor comments.

) error {
for _, sourceBlockchain := range cfg.SourceBlockchains {
if sourceBlockchain.GetSubnetID() == constants.PrimaryNetworkID {
if err := connectToPrimaryNetworkPeers(logger, network, cfg, sourceBlockchain); err != nil {
Copy link
Contributor

@bernard-avalabs bernard-avalabs Aug 16, 2024

Choose a reason for hiding this comment

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

(Probably not for this PR) Not sure if there are any latency requirements for InitializeConnectionsAndCheckStake, but if there are, we could consider parallelizing these connectToPrimaryNetworkPeers calls (up to some threshold concurrency level).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated #311 to include addressing followups from you and @geoff-vball in a follow-up

Comment on lines +117 to +139
// Fetch the warp quorum from the config and check if the connected stake exceeds the threshold
func checkForSufficientConnectedStake(
logger logging.Logger,
cfg *config.Config,
connectedValidators *peers.ConnectedCanonicalValidators,
destinationBlockchainID ids.ID,
) (bool, *config.WarpQuorum, error) {
quorum, err := cfg.GetWarpQuorum(destinationBlockchainID)
if err != nil {
logger.Error(
"Failed to get warp quorum from config",
zap.String("destinationBlockchainID", destinationBlockchainID.String()),
zap.Error(err),
)
return false, nil, err
}
return utils.CheckStakeWeightExceedsThreshold(
big.NewInt(0).SetUint64(connectedValidators.ConnectedWeight),
connectedValidators.TotalValidatorWeight,
quorum.QuorumNumerator,
quorum.QuorumDenominator,
), &quorum, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the suggestion to break up the quorum check and the stake weight check into separate functions.

@cam-schultz cam-schultz dismissed their stale review August 16, 2024 19:03

Need to update Github workflows to point to build_relayer.sh instead of build.sh

Copy link
Collaborator

@cam-schultz cam-schultz left a comment

Choose a reason for hiding this comment

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

The entry point path in .goreleaser.yml needs to be updated from main/main.go to relayer/main/main.go

https://github.com/ava-labs/awm-relayer/blob/main/.goreleaser.yml#L4

@iansuvak iansuvak merged commit 46daa55 into main Aug 16, 2024
7 checks passed
@iansuvak iansuvak deleted the demote-relayer branch August 16, 2024 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Warp Signature API API service for serving arbitrary Warp signatures from any VM
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Move relayer main package and related configs to it's own subfolder
5 participants