# 20200915 Substrate Seminar - Heartbeat Stream
- Share what I have been working on (and learned) in the past month, with tremendous help from [Seun]() and [Joshy]().
- [Manual Seal](https://substrate.dev/rustdocs/v2.0.0-rc6/sc_consensus_manual_seal/index.html) in Substrate. The simplest form of consensus engine, waiting for RPC to seal(create) and finalize a block.
- As dumb as it sounds, it can be converted to a more sound [Instant Seal](). This is what Ganache (in Ethereum space) is doing. It immediately create a block when a transaction come.
- But when using Instant Seal, we encountered three problems
- Not sure if the consensus engine is alive.
- Offchain worker is never kicked off when no txs come
- If txs come in a burst, say 5 txs come within a sec, 5 new blocks are immediately created. So it causes a lot of blocks be created.
- This diagram depicts the status:
![01-previous-state](https://i.imgur.com/cWT1K5N.png)(credit to Joshy again on the image :) )
## Can We Do Better?
This is what we come up with:
- Add a `heartbeat` period. When no txs come, we still want to create a block every once in a while, controlled by `heartbeat` period.
- Add a `cooldown` period. When a new block is created, we want to let it cool down for a certain time before creating another block.
So this is what we set out to do.
- Original Instant Seal
- Instant Seal with heartbeat (30s) and cooldown (10s)
## Code Walkthrough (The Fun/Scary Part)
- Original manual-seal
- How manual-seal is converted to instant-seal
- How instant-seal has the functionality of heartbeat and cooldown added
## Where I Get Stuck and the Epiphany
I am not going to write it down publicly here :smile:
To learn async rust, read these docs:
- [Rust Async book](https://rust-lang.github.io/async-book/)
- [Tokio Tutorial](https://tokio.rs/tokio/tutorial), particularly the last three chapters.
- [Snoyberg blog](https://www.snoyman.com/blog/2019/12/rust-crash-course-08-down-dirty-future). This post and the next one in the series.
- [The Substrate PR](https://github.com/paritytech/substrate/pull/6951), if you are interested in following the discussion.
Last but not least, I am still wrapping my head around async rust :joy: