Skip to content

Commit

Permalink
fix PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gwen917 committed Oct 16, 2023
1 parent 8b5eacd commit 62d4fac
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
29 changes: 15 additions & 14 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion messages/teleporter/message_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
10 changes: 9 additions & 1 deletion relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 {
Expand Down

0 comments on commit 62d4fac

Please sign in to comment.