Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update Timer.md with caveats #3827

Merged
merged 8 commits into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions doc/md/base/Timer.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
# Timer
Timers for one-off or periodic tasks.

Timers for one-off or periodic tasks. Applicable as part of the default mechanism.

Note: If `moc` is invoked with `-no-timer`, the importing will fail.

Note: The resolution of the timers is in the order of the block rate,
so durations should be chosen well above that. For frequent
canister wake-ups the heatbeat mechanism should be considered.
canister wake-ups the heartbeat mechanism should be considered.

Note: The functionality described below is enabled only when the actor does not override it by declaring an explicit `system func timer`.

Note: Timers are _not_ persisted across upgrades. One possible strategy
to re-establish timers after an upgrade is to walk stable variables
in the `post_upgrade` hook and distill necessary timer information
from there.
Comment on lines +14 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe some will come up with a good example. Maybe we could have made this work using a single well-known update method, but that wasn't in the Rust version either.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct?

is to walk stable variables

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I think it is common usage to walk (i.e. traverse) data structures.


Note: Basing security (e.g. access control) on timers is almost always
Copy link

@roelstorms roelstorms Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the underlying reason that security controls shouldn't use timers? Or is this based on my comment in slack?

I can't come up with a good scenario in which one would want to. Just wondering if this statements mean that timers are not very reliable or that usually if you need timers in a security control you there is a design issue. The thing we wanted to remark from ProdSec is that IF you use timers for security controls, make sure to reinstate them after an upgrade.

Agreed that access control would likely not need timers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is triggered by your slack comment. There are access control methods that use time, e.g. exponential lockout for mistyped passwords etc. These are problematic here, as there is no protection against reentrancy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a blurb. PTAL.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this comment back then. LGTM if you still want to merge it.

the wrong choice. Be sure to inform yourself about state-of-the art
dApp security. If you _must use_ timers for security controls, be sure
to consider reentrancy issues, and the vanishing of timers on upgrades
and reinstalls.

Note: For further usage information for timers on the IC please consult
https://internetcomputer.org/docs/current/developer-docs/backend/periodic-tasks#timers-library-limitations

## Type `Duration`
``` motoko no-repl
Expand Down
Loading