I was looking into the code of im-online pallet and found the following function here, if false is returned, a heartbeat is sent else AlreadyOnline Error is returned;

fn is_online_aux(authority_index: AuthIndex, authority: &ValidatorId<T>) -> bool {
        let current_session = T::ValidatorSet::session_index();

        ReceivedHeartbeats::<T>::contains_key(&current_session, &authority_index) ||
            AuthoredBlocks::<T>::get(&current_session, authority) != 0

Every time in a session, this function returns true because of number of blocks authored is non-zero which prevents a heartbeat being sent. I speculate the heartbeats are never sent out from a node. Kindly someone help me better understand what exactly is happening here.

2 Answers 2


You don't need to send a heartbeat, if the node has produced a block. Producing a block is essentially the same and even better to "proof" that you were online in a session. So, im-online isn't sending a heartbeat in this case.


Here is some extended explanations base on bkchr's answer.

The most common case is:

Your node is ready, and it's trying to produce blocks. But due to the consensus algorithm, BABE or whatever chose the block producer randomly. And you are very unlucky today. You didn't produce any blocks in the previous session.

Should the consensus system punish you? You are offline and not responsible for the network. Or it's just because you are so unlucky today.

And the consensus system doesn't want to punish the honest/unlucky guy. So, your node needs to send a heartbeat to say, "I'm always online, but I didn't get any chances.".

  • to me, its name shouldn't have been a heartbeat. Here, the node's heart is beating sometimes only and not always, how come the name makes any sense!!. And why do a node need to check if it has authored any block to know if its online because if it's running its code inherently means its online and not down!!. Mar 30, 2023 at 9:35
  • I believe that sending a heartbeat is the easiest way to prove it is online. Without any extra afford to the consensus system. Otherwise, to verify you are running some code, what proof should you send?
    – AurevoirXavier
    Mar 30, 2023 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.