Skip to content

Commit

Permalink
fix starcoin-rpc-server errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nkysg committed Oct 21, 2024
1 parent 433ad50 commit e42c8ab
Show file tree
Hide file tree
Showing 20 changed files with 181 additions and 173 deletions.
95 changes: 49 additions & 46 deletions Cargo.lock

Large diffs are not rendered by default.

68 changes: 34 additions & 34 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ jsonrpc-client-transports = "18"
jsonrpc-core = "18"
jsonrpc-core-client = "18"
jsonrpc-derive = "18"
openrpc-derive = { git = "https://github.com/starcoinorg/openrpc-rs", rev = "f8ab047e30927cdf2f605b61a219c975d6c4f666", features = [
openrpc-derive = { git = "https://github.com/starcoinorg/openrpc-rs", rev = "1f2f7d3495e3bd3ef3b6fcf7c4e0602cad090d5e", features = [
"jsonrpc",
] }
openrpc-schema = { git = "https://github.com/starcoinorg/openrpc-rs", rev = "f8ab047e30927cdf2f605b61a219c975d6c4f666" }
openrpc-schema = { git = "https://github.com/starcoinorg/openrpc-rs", rev = "1f2f7d3495e3bd3ef3b6fcf7c4e0602cad090d5e" }

jsonrpc-http-server = "18"
jsonrpc-ipc-server = "18"
Expand Down Expand Up @@ -402,37 +402,37 @@ sha2_0_10_6 = { package = "sha2", version = "0.10.6" }
siphasher = "0.3.10"
merkletree = { version = "0.22.1" }
mirai-annotations = "1.10.1"
move-binary-format = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-bytecode-source-map = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-bytecode-verifier = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-cli = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-command-line-common = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-compiler = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-compiler-v2 = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-core-types = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-coverage = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-disassembler = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-docgen = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-errmapgen = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-ir-compiler = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-ir-types = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-model = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-package = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-prover = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-prover-boogie-backend = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-prover-bytecode-pipeline = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-stackless-bytecode = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-prover-test-utils = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-resource-viewer = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-stdlib = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-transactional-test-runner = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-unit-test = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891", features = [
move-binary-format = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-bytecode-source-map = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-bytecode-verifier = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-cli = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-command-line-common = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-compiler = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-compiler-v2 = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-core-types = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-coverage = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-disassembler = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-docgen = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-errmapgen = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-ir-compiler = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-ir-types = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-model = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-package = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-prover = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-prover-boogie-backend = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-prover-bytecode-pipeline = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-stackless-bytecode = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-prover-test-utils = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-resource-viewer = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-stdlib = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-transactional-test-runner = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-unit-test = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec", features = [
"table-extension",
] }
move-vm-runtime = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-vm-types = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-table-extension = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891" }
move-vm-test-utils = { git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891", features = [
move-vm-runtime = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-vm-types = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-table-extension = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec" }
move-vm-test-utils = { git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec", features = [
"table-extension",
] }

Expand Down Expand Up @@ -479,7 +479,7 @@ rustc-serialize = "0.3.25"
rustyline = "9.1.2"
rustyline-derive = "0.6.0"
sc-peerset = { path = "network-p2p/peerset" }
schemars = { git = "https://github.com/starcoinorg/schemars", rev = "9b3705780b8fe9c8676ff82919869ba7405b1062" }
schemars = { git = "https://github.com/starcoinorg/schemars", rev = "a64c6ddf7ca4796e090208b1476de2e53772042f" }
scmd = { path = "commons/scmd" }
serde = { version = "1.0.130", features = ["derive"] }
serde-generate = { git = "https://github.com/starcoinorg/serde-reflection", rev = "eb95fd4e3b67e08d71432b522c53833a0b855d80" }
Expand Down Expand Up @@ -518,7 +518,7 @@ starcoin-chain-service = { path = "chain/service" }
starcoin-cmd = { path = "cmd/starcoin" }
starcoin-config = { path = "config" }
starcoin-consensus = { path = "consensus" }
starcoin-crypto = { git = "https://github.com/starcoinorg/starcoin-crypto", rev = "ca832ccccfd6f3df99620ee50003c9c2b2ffab69" }
starcoin-crypto = { git = "https://github.com/starcoinorg/starcoin-crypto", rev = "9eeaeb7e30065cc97160de7a1b42fab6ae88058e" }

