Skip to content
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

Reuse the batch message worker for both relay-level and chain-level message batching #20

Open
soareschen opened this issue Feb 15, 2023 · 0 comments
Assignees

Comments

@soareschen
Copy link
Collaborator

Summary

The current batch message worker works on relay-level message batching. This means that different relay contexts will have different batch message workers to group messages into different batches. The batch message worker needs to work on the relay-level, because it would later need to attach UpdateClient messages to the batched messages from the same counterparty chain.

Following the same principle, there should be a chain-level batch message worker, so that all messages sent to the same chain can potentially be batched together into one transaction. Since the majority of chain-level message batching logic is the same as the relay-level batching, we can refactor the current batch message worker code so that it could work at both levels.

Details

We will refactor the batch message worker to work on a chain context, then add constructs such that a relay context can pretend to be a chain context. There is a draft implementation available on how this can be done:

pub struct RelayToChain<Relay, Target> {
    pub relay: Relay,
    pub phantom: PhantomData<Target>,
}

impl<Relay, Target> HasMessageType for RelayToChain<Relay, Target>
where
    Relay: HasRelayTypes,
    Target: ChainTarget<Relay>,
{
    type Message = <Target::TargetChain as HasMessageType>::Message;
}

#[async_trait]
impl<Relay, Target> CanSendMessages for RelayToChain<Relay, Target>
where
    Relay: HasRelayTypes,
    Target: ChainTarget<Relay>,
    Relay: CanSendIbcMessages<Target>,
{
    async fn send_messages(
        &self,
        messages: Vec<Self::Message>,
    ) -> Result<Vec<Vec<Self::Event>>, Self::Error> {
        self.relay
            .send_messages(messages)
            .await
    }
}

The RelayToChain struct wraps a relay context with a Target and implements the chain context traits for it. The implementation can be done rather easily by forwarding the calls to the underlying target chain context. The main difference in behavior is the implementation of CanSendMessages, which sends the messages via the relay context so that the UpdateClient message can be appended.

Using RelayToChain, we can then pass in the relay context as a chain context to the new batch message worker.

@soareschen soareschen self-assigned this Feb 15, 2023
@soareschen soareschen transferred this issue from informalsystems/hermes Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant