Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(primitives): Channel Reuse #499

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ codegen-units = 1
lto = "fat"

[patch.crates-io]
op-alloy-protocol = { git = "https://github.com/alloy-rs/op-alloy", branch = "rf/feat/export-frame-consts" }
op-alloy-protocol = { git = "https://github.com/alloy-rs/op-alloy", branch = "rf/fix/use-native-u64" }

[workspace.dependencies]
# Workspace
Expand Down
2 changes: 1 addition & 1 deletion crates/derive/src/batch/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! [SingleBatch].

use alloy_rlp::{Buf, Decodable};
use kona_primitives::{block::BlockInfo, L2BlockInfo, RollupConfig};
use kona_primitives::{BlockInfo, L2BlockInfo, RollupConfig};

use crate::{errors::DecodeError, traits::L2ChainProvider};

Expand Down
8 changes: 4 additions & 4 deletions crates/derive/src/stages/channel_bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use async_trait::async_trait;
use core::fmt::Debug;
use hashbrown::HashMap;
use kona_primitives::{BlockInfo, Channel, ChannelID, Frame, RollupConfig, SystemConfig};
use kona_primitives::{BlockInfo, Channel, ChannelId, Frame, RollupConfig, SystemConfig};
use tracing::{trace, warn};

/// Provides frames for the [ChannelBank] stage.
Expand Down Expand Up @@ -43,9 +43,9 @@
/// The rollup configuration.
cfg: Arc<RollupConfig>,
/// Map of channels by ID.
channels: HashMap<ChannelID, Channel>,
channels: HashMap<ChannelId, Channel>,
/// Channels in FIFO order.
channel_queue: VecDeque<ChannelID>,
channel_queue: VecDeque<ChannelId>,
/// The previous stage of the derivation pipeline.
prev: P,
}
Expand Down Expand Up @@ -192,7 +192,7 @@
self.channels.remove(&channel_id);
self.channel_queue.remove(index);

frame_data.map_err(StageError::Custom)
frame_data.ok_or_else(|| StageError::Custom(anyhow!("Channel data is empty")))

Check warning on line 195 in crates/derive/src/stages/channel_bank.rs

View check run for this annotation

Codecov / codecov/patch

crates/derive/src/stages/channel_bank.rs#L195

Added line #L195 was not covered by tests
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ homepage.workspace = true
[dependencies]
# General
anyhow.workspace = true
hashbrown.workspace = true

# Alloy
alloy-eips.workspace = true
Expand Down
57 changes: 0 additions & 57 deletions crates/primitives/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,71 +1,14 @@
//! This module contains the various Block types.

use crate::BlockID;
use alloc::vec::Vec;
use alloy_consensus::{Header, TxEnvelope};
use alloy_eips::eip4895::Withdrawal;
use alloy_primitives::B256;
use alloy_rlp::{RlpDecodable, RlpEncodable};
use op_alloy_consensus::OpTxEnvelope;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Block Header Info
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Eq, Hash, PartialEq, Default)]
pub struct BlockInfo {
/// The block hash
pub hash: B256,
/// The block number
pub number: u64,
/// The parent block hash
pub parent_hash: B256,
/// The block timestamp
pub timestamp: u64,
}

impl BlockInfo {
/// Instantiates a new [BlockInfo].
pub fn new(hash: B256, number: u64, parent_hash: B256, timestamp: u64) -> Self {
Self { hash, number, parent_hash, timestamp }
}

/// Returns the block ID.
pub fn id(&self) -> BlockID {
BlockID { hash: self.hash, number: self.number }
}
}

impl core::fmt::Display for BlockInfo {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(
f,
"BlockInfo {{ hash: {}, number: {}, parent_hash: {}, timestamp: {} }}",
self.hash, self.number, self.parent_hash, self.timestamp
)
}
}

/// L2 Block Header Info
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, Default)]
pub struct L2BlockInfo {
/// The base [BlockInfo]
pub block_info: BlockInfo,
/// The L1 origin [BlockID]
pub l1_origin: BlockID,
/// The sequence number of the L2 block
pub seq_num: u64,
}

impl L2BlockInfo {
/// Instantiates a new [L2BlockInfo].
pub fn new(block_info: BlockInfo, l1_origin: BlockID, seq_num: u64) -> Self {
Self { block_info, l1_origin, seq_num }
}
}

/// The Block Kind
///
/// The block kinds are:
Expand Down
Loading