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

Fix handlers stuck in block range edge case #104

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion chaindexing/src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::nodes::NodeTask;
use crate::Config;
use crate::{contracts, states, HasRawQueryClient};

// TODO: Use just raw query client through for mutations
pub async fn start<S: Send + Sync + Clone + Debug + 'static>(config: &Config<S>) -> NodeTask {
let node_task = NodeTask::new();
let config = config.clone();
Expand Down
3 changes: 1 addition & 2 deletions chaindexing/src/handlers/handle_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub async fn run<'a, S: Send + Sync + Clone + Debug>(
while let Some(contract_addresses) = contract_addresses_stream.next().await {
for contract_address in contract_addresses {
let from_block_number = contract_address.next_block_number_to_handle_from as u64;
let to_block_number = from_block_number + blocks_per_batch;

let client = repo_client.clone();
let mut client = client.lock().await;
Expand All @@ -38,7 +37,7 @@ pub async fn run<'a, S: Send + Sync + Clone + Debug>(
*chain_id,
&contract_address.address,
from_block_number,
to_block_number,
blocks_per_batch,
)
.await;

Expand Down
7 changes: 4 additions & 3 deletions chaindexing/src/repos/postgres_repo/raw_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,14 @@ impl LoadsDataWithRawQuery for PostgresRepo {
chain_id: u64,
contract_address: &str,
from_block_number: u64,
to_block_number: u64,
limit: u64,
) -> Vec<Event> {
let query = format!(
"SELECT * from chaindexing_events
WHERE chain_id = {chain_id} AND contract_address= '{contract_address}'
AND block_number BETWEEN {from_block_number} AND {to_block_number}
ORDER BY block_number ASC, log_index ASC",
AND block_number >= {from_block_number}
ORDER BY block_number ASC, log_index ASC
LIMIT {limit}",
);

Self::load_data_list(client, &query).await
Expand Down
2 changes: 1 addition & 1 deletion chaindexing/src/repos/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub trait LoadsDataWithRawQuery: HasRawQueryClient {
chain_id: u64,
contract_address: &str,
from_block_number: u64,
to_block_number: u64,
limit: u64,
) -> Vec<Event>;

async fn load_data<Data: Send + DeserializeOwned>(
Expand Down
Loading