Skip to content

Commit

Permalink
Merge pull request #1502 from Phala-Network/faster-e2e
Browse files Browse the repository at this point in the history
phala-node: Configurable gossip duration.
  • Loading branch information
kvinwang authored Jan 2, 2024
2 parents 63fdb12 + e8d52cd commit 923a6c8
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
8 changes: 5 additions & 3 deletions e2e/src/fullstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ const quickMode = process.env.QUICK == '1';
let keyring;

const CENTS = 10_000_000_000;
const blockInterval = quickMode ? 100 : 1000;
const blockInterval = quickMode ? 100 : 300; // ms
const gossipDuration = 20; // ms

console.log(`Testing in ${inSgx ? "SGX Hardware" : "Software"} mode`);

Expand Down Expand Up @@ -1369,8 +1370,6 @@ class Cluster {
await this._reservePorts();
this._createProcesses();
await this._launchAndWait();
await this._createApi();
await this._transferPherryGasFree();
}

async kill() {
Expand Down Expand Up @@ -1498,6 +1497,8 @@ class Cluster {
waitNodeOutput(this.processNode),
...this.workers.map(w => waitPRuntimeOutput(w.processPRuntime)),
]);
await this._createApi();
await this._transferPherryGasFree();
// Launch relayers
await Promise.all(this.workers.map(w => waitRelayerOutput(w.processRelayer)));
}
Expand Down Expand Up @@ -1542,6 +1543,7 @@ function newNode(rpcPort, tmpPath, name = 'node') {
pathNode, [
'--dev',
`--block-millisecs=${blockInterval}`,
`--gossip-duration-millisecs=${gossipDuration}`,
'--base-path=' + path.resolve(tmpPath, 'phala-node'),
`--rpc-port=${rpcPort}`,
'--rpc-methods=Unsafe',
Expand Down
2 changes: 1 addition & 1 deletion standalone/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ pub(crate) mod tests {
sync,
transaction_pool,
..
} = new_full_base(config, false, |_, _| ())?;
} = new_full_base(config, false, |_, _| (), None)?;
Ok(sc_service_test::TestNetComponents::new(
task_manager,
client,
Expand Down
4 changes: 4 additions & 0 deletions standalone/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pub struct Cli {
/// Custom block duration in milliseconds (only useful with --dev)
#[arg(long)]
pub block_millisecs: Option<u64>,

/// Custom gossip duration in milliseconds.
#[arg(long)]
pub gossip_duration_millisecs: Option<u64>,
}

/// Possible subcommands of the main binary.
Expand Down
8 changes: 6 additions & 2 deletions standalone/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ pub fn run() -> sc_cli::Result<()> {
None => {
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|config| async move {
service::new_full(config, cli.no_hardware_benchmarks)
.map_err(sc_cli::Error::Service)
service::new_full(
config,
cli.no_hardware_benchmarks,
cli.gossip_duration_millisecs,
)
.map_err(sc_cli::Error::Service)
})
}
Some(Subcommand::Inspect(cmd)) => {
Expand Down
16 changes: 12 additions & 4 deletions standalone/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ pub fn new_full_base(
&sc_consensus_babe::BabeBlockImport<Block, FullClient, FullGrandpaBlockImport>,
&sc_consensus_babe::BabeLink<Block>,
),
gossip_duration_millis: Option<u64>,
) -> Result<NewFullBase, ServiceError> {
let hwbench = if !disable_hardware_benchmarks {
config.database.path().map(|database_path| {
Expand Down Expand Up @@ -547,7 +548,7 @@ pub fn new_full_base(

let grandpa_config = grandpa::Config {
// FIXME #1578 make this available through chainspec
gossip_duration: std::time::Duration::from_millis(333),
gossip_duration: std::time::Duration::from_millis(gossip_duration_millis.unwrap_or(333)),
justification_generation_period: 1, // https://github.com/paritytech/substrate/pull/14423#issuecomment-1633837906
name: Some(name),
observer_enabled: false,
Expand Down Expand Up @@ -624,9 +625,15 @@ pub fn new_full_base(
pub fn new_full(
config: Configuration,
disable_hardware_benchmarks: bool,
gossip_duration_millis: Option<u64>,
) -> Result<TaskManager, ServiceError> {
new_full_base(config, disable_hardware_benchmarks, |_, _| ())
.map(|NewFullBase { task_manager, .. }| task_manager)
new_full_base(
config,
disable_hardware_benchmarks,
|_, _| (),
gossip_duration_millis,
)
.map(|NewFullBase { task_manager, .. }| task_manager)
}

#[cfg(test)]
Expand Down Expand Up @@ -705,6 +712,7 @@ mod tests {
babe_link: &sc_consensus_babe::BabeLink<Block>| {
setup_handles = Some((block_import.clone(), babe_link.clone()));
},
None,
)?;

let node = sc_service_test::TestNetComponents::new(
Expand Down Expand Up @@ -900,7 +908,7 @@ mod tests {
sync,
transaction_pool,
..
} = new_full_base(config, false, |_, _| ())?;
} = new_full_base(config, false, |_, _| (), None)?;
Ok(sc_service_test::TestNetComponents::new(
task_manager,
client,
Expand Down

0 comments on commit 923a6c8

Please sign in to comment.