Skip to content

Commit 4b0ead4

Browse files
authored
feat: add host txns to the signet bundle (#119)
* feat: add host txns to the signet bundle * fix: skip serializing if empty
1 parent 4e9e6f3 commit 4b0ead4

File tree

9 files changed

+62
-8
lines changed

9 files changed

+62
-8
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ resolver = "2"
55
[workspace.package]
66
version = "0.10.1"
77
edition = "2021"
8-
rust-version = "1.81"
8+
rust-version = "1.85"
99
authors = ["init4"]
1010
license = "MIT OR Apache-2.0"
1111
homepage = "https://github.com/init4tech/signet-sdk"

crates/bundle/src/send/bundle.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ pub struct SignetEthBundle {
3939
pub bundle: EthSendBundle,
4040
/// Host fills to be applied with the bundle, represented as a signed
4141
/// permit2 fill.
42-
#[serde(default)]
42+
#[serde(default, skip_serializing_if = "Option::is_none")]
4343
pub host_fills: Option<SignedFill>,
44+
45+
/// Host transactions to be included in the host bundle.
46+
#[serde(default, skip_serializing_if = "Vec::is_empty")]
47+
pub host_txs: Vec<Bytes>,
4448
}
4549

4650
impl SignetEthBundle {
@@ -194,6 +198,7 @@ mod test {
194198
chainId: 100,
195199
}],
196200
}),
201+
host_txs: vec![b"host_tx1".into(), b"host_tx2".into()],
197202
};
198203

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

210+
#[test]
211+
fn send_bundle_ser_roundtrip_no_host_no_fills() {
212+
let bundle = SignetEthBundle {
213+
bundle: EthSendBundle {
214+
txs: vec![b"tx1".into(), b"tx2".into()],
215+
block_number: 1,
216+
min_timestamp: Some(2),
217+
max_timestamp: Some(3),
218+
reverting_tx_hashes: vec![B256::repeat_byte(4), B256::repeat_byte(5)],
219+
replacement_uuid: Some("uuid".to_owned()),
220+
..Default::default()
221+
},
222+
host_fills: None,
223+
host_txs: vec![],
224+
};
225+
226+
let serialized = serde_json::to_string(&bundle).unwrap();
227+
let deserialized: SignetEthBundle = serde_json::from_str(&serialized).unwrap();
228+
229+
assert_eq!(bundle, deserialized);
230+
}
231+
232+
#[test]
233+
fn test_deser_bundle_no_host_no_fills() {
234+
let json = r#"
235+
{"txs":["0x747831","0x747832"],"blockNumber":"0x1","minTimestamp":2,"maxTimestamp":3,"revertingTxHashes":["0x0404040404040404040404040404040404040404040404040404040404040404","0x0505050505050505050505050505050505050505050505050505050505050505"],"replacementUuid":"uuid"}"#;
236+
237+
let deserialized: SignetEthBundle = serde_json::from_str(json).unwrap();
238+
239+
assert!(deserialized.host_fills.is_none());
240+
assert!(deserialized.host_txs.is_empty());
241+
}
242+
205243
#[test]
206244
fn send_bundle_resp_ser_roundtrip() {
207245
let resp = SignetEthBundleResponse { bundle_hash: B256::repeat_byte(1) };

crates/extract/src/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'a, C: Extractable> HostEvents<'a, C> {
4646
}
4747

4848
/// Add a [`Zenith::BlockSubmitted`] event to the host events.
49-
pub fn ingest_block_submitted(
49+
pub const fn ingest_block_submitted(
5050
&mut self,
5151
event: ExtractedEvent<'a, C::Receipt, Zenith::BlockSubmitted>,
5252
) {

crates/sim/src/built.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,20 @@ use tracing::{error, trace};
1717
pub struct BuiltBlock {
1818
/// The host fill actions.
1919
pub(crate) host_fills: Vec<SignedFill>,
20+
21+
/// The host transactions to be included in a resulting bundle.
22+
pub(crate) host_txns: Vec<Bytes>,
23+
2024
/// Transactions in the block.
2125
pub(crate) transactions: Vec<TxEnvelope>,
22-
/// The block number for the block.
26+
27+
/// The block number for the Signet block.
2328
pub(crate) block_number: u64,
2429

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

33+
// -- Memoization fields --
2834
/// Memoized raw encoding of the block.
2935
pub(crate) raw_encoding: OnceLock<Bytes>,
3036
/// Memoized hash of the block.
@@ -47,6 +53,7 @@ impl BuiltBlock {
4753
pub const fn new(block_number: u64) -> Self {
4854
Self {
4955
host_fills: Vec::new(),
56+
host_txns: Vec::new(),
5057
transactions: Vec::new(),
5158
block_number,
5259
gas_used: 0,
@@ -87,6 +94,12 @@ impl BuiltBlock {
8794
&self.host_fills
8895
}
8996

97+
/// Get the current list of host transactions included in this block.
98+
#[allow(clippy::missing_const_for_fn)] // false positive, const deref
99+
pub fn host_txns(&self) -> &[Bytes] {
100+
&self.host_txns
101+
}
102+
90103
/// Unseal the block
91104
pub(crate) fn unseal(&mut self) {
92105
self.raw_encoding.take();
@@ -124,6 +137,7 @@ impl BuiltBlock {
124137
// extend the transactions with the decoded transactions.
125138
// As this builder does not provide bundles landing "top of block", its fine to just extend.
126139
self.transactions.extend(txs);
140+
self.host_txns.extend(bundle.host_txs);
127141

128142
if let Some(host_fills) = bundle.host_fills {
129143
self.host_fills.push(host_fills);

crates/sim/src/cache.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ mod test {
307307
..Default::default()
308308
},
309309
host_fills: None,
310+
host_txs: vec![],
310311
}
311312
}
312313

crates/sim/src/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<Db, Insp> SimEnv<Db, Insp> {
189189
}
190190

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

@@ -219,7 +219,7 @@ impl<Db, Insp> SimEnv<Db, Insp> {
219219
}
220220

221221
/// Set the execution timeout.
222-
pub fn set_finish_by(&mut self, timeout: std::time::Instant) {
222+
pub const fn set_finish_by(&mut self, timeout: std::time::Instant) {
223223
self.finish_by = timeout;
224224
}
225225
}

crates/test-utils/src/specs/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,6 @@ pub fn simple_bundle<'a>(
9494
extra_fields: Default::default(),
9595
},
9696
host_fills,
97+
host_txs: vec![],
9798
}
9899
}

crates/types/src/agg/fill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl AggregateFills {
224224
}
225225

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

crates/zenith/src/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ where
182182
}
183183

184184
/// Mutable access to the header.
185-
pub fn header_mut(&mut self) -> &mut ZenithHeader {
185+
pub const fn header_mut(&mut self) -> &mut ZenithHeader {
186186
&mut self.header
187187
}
188188

0 commit comments

Comments
 (0)