Open ravi-sawlani-yral opened 4 months ago
Here are the findings for the approach for infinite slots in hot or not game.
// system time is the time when first best placed.
map = BTreeMap<PostId, SystemTime>
queue = Vec<PostId>
both BTreeMap and Vec are from ic_stable_structures
Here is the flow for a bet.
map
.
b) if it does, ignore.
c) if it does not, put post_id in map
and push it at end of queue
. Current algo for betting slot on a post starts the slot after the first bet comes. So, the slot for each post is dynamic. Slot starts right after the first bet comes and slot lasts for 60 minutes. Slots are not linked to post created_at time to ensure the fairness in the game.
b) For a canister, with zero posts in queue
=> When the first bet comes, the timer is started and relevant changes are made to queue
and map
. the timer is stored in a global_timer
variable.
c) For canister with some posts in queue
=> new bet comes => Check if the global_timer
is running (i.e. has Some(TimerId)). If it is running, don't start a new timer. Just add the bet in map
and queue
.
d) when the old timer finishes, it evaluates the map
and queue
to setup another timer.
findings 2024-07-09
preferable choice:
https://github.com/TwistingTwists/test_u8_upgrade
Update: 2024-07-12
Here is a list of sub-tasks for the game. Will check them as we progress.
@abeeshake-yral Please comment on the timeline for UAT and delay expected in go-live
Expected to be finished today in first half!
-Ensure backward compatibility of the end points
UPDATED : https://github.com/go-bazzinga/hot-or-not-backend-canister/issues/341#issuecomment-2251905756
Backwards compatiblity todos:
did
files changed. Approved by Ravi. vec nat8 -> blobhot_or_not_details
= None
- can we play HON game on them? -- ( 0.5 day - 1 day ) First PR is up : https://github.com/go-bazzinga/hot-or-not-backend-canister/pull/352
Second PR is in progress. Will be raised today.
BBC - 3. in progress. expected to be done by tomorrow.
Second PR is up: #354
With second PR , Here is what is finished
While this is being reviewed, I will move on to finishing frontend tasks.
Betting starts when the first user bets on a given post. Betting slot is alloted thena and a timer for 1 hr is started.
We chose the second approach because it is more efficient.
post_2_Z => means post 2 for the user with id Z
When timer expires, post_1_Z is tabulate_hot_or_not_outcome_for_post_slot_v1
and post_1_Z is removed from the queue. Next timer is queued for the next post (post_2_Z) in queue.
Note that this second timer actually needs to run only for 1 minute since this timer is started at 05:00 and the expiry of this timer needs to be at 05:01. Computationally, the function tabulate_hot_or_not_outcome_for_post_slot_v1
after 1 hr for post_2_Z.
ic_stable_structures::btree_map::BTreeMap
because it has pop_first
and insert
methods. The Vec in ic_stable_structures doesn't have pop_first
.pub bet_timer_posts: ic_stable_structures::btreemap::BTreeMap<(SystemTimeInMs, PostId), (), Memory>,
Think of these sequentially.
A1. when first bet on post_1_Z is placed, and bet_timer_posts is empty. We insert into bet_timer_posts a tuple of (SystemTimeInMs, PostId) and start_timer
.
A2. when second bet on post_1_Z is placed, we check if PostId(post_1_Z) exists in bet_timer_posts. if it doesn't, then we insert into bet_timer_posts a tuple of (SystemTimeInMs, PostId). we don't ned to call start_timer
here. Since there must be a global timer running. It was set in A1.
A3. when first bet on post_2_Z is placed, we check if PostId(post_2_Z) exists in bet_timer_posts. It doesn't. So, we insert into bet_timer_posts a tuple of (SystemTimeInMs, PostId). we don't ned to call start_timer
here.
A4. when timer for post_1_Z expires, we tabulate_hot_or_not_outcome_for_post_slot_v1
for post_1_Z and remove it from bet_timer_posts. also, start the next timer (via start_timer
) for the next post (post_2_Z) in the queue bet_timer_posts.
Now, in A2 above, to check if the posts has already been betted upon, in O(1) time, we need a separate BTreeMap<PostId, ()>. we call this map first_bet_placed_at_hashmap
.
now this map needs to be updated always along with bet_timer_posts. at the cost of memory, we are optimising for lookup speed.
originally posted : https://github.com/go-bazzinga/hot-or-not-backend-canister/pull/354#issuecomment-2265673560
Komal reviewed the PR. Suggested a way to merge PR in one step. Testing that right now.
Blocked on call exceeded issue on my laptop. Will try on Adarsh's laptop
Next step for this is:
Error on Adarsh's laptop:
backend