Skip to content

Commit

Permalink
Start indexing settlement contract as its creation as latest
Browse files Browse the repository at this point in the history
  • Loading branch information
m-lord-renkse committed Nov 6, 2024
1 parent 039be41 commit 49998f6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
8 changes: 6 additions & 2 deletions crates/autopilot/src/boundary/events/settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ impl_event_retrieving! {

pub struct Indexer {
db: Postgres,
start_index: u64,
settlement_observer: settlement::Observer,
}

impl Indexer {
pub fn new(db: Postgres, settlement_observer: settlement::Observer) -> Self {
pub fn new(db: Postgres, settlement_observer: settlement::Observer, start_index: u64) -> Self {
Self {
db,
settlement_observer,
start_index,
}
}
}
Expand All @@ -29,7 +31,9 @@ const INDEX_NAME: &str = "settlements";
#[async_trait::async_trait]
impl EventStoring<contracts::gpv2_settlement::Event> for Indexer {
async fn last_event_block(&self) -> Result<u64> {
super::read_last_block_from_db(&self.db.pool, INDEX_NAME).await
super::read_last_block_from_db(&self.db.pool, INDEX_NAME)
.await
.map(|last_block| last_block.max(self.start_index))
}

async fn persist_last_indexed_block(&mut self, latest_block: u64) -> Result<()> {
Expand Down
4 changes: 3 additions & 1 deletion crates/autopilot/src/maintenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use {
shared::maintenance::Maintaining,
std::{future::Future, sync::Arc},
tokio::sync::Mutex,
tracing::Instrument,
};

/// Coordinates all the updates that need to run a new block
Expand Down Expand Up @@ -118,7 +119,8 @@ impl Maintenance {
.maintenance_stage_time
.with_label_values(&[label])
.start_timer();
fut.await
fut.instrument(tracing::info_span!("maintenance", label = label))
.await
}

/// Spawns a background task that runs on every new block but also
Expand Down
16 changes: 14 additions & 2 deletions crates/autopilot/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use {
chain::Chain,
clap::Parser,
contracts::{BalancerV2Vault, IUniswapV3Factory},
ethcontract::{dyns::DynWeb3, errors::DeployError, BlockNumber},
ethcontract::{common::DeploymentInformation, dyns::DynWeb3, errors::DeployError, BlockNumber},
ethrpc::block_stream::block_number_to_block_number_hash,
futures::StreamExt,
model::DomainSeparator,
Expand Down Expand Up @@ -363,11 +363,23 @@ pub async fn run(args: Arguments) {
infra::persistence::Persistence::new(args.s3.into().unwrap(), Arc::new(db.clone())).await;
let settlement_observer =
crate::domain::settlement::Observer::new(eth.clone(), persistence.clone());
let DeploymentInformation::BlockNumber(settlement_contract_start_index) = eth
.contracts()
.settlement()
.deployment_information()
.expect("deployment information")
else {
panic!("settlement contract start block not found");
};
let settlement_event_indexer = EventUpdater::new(
boundary::events::settlement::GPv2SettlementContract::new(
eth.contracts().settlement().clone(),
),
boundary::events::settlement::Indexer::new(db.clone(), settlement_observer),
boundary::events::settlement::Indexer::new(
db.clone(),
settlement_observer,
settlement_contract_start_index,
),
block_retriever.clone(),
skip_event_sync_start,
);
Expand Down
2 changes: 2 additions & 0 deletions crates/shared/src/event_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,9 @@ where

/// Get new events from the contract and insert them into the database.
pub async fn update_events(&mut self) -> Result<()> {
tracing::debug!("update_events");
let event_range = self.event_block_range().await?;
tracing::debug!("event_range: {event_range:?}");

if let Some(range) = event_range.history_range {
self.update_events_from_old_blocks(range).await?;
Expand Down

0 comments on commit 49998f6

Please sign in to comment.