-
Notifications
You must be signed in to change notification settings - Fork 412
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
Fix lag issue with Mailbox message sequence_and_tip #2879
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,6 @@ use hyperlane_core::{ | |
ChainCommunicationError, ChainResult, ContractLocator, HyperlaneDomain, H256, U256, | ||
}; | ||
use serde::Serialize; | ||
use std::num::NonZeroU64; | ||
|
||
use crate::verify; | ||
use crate::{signers::Signer, ConnectionConf}; | ||
|
@@ -42,15 +41,15 @@ pub trait WasmProvider: Send + Sync { | |
async fn wasm_query<T: Serialize + Sync + Send>( | ||
&self, | ||
payload: T, | ||
maybe_lag: Option<NonZeroU64>, | ||
block_height: Option<u64>, | ||
) -> ChainResult<Vec<u8>>; | ||
|
||
/// query to specific contract address | ||
async fn wasm_query_to<T: Serialize + Sync + Send>( | ||
&self, | ||
to: String, | ||
payload: T, | ||
maybe_lag: Option<NonZeroU64>, | ||
block_height: Option<u64>, | ||
) -> ChainResult<Vec<u8>>; | ||
|
||
/// query account info | ||
|
@@ -133,41 +132,19 @@ impl WasmProvider for WasmGrpcProvider { | |
Ok(height as u64) | ||
} | ||
|
||
async fn wasm_query<T>(&self, payload: T, maybe_lag: Option<NonZeroU64>) -> ChainResult<Vec<u8>> | ||
async fn wasm_query<T>(&self, payload: T, block_height: Option<u64>) -> ChainResult<Vec<u8>> | ||
where | ||
T: Serialize + Send + Sync, | ||
{ | ||
let mut client = WasmQueryClient::connect(self.get_conn_url()?).await?; | ||
|
||
let mut request = tonic::Request::new(QuerySmartContractStateRequest { | ||
address: self.get_contract_addr()?, | ||
query_data: serde_json::to_string(&payload)?.as_bytes().to_vec(), | ||
Comment on lines
-140
to
-144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good spot |
||
}); | ||
|
||
if let Some(lag) = maybe_lag { | ||
let height = self.latest_block_height().await?; | ||
let height = height.saturating_sub(lag.get()); | ||
|
||
request | ||
.metadata_mut() | ||
.insert("x-cosmos-block-height", height.into()); | ||
} | ||
|
||
let response = client | ||
.smart_contract_state(request) | ||
self.wasm_query_to(self.get_contract_addr()?, payload, block_height) | ||
.await | ||
.map_err(ChainCommunicationError::from_other)? | ||
.into_inner(); | ||
|
||
// TODO: handle query to specific block number | ||
Ok(response.data) | ||
} | ||
|
||
async fn wasm_query_to<T>( | ||
&self, | ||
to: String, | ||
payload: T, | ||
maybe_lag: Option<NonZeroU64>, | ||
block_height: Option<u64>, | ||
) -> ChainResult<Vec<u8>> | ||
where | ||
T: Serialize + Send + Sync, | ||
|
@@ -178,13 +155,10 @@ impl WasmProvider for WasmGrpcProvider { | |
query_data: serde_json::to_string(&payload)?.as_bytes().to_vec(), | ||
}); | ||
|
||
if let Some(lag) = maybe_lag { | ||
let height = self.latest_block_height().await?; | ||
let height = height.saturating_sub(lag.get()); | ||
|
||
if let Some(block_height) = block_height { | ||
request | ||
.metadata_mut() | ||
.insert("x-cosmos-block-height", height.into()); | ||
.insert("x-cosmos-block-height", block_height.into()); | ||
} | ||
|
||
let response = client | ||
|
@@ -193,7 +167,6 @@ impl WasmProvider for WasmGrpcProvider { | |
.map_err(ChainCommunicationError::from_other)? | ||
.into_inner(); | ||
|
||
// TODO: handle query to specific block number | ||
Ok(response.data) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use std::num::NonZeroU64; | ||
|
||
use crate::grpc::{WasmGrpcProvider, WasmProvider}; | ||
use hyperlane_core::ChainResult; | ||
|
||
/// Given a lag, returns the block height at the moment. | ||
/// If the lag is None, a block height of None is given, indicating that the | ||
/// tip directly can be used. | ||
pub(crate) async fn get_block_height_for_lag( | ||
provider: &WasmGrpcProvider, | ||
lag: Option<NonZeroU64>, | ||
) -> ChainResult<Option<u64>> { | ||
let block_height = match lag { | ||
Some(lag) => { | ||
let tip = provider.latest_block_height().await?; | ||
let block_height = tip - lag.get(); | ||
Some(block_height) | ||
} | ||
None => None, | ||
}; | ||
|
||
Ok(block_height) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
were these not used at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no 😛