Skip to content

Commit c32636f

Browse files
committed
Move ScheduledBundle into the scheduler crate alongside batch and tx
Relocate ScheduledBundle and BundleBlocks from the aggregate-prover crate to the scheduler crate, so the bundle handle sits next to ScheduledBatch and ScheduledTransaction. The handle is now generic over its artifact type A (opaque, like ScheduledBatch's P::BatchArtifact) rather than the receipt, which keeps the scheduler free of settlement/proof-system structs and avoids a scheduler -> aggregate-prover dependency cycle. SettlementArtifact stays in aggregate-prover; call sites move from ScheduledBundle<Receipt> to ScheduledBundle<SettlementArtifact<Receipt>>. The scheduler gains kaspa-hashes and vprogs-l1-types for the bundle's metadata fields, and the settler crate gains a scheduler dependency. Neutralize the moved bundle docs so the scheduler crate no longer names downstream crates (aggregate prover, settler, proof-receipt store), matching ScheduledBatch's generic voice.
1 parent 0e8f2fa commit c32636f

11 files changed

Lines changed: 50 additions & 47 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/tn10-flow/src/daemon.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ use kaspa_wrpc_client::prelude::KaspaRpcClient;
2121
use vprogs_core_atomics::AsyncQueue;
2222
use vprogs_l1_bridge::L1BridgeConfig;
2323
use vprogs_node_framework::{Node, NodeConfig};
24-
use vprogs_scheduling_scheduler::ExecutionConfig;
24+
use vprogs_scheduling_scheduler::{ExecutionConfig, ScheduledBundle};
2525
use vprogs_storage_manager::StorageConfig;
2626
use vprogs_storage_rocksdb_store::RocksDbStore;
27-
use vprogs_zk_aggregate_prover::{AggregateProverConfig, ScheduledBundle};
27+
use vprogs_zk_aggregate_prover::{AggregateProverConfig, SettlementArtifact};
2828
use vprogs_zk_backend_risc0_api::{Backend, ProofType, Receipt};
2929
use vprogs_zk_batch_prover::{BatchProverConfig, LaneProofRequest, LaneProofSource};
3030
use vprogs_zk_vm::{ProvingPipeline, Vm};
@@ -37,7 +37,7 @@ pub type V = Vm<Backend, Store>;
3737
pub type FlowNode = Node<Store, V>;
3838
/// Queue of bundle handles the aggregate prover publishes to the settlement worker (one per formed
3939
/// bundle).
40-
pub type FlowSettlementQueue = AsyncQueue<ScheduledBundle<Receipt>>;
40+
pub type FlowSettlementQueue = AsyncQueue<ScheduledBundle<SettlementArtifact<Receipt>>>;
4141

4242
/// Everything the bridge needs to follow our lane on the remote node.
4343
pub struct BridgeParams {

scheduling/scheduler/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ arc-swap.workspace = true
88
borsh.workspace = true
99
crossbeam-deque.workspace = true
1010
crossbeam-queue.workspace = true
11+
kaspa-hashes.workspace = true
1112
num_cpus.workspace = true
1213
tap.workspace = true
1314
thiserror.workspace = true
@@ -17,6 +18,7 @@ vprogs-core-hashing.workspace = true
1718
vprogs-core-macros.workspace = true
1819
vprogs-core-smt.workspace = true
1920
vprogs-core-types.workspace = true
21+
vprogs-l1-types.workspace = true
2022
vprogs-scheduling-execution-workers.workspace = true
2123
vprogs-state-batch-metadata.workspace = true
2224
vprogs-state-metadata.workspace = true

scheduling/scheduler/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod resource;
1010
mod resource_access;
1111
mod rollback;
1212
mod scheduled_batch;
13+
mod scheduled_bundle;
1314
mod scheduled_transaction;
1415
mod scheduler;
1516
mod state;
@@ -27,6 +28,7 @@ pub use pruning_worker::PruningWorker;
2728
pub(crate) use resource::Resource;
2829
pub(crate) use resource_access::ResourceAccess;
2930
pub use scheduled_batch::{ScheduledBatch, ScheduledBatchRef};
31+
pub use scheduled_bundle::{BundleBlocks, ScheduledBundle};
3032
pub use scheduled_transaction::ScheduledTransaction;
3133
pub(crate) use scheduled_transaction::ScheduledTransactionRef;
3234
pub use scheduler::Scheduler;

zk/aggregate-prover/src/scheduled_bundle.rs renamed to scheduling/scheduler/src/scheduled_bundle.rs

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ use vprogs_core_atomics::AtomicAsyncLatch;
66
use vprogs_core_macros::smart_pointer;
77
use vprogs_l1_types::SettlementInfo;
88

9-
use crate::SettlementArtifact;
10-
119
/// The L1 block span a bundle proves over.
1210
#[derive(Clone, Copy)]
1311
pub struct BundleBlocks {
@@ -17,26 +15,25 @@ pub struct BundleBlocks {
1715
pub block_prove_to: Hash,
1816
}
1917

20-
/// A bundle the aggregate prover has formed and published to the settlement queue.
18+
/// A formed bundle of proved batches, published to a settlement consumer before its artifact
19+
/// exists.
2120
///
22-
/// Mirrors [`ScheduledBatch`](vprogs_scheduling_scheduler::ScheduledBatch)'s artifact mechanism:
23-
/// the handle is pushed onto the settlement queue *before* its proof exists, so a consumer can pop
24-
/// it, read the immediate metadata (e.g. reconcile pacing against `batches`), and then await the
25-
/// proved [`SettlementArtifact`]. The aggregate worker fills the artifact via
21+
/// Mirrors [`ScheduledBatch`](crate::ScheduledBatch)'s artifact mechanism: the handle is published
22+
/// *before* its artifact exists, so a consumer can pop it, read the immediate metadata (e.g.
23+
/// reconcile pacing against `batches`), and then await the proved artifact `A`, filled via
2624
/// [`publish_artifact`](Self::publish_artifact) once proving completes.
2725
///
2826
/// A no-op bundle (all-empty prefix, or one that advanced no state) carries no artifact: it is
2927
/// constructed already resolved (latch open, artifact `None`) and the consumer skips it. Every
3028
/// formed bundle still produces exactly one handle, so a consumer that paces itself against proving
3129
/// can account for all submitted batches by summing each handle's `batches`.
3230
#[smart_pointer]
33-
pub struct ScheduledBundle<R> {
31+
pub struct ScheduledBundle<A> {
3432
/// Number of scheduled batches this bundle consumed (including empty batches in the ready
3533
/// prefix). Readable immediately, before the artifact is published.
3634
batches: usize,
37-
/// The bundle's first checkpoint index (bundle-start). With `from_block` it is the
38-
/// bundle-start coordinate that keys the aggregator receipt's prefix in the proof-receipt
39-
/// store. Immediate.
35+
/// The bundle's first checkpoint index (bundle-start). With `from_block`, the coordinate that
36+
/// keys the bundle's aggregate receipt. Immediate.
4037
checkpoint_index: u64,
4138
/// L1 block at the bundle's first checkpoint (the block it proves *from*), pairing with
4239
/// `block_prove_to`. Together with `checkpoint_index` it keys the aggregator receipt and keeps
@@ -45,19 +42,18 @@ pub struct ScheduledBundle<R> {
4542
/// L1 block the bundle proves through (its final block). Immediate, for logging / pacing.
4643
block_prove_to: Hash,
4744
/// Most-recent covenant settlement visible on chain as of the bundle's final block, or `None`
48-
/// until one lands. Lets the settler skip a bundle an external settlement already covered: the
49-
/// same redundancy the aggregate prover applies when forming bundles. Immediate.
45+
/// until one lands. Immediate.
5046
latest_settlement: Option<SettlementInfo>,
51-
/// The proved settlement, filled via [`publish_artifact`](Self::publish_artifact). `None` for
52-
/// a no-op bundle that advanced no state.
53-
settlement: ArcSwapOption<SettlementArtifact<R>>,
47+
/// The proved artifact, filled via [`publish_artifact`](Self::publish_artifact). `None` for a
48+
/// no-op bundle that advanced no state.
49+
artifact: ArcSwapOption<A>,
5450
/// Opens when the artifact has been published (or resolved as a no-op).
5551
artifact_published: AtomicAsyncLatch,
5652
}
5753

58-
impl<R> ScheduledBundle<R> {
59-
/// Creates an unresolved bundle handle: its metadata is readable immediately, the settlement
60-
/// artifact is filled later via [`publish_artifact`](Self::publish_artifact).
54+
impl<A> ScheduledBundle<A> {
55+
/// Creates an unresolved bundle handle: its metadata is readable immediately, the artifact is
56+
/// filled later via [`publish_artifact`](Self::publish_artifact).
6157
pub fn new(
6258
batches: usize,
6359
checkpoint_index: u64,
@@ -71,13 +67,13 @@ impl<R> ScheduledBundle<R> {
7167
from_block,
7268
block_prove_to,
7369
latest_settlement,
74-
settlement: ArcSwapOption::empty(),
70+
artifact: ArcSwapOption::empty(),
7571
artifact_published: AtomicAsyncLatch::new(),
7672
}))
7773
}
7874

7975
/// Creates an immediately-resolved no-op bundle: it advanced no state, so it carries no
80-
/// settlement and its artifact latch is already open.
76+
/// artifact and its artifact latch is already open.
8177
pub fn resolved_noop(
8278
batches: usize,
8379
checkpoint_index: u64,
@@ -93,7 +89,7 @@ impl<R> ScheduledBundle<R> {
9389
from_block,
9490
block_prove_to,
9591
latest_settlement,
96-
settlement: ArcSwapOption::empty(),
92+
artifact: ArcSwapOption::empty(),
9793
artifact_published,
9894
}))
9995
}
@@ -124,22 +120,22 @@ impl<R> ScheduledBundle<R> {
124120
self.latest_settlement
125121
}
126122

127-
/// Publishes the bundle's settlement artifact and opens the `artifact_published` latch. A
128-
/// `None` artifact resolves the handle as a no-op (the consumer skips it).
129-
pub fn publish_artifact(&self, artifact: Option<SettlementArtifact<R>>) {
123+
/// Publishes the bundle's artifact and opens the `artifact_published` latch. A `None` artifact
124+
/// resolves the handle as a no-op (the consumer skips it).
125+
pub fn publish_artifact(&self, artifact: Option<A>) {
130126
if let Some(artifact) = artifact {
131-
self.settlement.store(Some(Arc::new(artifact)));
127+
self.artifact.store(Some(Arc::new(artifact)));
132128
}
133129
self.artifact_published.open();
134130
}
135131

136-
/// Returns the published settlement artifact, or `None` if the bundle resolved as a no-op.
132+
/// Returns the published artifact, or `None` if the bundle resolved as a no-op.
137133
///
138134
/// Must be called after [`wait_artifact_published`](Self::wait_artifact_published): the handle
139135
/// is visible to consumers before its artifact exists, so an early call returns `None` for an
140136
/// unresolved bundle rather than panicking.
141-
pub fn artifact(&self) -> Option<Arc<SettlementArtifact<R>>> {
142-
self.settlement.load_full()
137+
pub fn artifact(&self) -> Option<Arc<A>> {
138+
self.artifact.load_full()
143139
}
144140

145141
/// Waits until the bundle's artifact has been published (or resolved as a no-op).

sim/src/driver/l2_driver.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use vprogs_core_test_utils::ResourceIdExt;
2020
use vprogs_core_types::{AccessMetadata, ResourceId, SchedulerTransaction};
2121
use vprogs_l1_types::ChainBlockMetadata;
2222
use vprogs_l1_wallet::{build, encode_activity_payload};
23-
use vprogs_scheduling_scheduler::{Processor, Scheduler};
23+
use vprogs_scheduling_scheduler::{Processor, ScheduledBundle, Scheduler};
2424
use vprogs_storage_rocksdb_store::RocksDbStore;
25-
use vprogs_zk_aggregate_prover::{AggregateProverConfig, ScheduledBundle, SettlementArtifact};
25+
use vprogs_zk_aggregate_prover::{AggregateProverConfig, SettlementArtifact};
2626
use vprogs_zk_backend_risc0_api::{Backend, ProofType, Receipt};
2727
use vprogs_zk_backend_risc0_covenant::{
2828
Settlement, SettlementDevInput, build_dev_redeem_script, dev_redeem_script_len,
@@ -163,7 +163,7 @@ pub struct L2Driver {
163163
/// Queue the in-process aggregate prover publishes each bundle handle onto (real_e2e only).
164164
/// The driver pops from it to settle proved bundles. `None` in the other modes and before
165165
/// the proving stack is built.
166-
settlement_queue: Option<AsyncQueue<ScheduledBundle<Receipt>>>,
166+
settlement_queue: Option<AsyncQueue<ScheduledBundle<SettlementArtifact<Receipt>>>>,
167167
/// Batches submitted to the aggregate prover but not yet accounted by a bundle outcome
168168
/// (real_e2e only). Gates the settlement back-pressure and is reconciled by each outcome's
169169
/// `batches`.
@@ -198,7 +198,7 @@ fn build_exec(
198198
proving: bool,
199199
covenant_id: Option<Hash>,
200200
consensus: Weak<Consensus>,
201-
) -> (Exec, Option<AsyncQueue<ScheduledBundle<Receipt>>>) {
201+
) -> (Exec, Option<AsyncQueue<ScheduledBundle<SettlementArtifact<Receipt>>>>) {
202202
let db = tempfile::tempdir().expect("temp db dir");
203203
let store = RocksDbStore::open(db.path().join("l2"));
204204
let (pipeline, settlement_queue) = if proving {

zk/aggregate-prover/src/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use kaspa_hashes::Hash;
22
use vprogs_core_atomics::AsyncQueue;
3+
use vprogs_scheduling_scheduler::ScheduledBundle;
34
use vprogs_zk_batch_prover::LaneProofSource;
45

5-
use crate::ScheduledBundle;
6+
use crate::SettlementArtifact;
67

78
/// Static configuration for the aggregate prover.
89
///
@@ -22,5 +23,5 @@ pub struct AggregateProverConfig<L: LaneProofSource, R: Send + Sync + 'static> {
2223
/// before its proof exists; the consumer awaits the artifact), for a settlement worker to act
2324
/// on. `None` runs the prover without settling (e.g. exec/test paths); proved bundles are
2425
/// then only logged.
25-
pub settlement_queue: Option<AsyncQueue<ScheduledBundle<R>>>,
26+
pub settlement_queue: Option<AsyncQueue<ScheduledBundle<SettlementArtifact<R>>>>,
2627
}

zk/aggregate-prover/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ mod backend;
22
mod command;
33
mod config;
44
mod prover;
5-
mod scheduled_bundle;
65
mod settlement_artifact;
76
mod worker;
87

98
pub use backend::Backend;
109
pub use config::AggregateProverConfig;
1110
pub use prover::AggregateProver;
12-
pub use scheduled_bundle::{BundleBlocks, ScheduledBundle};
1311
pub use settlement_artifact::SettlementArtifact;

zk/aggregate-prover/src/worker.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ use vprogs_core_atomics::AsyncQueue;
99
use vprogs_core_codec::Reader;
1010
use vprogs_core_smt::EMPTY_HASH;
1111
use vprogs_l1_types::{ChainBlockMetadata, SettlementInfo};
12-
use vprogs_scheduling_scheduler::{Processor, ScheduledBatch};
12+
use vprogs_scheduling_scheduler::{BundleBlocks, Processor, ScheduledBatch, ScheduledBundle};
1313
use vprogs_storage_types::Store;
1414
use vprogs_zk_abi::batch_aggregator::{Inputs as AggregatorInputs, StateTransition};
1515
use vprogs_zk_batch_prover::{LaneProofRequest, LaneProofSource};
1616

1717
use crate::{
18-
AggregateProver, AggregateProverConfig, Backend, BundleBlocks, ScheduledBundle,
19-
SettlementArtifact, command::Command,
18+
AggregateProver, AggregateProverConfig, Backend, SettlementArtifact, command::Command,
2019
};
2120

2221
/// Background worker that accumulates scheduled batches, forms bundles from the consecutively-ready
@@ -34,7 +33,7 @@ pub(crate) struct Worker<S: Store, P: Processor<S>, B: Backend, L: LaneProofSour
3433
lane_source: L,
3534
/// Queue each formed bundle's [`ScheduledBundle`] handle is published onto for on-chain
3635
/// settlement, or `None` to run without settling.
37-
settlement_queue: Option<AsyncQueue<ScheduledBundle<B::Receipt>>>,
36+
settlement_queue: Option<AsyncQueue<ScheduledBundle<SettlementArtifact<B::Receipt>>>>,
3837
/// Batches accumulated but not yet bundled, in scheduling order.
3938
queued: VecDeque<ScheduledBatch<S, P>>,
4039
/// Last settled L1 block (the lower bound a new bundle chains from). `None` at genesis.
@@ -277,7 +276,7 @@ where
277276

278277
/// Publishes a formed bundle's handle onto the settlement queue, if one is wired. With no queue
279278
/// the prover runs without settling and the handle is dropped.
280-
fn emit(&self, bundle: ScheduledBundle<B::Receipt>) {
279+
fn emit(&self, bundle: ScheduledBundle<SettlementArtifact<B::Receipt>>) {
281280
if let Some(queue) = &self.settlement_queue {
282281
queue.push(bundle);
283282
}

zk/backend/risc0/settler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ tokio = { workspace = true, features = ["ma
1616
vprogs-core-atomics.workspace = true
1717
vprogs-core-smt.workspace = true
1818
vprogs-l1-wallet.workspace = true
19+
vprogs-scheduling-scheduler.workspace = true
1920
vprogs-zk-aggregate-prover.workspace = true
2021
vprogs-zk-backend-risc0-api = { workspace = true, features = ["host"] }
2122
vprogs-zk-backend-risc0-covenant.workspace = true

0 commit comments

Comments
 (0)