-
Notifications
You must be signed in to change notification settings - Fork 24
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
Conversation
c0f394c
to
0fb6427
Compare
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.
One nit otherwise LGTM
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 this structure will much better suit us going forward.
```bash | ||
go generate ./... | ||
``` | ||
1. [AWM Relayer](relayer/README.md) |
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.
Should this be ICM relayer now?
May also be helpful to include a 1 sentence description of each service at the top level here.
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'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?
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.
Ah yeah good call
relayer/main/main.go
Outdated
@@ -534,3 +535,125 @@ func initializeMetrics() (prometheus.Gatherer, prometheus.Registerer, error) { | |||
} | |||
return gatherer, registry, nil | |||
} | |||
|
|||
func initializeConnectionsAndCheckStake( |
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.
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.
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 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?
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.
Sounds good to me 👍
Co-authored-by: Michael Kaplan <55204436+michaelkaplan13@users.noreply.github.com> Signed-off-by: Ian Suvak <ian.suvak@avalabs.org>
relayer/network_utils.go
Outdated
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 |
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.
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.
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.
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.
// 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 | ||
} |
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.
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
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 like the suggestion to break up the quorum check and the stake weight check into separate functions.
Questions on checking sufficient stake
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.
LGTM. I left once comment about the level of one of the logs, but don't feel strongly either way.
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.
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 { |
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.
(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).
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.
Updated #311 to include addressing followups from you and @geoff-vball in a follow-up
// 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 | ||
} |
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 like the suggestion to break up the quorum check and the stake weight check into separate functions.
Need to update Github workflows to point to build_relayer.sh instead of build.sh
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.
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
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
torelayer/main
relayer/config
peers.AppRequestNetwork
to it's ownmain.go
Kept at top level
Not moved
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
How is this documented
Updated READMEs