Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Jun 12, 2024
1 parent 896379c commit f6c34f6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
3 changes: 2 additions & 1 deletion bin/deriver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ async fn main() -> Result<()> {

// Continuously step on the pipeline and validate payloads.
loop {
info!(target: "loop", "Validated payload attributes number {}", derived_attributes_count);
info!(target: "loop", "Pending l2 safe head num: {}", pipeline.cursor.block_info.number);
match pipeline.step().await {
Ok(_) => info!(target: "loop", "Stepped derivation pipeline"),
Err(e) => warn!(target: "loop", "Error stepping derivation pipeline: {:?}", e),
Expand All @@ -45,7 +47,6 @@ async fn main() -> Result<()> {
continue;
}
derived_attributes_count += 1;
info!(target: "loop", "Validated payload attributes number {}", derived_attributes_count);
match l2_provider.l2_block_info_by_number(pipeline.cursor.block_info.number + 1).await {
Ok(bi) => pipeline.update_cursor(bi),
Err(e) => {
Expand Down
41 changes: 24 additions & 17 deletions crates/derive/src/stages/attributes_queue/deposits.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Contains a helper method to derive deposit transactions from L1 Receipts.
use crate::types::{DepositError, RawTransaction};
use crate::types::RawTransaction;
use alloc::vec::Vec;
use alloy_consensus::Receipt;
use alloy_primitives::{Address, Log, B256};
use alloy_primitives::{Address, B256};
use kona_primitives::{decode_deposit, DEPOSIT_EVENT_ABI_HASH};

/// Derive deposits for transaction receipts.
Expand All @@ -16,27 +16,34 @@ pub(crate) async fn derive_deposits(
receipts: Vec<Receipt>,
deposit_contract: Address,
) -> anyhow::Result<Vec<RawTransaction>> {
let receipts = receipts.into_iter().filter(|r| r.status).collect::<Vec<_>>();
// Flatten the list of receipts into a list of logs.
let addr = |l: &Log| l.address == deposit_contract;
let topics = |l: &Log| l.data.topics().first().map_or(false, |i| *i == DEPOSIT_EVENT_ABI_HASH);
let filter_logs =
|r: Receipt| r.logs.into_iter().filter(|l| addr(l) && topics(l)).collect::<Vec<Log>>();
let logs = receipts.into_iter().flat_map(filter_logs).collect::<Vec<Log>>();
// TODO(refcell): are logs **and** receipts guaranteed to be _in order_?
// If not, we need to somehow get the index of each log in the block.
logs.iter()
.enumerate()
.map(|(i, l)| decode_deposit(block_hash, i, l))
.collect::<Result<Vec<_>, DepositError>>()
.map_err(|e| anyhow::anyhow!(e))
let mut global_index = 0;
let mut res = Vec::new();
for r in receipts.iter() {
if !r.status {
continue;
}
for l in r.logs.iter() {
let curr_index = global_index;
global_index += 1;
if !l.data.topics().first().map_or(false, |i| *i == DEPOSIT_EVENT_ABI_HASH) {
continue;
}
if l.address != deposit_contract {
continue;
}
let decoded = decode_deposit(block_hash, curr_index, l).map_err(|e| anyhow::anyhow!(e))?;
res.push(decoded);
}
}
Ok(res)
}

#[cfg(test)]
mod tests {
use super::*;
use crate::types::DepositError;
use alloc::vec;
use alloy_primitives::{address, Bytes, LogData, U256, U64};
use alloy_primitives::{address, Log, Bytes, LogData, U256, U64};

fn generate_valid_log() -> Log {
let deposit_contract = address!("1111111111111111111111111111111111111111");
Expand Down

0 comments on commit f6c34f6

Please sign in to comment.