Skip to content

Commit

Permalink
ingest frame
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Feb 25, 2024
1 parent de26f36 commit 8c867d6
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion crates/derive/src/stages/channel_bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use hashbrown::HashMap;
use crate::{
params::{ChannelID, MAX_CHANNEL_BANK_SIZE},
traits::{ChainProvider, DataAvailabilityProvider},
types::{BlockInfo, Channel, RollupConfig},
types::{BlockInfo, Channel, Frame, RollupConfig},
};

use super::l1_retrieval::L1Retrieval;
Expand Down Expand Up @@ -81,4 +81,28 @@ where
}
Ok(())
}

/// Adds new L1 data to the channel bank. Should only be called after all data has been read.
pub fn ingest_frame(&mut self, frame: Frame) -> Result<()> {
let origin = *self.origin().ok_or(anyhow!("No origin"))?;

let current_channel = self.channels.entry(frame.id).or_insert_with(|| {
// Create a new channel
let channel = Channel::new(frame.id, origin);
self.channel_queue.push_back(frame.id);
channel
});

// Check if the channel is not timed out. If it has, ignore the frame.
if current_channel.open_block_number() + self.cfg.channel_timeout < origin.number {
return Ok(());
}

// Ingest the frame. If it fails, ignore the frame.
if current_channel.add_frame(frame, origin).is_err() {
return Ok(());
}

self.prune()
}
}

0 comments on commit 8c867d6

Please sign in to comment.