From 62d4facaad8a96b664f78e8fece225b38981c275 Mon Sep 17 00:00:00 2001 From: Gwen Date: Mon, 16 Oct 2023 10:51:41 -0400 Subject: [PATCH] fix PR comments --- config/config.go | 29 +++++++++++++------------- main/main.go | 2 +- messages/teleporter/message_manager.go | 2 +- relayer/relayer.go | 10 ++++++++- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/config/config.go b/config/config.go index 11fbe6fd..19f371b2 100644 --- a/config/config.go +++ b/config/config.go @@ -202,35 +202,36 @@ func (c *Config) Validate() error { return nil } -// GetSourceIDs returns the Subnet, Chain IDs and Allowed Destination Chain IDs of all subnets configured as a source -func (cfg *Config) GetSourceIDs() ([]ids.ID, []ids.ID, map[ids.ID]map[ids.ID]bool, error) { +// GetSourceIDs returns the Subnet and Chain IDs of all subnets configured as a source +func (cfg *Config) GetSourceIDs() ([]ids.ID, []ids.ID, error) { var sourceSubnetIDs []ids.ID var sourceChainIDs []ids.ID - allowedDestinationChainIDMap := make(map[ids.ID]map[ids.ID]bool) for _, s := range cfg.SourceSubnets { subnetID, err := ids.FromString(s.SubnetID) if err != nil { - return nil, nil, nil, fmt.Errorf("invalid subnetID in configuration. error: %v", err) + return nil, nil, fmt.Errorf("invalid subnetID in configuration. error: %v", err) } sourceSubnetIDs = append(sourceSubnetIDs, subnetID) chainID, err := ids.FromString(s.ChainID) if err != nil { - return nil, nil, nil, fmt.Errorf("invalid subnetID in configuration. error: %v", err) + return nil, nil, fmt.Errorf("invalid subnetID in configuration. error: %v", err) } sourceChainIDs = append(sourceChainIDs, chainID) + } + return sourceSubnetIDs, sourceChainIDs, nil +} - allowedDestinationChainIDs := make(map[ids.ID]bool) - for _, chainIDStr := range s.AllowedDestinations { - chainID, err := ids.FromString(chainIDStr) - if err != nil { - return nil, nil, nil, fmt.Errorf("invalid chainID in configuration. error: %v", err) - } - allowedDestinationChainIDs[chainID] = true +func (s *SourceSubnet) GetAllowedDestination() (map[ids.ID]bool, error) { + allowedDestinationChainIDs := make(map[ids.ID]bool) + for _, chainIDStr := range s.AllowedDestinations { + chainID, err := ids.FromString(chainIDStr) + if err != nil { + return nil, fmt.Errorf("invalid chainID in configuration. error: %v", err) } - allowedDestinationChainIDMap[chainID] = allowedDestinationChainIDs + allowedDestinationChainIDs[chainID] = true } - return sourceSubnetIDs, sourceChainIDs, allowedDestinationChainIDMap, nil + return allowedDestinationChainIDs, nil } func (s *SourceSubnet) Validate() error { diff --git a/main/main.go b/main/main.go index fe90c374..e9e78287 100644 --- a/main/main.go +++ b/main/main.go @@ -86,7 +86,7 @@ func main() { // Initialize the global app request network logger.Info("Initializing app request network") - sourceSubnetIDs, sourceChainIDs, allowedDestinationChainIDs, err := cfg.GetSourceIDs() + sourceSubnetIDs, sourceChainIDs, err := cfg.GetSourceIDs() if err != nil { logger.Error( "Failed to get source IDs", diff --git a/messages/teleporter/message_manager.go b/messages/teleporter/message_manager.go index 73a45ada..0dd3867e 100644 --- a/messages/teleporter/message_manager.go +++ b/messages/teleporter/message_manager.go @@ -113,7 +113,7 @@ func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageI // If allowedDestinations is not empty, then only the allowed destinations are allowed if _, exist := m.allowedDestinations[destinationChainID]; !exist && len(m.allowedDestinations) > 0 { m.logger.Info( - "Destination chain not allowed to receive messages.", + "Relayer not configured to relay between source and destination", zap.String("destinationChainID", destinationChainID.String()), zap.String("warpMessageID", warpMessageInfo.WarpUnsignedMessage.ID().String()), zap.String("teleporterMessageID", teleporterMessage.MessageID.String()), diff --git a/relayer/relayer.go b/relayer/relayer.go index cc6945f5..a35d1452 100644 --- a/relayer/relayer.go +++ b/relayer/relayer.go @@ -47,7 +47,6 @@ func NewRelayer( network *peers.AppRequestNetwork, responseChan chan message.InboundMessage, destinationClients map[ids.ID]vms.DestinationClient, - allowedDestinationChainIDs map[ids.ID]bool, ) (*Relayer, vms.Subscriber, error) { sub := vms.NewSubscriber(logger, sourceSubnetInfo, db) @@ -69,6 +68,15 @@ func NewRelayer( return nil, nil, err } + allowedDestinationChainIDs, err := sourceSubnetInfo.GetAllowedDestination() + if err != nil { + logger.Error( + "Failed to get allowed destination", + zap.Error(err), + ) + return nil, nil, err + } + // Create message managers for each supported message protocol messageManagers := make(map[common.Hash]messages.MessageManager) for address, config := range sourceSubnetInfo.MessageContracts {