Skip to content

Commit

Permalink
Returning resolved event move object instead of bytes (MystenLabs#2435)
Browse files Browse the repository at this point in the history
* Convert event bytes to SuiMoveStruct

* add bcs bytes back in the event data

* [ts-sdk] relax the definition for events

* fixup after rebase

Co-authored-by: Chris Li <[email protected]>
  • Loading branch information
patrickkuo and 666lcz authored Jun 15, 2022
1 parent 74d519b commit 748fe8a
Show file tree
Hide file tree
Showing 17 changed files with 949 additions and 809 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ created: object(108)
written: object(107)

task 6 'run'. lines 18-18:
events: MoveEvent { type_: StructTag { address: Sui, module: Identifier("ObjectBasics"), name: Identifier("NewValueEvent"), type_params: [] }, contents: [20, 0, 0, 0, 0, 0, 0, 0] }
events: MoveEvent(MoveObject { type_: StructTag { address: Sui, module: Identifier("ObjectBasics"), name: Identifier("NewValueEvent"), type_params: [] }, contents: [20, 0, 0, 0, 0, 0, 0, 0] })
written: object(105), object(108), object(109)

task 7 'run'. lines 20-20:
Expand Down
6 changes: 3 additions & 3 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub use temporary_store::AuthorityTemporaryStore;

mod authority_store;
pub use authority_store::{
AuthorityStore, AuthorityStoreWrapper, GatewayStore, SuiDataStore, UpdateType,
AuthorityStore, GatewayStore, ResolverWrapper, SuiDataStore, UpdateType,
};
use sui_types::messages_checkpoint::{
CheckpointRequest, CheckpointRequestType, CheckpointResponse,
Expand Down Expand Up @@ -241,7 +241,7 @@ pub struct AuthorityState {

indexes: Option<Arc<IndexStore>>,

module_cache: SyncModuleCache<AuthorityStoreWrapper>, // TODO: use strategies (e.g. LRU?) to constraint memory usage
pub module_cache: SyncModuleCache<ResolverWrapper<AuthorityStore>>, // TODO: use strategies (e.g. LRU?) to constraint memory usage

event_handler: Option<Arc<EventHandler>>,

Expand Down Expand Up @@ -929,7 +929,7 @@ impl AuthorityState {
indexes,
// `module_cache` uses a separate in-mem cache from `event_handler`
// this is because they largely deal with different types of MoveStructs
module_cache: SyncModuleCache::new(AuthorityStoreWrapper(store.clone())),
module_cache: SyncModuleCache::new(ResolverWrapper(store.clone())),
event_handler,
checkpoints,
batch_channels: tx,
Expand Down
6 changes: 3 additions & 3 deletions crates/sui-core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,10 +1129,10 @@ impl<const A: bool, S: Eq + Serialize + for<'de> Deserialize<'de>> ModuleResolve
}

/// A wrapper to make Orphan Rule happy
pub struct AuthorityStoreWrapper(pub Arc<AuthorityStore>);
pub struct ResolverWrapper<T: ModuleResolver>(pub Arc<T>);

impl ModuleResolver for AuthorityStoreWrapper {
type Error = SuiError;
impl<T: ModuleResolver> ModuleResolver for ResolverWrapper<T> {
type Error = T::Error;
fn get_module(&self, module_id: &ModuleId) -> Result<Option<Vec<u8>>, Self::Error> {
self.0.get_module(module_id)
}
Expand Down
6 changes: 3 additions & 3 deletions crates/sui-core/src/event_handler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use crate::authority::{AuthorityStore, AuthorityStoreWrapper};
use crate::authority::{AuthorityStore, ResolverWrapper};
use crate::streamer::Streamer;
use move_bytecode_utils::module_cache::SyncModuleCache;
use std::sync::Arc;
Expand All @@ -16,7 +16,7 @@ use tracing::{debug, error};
const EVENT_DISPATCH_BUFFER_SIZE: usize = 1000;

pub struct EventHandler {
module_cache: SyncModuleCache<AuthorityStoreWrapper>,
module_cache: SyncModuleCache<ResolverWrapper<AuthorityStore>>,
streamer_queue: Sender<EventEnvelope>,
}

Expand All @@ -25,7 +25,7 @@ impl EventHandler {
let (tx, rx) = mpsc::channel::<EventEnvelope>(EVENT_DISPATCH_BUFFER_SIZE);
Streamer::spawn(rx);
Self {
module_cache: SyncModuleCache::new(AuthorityStoreWrapper(validator_store)),
module_cache: SyncModuleCache::new(ResolverWrapper(validator_store)),
streamer_queue: tx,
}
}
Expand Down
18 changes: 10 additions & 8 deletions crates/sui-core/src/gateway_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::time::Duration;
use anyhow::anyhow;
use async_trait::async_trait;
use futures::future;
use move_bytecode_utils::module_cache::ModuleCache;
use move_bytecode_utils::module_cache::SyncModuleCache;
use move_core_types::identifier::Identifier;
use move_core_types::language_storage::TypeTag;
use once_cell::sync::Lazy;
Expand All @@ -34,6 +34,7 @@ use sui_types::{
SUI_FRAMEWORK_ADDRESS,
};

use crate::authority::ResolverWrapper;
use crate::transaction_input_checker;
use crate::{
authority::{GatewayStore, UpdateType},
Expand All @@ -44,8 +45,8 @@ use crate::{
use sui_json::{resolve_move_function_args, SuiJsonCallArg, SuiJsonValue};
use sui_json_rpc_api::rpc_types::{
GetObjectDataResponse, GetRawObjectDataResponse, MergeCoinResponse, PublishResponse,
SplitCoinResponse, SuiMoveObject, SuiObject, SuiObjectInfo, TransactionEffectsResponse,
TransactionResponse,
SplitCoinResponse, SuiMoveObject, SuiObject, SuiObjectInfo, SuiTransactionEffects,
TransactionEffectsResponse, TransactionResponse,
};

use crate::transaction_input_checker::InputObjects;
Expand Down Expand Up @@ -183,6 +184,7 @@ pub struct GatewayState<A> {
/// from a gateway.
next_tx_seq_number: AtomicU64,
metrics: &'static GatewayMetrics,
module_cache: SyncModuleCache<ResolverWrapper<GatewayStore>>,
}

impl<A> GatewayState<A> {
Expand All @@ -202,10 +204,11 @@ impl<A> GatewayState<A> {
let store = Arc::new(GatewayStore::open(path, None));
let next_tx_seq_number = AtomicU64::new(store.next_sequence_number()?);
Ok(Self {
store,
store: store.clone(),
authorities,
next_tx_seq_number,
metrics: &METRICS,
module_cache: SyncModuleCache::new(ResolverWrapper(store)),
})
}

Expand Down Expand Up @@ -400,8 +403,7 @@ where
&self,
object: Object,
) -> Result<SuiObject<T>, anyhow::Error> {
let cache = ModuleCache::new(&*self.store);
let layout = object.get_layout(ObjectFormatOptions::default(), &cache)?;
let layout = object.get_layout(ObjectFormatOptions::default(), &self.module_cache)?;
SuiObject::<T>::try_from(object, layout)
}

Expand Down Expand Up @@ -934,7 +936,7 @@ where
return Ok(TransactionResponse::EffectResponse(
TransactionEffectsResponse {
certificate: certificate.try_into()?,
effects: effects.into(),
effects: SuiTransactionEffects::try_from(effects, &self.module_cache)?,
timestamp_ms: None,
},
));
Expand Down Expand Up @@ -1222,7 +1224,7 @@ where

Ok(TransactionEffectsResponse {
certificate: cert.try_into()?,
effects: effect.into(),
effects: SuiTransactionEffects::try_from(effect, &self.module_cache)?,
timestamp_ms: None,
})
}
Expand Down
1 change: 1 addition & 0 deletions crates/sui-json-rpc-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ serde_with = { version = "1.14.0", features = ["hex"] }
colored = "2.0.0"
either = "1.6.1"
move-core-types = { git = "https://github.com/move-language/move", rev = "c2949bc7967de5b93f0850ce4987fc06c529f9f2", features = ["address20"] }
move-bytecode-utils = { git = "https://github.com/move-language/move", rev = "c2949bc7967de5b93f0850ce4987fc06c529f9f2" }
itertools = "0.10.3"

sui-types = { path = "../sui-types" }
Expand Down
Loading

0 comments on commit 748fe8a

Please sign in to comment.