fluidex / rollup-state-manager

5 stars 6 forks source link

dynamic tx_num (in a block) depending on workload #224

Open HAOYUatHZ opened 2 years ago

HAOYUatHZ commented 2 years ago

before

for now we use fixed n_tx

pub fn flush_with_nop(&mut self) {
    let mut cnt = 0;
    while self.buffered_txs.len() % self.n_tx != 0 {
        self.nop();
        cnt += 1;
    }
    log::debug!("flush with {} nop", cnt);
}

n_tx is params::NTXS

after

we should replace params::NTXS with params::TX_SLOT_NUM for example,

TX_SLOT_NUM = [2, 16, 64, 512]

use

pub fn parse_env_to_collection<F, I>(name: &str) -> F
where
    I: FromStr,
    I::Err: std::fmt::Debug,
    F: FromIterator<I>,
{
    get_env(name)
        .split(',')
        .map(|p| p.parse::<I>().unwrap())
        .collect()
}

and then sort them

compare one by one (basic idea, should use for loop or iter:

if self.buffered_txs.len() > 512 * 10 {
    n_tx = 512
} else if self.buffered_txs.len() > 64 * 10 {
    n_tx = 64
} else if self.buffered_txs.len() > 16 * 10 {
    n_tx = 16
} ....

then flush_with_nop

also need the same logic to decide n_tx in pop_all_blocks

we should also record whether it's a large or medium or small block I think we can record this info in pop_all_blocks's forge_with_txs? so we add block_type (small, medium, large) in L2BlockDetail

lispc commented 2 years ago

i suggest a list. 'tx_slot_num'. eg [2, 16, 64, 512]

HAOYUatHZ commented 2 years ago

i suggest a list. 'tx_slot_num'. eg [2, 16, 64, 512]

This loos good. But I am not sure whether it's easy to achieve based on current codes.

    pub static ref NTXS: usize = std::env::var("NTXS")
        .expect("NTXS not set in ENV")
        .parse::<usize>()
        .expect("parse NTXS");
HAOYUatHZ commented 2 years ago

maybe we should refactor the current params and use config.

pub fn parse_env_to_collection<F, I>(name: &str) -> F
where
    I: FromStr,
    I::Err: std::fmt::Debug,
    F: FromIterator<I>,
{
    get_env(name)
        .split(',')
        .map(|p| p.parse::<I>().unwrap())
        .collect()
}