message: perf: decrease max memory and increase speed, during chain root mmr migration
diff: @@ -35,10 +35,18 @@ impl Migration for AddChainRootMMR {
  pbi.set_position(0);
  pbi.enable_steady_tick(5000);
  + let mut block_number = 0;
  + let mut mmr_size = 0;
  +
  + loop {
  let db_txn = chain_db.begin_transaction();
  - let mut mmr = ChainRootMMR::new(0, &db_txn);
  + let mut mmr = ChainRootMMR::new(mmr_size, &db_txn);
  +
  + for _ in 0..10000 {
  + if block_number > tip_number {
  + break;
  + }
  - for block_number in 0..=tip_number {
  let block_hash = chain_db.get_block_hash(block_number).ok_or_else(|| {
  let err = format!(
  "tip is {} but hash for block#{} is not found",
  @@ -57,16 +65,18 @@ impl Migration for AddChainRootMMR {
  .map_err(|e| InternalErrorKind::MMR.other(e))?;
  pbi.inc(1);
  - if block_number % 10000 == 0 {
  - let mmr_size = mmr.mmr_size();
  - mmr.commit().map_err(|e| InternalErrorKind::MMR.other(e))?;
  - mmr = ChainRootMMR::new(mmr_size, &db_txn);
  - }
  + block_number += 1;
  }
  + mmr_size = mmr.mmr_size();
  mmr.commit().map_err(|e| InternalErrorKind::MMR.other(e))?;
  db_txn.commit()?;
  + if block_number > tip_number {
  + break;
  + }
  + }
  +
  pbi.finish_with_message("done!");
  Ok(chain_db.into_inner())
  