Skip to content

Commit

Permalink
Add option to start node in prover mode (#269)
Browse files Browse the repository at this point in the history
* Add option to start node in prover mode

* Lint

* Lint
  • Loading branch information
ercecan authored Mar 20, 2024
1 parent 80a3a68 commit a12d5d8
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
11 changes: 11 additions & 0 deletions examples/demo-rollup/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ struct Args {
/// The path to the sequencer config. If set, runs the node in sequencer mode, otherwise in full node mode.
#[arg(long)]
sequencer_config_path: Option<String>,

/// If set, runs the node in prover mode, else in full node mode.
/// Can't be set if sequencer_config_path is set.
#[arg(long, conflicts_with = "sequencer_config_path")]
prover: bool,
}

#[derive(clap::ValueEnum, Clone, Debug)]
Expand All @@ -65,6 +70,7 @@ async fn main() -> Result<(), anyhow::Error> {
.unwrap()
});

let is_prover = args.prover;
match args.da_layer {
SupportedDaLayer::Mock => {
let kernel_genesis_paths = &BasicKernelGenesisPaths {
Expand All @@ -84,6 +90,7 @@ async fn main() -> Result<(), anyhow::Error> {
rollup_config_path,
RollupProverConfig::Execute,
sequencer_config,
is_prover,
)
.await?;
}
Expand All @@ -105,6 +112,7 @@ async fn main() -> Result<(), anyhow::Error> {
rollup_config_path,
RollupProverConfig::Execute,
sequencer_config,
is_prover,
)
.await?;
}
Expand All @@ -126,6 +134,7 @@ async fn main() -> Result<(), anyhow::Error> {
rollup_config_path,
RollupProverConfig::Execute,
sequencer_config,
is_prover,
)
.await?;
}
Expand All @@ -150,6 +159,7 @@ async fn start_rollup<S, DaC>(
// <S as RollupBlueprint>::DaSpec,
// >>::GenesisPaths,
sequencer_config: Option<SequencerConfig>,
is_prover: bool,
) -> Result<(), anyhow::Error>
where
DaC: serde::de::DeserializeOwned + DebugTrait + Clone,
Expand Down Expand Up @@ -184,6 +194,7 @@ where
kernel_genesis,
rollup_config,
prover_config,
is_prover,
)
.await
.unwrap();
Expand Down
27 changes: 24 additions & 3 deletions examples/demo-rollup/tests/test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use tracing::warn;
pub enum NodeMode {
FullNode(SocketAddr),
SequencerNode,
#[allow(dead_code)]
Prover(SocketAddr),
}

pub async fn start_rollup(
Expand Down Expand Up @@ -64,9 +66,11 @@ pub async fn start_rollup(
aggregated_proof_block_jump: 1,
},
sequencer_client: match node_mode {
NodeMode::FullNode(socket_addr) => Some(SequencerClientRpcConfig {
url: format!("http://localhost:{}", socket_addr.port()),
}),
NodeMode::FullNode(socket_addr) | NodeMode::Prover(socket_addr) => {
Some(SequencerClientRpcConfig {
url: format!("http://localhost:{}", socket_addr.port()),
})
}
NodeMode::SequencerNode => None,
},
};
Expand All @@ -93,6 +97,23 @@ pub async fn start_rollup(
kernel_genesis,
rollup_config.clone(),
rollup_prover_config,
false,
)
.await
.unwrap();
rollup
.run_and_report_rpc_port(Some(rpc_reporting_channel))
.await
.unwrap();
}
NodeMode::Prover(_) => {
let rollup = mock_demo_rollup
.create_new_rollup(
&rt_genesis_paths,
kernel_genesis,
rollup_config.clone(),
rollup_prover_config,
true,
)
.await
.unwrap();
Expand Down
4 changes: 2 additions & 2 deletions full-node/sov-stf-runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ where
state_root: StateRoot<Stf, Vm, Da::Spec>,
listen_address: SocketAddr,
#[allow(dead_code)]
prover_service: Ps,
prover_service: Option<Ps>,
sequencer_client: Option<SequencerClient>,
sequencer_pub_key: Vec<u8>,
phantom: std::marker::PhantomData<C>,
Expand Down Expand Up @@ -119,7 +119,7 @@ where
stf: Stf,
mut storage_manager: Sm,
init_variant: InitVariant<Stf, Vm, Da::Spec>,
prover_service: Ps,
prover_service: Option<Ps>,
sequencer_client: Option<SequencerClient>,
sequencer_pub_key: Vec<u8>,
) -> Result<Self, anyhow::Error> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn initialize_runner(
stf,
storage_manager,
init_variant,
prover_service,
Some(prover_service),
None,
vec![0u8; 32],
)
Expand Down
2 changes: 1 addition & 1 deletion full-node/sov-stf-runner/tests/runner_reorg_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async fn runner_execution(
stf,
storage_manager,
init_variant,
prover_service,
Some(prover_service),
None,
vec![0u8; 32],
)
Expand Down
12 changes: 9 additions & 3 deletions module-system/sov-modules-rollup-blueprint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ pub trait RollupBlueprint: Sized + Send + Sync {
kernel_genesis_config: <Self::NativeKernel as Kernel<Self::NativeContext, Self::DaSpec>>::GenesisConfig,
rollup_config: RollupConfig<Self::DaConfig>,
prover_config: RollupProverConfig,
is_prover: bool,
) -> Result<Rollup<Self>, anyhow::Error>
where
<Self::NativeContext as Spec>::Storage: NativeStorage,
Expand All @@ -231,9 +232,14 @@ pub trait RollupBlueprint: Sized + Send + Sync {
// Maybe whole "prev_root" can be initialized inside runner
// Getting block here, so prover_service doesn't have to be `Send`
let last_finalized_block_header = da_service.get_last_finalized_block_header().await?;
let prover_service = self
.create_prover_service(prover_config, &rollup_config, &da_service)
.await;

let prover_service = match is_prover {
true => Some(
self.create_prover_service(prover_config, &rollup_config, &da_service)
.await,
),
false => None,
};

let ledger_db = self.create_ledger_db(&rollup_config);
let genesis_config = self.create_genesis_config(
Expand Down

0 comments on commit a12d5d8

Please sign in to comment.