Mina is a succinct Proof-of-Stake blockchain utilizing zero-knowledge proofs to secure the protocol.
Introduction
In running a Block Producer Node node, I would find myself I found my watching the timer tick down for when my next block was to be produced. However, as multiple block producers could produce blocks for a given slot, I was disappointed when my block was orphaned. Rather than watching a timer, I created a simple bot to alert me upon production of a block.
Telegram Bot Services
The bot relies on the following services to function:
- GraphQL subscription for notifications of new blocks
- GraphQL query to determine canonical and orphaned blocks
- Postgres Database for collection of data
- Telegram script for subscription events
- Telegram script for sending notifications
Flow of Events
A GraphQL subscription waits for the notification of a new block in a Mina daemon. When a new block is received, the best chain is utilized to determine if the block is currently considered canonical or orphaned. The processed data is inserted into a postgres database. An example of the GraphQL subscription follows with the re-labeling of orphaned blocks:
Parsing Block 140323 with Hash 3NK...wqFC Created by B62...DBW6 [canonical]
Parsing Block 140323 with Hash 3NL...bf4bs Created by B62...DBW6 [orphaned]
Parsing Block 140323 with Hash 3NL...FQS86 Created by B62...DBW6 [canonical]
Updating Block 140323 3NK...wqFC from canonical to orphaned
Parsing New Block 140323 with Hash 3NK...pRkx Created by B62...YnaG [canonical]
Updating Block 140323 3NL...FQS86 from canonical to orphaned
As seen above, the block producer B62…DBW6 produced several different blocks and the GraphQL subscription service processed the blocks as they were received.
A telegram script periodically polls the databases for the latest blocks and if the latest block has at least 1 block confirmation or a period of time has passed, a telegram alert for the block production is sent to subscribers of the public key. An example follows:
['Canonical Block 140323 Produced by Figment [720.0 Mina],
'Orphaned Block 140323 Produced by AURO(Supercharged) [1440.0 Mina],
'Orphaned Block 140323 Produced by AURO(Supercharged) [1440.0 Mina],
'Orphaned Block 140323 Produced by AURO(Supercharged) [1440.0 Mina]' ]
As seen above, AURO produced 3 orphaned blocks that would’ve yielded 1440 Mina but Figment’s block was selected as the canonical block.
Utilizing the Telegram Bot
Utilizing the Telegram bot is simply done by subscribing to alerts by messaging @block_producer_bot on telegram with the /help
option:
Subscribing to Block Production Alerts
To subscribe to Block Production Alerts, send a bot a message such as:
Upon the production of a block, the bot will send messages upon block production as follows:
Subscribing to Transaction Alerts
Subscribing to transactions can be done as simple as the subscriptions to transactions. An example follows:
Conclusion
Questions? Comments? Requests?
Feel free to reach out!