Skip to content
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
[workspace.package]
version = "0.10.1"
edition = "2021"
rust-version = "1.81"
rust-version = "1.85"
authors = ["init4"]
license = "MIT OR Apache-2.0"
homepage = "https://github.com/init4tech/signet-sdk"
Expand Down
40 changes: 39 additions & 1 deletion crates/bundle/src/send/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ pub struct SignetEthBundle {
pub bundle: EthSendBundle,
/// Host fills to be applied with the bundle, represented as a signed
/// permit2 fill.
#[serde(default)]
#[serde(default, skip_serializing_if = "Option::is_none")]
pub host_fills: Option<SignedFill>,

/// Host transactions to be included in the host bundle.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub host_txs: Vec<Bytes>,
}

impl SignetEthBundle {
Expand Down Expand Up @@ -194,6 +198,7 @@ mod test {
chainId: 100,
}],
}),
host_txs: vec![b"host_tx1".into(), b"host_tx2".into()],
};

let serialized = serde_json::to_string(&bundle).unwrap();
Expand All @@ -202,6 +207,39 @@ mod test {
assert_eq!(bundle, deserialized);
}

#[test]
fn send_bundle_ser_roundtrip_no_host_no_fills() {
let bundle = SignetEthBundle {
bundle: EthSendBundle {
txs: vec![b"tx1".into(), b"tx2".into()],
block_number: 1,
min_timestamp: Some(2),
max_timestamp: Some(3),
reverting_tx_hashes: vec![B256::repeat_byte(4), B256::repeat_byte(5)],
replacement_uuid: Some("uuid".to_owned()),
..Default::default()
},
host_fills: None,
host_txs: vec![],
};

let serialized = serde_json::to_string(&bundle).unwrap();
let deserialized: SignetEthBundle = serde_json::from_str(&serialized).unwrap();

assert_eq!(bundle, deserialized);
}

#[test]
fn test_deser_bundle_no_host_no_fills() {
let json = r#"
{"txs":["0x747831","0x747832"],"blockNumber":"0x1","minTimestamp":2,"maxTimestamp":3,"revertingTxHashes":["0x0404040404040404040404040404040404040404040404040404040404040404","0x0505050505050505050505050505050505050505050505050505050505050505"],"replacementUuid":"uuid"}"#;

let deserialized: SignetEthBundle = serde_json::from_str(json).unwrap();

assert!(deserialized.host_fills.is_none());
assert!(deserialized.host_txs.is_empty());
}

#[test]
fn send_bundle_resp_ser_roundtrip() {
let resp = SignetEthBundleResponse { bundle_hash: B256::repeat_byte(1) };
Expand Down
2 changes: 1 addition & 1 deletion crates/extract/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'a, C: Extractable> HostEvents<'a, C> {
}

/// Add a [`Zenith::BlockSubmitted`] event to the host events.
pub fn ingest_block_submitted(
pub const fn ingest_block_submitted(
&mut self,
event: ExtractedEvent<'a, C::Receipt, Zenith::BlockSubmitted>,
) {
Expand Down
16 changes: 15 additions & 1 deletion crates/sim/src/built.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ use tracing::{error, trace};
pub struct BuiltBlock {
/// The host fill actions.
pub(crate) host_fills: Vec<SignedFill>,

/// The host transactions to be included in a resulting bundle.
pub(crate) host_txns: Vec<Bytes>,

/// Transactions in the block.
pub(crate) transactions: Vec<TxEnvelope>,
/// The block number for the block.

/// The block number for the Signet block.
pub(crate) block_number: u64,

/// The amount of gas used by the block so far
pub(crate) gas_used: u64,

// -- Memoization fields --
/// Memoized raw encoding of the block.
pub(crate) raw_encoding: OnceLock<Bytes>,
/// Memoized hash of the block.
Expand All @@ -47,6 +53,7 @@ impl BuiltBlock {
pub const fn new(block_number: u64) -> Self {
Self {
host_fills: Vec::new(),
host_txns: Vec::new(),
transactions: Vec::new(),
block_number,
gas_used: 0,
Expand Down Expand Up @@ -87,6 +94,12 @@ impl BuiltBlock {
&self.host_fills
}

/// Get the current list of host transactions included in this block.
#[allow(clippy::missing_const_for_fn)] // false positive, const deref
pub fn host_txns(&self) -> &[Bytes] {
&self.host_txns
}

/// Unseal the block
pub(crate) fn unseal(&mut self) {
self.raw_encoding.take();
Expand Down Expand Up @@ -124,6 +137,7 @@ impl BuiltBlock {
// extend the transactions with the decoded transactions.
// As this builder does not provide bundles landing "top of block", its fine to just extend.
self.transactions.extend(txs);
self.host_txns.extend(bundle.host_txs);

if let Some(host_fills) = bundle.host_fills {
self.host_fills.push(host_fills);
Expand Down
1 change: 1 addition & 0 deletions crates/sim/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ mod test {
..Default::default()
},
host_fills: None,
host_txs: vec![],
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/sim/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl<Db, Insp> SimEnv<Db, Insp> {
}

/// Get a reference to the database.
pub fn db_mut(&mut self) -> &mut InnerDb<Db> {
pub const fn db_mut(&mut self) -> &mut InnerDb<Db> {
&mut self.db
}

Expand Down Expand Up @@ -219,7 +219,7 @@ impl<Db, Insp> SimEnv<Db, Insp> {
}

/// Set the execution timeout.
pub fn set_finish_by(&mut self, timeout: std::time::Instant) {
pub const fn set_finish_by(&mut self, timeout: std::time::Instant) {
self.finish_by = timeout;
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/test-utils/src/specs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@ pub fn simple_bundle<'a>(
extra_fields: Default::default(),
},
host_fills,
host_txs: vec![],
}
}
2 changes: 1 addition & 1 deletion crates/types/src/agg/fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl AggregateFills {
}

/// Mutably borrow the current fill mapping
pub fn fills_mut(&mut self) -> &mut HashMap<(u64, Address), HashMap<Address, U256>> {
pub const fn fills_mut(&mut self) -> &mut HashMap<(u64, Address), HashMap<Address, U256>> {
&mut self.fills
}

Expand Down
2 changes: 1 addition & 1 deletion crates/zenith/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ where
}

/// Mutable access to the header.
pub fn header_mut(&mut self) -> &mut ZenithHeader {
pub const fn header_mut(&mut self) -> &mut ZenithHeader {
&mut self.header
}

Expand Down
Loading