Skip to content

Commit

Permalink
add primary network anycast todos
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-schultz committed Oct 3, 2023
1 parent 40c568a commit 2f54152
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions messages/block_hash_publisher/message_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func NewMessageManager(
// ShouldSendMessage returns true if the message should be sent to ANY of the configured destination chains
// This saves us from having to aggregate signatures in that case. Decisions about which destination chains to send to are made in SendMessage
func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageInfo, _ ids.ID) (bool, error) {
// TODO: Handle the primary network case. If it's the primary network, only check the passed in destinationChainID
for _, destination := range m.destinations {
if destination.shouldSend(warpMessageInfo.BlockTimestamp, warpMessageInfo.BlockNumber) {
return true, nil
Expand All @@ -118,6 +119,7 @@ func (m *messageManager) ShouldSendMessage(warpMessageInfo *vmtypes.WarpMessageI
}

func (m *messageManager) SendMessage(signedMessage *warp.Message, warpMessageInfo *vmtypes.WarpMessageInfo, _ ids.ID) error {
// TODO: Handle the primary network case. If it's the primary network, only send to the passed in destinationChainID
m.logger.Info(
"DEBUG SENDING",
zap.String("destinationInfo", fmt.Sprintf("%#v", m.destinations)),
Expand Down
4 changes: 0 additions & 4 deletions relayer/message_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ func newMessageRelayer(
}

func (r *messageRelayer) relayMessage(requestID uint32, messageManager messages.MessageManager) error {
// TODONOW: destinationChainID may be nil/empty, in which case it is an anycast message -> set by subscriber
// ShouldSendMessage makes decisions based ONLY on the message contents, not the relayer config.
// This means that it won't make any decisions about anycase messages based on the relayer config.
// SendMessage handles sending anycast messages to the correct destination chain, based on the relayer config
shouldSend, err := messageManager.ShouldSendMessage(r.warpMessageInfo, r.destinationChainID)
if err != nil {
r.logger.Error(
Expand Down
7 changes: 7 additions & 0 deletions relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func NewRelayer(
messageManagers := make(map[common.Hash]messages.MessageManager)
for address, config := range sourceSubnetInfo.MessageContracts {
addressHash := common.HexToHash(address)
// TODO: To handle the primary network case, the messageManager needs to know if its source subnet is the primary network
messageManager, err := messages.NewMessageManager(logger, addressHash, config, destinationClients)
if err != nil {
logger.Error(
Expand Down Expand Up @@ -206,6 +207,12 @@ func (r *Relayer) RelayMessage(warpMessageInfo *vmtypes.WarpMessageInfo, metrics
return nil
}

// TODO: To handle anycasting for the primary network, we need to call newMessageRelayer in a loop for each of the
// configured destinations. We can get the configured destinations from messageManage.
// This is necessary because in the primary network case, each destination will have a different aggregate signature.
// For anycasting from any other network, we only need to create a single aggregate signature, so we fan out in
// messageManager instead.

// Create and run the message relayer to attempt to deliver the message to the destination chain
messageRelayer := newMessageRelayer(r.logger, metrics, r, warpMessageInfo, warpMessageInfo.DestinationChainID, r.responseChan, messageCreator)
if err != nil {
Expand Down

0 comments on commit 2f54152

Please sign in to comment.