Skip to content

Commit

Permalink
core: event sending module relocation
Browse files Browse the repository at this point in the history
## Description

Make it so that the module that is associated as the "sending module"
for an event is relocated by linkage. This fixes an issue (captured in a
regression test) where if the function that is called by the PTB is from
some upgraded version of the package, it cannot be found because the
Event's package ID still points to the original version of the package.

## Test plan

Introduced a regression test -- before the change, the "sending module"
in the response returned `null`.

```
sui$ cargo nextest run -p sui-graphql-e2e-tests -- sending_module
```
  • Loading branch information
amnn committed Oct 3, 2024
1 parent f39f977 commit bd9f067
Show file tree
Hide file tree
Showing 10 changed files with 1,133 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
processed 6 tasks

init:
A: object(0,0)

task 1, lines 6-11:
//# publish --upgradeable --sender A
created: object(1,0), object(1,1)
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 5327600, storage_rebate: 0, non_refundable_storage_fee: 0

task 2, lines 13-28:
//# upgrade --package P --upgrade-capability 1,1 --sender A
created: object(2,0)
mutated: object(0,0), object(1,1)
gas summary: computation_cost: 1000000, storage_cost: 6802000, storage_rebate: 2595780, non_refundable_storage_fee: 26220

task 3, line 30:
//# run P::M1::emit --sender A
events: Event { package_id: P, transaction_module: Identifier("M1"), sender: A, type_: StructTag { address: fake(1,0), module: Identifier("M0"), name: Identifier("Event"), type_params: [] }, contents: [42, 0, 0, 0, 0, 0, 0, 0] }
mutated: object(0,0)
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880

task 4, line 32:
//# create-checkpoint
Checkpoint created: 1

task 5, lines 34-44:
//# run-graphql
Response: {
"data": {
"events": {
"nodes": [
{
"sendingModule": {
"package": {
"address": "0xf847f63b795fdbc978a23fc181ea5180f55755e446fae1f1ce7865234cac7984"
},
"name": "M1"
}
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

//# init --protocol-version 62 --addresses P=0x0 --accounts A --simulator

//# publish --upgradeable --sender A
module P::M0 {
public struct Event has copy, drop {
value: u64
}
}

//# upgrade --package P --upgrade-capability 1,1 --sender A
module P::M0 {
public struct Event has copy, drop {
value: u64
}

public fun emit() {
sui::event::emit(Event { value: 42 })
}
}

module P::M1 {
public fun emit() {
P::M0::emit()
}
}

//# run P::M1::emit --sender A

//# create-checkpoint

//# run-graphql
{
events {
nodes {
sendingModule {
package { address }
name
}
}
}
}
3 changes: 2 additions & 1 deletion crates/sui-open-rpc/spec/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@
"name": "Result",
"value": {
"minSupportedProtocolVersion": "1",
"maxSupportedProtocolVersion": "61",
"maxSupportedProtocolVersion": "62",
"protocolVersion": "6",
"featureFlags": {
"accept_zklogin_in_multisig": false,
Expand Down Expand Up @@ -1342,6 +1342,7 @@
"recompute_has_public_transfer_in_execution": false,
"record_consensus_determined_version_assignments_in_prologue": false,
"reject_mutable_random_on_entry_functions": false,
"relocate_event_module": false,
"reshare_at_same_initial_version": false,
"resolve_abort_locations_to_package_id": false,
"rethrow_serialization_type_layout_errors": false,
Expand Down
14 changes: 13 additions & 1 deletion crates/sui-protocol-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tracing::{info, warn};

/// The minimum and maximum protocol versions supported by this build.
const MIN_PROTOCOL_VERSION: u64 = 1;
const MAX_PROTOCOL_VERSION: u64 = 61;
const MAX_PROTOCOL_VERSION: u64 = 62;

// Record history of protocol version allocations here:
//
Expand Down Expand Up @@ -183,6 +183,7 @@ const MAX_PROTOCOL_VERSION: u64 = 61;
// Version 61: Switch to distributed vote scoring in consensus in testnet
// Further reduce minimum number of random beacon shares.
// Add feature flag for Mysticeti fastpath.
// Version 62: Makes the event's sending module package upgrade-aware.

#[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
pub struct ProtocolVersion(u64);
Expand Down Expand Up @@ -541,6 +542,10 @@ struct FeatureFlags {
// Enables Mysticeti fastpath.
#[serde(skip_serializing_if = "is_false")]
mysticeti_fastpath: bool,

// Makes the event's sending module version-aware.
#[serde(skip_serializing_if = "is_false")]
relocate_event_module: bool,
}

fn is_false(b: &bool) -> bool {
Expand Down Expand Up @@ -1615,6 +1620,10 @@ impl ProtocolConfig {
pub fn mysticeti_fastpath(&self) -> bool {
self.feature_flags.mysticeti_fastpath
}

pub fn relocate_event_module(&self) -> bool {
self.feature_flags.relocate_event_module
}
}

#[cfg(not(msim))]
Expand Down Expand Up @@ -2808,6 +2817,9 @@ impl ProtocolConfig {
cfg.feature_flags.mysticeti_fastpath = true;
}
}
62 => {
cfg.feature_flags.relocate_event_module = true;
}
// Use this template when making changes:
//
// // modify an existing constant.
Expand Down
Loading

0 comments on commit bd9f067

Please sign in to comment.