Dfx 0.8.4 is promoted

Release notes: Highlights of what’s new in 0.8.4 :: Internet Computer

Highlights:

  • added rust canister type
  • added support for canister heartbeat (rust canisters only, replica only, not in emulator)
  • updated dependencies in the starter project and added some polish
  • added dfx deploy --mode=reinstall <canister>
14 Likes

Woot! I really appreciate this small feature! It was kind of a pain to start up a new test project, and at least for me it was just at that threshold of not doing it often enough to warrant spending time automating it, but kicking myself every time I started a new demo project :slight_smile:

4 Likes

This is amazing. Gonna try as soon as I can!

Thanks!

1 Like

Crossing my fingers for Motoko heartbeat support soon… :pray:

3 Likes

@ericswanson

Well, the heartbeat doesn’t work. Am I doing something wrong again?

#[init]
fn init() {
    log("INIT");
}

#[heartbeat]
fn tick() {
    log("HEARTBEAT!");
}

Replica’s output:

$ dfx start --clean
Starting webserver for /_/
binding to: 127.0.0.1:34953
Nov 20 18:42:50.773 INFO ic-starter. Configuration: ValidatedConfig { replica_path: Some("/home/alexander/.cache/dfinity/versions/0.8.4/replica"), replica_version: "0.8.0", log_level: Warning, cargo_bin: "cargo", cargo_opts: "", state_dir: "/home/alexander/IdeaProjects/ic-cron/example/e2e-test/.dfx/state/replicated_state", http_listen_addr: 127.0.0.1:0, http_port_file: Some("/home/alexander/IdeaProjects/ic-cron/example/e2e-test/.dfx/replica-configuration/replica-1.port"), metrics_addr: None, provisional_whitelist: Some(All), artifact_pool_dir: "/home/alexander/IdeaProjects/ic-cron/example/e2e-test/.dfx/state/replicated_state/node-100/ic_consensus_pool", crypto_root: "/home/alexander/IdeaProjects/ic-cron/example/e2e-test/.dfx/state/replicated_state/node-100/crypto", state_manager_root: "/home/alexander/IdeaProjects/ic-cron/example/e2e-test/.dfx/state/replicated_state/node-100/state", registry_local_store_path: "/home/alexander/IdeaProjects/ic-cron/example/e2e-test/.dfx/state/replicated_state/ic_registry_local_store", unit_delay: None, initial_notary_delay: Some(600ms), detect_consensus_starvation: None, consensus_pool_backend: Some("rocksdb"), state_dir_holder: None }, Application: starter
Nov 20 18:42:50.773 INFO Initialize replica configuration "/home/alexander/IdeaProjects/ic-cron/example/e2e-test/.dfx/state/replicated_state/ic.json5", Application: starter
Nov 20 18:42:56.047 WARN s:aridc-guyup-qekry-6hi6x-wvgcv-6oafq-7makp-vvrnu-ldqol-dzqpd-gae/n:6ycaa-hg6hq-cstkq-6kpne-jx3wb-ral6t-wba5w-uzot6-3keqg-mzqrs-zqe/ic_p2p/download_management PeerManagerImpl::new(): relay_config = None
version: 0.7.0
 Nov 20 21:42:56.079 INFO Log Level: INFO
 Nov 20 21:42:56.079 INFO Starting server. Listening on http://127.0.0.1:8000/

[Canister rrkah-fqaaa-aaaaa-aaaaq-cai] 2021-11-20 18:43:16.492139289: [caller: rwlgt-iiaaa-aaaaa-aaaaa-cai]: INIT

I followed the example here when testing it: GitHub - akhi3030/heartbeat-example: A simple example of how to use the heartbeat functionality in rust canister smart contracts on the Internet Computer

I think this would work:

#[export_name = "canister_heartbeat"]
fn tick() {
    log("HEARTBEAT!");
}
1 Like

BTW do you know how reliable this canister heartbeat is?

Would it be reliable enough to use to periodically (say, every day) mint new tokens in an autonomous token canister? For example, to implement an automatic inflation mechanism for a token. This is a use case that is possible in IC but not possible in Ethereum.

2 Likes

Hey @ericswanson!

Heartbeat works like a charm, thanks a lot!

But, I’ve just figured out ticks fail silently if you call caller() inside a heartbeat callback. This is why it wasn’t working for me for the first time. I understand why it fails, but you should definitely add an error message.

Btw, ic_cdk_macros::heartbeat also works as expected.

Great job!

1 Like

I believe it should work pretty much all the time, if you keep in mind the following things:

  1. Since heartbeat is a transaction, you should limit the amount of work you do per a single tick - to fit in cycles-consumed-per-message limit.
  2. You should expect your cycles balance to drain over time, so don’t forget to top it up.
1 Like
#[export_name = "canister_heartbeat"]
async fn tick() {
    ic_cdk::api::print("HEARTBEAT!");
}

I trid this, and when installing:

sudo dfx deploy --no-wallet caller                                                                                       
Deploying: caller
All canisters have already been created.
Building canisters...
Installing canisters...
Installing code for canister caller, with canister_id rwlgt-iiaaa-aaaaa-aaaaa-cai
The Replica returned an error: code 5, message: "Wasm module of canister rwlgt-iiaaa-aaaaa-aaaaa-cai is not valid: Wasm module has an invalid function signature. Expected return type [] for 'canister_heartbeat', got [I32]."
3 Likes

I am also running into this problem, I would love to be able to do async code within a heartbeat, such as doing a cross-canister call. I hope the ic_cdk::block_on or spawn will still work

1 Like