Skip to content

Commit

Permalink
Merge pull request #761 from matter-labs/dvush/seal-withdraw-block-fa…
Browse files Browse the repository at this point in the history
…ster

Dvush/seal withdraw block faster
  • Loading branch information
dvush authored Jun 23, 2020
2 parents da0670e + 32af2ea commit bab346b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
11 changes: 11 additions & 0 deletions core/models/src/config_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ pub struct ConfigurationOptions {
pub idle_provers: u32,
/// Max number of miniblocks (produced every period of `TX_MINIBATCH_CREATE_TIME`) if one block.
pub max_miniblock_iterations: usize,
/// Max number of miniblocks for block with withdraw operations (defaults to `max_minblock_iterations`).
pub max_miniblock_iterations_withdraw_block: usize,
}

impl ConfigurationOptions {
Expand All @@ -138,6 +140,14 @@ impl ConfigurationOptions {
pub fn from_env() -> Self {
let mut available_block_chunk_sizes = block_chunk_sizes().to_vec();
available_block_chunk_sizes.sort();

let max_miniblock_iterations_withdraw_block =
if env::var("WITHDRAW_BLOCK_MINIBLOCKS_ITERATIONS").is_ok() {
parse_env("WITHDRAW_BLOCK_MINIBLOCKS_ITERATIONS")
} else {
parse_env("MINIBLOCKS_ITERATIONS")
};

Self {
rest_api_server_address: parse_env("REST_API_BIND"),
json_rpc_http_server_address: parse_env("HTTP_RPC_API_BIND"),
Expand Down Expand Up @@ -166,6 +176,7 @@ impl ConfigurationOptions {
ticker_url: parse_env("TICKER_URL"),
idle_provers: parse_env("IDLE_PROVERS"),
max_miniblock_iterations: parse_env("MINIBLOCKS_ITERATIONS"),
max_miniblock_iterations_withdraw_block,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions core/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ fn main() {
executed_tx_notify_sender,
config_opts.available_block_chunk_sizes.clone(),
config_opts.max_miniblock_iterations,
config_opts.max_miniblock_iterations_withdraw_block,
);
let state_keeper_task = start_state_keeper(state_keeper, pending_block, &main_runtime);

Expand Down
13 changes: 12 additions & 1 deletion core/server/src/state_keeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub struct PlasmaStateKeeper {

available_block_chunk_sizes: Vec<usize>,
max_miniblock_iterations: usize,
max_miniblock_iterations_withdraw_block: usize,
}

pub struct PlasmaStateInitParams {
Expand Down Expand Up @@ -232,6 +233,7 @@ impl PlasmaStateInitParams {
}

impl PlasmaStateKeeper {
#[allow(clippy::too_many_arguments)]
pub fn new(
initial_state: PlasmaStateInitParams,
fee_account_address: Address,
Expand All @@ -240,6 +242,7 @@ impl PlasmaStateKeeper {
executed_tx_notify_sender: mpsc::Sender<ExecutedOpsNotify>,
available_block_chunk_sizes: Vec<usize>,
max_miniblock_iterations: usize,
max_miniblock_iterations_withdraw_block: usize,
) -> Self {
assert!(!available_block_chunk_sizes.is_empty());

Expand Down Expand Up @@ -271,6 +274,7 @@ impl PlasmaStateKeeper {
executed_tx_notify_sender,
available_block_chunk_sizes,
max_miniblock_iterations,
max_miniblock_iterations_withdraw_block,
};

let root = keeper.state.root_hash();
Expand Down Expand Up @@ -471,7 +475,14 @@ impl PlasmaStateKeeper {

if !self.pending_block.success_operations.is_empty() {
self.pending_block.pending_block_iteration += 1;
if self.pending_block.pending_block_iteration > self.max_miniblock_iterations {

// If pending block contains withdrawals we seal it faster
let max_miniblock_iterations = if self.pending_block.withdrawals_amount > 0 {
self.max_miniblock_iterations_withdraw_block
} else {
self.max_miniblock_iterations
};
if self.pending_block.pending_block_iteration > max_miniblock_iterations {
self.seal_pending_block().await;
self.notify_executed_ops(&mut executed_ops).await;
return;
Expand Down
1 change: 1 addition & 0 deletions core/testkit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ pub fn spawn_state_keeper(
executed_tx_notify_sender,
block_chunks_sizes,
max_miniblock_iterations,
max_miniblock_iterations,
);

let (stop_state_keeper_sender, stop_state_keeper_receiver) = oneshot::channel::<()>();
Expand Down
2 changes: 2 additions & 0 deletions etc/env/dev.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,5 @@ ETH_WATCH_POLL_INTERVAL=300

# Determines block formation time
MINIBLOCKS_ITERATIONS=50
# Determines block formation time if block contains withdrawals
WITHDRAW_BLOCK_MINIBLOCKS_ITERATIONS=20

0 comments on commit bab346b

Please sign in to comment.