Skip to content

Commit

Permalink
refactor(client): separate event and MMR block tracking
Browse files Browse the repository at this point in the history
- Split block tracking into two separate fields:
  - latest_processed_events_block: for event processing
  - latest_processed_mmr_block: for MMR updates
- Add validation to prevent block number regression
- Improve logging messages to distinguish between event and MMR processing
- Fix block range calculation in process_new_events
- Update MMR state tracking in update_mmr method
- Update related configuration and scripts

The changes help prevent state regression errors and provide better
visibility into the client's processing state for both events and MMR updates.
  • Loading branch information
ametel01 committed Jan 13, 2025
1 parent 0fe544d commit 1794e8f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
4 changes: 2 additions & 2 deletions config/anvil.messaging.docker.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"chain": "ethereum",
"rpc_url": "http://anvil:8545",
"contract_address": "0x9720a8101A706307866bd9849F9F14E823dE1F6e",
"contract_address": "0x49Cf40BEe86Ab8bD080eE7918eD1d2D26DCF4c8b",
"sender_address": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
"private_key": "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80",
"interval": 2,
"from_block": 7480941
"from_block": 7484849
}
19 changes: 6 additions & 13 deletions crates/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl LightClient {
let starknet_private_key = get_env_var("STARKNET_PRIVATE_KEY")?;
let starknet_account_address = get_env_var("STARKNET_ACCOUNT_ADDRESS")?;
let chain_id = get_env_var("CHAIN_ID")?.parse::<u64>()?;

// Initialize providers
let starknet_provider = StarknetProvider::new(&starknet_rpc_url)?;

Expand Down Expand Up @@ -152,7 +152,7 @@ impl LightClient {
let to_block = if self.blocks_per_run > 0 {
std::cmp::min(
self.latest_processed_events_block + self.blocks_per_run,
latest_block
latest_block,
)
} else {
latest_block
Expand All @@ -164,8 +164,7 @@ impl LightClient {
if from_block > to_block {
error!(
from_block,
to_block,
"Invalid block range: from_block is greater than to_block"
to_block, "Invalid block range: from_block is greater than to_block"
);
return Ok(());
}
Expand Down Expand Up @@ -209,10 +208,7 @@ impl LightClient {
);

if !events.events.is_empty() {
info!(
event_count = events.events.len(),
"Processing new events"
);
info!(event_count = events.events.len(), "Processing new events");

// Process the events and update MMR
self.handle_events().await?;
Expand Down Expand Up @@ -261,8 +257,7 @@ impl LightClient {
if latest_mmr_block >= latest_relayed_block {
info!(
latest_mmr_block,
latest_relayed_block,
"MMR already up to date with latest relayed block"
latest_relayed_block, "MMR already up to date with latest relayed block"
);
return Ok(());
}
Expand Down Expand Up @@ -292,9 +287,7 @@ impl LightClient {
// Update our tracking of the latest processed MMR block
self.latest_processed_mmr_block = latest_relayed_block;

info!(
"Proof verification completed successfully"
);
info!("Proof verification completed successfully");
Ok(())
}
}
2 changes: 1 addition & 1 deletion crates/client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Args {
start_block: u64,

/// Maximum number of blocks to process in each loop run (0 for unlimited)
#[arg(short = 'n', long, default_value = "0")]
#[arg(short = 'n', long, default_value = "100")]
blocks_per_run: u64,
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/run_relayer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -e

# Use RELAYER_INTERVAL from environment, default to 720 if not set
# Use RELAYER_INTERVAL from environment, default to 3 if not set
INTERVAL_MINUTES=${RELAYER_INTERVAL:-3}
MAX_RETRIES=3
RETRY_DELAY=10 # seconds
Expand Down

0 comments on commit 1794e8f

Please sign in to comment.