0xMiden / 0xMiden/protocol

Emit events from transactions

Offen
#3,803 11 Kommentare 2 Reaktionen 1 zugewiesene Person Beansprucht von @partylikeits1983 Auf GitHub ansehen
kernels
Vorherrschende Sprache
Rust
Sterne
132
Forks
167
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
110

Beschreibung

Events would be a transaction-level construct - similar to output notes and account delta.

### Flow
The process would look as follows:
- The developer wants to emit some set of events during transaction execution.
- As the events are emitted, we build a cryptographic commitment to them (tracked in the transaction kernel).
- At the end of the transaction kernel, commitment to these events is returned via the output stack (similar how we return commitment to the output notes).
- When the client syncs with the node (e.g., via the `SyncTransactions` endpoint), they also get all the events emitted in the returned transaction.
- The client can then interpret these events as needed in the context of the specific account.

### Kernel changes
To support this at the blockchain level, we can introduce a new kernel procedure, e.g. `log`. The usage could be something like:

```
use miden::protocol::tx

begin
# OS => [event_topic, EVENT_PAYLOAD]
# Advice map: {
# EVENT_PAYLOAD => [PAYLOAD_PREIMAGE]
# }
exec.tx::log
end
```

### Event parameters
To make events useful, users should be able to supply a bunch of parameters:
- event topic, used by clients for easy filtering of events. We can add some standard topics later, but similarly to note attachments, the developers should have freedom to define their topics.
- event payload

The payload should be a key, the preimage of which would be provided via the advice map, and the in kernel, `log` logic would verify that the provided preimage hashes to the `EVENT_PAYLOAD`.

In addition, `log` should emit a host event that tells the host to add the `EVENT_PAYLOAD` to the re-constructed transaction, so that the transaction incl. its event data can be sent to the node RPC.

### Node side
The node needs to store these emitted events during tx execution, and expose them over gRPC e.g. via `GetTxEvents(tx_id)` or `GetAccountEvents(account_id)`. TBD with the node and client teams on what exactly we want to expose, but as a starting point we can just have `GetTxEvents(tx_id)`.

_Reworked from comments by @mmagician and @bobbinth in https://github.com/0xMiden/protocol/discussions/2152_

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.