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

0xmovses/aptos event monitoring #388

Closed
wants to merge 20 commits into from

Conversation

0xmovses
Copy link
Contributor

@0xmovses 0xmovses commented Aug 19, 2024

Summary

Implements Stream for MovementCounterpartyMonitoring. We cannot subscribe to a ws on aptos-core because this functionality is not provided out-of-the-box, additionally the indexer only streams transactions no events. So we must query the rest end point directly.

MovementCounterpartyMonitoring must be Stream in order for the BridgeService to correctly operate, this is exemplified in the shared/tests code, it is also a trait bound.

Changelog

  • Implements Stream for MovementCounterpartyMonitoring
  • Uses `try_stream!
  • Updates move module to correctly capture all the events in a struct and query by field. (I borrowed this pattern from the aptos governance module)

Testing

More top-level code needs to be added before I can integrate test this. In an attempt to keep the PR small. Will add that in a separate PR.

@0xmovses 0xmovses marked this pull request as draft August 19, 2024 16:03
@0xmovses 0xmovses marked this pull request as ready for review August 20, 2024 16:40
client.counterparty_address,
struct_tag.as_str(),
"bridge_transfer_assets_locked",
Some(1),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it's polling the first page, unlimited. Taking a look at the aptos method,

async fn get_bcs_with_page(
        &self,
        url: Url,
        start: Option<u64>,
        limit: Option<u16>,
    ) -> AptosResult<Response<bytes::Bytes>> {
        let mut request = self.inner.get(url).header(ACCEPT, BCS);
        if let Some(start) = start {
            request = request.query(&[("start", start)])
        }

        if let Some(limit) = limit {
            request = request.query(&[("limit", limit)])
        }

        let response = request.send().await?;
        self.check_and_parse_bcs_response(response).await
    }
    ```
not sure if pagination is being handled correctly as you'd want to use the previous start as the limit. 🤔 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point. I can only meaningfully tweak this once I have the integration test so I can see what behaviour its giving me. I can try here but I'd be flying blind. But I have an idea for how to handle pagination within the Stream

.map_err(|e| Error::msg(e.to_string()))?;

// Process responses and return results
let locked_events = process_response(locked_response, CounterpartyEventKind::Locked)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like process_response could be process_responses instead and return a tuple of locked_Events, completed_eventes and cancelled_events

Copy link
Contributor

@andygolay andygolay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, pending completion of the outstanding todos and integration testing

_rest_url: &str,
_listener: UnboundedReceiver<MovementChainEvent<MovementAddress, MovementHash>>,
) -> Result<Self, anyhow::Error> {
todo!()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps it would make sense to list the todos in the Outstanding Issues section of the PR?

@0xmovses
Copy link
Contributor Author

closing as all these changes are in #399

@0xmovses 0xmovses closed this Sep 10, 2024
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

Successfully merging this pull request may close these issues.

3 participants