Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIMD-0057: Events #57

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

mschneider
Copy link

@mschneider mschneider commented Jun 13, 2023

Propose a new event logging mechanism that is reliable and efficient.
Browser clients should be able to receive emitted events with minimal latency.
3rd party indexers should allow to horizontally scale access to historic
events.

@mschneider mschneider changed the title SIMDXX: Events SIM57: Events Jun 13, 2023
@mschneider mschneider changed the title SIM57: Events SIMD57: Events Jun 13, 2023
@mschneider mschneider changed the title SIMD57: Events SIMD-0057: Events Jun 13, 2023
actual application. It also causeses unnecessary overhead in replay as a new
execution context neeeds to be created, for something as trivial as a log
message. There is a potential security risk in the this system in that external
programs could spoof anchor events (and the program emitting them) with CPI

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spoofing risk was mitigated by adding in a PDA event authority that must sign the self CPI

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to confirm, does this require to add another account per program that wants to emit logs to the transaction?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but it’s only 34 bytes. (0 data, only pubkey + flags)

Copy link

@theDefiBat theDefiBat Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jarry-xiao
Copy link

I fully support the development of more robust indexing solutions + persistent event data, but it's hard for me to see a strict benefit in the near term future of native events over CPI events (which is admittedly a hack). From a resource allocation standpoint, this feels like large engineering lift + ecosystem buy-in lift for insufficient gain IMO. No opposition if a native solution gets prioritized and implemented with 5x improvement to existing devex.

proposals/0057-events.md Outdated Show resolved Hide resolved
proposals/0057-events.md Outdated Show resolved Hide resolved
proposals/0057-events.md Outdated Show resolved Hide resolved
proposals/0057-events.md Show resolved Hide resolved

```
#include <sol/emit.h>
void sol_emit_(/* r1 */ uint64_t len,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is the "Discriminator" expressed?

Also it seems better that the program specify the addresses it wants to associate with the event no? This would be part of the price, and allow the indexing backends to only persist the addresses that actually matter instead of requiring every address in the transaction.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discriminator: not at all, i thought we can get by without supporting it explicitly in the standard. clients can decide to have an index on the program id + first n (1..32) bytes for performance reasons, but that's implementation detail.

indexing backends anyways have a gsfa index, an additional discriminator -> signature index can be used for index joins. do you think that's unrealistic?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, what's a gsfa?

clients can decide to have an index on the program id + first n (1..32) bytes for performance reasons, but that's implementation detail.

i think leaving this as an implementation detail means we could then expect to see different behaviours across rpc endpoints, but that's the problem with sol_log() that this proposal is attempting to solve though

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gsfa = getSignaturesForAddress

imo this is very application specific, i would expect the program IDL to declare to the indexing provider which parts of the event (for each event type) need indexing and hence which queries can have improved latency. the difference here is that the data query API is defined which is important for compatibility, so same query bytes -> same result bytes. latency is still dependent on rpc provider, it's not something you could enforce via spec.

we could add the discriminator ofc. but i thought at this point it's better to just leave it out of the spec to keep stuff lightweight and implement a 8 byte prefix index in the reference client.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that this proposal is attempting to solve though

just want to comment again on this:

proposal solves provider specific truncation and lack of query api schema, basically enforces data consistency across providers.

it does not guarantee reliable query performance, similar to how SQL spec can't enforce query performance.

```
#include <sol/emit.h>
void sol_emit_(/* r1 */ uint64_t len,
/* r2 */ const char *message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mschneider OCD thing - In other syscalls, pointer comes first and length afterwards. Could we swap arguments here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The events should have a sequence number so that I can "subscribe" to an event stream and restart at a specific sequence number. This would match up with the event behavior for aptos, sui, and (via a hack or two) algorand.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jumpsiegel wrong thread to post the comment, but I second that

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the events on stream and when queried via rpc call include a sequence number, just to clarify, would it be enough to be able to send a request to backfill missing events (once you notice discontinuity?) i find stream semantic for historic events hard to reason about. curious to see the api's you mentioned, could you drop me the links @jumpsiegel ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@mschneider mschneider Sep 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jumpsiegel i added a way to query events directly and included the sequence number for that purpose. Due to the way solana randomizes block entry execution there is some weirdness around how events can change their order inside the response, I clarified that. Please let me know if this is sufficient

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit, I am confused by this statement. Does this mean different validators might have events with different sequence numbers? ie, the sequence number is non-deterministic and not part of consensus.. The effect of this would be that if I change event providers (validators) while going through a load balancer, the sequence numbers would change and I would find myself scrambling to figure out what I have missed?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the current behaviour of gSFA. @mvines mentioned it's possible to clean up, so i'll update the proposal wrt. i think it's a huge improvement to change this part.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in general sequence numbers can still change due to block re-orgs. i updated the proposal text, would appreciate a final review and ideally thumbs-up, so we can get started on implementation :)

@jacobcreech jacobcreech added standard SIMD in the Standard category core Standard SIMD with type Core labels Aug 16, 2023
The response is sorted by the following priorities:

1. slots ascending
2. signature order for transactions inside a block
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than trying to order by signature here, there is a single natural ordering of how transactions are placed in entries and then in a block. This order is common across the cluster (solana-ledger-tool outputs it). During replay, the entry transactions are intentionally shuffled randomly but if that shuffling didn't exist then the entire cluster would replay entries the same way

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wasn't aware, if we can keep that alive across replay, we should be able to have even more easy indexing. Will adapt.

Comment on lines +119 to +121
Bank deltas are currently hashed via sha256, the sha256 syscall charges
85 + 0.5 CU / byte. blake3 a roughly 2x faster to compute hash, would be
sufficient as well, hence 100 + 0.25 * len CU would be a good approximation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current best implementations of BLAKE3 are significantly slower than SHA-256 below 4kB
https://forum.solana.com/t/blake3-slower-than-sha-256-for-small-inputs/829

I have an experimental rewrite that makes BLAKE3 fast again, but that won't get backported to Rust anytime soon.
Therefore, I think we should use the SHA256 pricing instead.

Copy link
Contributor

@ripatel-fd ripatel-fd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather bring these fixes to the existing log mechanism instead of adding a new log facility with a different name.

I like some important fixes this SIMD proposes, but we should be able to bring those to the current log mechanism

  • Removing truncation
  • Supporting binary logs (no more UTF-8 validation)
  • Accounting storage cost in fees

Supporting two log mechanisms is more complicated for the developers of programs, frontends, API infrastructure, and core developers. Retiring the old log mechanism is not an option, since it's unreasonable to expect all programs to adopt the new event API (some are immutable)

Keeping a unified log mechanism could look like so:

  • Add "log v2" core and RPC APIs
  • Expand the functionality of the log collector to support both binary (v2) and text logs (v1/v2)
  • Enforce the fee changes onto log v1
  • Ensure that all messages are visible via either API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Standard SIMD with type Core standard SIMD in the Standard category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants