Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: writing tx to bootloader memory is no longer quadratic #2479

Merged
merged 3 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{

const EMPTY_TXS_ROLLING_HASH: H256 = H256::zero();

#[derive(Debug, Clone)]
#[derive(Debug)]
pub(crate) struct BootloaderL2Block {
pub(crate) number: u32,
pub(crate) timestamp: u64,
Expand Down Expand Up @@ -56,12 +56,6 @@ impl BootloaderL2Block {
self.txs_rolling_hash = concat_and_hash(self.txs_rolling_hash, tx_hash)
}

pub(crate) fn interim_version(&self) -> BootloaderL2Block {
let mut interim = self.clone();
joonazan marked this conversation as resolved.
Show resolved Hide resolved
interim.max_virtual_blocks_to_create = 0;
interim
}

pub(crate) fn make_snapshot(&self) -> L2BlockSnapshot {
L2BlockSnapshot {
txs_rolling_hash: self.txs_rolling_hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::{
/// Serves two purposes:
/// - Tracks where next tx should be pushed to in the bootloader memory.
/// - Tracks which transaction should be executed next.
#[derive(Debug, Clone)]
#[derive(Debug)]
pub struct BootloaderState {
/// ID of the next transaction to be executed.
/// See the structure doc-comment for a better explanation of purpose.
Expand Down
22 changes: 15 additions & 7 deletions core/lib/multivm/src/versions/vm_latest/bootloader_state/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ pub(super) fn apply_tx_to_memory(
.zip(bootloader_tx.encoded.clone()),
);

let bootloader_l2_block = if start_new_l2_block {
bootloader_l2_block.clone()
} else {
bootloader_l2_block.interim_version()
};
apply_l2_block(memory, &bootloader_l2_block, tx_index);
apply_l2_block_inner(memory, bootloader_l2_block, tx_index, start_new_l2_block);

// Note, +1 is moving for pointer
let compressed_bytecodes_offset = COMPRESSED_BYTECODES_OFFSET + 1 + compressed_bytecodes_size;
Expand All @@ -93,6 +88,15 @@ pub(crate) fn apply_l2_block(
memory: &mut BootloaderMemory,
bootloader_l2_block: &BootloaderL2Block,
txs_index: usize,
) {
apply_l2_block_inner(memory, bootloader_l2_block, txs_index, true)
}

fn apply_l2_block_inner(
memory: &mut BootloaderMemory,
bootloader_l2_block: &BootloaderL2Block,
txs_index: usize,
start_new_l2_block: bool,
) {
// Since L2 block information start from the `TX_OPERATOR_L2_BLOCK_INFO_OFFSET` and each
// L2 block info takes `TX_OPERATOR_SLOTS_PER_L2_BLOCK_INFO` slots, the position where the L2 block info
Expand All @@ -110,7 +114,11 @@ pub(crate) fn apply_l2_block(
),
(
block_position + 3,
bootloader_l2_block.max_virtual_blocks_to_create.into(),
if start_new_l2_block {
joonazan marked this conversation as resolved.
Show resolved Hide resolved
bootloader_l2_block.max_virtual_blocks_to_create.into()
} else {
U256::zero()
},
),
])
}
Expand Down
Loading