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

Gas Profiling Implementation #2616

Merged
merged 8 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion Cargo.lock

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

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"moveos/moveos-commons/bcs_ext",
"moveos/moveos-commons/moveos-common",
"moveos/moveos-commons/timeout-join-handler",
"moveos/moveos-commons/moveos-common",
"moveos/moveos-compiler",
"moveos/moveos-config",
"moveos/moveos-object-runtime",
Expand All @@ -18,6 +19,7 @@ members = [
"moveos/raw-store",
"moveos/smt",
"moveos/moveos-eventbus",
"moveos/moveos-gas-profiling",
"crates/data_verify",
"crates/rooch",
"crates/rooch-benchmarks",
Expand Down Expand Up @@ -103,6 +105,7 @@ moveos-object-runtime = { path = "moveos/moveos-object-runtime" }
moveos-compiler = { path = "moveos/moveos-compiler" }
moveos-eventbus = { path = "moveos/moveos-eventbus" }
accumulator = { path = "moveos/moveos-commons/accumulator" }
moveos-gas-profiling = { path = "moveos/moveos-gas-profiling" }

# crates for Rooch
rooch = { path = "crates/rooch" }
Expand Down Expand Up @@ -347,6 +350,9 @@ vergen-git2 = { version = "1.0.0", features = ["build", "cargo", "rustc"] }
vergen-pretty = "0.3.5"
crossbeam-channel = "0.5.13"

inferno = "0.11.14"
handlebars = "4.2.2"

# Note: the BEGIN and END comments below are required for external tooling. Do not remove.
# BEGIN MOVE DEPENDENCIES
move-abigen = { git = "https://github.com/rooch-network/move", rev = "c05b5f71a24beb498eb743d73be4f69d8d325e62" }
Expand Down
1 change: 1 addition & 0 deletions crates/rooch-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ rooch-types = { workspace = true }
rooch-genesis = { workspace = true }
rooch-event = { workspace = true }
rooch-store = { workspace = true }
hex = "0.4.3"
2 changes: 2 additions & 0 deletions crates/rooch-executor/src/actor/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl Message for ExecuteViewFunctionMessage {

#[derive(Debug, Serialize, Deserialize)]
pub struct StatesMessage {
pub state_root: Option<H256>,
pub access_path: AccessPath,
}

Expand Down Expand Up @@ -126,6 +127,7 @@ impl Message for AnnotatedStatesMessage {

#[derive(Debug, Serialize, Deserialize)]
pub struct ListStatesMessage {
pub state_root: Option<H256>,
pub access_path: AccessPath,
pub cursor: Option<FieldKey>,
pub limit: usize,
Expand Down
14 changes: 12 additions & 2 deletions crates/rooch-executor/src/actor/reader_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ impl Handler<StatesMessage> for ReaderExecutorActor {
msg: StatesMessage,
_ctx: &mut ActorContext,
) -> Result<Vec<Option<ObjectState>>, anyhow::Error> {
let resolver = RootObjectResolver::new(self.root.clone(), &self.moveos_store);
let resolver = if let Some(state_root) = msg.state_root {
let root_object_meta = ObjectMeta::root_metadata(state_root, 55);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

How should we handle the size parameter?
Should it be passed from the client or retrieved from Node?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another way to implement it is to modify the state_resolver StateReader trait to support get_states and list_states by state root, so there is no need to construct a new RootObject

Copy link
Contributor

Choose a reason for hiding this comment

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

In the read-only case, the VM do not use the size param, it can be zero.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It is workable to implement this by directly setting the RootObject size to 0, but is there any ambiguity in constructing the RootObject for any state root query, such as the state root of a child object tree?

Copy link
Contributor

Choose a reason for hiding this comment

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

The size is used by the ObjectRuntime; if the contract removes an element, the size will reduce. We do not record all Global root objects. This is a workaround solution; we will need to refactor in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do not need to record all Global root objects , just modify the state_resolver StateReader trait to support get_states and list_states by state root , and it can elegantly solve the querying arbitrary state root scenarios.
It can be put in the subsequent refactor.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is already a StatelessResolver, which supports get_states by root; StateResolver is for the pin on a state_root and get states many times.

RootObjectResolver::new(root_object_meta, &self.moveos_store)
} else {
RootObjectResolver::new(self.root.clone(), &self.moveos_store)
};
resolver.get_states(msg.access_path)
}
}
Expand All @@ -170,7 +175,12 @@ impl Handler<ListStatesMessage> for ReaderExecutorActor {
msg: ListStatesMessage,
_ctx: &mut ActorContext,
) -> Result<Vec<StateKV>, anyhow::Error> {
let resolver = RootObjectResolver::new(self.root.clone(), &self.moveos_store);
let resolver = if let Some(state_root) = msg.state_root {
let root_object_meta = ObjectMeta::root_metadata(state_root, 55);
RootObjectResolver::new(root_object_meta, &self.moveos_store)
} else {
RootObjectResolver::new(self.root.clone(), &self.moveos_store)
};
resolver.list_states(msg.access_path, msg.cursor, msg.limit)
}
}
Expand Down
22 changes: 17 additions & 5 deletions crates/rooch-executor/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,16 @@ impl ExecutorProxy {
.await?
}

pub async fn get_states(&self, access_path: AccessPath) -> Result<Vec<Option<ObjectState>>> {
pub async fn get_states(
&self,
access_path: AccessPath,
state_root: Option<H256>,
) -> Result<Vec<Option<ObjectState>>> {
self.reader_actor
.send(StatesMessage { access_path })
.send(StatesMessage {
state_root,
access_path,
})
.await?
}

Expand All @@ -133,12 +140,14 @@ impl ExecutorProxy {

pub async fn list_states(
&self,
state_root: Option<H256>,
access_path: AccessPath,
cursor: Option<FieldKey>,
limit: usize,
) -> Result<Vec<StateKV>> {
self.reader_actor
.send(ListStatesMessage {
state_root,
access_path,
cursor,
limit,
Expand Down Expand Up @@ -261,7 +270,7 @@ impl ExecutorProxy {
}

pub async fn chain_id(&self) -> Result<ChainID> {
self.get_states(AccessPath::object(ChainID::chain_id_object_id()))
self.get_states(AccessPath::object(ChainID::chain_id_object_id()), None)
.await?
.into_iter()
.next()
Expand All @@ -271,7 +280,7 @@ impl ExecutorProxy {
}

pub async fn bitcoin_network(&self) -> Result<BitcoinNetwork> {
self.get_states(AccessPath::object(BitcoinNetwork::object_id()))
self.get_states(AccessPath::object(BitcoinNetwork::object_id()), None)
.await?
.into_iter()
.next()
Expand All @@ -283,7 +292,10 @@ impl ExecutorProxy {
//TODO provide a trait to abstract the async state reader, elemiate the duplicated code bwteen RpcService and Client
pub async fn get_sequence_number(&self, address: AccountAddress) -> Result<u64> {
Ok(self
.get_states(AccessPath::object(Account::account_object_id(address)))
.get_states(
AccessPath::object(Account::account_object_id(address)),
None,
)
.await?
.pop()
.flatten()
Expand Down
10 changes: 10 additions & 0 deletions crates/rooch-open-rpc-spec/schemas/openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,13 @@
"$ref": "#/components/schemas/moveos_types::access_path::AccessPath"
}
},
{
"name": "state_root",
"required": true,
"schema": {
"$ref": "#/components/schemas/moveos_types::state_root_hash::StateRootHash"
}
},
{
"name": "state_option",
"schema": {
Expand Down Expand Up @@ -3402,6 +3409,9 @@
"moveos_types::state::FieldKey": {
"type": "string"
},
"moveos_types::state_root_hash::StateRootHash": {
"type": "string"
},
"primitive_types::H256": {
"type": "string"
},
Expand Down
14 changes: 14 additions & 0 deletions crates/rooch-rpc-api/src/jsonrpc_types/rpc_options.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) RoochNetwork
// SPDX-License-Identifier: Apache-2.0

use crate::jsonrpc_types::H256View;
use moveos_types::h256::H256;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand All @@ -11,6 +13,8 @@ pub struct StateOptions {
pub decode: bool,
/// If true, result with display rendered is returned
pub show_display: bool,
/// The state root of remote stateDB
pub state_root: Option<H256View>,
}

impl StateOptions {
Expand All @@ -27,6 +31,16 @@ impl StateOptions {
self.show_display = show_display;
self
}

pub fn state_root(mut self, state_root: Option<H256>) -> Self {
match state_root {
None => {}
Some(h256) => {
self.state_root = Some(H256View::from(h256));
}
}
self
}
}

#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema, Eq, PartialEq, Default)]
Expand Down
Loading
Loading