casper-network / casper-node

Reference client for CASPER protocol
https://casper.network
Apache License 2.0
393 stars 223 forks source link

Extend SSE for common events (delegation, undelegation, redelegation, bid changes...) #4136

Open GuybrushX opened 1 year ago

GuybrushX commented 1 year ago

According to my knowledge and experience there are at least 3 ways on how to delegate:

  1. Call the "delegate" entrypoint of the Auction system contract. Example:
  2. Deploy your own version of the Auction Smart Contract and call it's delegate entrypoint (I think?). Example:
  3. Deploy a custom smart contract calling the Auction System Contract as seen here:

In case no. 3 you even have to parse the transforms which seem to be not well documented publicly.

On top of that there are at least 3 ways I'm aware of to specify the target so you have 3 different data types:

  1. PublicKey
  2. Account Hash
  3. URef (Main Purse?)

Right now it's super tedious to detect all of those actions/deploys and to make sense out of them. Even https://cspr.live doesn't detect case no. 3 properly but shows "WASM Deploy" only. And I'm talking about "delegate" only so far - but there are much more like "undelegate", "redelegate", "withdraw_bid" and so on.

Therefore I think the SSE endpoint should be extended to handle all that parsing internally (which is done already anyway) and provide events like "Delegate", "Undelegate", the new "Redelegate", "WithdrawBid" and so on for all possible cases which are straightforward and ready to consume without the possibility of missing something. That would greatly enhance the developer experience and all development of tools which need to track such events.

Examples for such event consumers:

Are there any reasons why this doesn't exist yet?

darthsiroftardis commented 1 year ago

Hey @GuybrushX , thank you reaching out and posting the issue.

First, let me discuss the interactions related to the auction to make sure we are on the same page. To invoke the staking related entrypoints, i.e "delegate", "undelegate", "redelegate" and "add_bid", you only need to invoke the entrypoint and provide the necessary runtime arguments.

To invoke the entrypoints, you can use method 1 as you mentioned in the issue, i.e a direction invocation of the "delegate" entrypoint. You can also send some compiled Wasm (what is also called session-code) to invoke the relevant entrypoint as well. What you CANNOT do however, is implement your own auction contract to participate in the staking of token for a given Casper network. There is only one auction contract that interacts with the staking pool and rewards and that is the native implementation of the auction contract which is baked into the binary of a Casper node.

Secondly, when it comes to the specifying the "target" in relation to auction interactions, you can only specify the PublicKey of the delegator and/or validator.

Now, on the whole, I am guessing what you are trying to do here is consume the SSE events and detect the invocation of entrypoints on the auction that you find relevant is that correct?

GuybrushX commented 1 year ago

Hey @GuybrushX , thank you reaching out and posting the issue.

First, let me discuss the interactions related to the auction to make sure we are on the same page. To invoke the staking related entrypoints, i.e "delegate", "undelegate", "redelegate" and "add_bid", you only need to invoke the entrypoint and provide the necessary runtime arguments.

To invoke the entrypoints, you can use method 1 as you mentioned in the issue, i.e a direction invocation of the "delegate" entrypoint. You can also send some compiled Wasm (what is also called session-code) to invoke the relevant entrypoint as well. What you CANNOT do however, is implement your own auction contract to participate in the staking of token for a given Casper network. There is only one auction contract that interacts with the staking pool and rewards and that is the native implementation of the auction contract which is baked into the binary of a Casper node.

Hi @darthsiroftardis and thanks for your fast reply.

Some interesting information in here. Maybe I got a few things not 100% right which basically just confirms my issue: "complicated chaos" ;-)

Secondly, when it comes to the specifying the "target" in relation to auction interactions, you can only specify the PublicKey of the delegator and/or validator.

Yeah, in regards to the target I mixed that with transfers -> transfers can have the 3 mentioned types as far as I understand it. Now, on the whole, I am guessing what you are trying to do here is consume the SSE events and detect the invocation of entrypoints on the auction that you find relevant is that correct?

Yes, correct. One example is the notification thing I've mentioned above. But I know there are also the other already existing tools which are having a hard time (or just do it wrong) to detect all activities (not only delegate and undelegate) so they are producing wrong/missing data as seen with the 3. way of undelegation which even cspr.live gets wrong and detects it as a "WASM deploy" only because obviously they don't parse the transforms.

My current goal is to get informed about all events in all it's possible ways and it seems that currently that is a huge task since there are so many different (and when it comes to parse transforms) complicated ways.

Let's say I want to develop a bot to send out notifications about fee changes or that a specific node has an empty delegator slot again because someone undelegated or that a big amount of account X was undelegated from node Y etc.

Right now there are at least those 3 ways I've mentioned above instead of 1 SSE event so I have to understand and parse everything myself on a very low level and without proper documentation.

Or in the words of a developer friend when we talked about transforms: Transforms should not be in response at all. This is *** which scares every single dev