|
1 | 1 | use candid::{candid_method, Nat, Principal};
|
2 | 2 | use ic_cdk::trap;
|
3 |
| -use ic_cdk_macros::{init, query, update}; |
| 3 | +use ic_cdk_macros::{init, post_upgrade, query, update}; |
4 | 4 | use ic_cdk_timers::TimerId;
|
5 | 5 | use ic_crypto_sha::Sha256;
|
6 | 6 | 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);
|
39 | 39 | const ACCOUNT_BLOCK_IDS_MEMORY_ID: MemoryId = MemoryId::new(3);
|
40 | 40 | const ACCOUNT_DATA_MEMORY_ID: MemoryId = MemoryId::new(4);
|
41 | 41 |
|
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); |
44 | 44 |
|
45 | 45 | type VM = VirtualMemory<DefaultMemoryImpl>;
|
46 | 46 | type StateCell = StableCell<State, VM>;
|
@@ -236,7 +236,13 @@ fn init(index_arg: Option<IndexArg>) {
|
236 | 236 | });
|
237 | 237 |
|
238 | 238 | // 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)); |
240 | 246 | }
|
241 | 247 |
|
242 | 248 | async fn get_blocks_from_ledger(start: u64) -> Result<GetBlocksResponse, String> {
|
@@ -667,9 +673,8 @@ fn compute_wait_time_test() {
|
667 | 673 | (max_blocks * n as f64 / 100f64) as usize
|
668 | 674 | }
|
669 | 675 |
|
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 |
673 | 678 | }
|
674 | 679 |
|
675 | 680 | assert_eq!(wait_time(100), compute_wait_time(blocks(0)));
|
|
0 commit comments