starcoin-decrypt = { path = "commons/decrypt" }
starcoin-dev = { path = "vm/dev" }
Expand Down Expand Up @@ -614,7 +614,7 @@ unsigned-varint = { version = "0.6.0", features = [
"futures",
"asynchronous_codec",
] }
vm = { package = "move-binary-format", git = "https://github.com/starcoinorg/move", rev = "a5e99a08dc30a72723556bc678a318a1f9783891", features = [
vm = { package = "move-binary-format", git = "https://github.com/starcoinorg/move", rev = "3486a4d205a2dcb92e49904e7c97114a6478e2ec", features = [
"fuzzing",
] }
vm-status-translator = { path = "vm/vm-status-translator" }
Expand Down
6 changes: 4 additions & 2 deletions etc/starcoin_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,12 @@ StateKey:
STRUCT:
- handle:
TYPENAME: TableHandle
- key: BYTES
- key:
SEQ: U8
2:
Raw:
NEWTYPE: BYTES
NEWTYPE:
SEQ: U8
StateValueMetadata:
ENUM:
0:
Expand Down
2 changes: 1 addition & 1 deletion executor/benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
anyhow = { workspace = true }
clap = { features = ["derive"], workspace = true }
itertools = { features = ["use_alloc"], workspace = true }
rand = { workspace = true }
rand_0_7_3 = { workspace = true }
rayon = { workspace = true }
starcoin-accumulator = { workspace = true }
starcoin-crypto = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions executor/benchmark/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) The Diem Core Contributors
// SPDX-License-Identifier: Apache-2.0

use rand::{rngs::StdRng, SeedableRng};
use rand_0_7_3::{prelude::StdRng, SeedableRng};
use starcoin_config::ChainNetwork;
use starcoin_crypto::keygen::KeyGen;
use starcoin_crypto::{
Expand Down Expand Up @@ -171,7 +171,7 @@ impl TransactionGenerator {
transactions.push(Transaction::BlockMetadata(block_meta));

for j in 0..block_size {
let indices = rand::seq::index::sample(&mut self.rng, self.accounts.len(), 1);
let indices = rand_0_7_3::seq::index::sample(&mut self.rng, self.accounts.len(), 1);
// let sender_idx = indices.index(0);
let receiver_idx = indices.index(0);

Expand Down Expand Up @@ -207,7 +207,7 @@ struct TxnExecutor<'test, S> {
block_receiver: mpsc::Receiver<Vec<Transaction>>,
}

impl<'test, S: ChainStateReader + ChainStateWriter> TxnExecutor<'test, S> {
impl<'test, S: ChainStateReader + ChainStateWriter + Sync> TxnExecutor<'test, S> {
fn new(chain_state: &'test S, block_receiver: mpsc::Receiver<Vec<Transaction>>) -> Self {
Self {
chain_state,
Expand Down
1 change: 1 addition & 0 deletions rpc/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ path = "src/generate_schema.rs"
[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
bytes = { workspace = true }
bcs-ext = { workspace = true }
clap = { features = ["derive"], workspace = true }
futures = { workspace = true }
Expand Down
22 changes: 11 additions & 11 deletions rpc/api/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,35 @@ use crate::types::{
StateWithProofView, StateWithTableItemProofView, StrView, StructTagView, TableInfoView,
};
use crate::FutureResult;
use bytes::Bytes;
use openrpc_derive::openrpc;
use schemars::JsonSchema;
use serde::Deserialize;
use serde::Serialize;
use starcoin_crypto::HashValue;
use starcoin_types::language_storage::{ModuleId, StructTag};
use starcoin_types::{
access_path::AccessPath, account_address::AccountAddress, account_state::AccountState,
};
use starcoin_types::{account_address::AccountAddress, account_state::AccountState};
use starcoin_vm_types::state_store::state_key::StateKey;
use starcoin_vm_types::state_store::table::TableHandle;
#[openrpc]
pub trait StateApi {
#[rpc(name = "state.get")]
fn get(&self, access_path: AccessPath) -> FutureResult<Option<Vec<u8>>>;
fn get(&self, state_key: StateKey) -> FutureResult<Option<Bytes>>;

/// Return state from StateTree storage directly by tree node key.
#[rpc(name = "state.get_state_node_by_node_hash")]
fn get_state_node_by_node_hash(&self, key_hash: HashValue) -> FutureResult<Option<Vec<u8>>>;
fn get_state_node_by_node_hash(&self, key_hash: HashValue) -> FutureResult<Option<Bytes>>;

/// Return the Resource Or Code at the `access_path`, and provide a State Proof.
#[rpc(name = "state.get_with_proof")]
fn get_with_proof(&self, access_path: AccessPath) -> FutureResult<StateWithProofView>;
fn get_with_proof(&self, state_key: StateKey) -> FutureResult<StateWithProofView>;

/// Same as `state.get_with_proof` but return `StateWithProof` in BCS serialize bytes.
#[rpc(name = "state.get_with_proof_raw")]
fn get_with_proof_raw(&self, access_path: AccessPath) -> FutureResult<StrView<Vec<u8>>>;
fn get_with_proof_raw(&self, state_key: StateKey) -> FutureResult<StrView<Vec<u8>>>;

#[rpc(name = "state.get_account_state")]
fn get_account_state(&self, address: AccountAddress) -> FutureResult<Option<AccountState>>;
fn get_account_state(&self, address: AccountAddress) -> FutureResult<AccountState>;

#[rpc(name = "state.get_account_state_set")]
fn get_account_state_set(
Expand All @@ -51,21 +51,21 @@ pub trait StateApi {
#[rpc(name = "state.get_with_proof_by_root")]
fn get_with_proof_by_root(
&self,
access_path: AccessPath,
state_key: StateKey,
state_root: HashValue,
) -> FutureResult<StateWithProofView>;

/// Same as `state.get_with_proof_by_root` but return `StateWithProof` in BCS serialize bytes.
#[rpc(name = "state.get_with_proof_by_root_raw")]
fn get_with_proof_by_root_raw(
&self,
access_path: AccessPath,
state_key: StateKey,
state_root: HashValue,
) -> FutureResult<StrView<Vec<u8>>>;

/// Return the TableInfo according to queried AccountAddress
#[rpc(name = "state.get_table_info")]
fn get_table_info(&self, address: AccountAddress) -> FutureResult<Option<TableInfoView>>;
fn get_table_info(&self, address: AccountAddress) -> FutureResult<TableInfoView>;

/// Return the TableItem value and provide a State Proof at `state_root`
#[rpc(name = "state.get_with_table_item_proof")]
Expand Down
17 changes: 8 additions & 9 deletions rpc/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ use starcoin_types::sync_status::SyncStatus;
use starcoin_types::system_events::MintBlockEvent;
use starcoin_types::transaction::{RawUserTransaction, SignedUserTransaction};
use starcoin_vm_types::language_storage::{ModuleId, StructTag};
use starcoin_vm_types::state_store::state_key::StateKey;
use starcoin_vm_types::state_store::table::TableHandle;
use starcoin_vm_types::token::token_code::TokenCode;
use starcoin_vm_types::transaction::DryRunTransaction;
Expand Down Expand Up @@ -501,28 +502,26 @@ impl RpcClient {
RemoteStateReader::new(self, state_root_opt)
}

pub fn state_get(&self, access_path: AccessPath) -> anyhow::Result<Option<Vec<u8>>> {
self.call_rpc_blocking(|inner| inner.state_client.get(access_path))
pub fn state_get(&self, state_key: StateKey) -> anyhow::Result<Option<Vec<u8>>> {
self.call_rpc_blocking(|inner| inner.state_client.get(state_key))
.map_err(map_err)
.map(|v| v.map(|s| s.to_vec()))
}

pub fn state_get_with_proof(
&self,
access_path: AccessPath,
) -> anyhow::Result<StateWithProofView> {
self.call_rpc_blocking(|inner| inner.state_client.get_with_proof(access_path))
pub fn state_get_with_proof(&self, state_key: StateKey) -> anyhow::Result<StateWithProofView> {
self.call_rpc_blocking(|inner| inner.state_client.get_with_proof(state_key))
.map_err(map_err)
}

pub fn state_get_with_proof_by_root(
&self,
access_path: AccessPath,
state_key: StateKey,
state_root: HashValue,
) -> anyhow::Result<StateWithProofView> {
self.call_rpc_blocking(|inner| {
inner
.state_client
.get_with_proof_by_root(access_path, state_root)
.get_with_proof_by_root(state_key, state_root)
})
.map_err(map_err)
}
Expand Down
4 changes: 2 additions & 2 deletions rpc/client/src/remote_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ impl<'a> RemoteStateReader<'a> {
}

impl<'a> ChainStateReader for RemoteStateReader<'a> {
fn get_with_proof(&self, access_path: &AccessPath) -> Result<StateWithProof> {
fn get_with_proof(&self, state_key: &StateKey) -> Result<StateWithProof> {
self.client
.state_get_with_proof_by_root(access_path.clone(), self.state_root)
.state_get_with_proof_by_root(state_key.clone(), self.state_root)
.map(Into::into)
}

Expand Down
1 change: 1 addition & 0 deletions rpc/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ thiserror = { workspace = true }
vm-status-translator = { workspace = true }
starcoin-vm-runtime = { workspace = true }
starcoin-dag = { workspace = true }
bytes = { workspace = true }

[dev-dependencies]
starcoin-chain-mock = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion rpc/server/src/module/chain_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ use starcoin_rpc_api::types::{
TransactionInfoWithProofView, TransactionView,
};
use starcoin_rpc_api::FutureResult;
use starcoin_vm_types::StateView;
use starcoin_statedb::ChainStateDB;
use starcoin_storage::Storage;
use starcoin_types::access_path::AccessPath;
use starcoin_types::block::BlockNumber;
use starcoin_types::filter::Filter;
use starcoin_types::startup_info::ChainInfo;
use starcoin_vm_types::StateView;
use std::convert::TryInto;
use std::sync::Arc;

Expand Down
20 changes: 10 additions & 10 deletions rpc/server/src/module/contract_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use starcoin_txpool_api::TxPoolSyncService;
use starcoin_types::account_address::AccountAddress;
use starcoin_types::language_storage::{ModuleId, StructTag};
use starcoin_types::transaction::{DryRunTransaction, RawUserTransaction, TransactionPayload};
use starcoin_vm_types::access_path::AccessPath;
use starcoin_vm_types::file_format::CompiledModule;
use starcoin_vm_types::state_store::state_key::StateKey;
use starcoin_vm_types::state_store::StateView;
use starcoin_vm_types::transaction::authenticator::AccountPublicKey;
use std::str::FromStr;
Expand Down Expand Up @@ -86,8 +86,9 @@ where
{
fn get_code(&self, module_id: StrView<ModuleId>) -> FutureResult<Option<StrView<Vec<u8>>>> {
let service = self.chain_state.clone();
let state_key = StateKey::module(module_id.0.address(), module_id.0.name());
let f = async move {
let code = service.get(AccessPath::from(&module_id.0)).await?;
let code = service.get(state_key).await?.map(|v| v.to_vec());
Ok(code.map(StrView))
};
Box::pin(f.map_err(map_err).boxed())
Expand All @@ -102,17 +103,16 @@ where
let playground = self.playground.clone();
let f = async move {
let state_root = service.clone().state_root().await?;
let data = service
.get(AccessPath::resource_access_path(
addr,
resource_type.0.clone(),
))
.await?;
let state_key = StateKey::resource(&addr, &resource_type.0)?;
let data = service.get(state_key).await?;
match data {
None => Ok(None),
Some(d) => {
let value =
playground.view_resource(state_root, &resource_type.0, d.as_slice())?;
let value = playground.view_resource(
state_root,
&resource_type.0,
d.to_vec().as_slice(),
)?;
Ok(Some(value.into()))
}
}
Expand Down
Loading

0 comments on commit e42c8ab

Please sign in to comment.