yral-dapp / hot-or-not-backend-canister

Other
8 stars 6 forks source link

Bets stuck in 00:00:00 once timer logic is fixed #387

Closed abhishek-tripathi-yral closed 3 weeks ago

abhishek-tripathi-yral commented 3 weeks ago

komal's very useful input

 gets the whole canister data as JSON 

`curl --location '[https://icp-off-chain-agent.fly.dev/get-snapshot?canister_id=pbssx-saaaa-aaaag-agjua-cai'`](https://icp-off-chain-agent.fly.dev/get-snapshot?canister_id=pbssx-saaaa-aaaag-agjua-cai%27`)

slot_details_map is empty.

abhishek-tripathi-yral commented 3 weeks ago
  1. slot_details_map is not related to calculating outcomes when timer expires.
  2. if a bet has "AwaitingResult" => It has hot_or_not_details != null.
  3. What is the use of slot_details_map?

    1. GET active_room_id when bet is placed

    2. slot_details_map is EMPTY for all canisters. .insert doesn't work.

harshita-srivastava-yral commented 3 weeks ago
abhishek-tripathi-yral commented 3 weeks ago

https://gist.github.com/abeeshake-yral/14fd127c2fb5f891246134f4503f8b1d

komal-sai-yral commented 3 weeks ago

Hypothesis: This is timer spawn code in add_post_v2. creator_consent_for_inclusion_in_hot_or_not is False by default and hence timers are not being launched. canister updates however are launching timers due to which game resolves for few slots of few posts (since hot_or_not_details is Some by then)

    if post_details.creator_consent_for_inclusion_in_hot_or_not {       <------------ likely culprit
        // * schedule hot_or_not outcome tabulation for the 48 hours after the post is created
        (1..=48).for_each(|slot_number: u8| {
            ic_cdk_timers::set_timer(
                Duration::from_secs(slot_number as u64 * 60 * 60),
                move || {
                    CANISTER_DATA.with(|canister_data_ref_cell| {
                        tabulate_hot_or_not_outcome_for_post_slot(
                            &mut canister_data_ref_cell.borrow_mut(),
                            post_id,
                            slot_number,
                        );
                    });
                },
            );
        })
    }
abhishek-tripathi-yral commented 3 weeks ago

Agree partially with the hypothesis given above. This is ONE of the reasons why timers are stuck.

Why I think there could be more reasons => https://github.com/go-bazzinga/hot-or-not-backend-canister/pull/389#discussion_r1741444518

Natasha-GB commented 3 weeks ago
abhishek-tripathi-yral commented 3 weeks ago

updated tests in the PR.

harshita-srivastava-yral commented 3 weeks ago
harshita-srivastava-yral commented 2 weeks ago
harshita-srivastava-yral commented 2 weeks ago
harshita-srivastava-yral commented 2 weeks ago

@abeeshake-yral We were firing all request at once and not 25 request at a time, we are now rectifying the same. This should get the issue resolved.