arbos/arbos_types/
message_with_meta.rs

1use alloy_primitives::{B256, keccak256};
2
3use super::incoming_message::L1IncomingMessage;
4
5/// An L1 incoming message with additional metadata.
6#[derive(Debug, Clone, Default)]
7pub struct MessageWithMetadata {
8    pub message: L1IncomingMessage,
9    pub delayed_messages_read: u64,
10}
11
12/// Extended message info including block hash and metadata.
13#[derive(Debug, Clone)]
14pub struct MessageWithMetadataAndBlockInfo {
15    pub message_with_meta: MessageWithMetadata,
16    pub block_hash: Option<B256>,
17    pub block_metadata: Option<Vec<u8>>,
18}
19
20impl MessageWithMetadata {
21    /// ABI-style commitment hash fed into the MEL local message accumulator.
22    /// Only includes MEL (minimum execution layer) consensus fields.
23    ///
24    /// TODO: packed concatenation, not yet reconciled with the on-chain
25    /// `abi.encode` layout (Nitro's `MessageWithMetadata` hashing uses RLP).
26    pub fn abi_hash(&self) -> B256 {
27        let serialized = self.message.serialize();
28        let mut data = Vec::new();
29        data.extend_from_slice(&serialized);
30        data.extend_from_slice(&self.delayed_messages_read.to_be_bytes());
31        keccak256(&data)
32    }
33
34    /// Returns a shallow copy with only consensus-relevant fields.
35    pub fn with_only_mel_consensus_fields(&self) -> Self {
36        MessageWithMetadata {
37            message: L1IncomingMessage {
38                header: self.message.header.clone(),
39                l2_msg: self.message.l2_msg.clone(),
40                legacy_batch_gas_cost: None,
41                batch_data_stats: None,
42            },
43            delayed_messages_read: self.delayed_messages_read,
44        }
45    }
46}