List Subscribers for a specified stream

+2 votes

How can I retrieve the list of subscribers for a specified stream?

Is there an equivalent API command to "liststreampublishers" for listing the subscriber(s) for a stream, such as "liststreamsubscribers"?

Thanks.

asked Jul 19, 2017 by WRM

1 Answer

+1 vote

When a node subscribes to a stream, that is not an event that takes place on the chain itself, so it's not immediately visible to other nodes. Even if we created some notification mechanism for subscribing, a node could easily violate that mechanism by subscribing secretly.

So if you want to maintain information about who is subscribed to a stream, you should create a new stream for nodes to self-report when they subscribe. Then you can use liststreampublishers on that second stream to retrieve the list of subscribers.

answered Jul 20, 2017 by MultiChain
Thanks for your reply.

However, while I understand your suggestion, to accurately maintain a "subscription" stream of "subscribe" and "unsubscribe" requests would need to be issued (control) via a UI and if a request is done via the cli would it not circumvent the "self-reporting"?
Yes, you'd need some kind of mechanism in place to ensure that, when a node subscribes to a stream, it also reports this fact to the other stream. This is not something taken care of by MultiChain's command line.

Let me explain why. In MultiChain we avoid "fake security", that is implementing functionality which looks like it's trustworthy, but can be easily circumvented by a misbehaving node. This is because the whole point of a blockchain is to create a system which is secure against misbehaving nodes. For this same reason there are no read permissions in streams, because a misbehaving node would be able to read a stream if it wanted to, even if it didn't have the permission. After all, the data is there on its disk.

If you want to create a secure mechanism for knowing which node is reading a stream, you will need to first encrypt the data in the stream. Then, when a node wants to read that data, it sends a request on the chain for everyone to see. Then it can delivered the password off-chain, or on-chain using the confidential stream pattern: https://www.multichain.com/developers/stream-confidentiality/
Thanks for your comprehensive reply.

It's reassuring the explanation to avoid "fake security" and also welcome gaining more insight into MultiChain.

I have further observed that if I create a stream (e.g. customers) on node A and try to interrogate the stream (using liststreampublishers, liststreamkeys etc) from node B which has not subscribe (automatically or explicitly) to this "customers" stream, a RPC error code -703 RPC_NOT_SUBSCRIBED is reported as expected.

Obviously, a list of subscribers (subscribe events) are internally maintained, can this be exposed (readonly) via a RPC API command?
If you use liststreams on a node, it will include a field telling you whether each stream is subscribed to.
Thanks for you reply.

Yes, while the liststreams provide a boolean flag to indicate if the stream is subscribed to, together with the creator node and the transaction (txid), I would like to obtain an array of the list of nodes which are subscribed to the stream.

When a node subscribes to a stream, is there a transaction record available?
As I mentioned, each node does not automatically share whether it is subscribed or not with other nodes.
Thanks for your reply.

Final question on this matter....

For audit purposes, does MultiChain record a timestamp on the node when a "subscribe/unsubscribe" request is actioned?
You can look in this file to see log items relating to subscribes and unsubscribes: ~/.multichain/[chain-name]/wallet/txs.log
Thanks for your rely.
...