ergoplatform / ergo

Ergo protocol description & reference client implementation
https://ergoplatform.org/
Creative Commons Zero v1.0 Universal
499 stars 169 forks source link

Add node events notifications #1986

Open arobsn opened 1 year ago

arobsn commented 1 year ago

Having realtime notifications can improve the overall developer/mining experience and avoid unnecessary endpoing pooling.

Bitcoin uses ZeroMQ to broadcast node events to listeners.

ZeroMQ is a high-performance asynchronous messaging library, aimed at use in distributed or concurrent applications. It provides a message queue, but unlike message-oriented middleware, a ZeroMQ system can run without a dedicated message broker.

I propose we start discussing Ergo's implementation from the following structure:

  1. block:
    • added - On new block.
    • removed - On block rollback.
    • candidate - On new candidate.
  2. transaction:
    • added - When a transaction is accepted by the mempool and/or included in a block.
    • removed - When a transaction is removed from the mempool.

References

ross-weir commented 1 year ago

Would be a very good addition for sure.

IMO would be worth considering websockets when selecting a solution so browser based dapps/wallet extensions/etc are supported (ZeroMQ seems to support WS as a transport).

Maybe even graphql pub/sub which could lead to a gql alternative to the rest api

satsen commented 1 year ago

Writing this comment here for those who weren't in the chat a few weeks ago. I opined that adding things like this to the node could lead to it becoming bloated over time and that it would be one more thing for node operators and developers to think about. As part of a past ErgoHack, I made a library for connecting to nodes (through TCP), which is available for every node that has the port forwarded/accessible/reachable and does not need any modifications to the code whatsoever.

The library is here: https://github.com/Satergo/Ergonnection, and it can be used directly without needing ZeroMQ or anything (and it will be as fast as it gets in terms of latency), but if you for some reason need ZeroMQ, you can use the tool that Luivatra built using the library: https://github.com/cruxfinance/ergo-node-zmqpub