Skip to content

Commit 794fc5b

Browse files
committed
Merge branch 'fix_upgrade_and_max_delay' into 'master'
fix [icrc index-ng] post_upgrade timer and reduce timers - reduce the sync wait time to 2 seconds for max time and 1 seconds for retries - [fix] start timers in the `post_upgrade` See merge request dfinity-lab/public/ic!12581
2 parents b6f0aca + 7ed406b commit 794fc5b

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

rs/rosetta-api/icrc1/index-ng/src/main.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use candid::{candid_method, Nat, Principal};
22
use ic_cdk::trap;
3-
use ic_cdk_macros::{init, query, update};
3+
use ic_cdk_macros::{init, post_upgrade, query, update};
44
use ic_cdk_timers::TimerId;
55
use ic_crypto_sha::Sha256;
66
use ic_icrc1::blocks::{encoded_block_to_generic_block, generic_block_to_encoded_block};
@@ -39,8 +39,8 @@ const BLOCK_LOG_DATA_MEMORY_ID: MemoryId = MemoryId::new(2);
3939
const ACCOUNT_BLOCK_IDS_MEMORY_ID: MemoryId = MemoryId::new(3);
4040
const ACCOUNT_DATA_MEMORY_ID: MemoryId = MemoryId::new(4);
4141

42-
const DEFAULT_MAX_WAIT_TIME: Duration = Duration::from_secs(60);
43-
const DEFAULT_RETRY_WAIT_TIME: Duration = Duration::from_secs(10);
42+
const DEFAULT_MAX_WAIT_TIME: Duration = Duration::from_secs(2);
43+
const DEFAULT_RETRY_WAIT_TIME: Duration = Duration::from_secs(1);
4444

4545
type VM = VirtualMemory<DefaultMemoryImpl>;
4646
type StateCell = StableCell<State, VM>;
@@ -236,7 +236,13 @@ fn init(index_arg: Option<IndexArg>) {
236236
});
237237

238238
// set the first build_index to be called after init
239-
set_build_index_timer(Duration::from_secs(1));
239+
set_build_index_timer(Duration::from_secs(0));
240+
}
241+
242+
#[post_upgrade]
243+
fn post_upgrade() {
244+
// set the first build_index to be called after init
245+
set_build_index_timer(Duration::from_secs(0));
240246
}
241247

242248
async fn get_blocks_from_ledger(start: u64) -> Result<GetBlocksResponse, String> {
@@ -667,9 +673,8 @@ fn compute_wait_time_test() {
667673
(max_blocks * n as f64 / 100f64) as usize
668674
}
669675

670-
fn wait_time(n: u64) -> Duration {
671-
let max_wait_time = DEFAULT_MAX_WAIT_TIME.as_secs() as f64;
672-
Duration::from_secs((max_wait_time * n as f64 / 100f64) as u64)
676+
fn wait_time(n: u32) -> Duration {
677+
DEFAULT_MAX_WAIT_TIME * n / 100
673678
}
674679

675680
assert_eq!(wait_time(100), compute_wait_time(blocks(0)));

rs/rosetta-api/icrc1/index-ng/tests/tests.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -762,3 +762,24 @@ fn test_list_subaccounts() {
762762
.collect();
763763
assert_eq!(expected_batch_2, batch_2);
764764
}
765+
766+
#[test]
767+
fn test_post_upgrade_start_timer() {
768+
let env = &StateMachine::new();
769+
let ledger_id = install_ledger(
770+
env,
771+
vec![(account(1, 0), 10_000_000)],
772+
default_archive_options(),
773+
);
774+
let index_id = install_index(env, ledger_id);
775+
776+
wait_until_sync_is_completed(env, index_id, ledger_id);
777+
778+
env.upgrade_canister(index_id, index_wasm(), vec![])
779+
.unwrap();
780+
781+
// check that the index syncs the new block (wait_until_sync_is_completed fails
782+
// if the new block is not synced).
783+
transfer(env, ledger_id, account(1, 0), account(2, 0), 2_000_000);
784+
wait_until_sync_is_completed(env, index_id, ledger_id);
785+
}

0 commit comments

Comments
 (0)