Skip to content

Commit

Permalink
Merge pull request #411 from ava-labs/demote-relayer
Browse files Browse the repository at this point in the history
Move relayer to subfolder
  • Loading branch information
iansuvak authored Aug 16, 2024
2 parents 21e89af + aae5c4b commit 46daa55
Show file tree
Hide file tree
Showing 48 changed files with 733 additions and 671 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ref. https://goreleaser.com/customization/build/
builds:
- id: awm-relayer
main: ./main/main.go
main: ./relayer/main/main.go
binary: awm-relayer
flags:
- -v
Expand Down
454 changes: 7 additions & 447 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package database

import (
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/awm-relayer/config"
"github.com/ava-labs/awm-relayer/relayer/config"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"go.uber.org/zap"
Expand Down
2 changes: 1 addition & 1 deletion database/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/awm-relayer/config"
"github.com/ava-labs/awm-relayer/relayer/config"
"github.com/ethereum/go-ethereum/common"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
Expand Down
1 change: 1 addition & 0 deletions database/mocks/mock_database.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion database/relayer_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/awm-relayer/config"
"github.com/ava-labs/awm-relayer/relayer/config"
"github.com/ava-labs/awm-relayer/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
Expand Down
2 changes: 1 addition & 1 deletion messages/off-chain-registry/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
warpPayload "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload"
"github.com/ava-labs/awm-relayer/config"
"github.com/ava-labs/awm-relayer/messages"
"github.com/ava-labs/awm-relayer/relayer/config"
"github.com/ava-labs/awm-relayer/vms"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
"github.com/ava-labs/subnet-evm/ethclient"
Expand Down
2 changes: 1 addition & 1 deletion messages/off-chain-registry/message_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
"github.com/ava-labs/avalanchego/vms/platformvm/warp/payload"
"github.com/ava-labs/awm-relayer/config"
"github.com/ava-labs/awm-relayer/relayer/config"
mock_evm "github.com/ava-labs/awm-relayer/vms/evm/mocks"
mock_vms "github.com/ava-labs/awm-relayer/vms/mocks"
teleporterregistry "github.com/ava-labs/teleporter/abi-bindings/go/teleporter/registry/TeleporterRegistry"
Expand Down
2 changes: 1 addition & 1 deletion messages/teleporter/message_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
warpPayload "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload"
"github.com/ava-labs/awm-relayer/config"
"github.com/ava-labs/awm-relayer/messages"
pbDecider "github.com/ava-labs/awm-relayer/proto/pb/decider"
"github.com/ava-labs/awm-relayer/relayer/config"
"github.com/ava-labs/awm-relayer/utils"
"github.com/ava-labs/awm-relayer/vms"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
Expand Down
2 changes: 1 addition & 1 deletion messages/teleporter/message_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
warpPayload "github.com/ava-labs/avalanchego/vms/platformvm/warp/payload"
"github.com/ava-labs/awm-relayer/config"
"github.com/ava-labs/awm-relayer/relayer/config"
mock_evm "github.com/ava-labs/awm-relayer/vms/evm/mocks"
mock_vms "github.com/ava-labs/awm-relayer/vms/mocks"
"github.com/ava-labs/subnet-evm/accounts/abi/bind"
Expand Down
121 changes: 0 additions & 121 deletions peers/app_request_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ package peers

import (
"context"
"fmt"
"math/big"
"os"
"sync"
"time"
Expand All @@ -17,13 +15,10 @@ import (
avagoCommon "github.com/ava-labs/avalanchego/snow/engine/common"
snowVdrs "github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/subnets"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/logging"
"github.com/ava-labs/avalanchego/utils/set"
"github.com/ava-labs/avalanchego/vms/platformvm/warp"
"github.com/ava-labs/awm-relayer/config"
"github.com/ava-labs/awm-relayer/peers/validators"
"github.com/ava-labs/awm-relayer/utils"
"github.com/prometheus/client_golang/prometheus"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -111,32 +106,6 @@ func NewNetwork(
return arNetwork, nil
}

// TODO: remove dependence on Relayer specific config since this is meant to be a generic AppRequestNetwork file
func (n *AppRequestNetwork) InitializeConnectionsAndCheckStake(cfg *config.Config) error {
// Manually connect to the validators of each of the source subnets.
// We return an error if we are unable to connect to sufficient stake on any of the subnets.
// Sufficient stake is determined by the Warp quora of the configured supported destinations,
// or if the subnet supports all destinations, by the quora of all configured destinations.
for _, sourceBlockchain := range cfg.SourceBlockchains {
if sourceBlockchain.GetSubnetID() == constants.PrimaryNetworkID {
if err := n.connectToPrimaryNetworkPeers(cfg, sourceBlockchain); err != nil {
return fmt.Errorf(
"failed to connect to primary network peers: %w",
err,
)
}
} else {
if err := n.connectToNonPrimaryNetworkPeers(cfg, sourceBlockchain); err != nil {
return fmt.Errorf(
"failed to connect to non-primary network peers: %w",
err,
)
}
}
}
return nil
}

// ConnectPeers connects the network to peers with the given nodeIDs.
// Returns the set of nodeIDs that were successfully connected to.
func (n *AppRequestNetwork) ConnectPeers(nodeIDs set.Set[ids.NodeID]) set.Set[ids.NodeID] {
Expand Down Expand Up @@ -272,93 +241,3 @@ func (n *AppRequestNetwork) RegisterRequestID(requestID uint32, numExpectedRespo
func (n *AppRequestNetwork) GetSubnetID(blockchainID ids.ID) (ids.ID, error) {
return n.validatorClient.GetSubnetID(context.Background(), blockchainID)
}

// Private helpers

// Connect to the validators of the source blockchain. For each destination blockchain,
// verify that we have connected to a threshold of stake.
func (n *AppRequestNetwork) connectToNonPrimaryNetworkPeers(
cfg *config.Config,
sourceBlockchain *config.SourceBlockchain,
) error {
subnetID := sourceBlockchain.GetSubnetID()
connectedValidators, err := n.ConnectToCanonicalValidators(subnetID)
if err != nil {
n.logger.Error(
"Failed to connect to canonical validators",
zap.String("subnetID", subnetID.String()),
zap.Error(err),
)
return err
}
for _, destination := range sourceBlockchain.SupportedDestinations {
blockchainID := destination.GetBlockchainID()
if ok, quorum, err := n.checkForSufficientConnectedStake(cfg, connectedValidators, blockchainID); !ok {
n.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
}

// Connect to the validators of the destination blockchains. Verify that we have connected
// to a threshold of stake for each blockchain.
func (n *AppRequestNetwork) connectToPrimaryNetworkPeers(
cfg *config.Config,
sourceBlockchain *config.SourceBlockchain,
) error {
for _, destination := range sourceBlockchain.SupportedDestinations {
blockchainID := destination.GetBlockchainID()
subnetID := cfg.GetSubnetID(blockchainID)
connectedValidators, err := n.ConnectToCanonicalValidators(subnetID)
if err != nil {
n.logger.Error(
"Failed to connect to canonical validators",
zap.String("subnetID", subnetID.String()),
zap.Error(err),
)
return err
}

if ok, quorum, err := n.checkForSufficientConnectedStake(cfg, connectedValidators, blockchainID); !ok {
n.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
}

// Fetch the warp quorum from the config and check if the connected stake exceeds the threshold
func (n *AppRequestNetwork) checkForSufficientConnectedStake(
cfg *config.Config,
connectedValidators *ConnectedCanonicalValidators,
destinationBlockchainID ids.ID,
) (bool, *config.WarpQuorum, error) {
quorum, err := cfg.GetWarpQuorum(destinationBlockchainID)
if err != nil {
n.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
}
Loading

0 comments on commit 46daa55

Please sign in to comment.