Skip to content

Commit

Permalink
Merge branch 'main' into gas_profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
steelgeek091 authored Sep 23, 2024
2 parents 1dd7886 + 1df2882 commit ae435ad
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 47 deletions.
80 changes: 48 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ strum_macros = "^0.26"
sha2 = "0.10.2"
sha3 = "0.10.8"
smallvec = "1.6.1"
thiserror = "1.0.63"
thiserror = "1.0.64"
tiny-keccak = { version = "2", features = ["keccak", "sha3"] }
tiny-bip39 = "1.0.0"
tokio = { version = "1.40.0", features = ["full"] }
Expand Down Expand Up @@ -286,7 +286,7 @@ diesel = { version = "2.2.4", features = [
] }
diesel-derive-enum = { version = "2.1.0", features = ["sqlite"] }
diesel_migrations = { version = "2.2.0" }
axum = { version = "0.7.5", default-features = false, features = [
axum = { version = "0.7.6", default-features = false, features = [
"tokio",
"http1",
"http2",
Expand Down
25 changes: 21 additions & 4 deletions crates/rooch-relayer/src/actor/bitcoin_relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ impl BitcoinRelayer {
sync_block_interval,
latest_sync_timestamp: 0u64,
sync_to_latest: false,
batch_size: 10,
batch_size: 5,
})
}

async fn sync_block(&mut self) -> Result<()> {
if !self.buffer.is_empty() {
if self.buffer.len() > self.batch_size {
return Ok(());
}
if self.sync_to_latest
Expand All @@ -76,7 +76,17 @@ impl BitcoinRelayer {
self.latest_sync_timestamp = chrono::Utc::now().timestamp() as u64;

let pending_block_module = self.move_caller.as_module_binding::<PendingBlockModule>();
let best_block_in_rooch = pending_block_module.get_best_block()?;
let best_block_in_rooch = if self.buffer.is_empty() {
pending_block_module.get_best_block()?
} else {
let last_block = self.buffer.last().unwrap();
let last_block_hash = last_block.header_info.hash;
let last_block_height = last_block.header_info.height;
Some(BlockHeightHash {
block_hash: last_block_hash.into_address(),
block_height: last_block_height as u64,
})
};
let best_block_hash_in_bitcoin = self.rpc_client.get_best_block_hash().await?;

//The start block is included
Expand Down Expand Up @@ -118,6 +128,7 @@ impl BitcoinRelayer {

let mut next_block_hash = start_block_hash;

let mut batch_count = 0;
while let Some(next_hash) = next_block_hash {
let header_info = self.rpc_client.get_block_header_info(next_hash).await?;
let block = self.rpc_client.get_block(next_hash).await?;
Expand All @@ -132,11 +143,17 @@ impl BitcoinRelayer {
);
break;
}
info!(
"BitcoinRelayer buffer block, height: {}, hash: {}",
next_block_height, header_info.hash
);
self.buffer.push(BlockResult { header_info, block });
if self.buffer.len() > self.batch_size {
if batch_count > self.batch_size {
break;
}
batch_count += 1;
}

Ok(())
}

Expand Down
Loading

0 comments on commit ae435ad

Please sign in to comment.