diff --git a/Cargo.toml b/Cargo.toml index 129a22dc..e5e1a23c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/crates/bundle/src/send/bundle.rs b/crates/bundle/src/send/bundle.rs index ee5baf08..bb031dbb 100644 --- a/crates/bundle/src/send/bundle.rs +++ b/crates/bundle/src/send/bundle.rs @@ -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, + + /// Host transactions to be included in the host bundle. + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub host_txs: Vec, } impl SignetEthBundle { @@ -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(); @@ -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) }; diff --git a/crates/extract/src/block.rs b/crates/extract/src/block.rs index a0d7d0fa..a17616ca 100644 --- a/crates/extract/src/block.rs +++ b/crates/extract/src/block.rs @@ -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>, ) { diff --git a/crates/sim/src/built.rs b/crates/sim/src/built.rs index 890e4c1a..a957a78f 100644 --- a/crates/sim/src/built.rs +++ b/crates/sim/src/built.rs @@ -17,14 +17,20 @@ use tracing::{error, trace}; pub struct BuiltBlock { /// The host fill actions. pub(crate) host_fills: Vec, + + /// The host transactions to be included in a resulting bundle. + pub(crate) host_txns: Vec, + /// Transactions in the block. pub(crate) transactions: Vec, - /// 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, /// Memoized hash of the block. @@ -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, @@ -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(); @@ -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); diff --git a/crates/sim/src/cache.rs b/crates/sim/src/cache.rs index 2d0a1aad..d728e4ed 100644 --- a/crates/sim/src/cache.rs +++ b/crates/sim/src/cache.rs @@ -307,6 +307,7 @@ mod test { ..Default::default() }, host_fills: None, + host_txs: vec![], } } diff --git a/crates/sim/src/env.rs b/crates/sim/src/env.rs index 167d0922..fc62116e 100644 --- a/crates/sim/src/env.rs +++ b/crates/sim/src/env.rs @@ -189,7 +189,7 @@ impl SimEnv { } /// Get a reference to the database. - pub fn db_mut(&mut self) -> &mut InnerDb { + pub const fn db_mut(&mut self) -> &mut InnerDb { &mut self.db } @@ -219,7 +219,7 @@ impl SimEnv { } /// 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; } } diff --git a/crates/test-utils/src/specs/mod.rs b/crates/test-utils/src/specs/mod.rs index 918243aa..dd5aafda 100644 --- a/crates/test-utils/src/specs/mod.rs +++ b/crates/test-utils/src/specs/mod.rs @@ -94,5 +94,6 @@ pub fn simple_bundle<'a>( extra_fields: Default::default(), }, host_fills, + host_txs: vec![], } } diff --git a/crates/types/src/agg/fill.rs b/crates/types/src/agg/fill.rs index 5233a828..a604656f 100644 --- a/crates/types/src/agg/fill.rs +++ b/crates/types/src/agg/fill.rs @@ -224,7 +224,7 @@ impl AggregateFills { } /// Mutably borrow the current fill mapping - pub fn fills_mut(&mut self) -> &mut HashMap<(u64, Address), HashMap> { + pub const fn fills_mut(&mut self) -> &mut HashMap<(u64, Address), HashMap> { &mut self.fills } diff --git a/crates/zenith/src/block.rs b/crates/zenith/src/block.rs index 8ad4f0dc..30f31fae 100644 --- a/crates/zenith/src/block.rs +++ b/crates/zenith/src/block.rs @@ -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 }