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

Casper 2.0 Native Events #511

Open
zie1ony opened this issue Aug 14, 2024 · 0 comments
Open

Casper 2.0 Native Events #511

zie1ony opened this issue Aug 14, 2024 · 0 comments

Comments

@zie1ony
Copy link
Contributor

zie1ony commented Aug 14, 2024

Native Events

Casper 2.0 introduces a new way to emit native events. Here is how we can
integrate it with Odra.

Step 1: Contract Installation

On contract installation it's possible to define a contract's topics. Because we
already have a good tooling for serialization/deserialization Rust structs
into/from bytes we can have just one topic: events.

FFI to use:

pub fn casper_add_package_version(
    package_hash_ptr: *const u8,
    package_hash_size: usize,
    version_ptr: *const u32,
    entry_points_ptr: *const u8,
    entry_points_size: usize,
    named_keys_ptr: *const u8,
    named_keys_size: usize,
    message_topics_ptr: *const u8, // <- This 
    message_topics_size: usize,    // <- and this.
    output_ptr: *mut u8,
    output_size: usize,
) -> i32;

Step 2: Event emitting.

On event emission using ContractEnv::emit_event from the point of view of the
contract developer nothing changes. The event is emitted using new ffi:

pub fn casper_emit_message(
    topic_name_ptr: *const u8,
    topic_name_size: usize,
    message_ptr: *const u8,
    message_size: usize,
) -> i32;

Step 3: Testing events.

The main change between CES and Native Events is how they are emitted to the outside world.
In CES, they were simply recorded in the contract's state, so even old events could be retrieved.
In Native Events, they are emitted in processing_results of each deploy.

It takes a form of this struct:

pub struct Message {
    /// The identity of the entity that produced the message.
    entity_hash: EntityAddr, // TODO: this should be EntityAddr
    /// The payload of the message.
    message: MessagePayload,
    /// The name of the topic on which the message was emitted on.
    topic_name: String,
    /// The hash of the name of the topic.
    topic_name_hash: TopicNameHash,
    /// Message index in the topic.
    topic_index: u32,
    /// Message index in the block.
    block_index: u64,
}

This means we have to drop the old style of testing events:

  1. Remove HostRef::get_event,
  2. Remove HostEnv::events_count and all dependant code,

Accessing events have to be organized around HostEnv::last_call_result.

odra_vm has to be adjusted to support that.

Step 4: Livenet

Same HostEnv should work both for tests and for livenet.

Message format

In CES events can't be nested structs or enums. Since the inception of CES we
implemented Contract Metadata format, that allows for that. We should serialize
events like any other odra_struct, because right now we have a specialized
serialization for events. It should be discussed with Make.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🆕 Discuss
Development

No branches or pull requests

1 participant