Skip to content

Add documentation about measuring time #35

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

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/pages/core/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"entrypoints": "Entrypoints",
"architecture": "Architecture",
"standard-library": "Standard Library",
"advanced": "Advanced",
"specification": "Specification"
}
17 changes: 17 additions & 0 deletions src/pages/core/advanced.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
tags: ["core", "advanced"]
---

import { Callout } from "nextra/components";

# Advanced topics

In this part of the documentation, we go over some more "advanced" things you
can do with the functionality CosmWasm core offers.

<Callout>
While the name of this section is "advanced", this doesn't mean that we want
to imply that you only need these functions in advanced contexts. The wording
"advanced" moreso refers to the fact that you should be familiar with
endpoints, the structs that are passed to the endpoints, etc.
</Callout>
3 changes: 3 additions & 0 deletions src/pages/core/advanced/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"measuring-time": "Measuring time"
}
31 changes: 31 additions & 0 deletions src/pages/core/advanced/measuring-time.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
tags: ["core", "advanced"]
---

import { Callout } from "nextra/components";

# Measuring time

Accessing the current time is useful in a lot of different contexts but time is
hard. It is hard to coordinate, hard to keep in sync, and this gets worse in
distributed settings such as blockchains.

In CosmWasm, we solve this by passing you some information about the blockchain
you are running on whenever an entrypoint is invoked.

In each of the entrypoints, you get a parameter of the type `Env` and this
struct contains the field `block`. The struct contained in this field has a
bunch of different information about the current state of the blockchain you are
running on.

> The documentation about the `BlockInfo` struct can be
> [found here](https://docs.rs/cosmwasm-std/latest/cosmwasm_std/struct.BlockInfo.html)

The timestamp contained in this struct can be safely used in your program as the
source of the current time. Well, kinda. It won't be 100% matching the current
time, as it is the timestamp of the block we are currently operating on.

But you can rely on this timestamp to have the following properties:

- Consistent across the chain (every validator on the chain has the same info)
- Monotonic (it will ever only increase or stay the same; never decrease)