Skip to content

Commit

Permalink
[dev branch]table extension compatible dry run (#3706)
Browse files Browse the repository at this point in the history
* change dry_out return value

* add DryRunOutputViewV2 for StateKey

* add dry_run_table_item, dry_run_state_key

* remove dry_run_table_item, dry_run_state_key

* reset proxima

* reset proxima
  • Loading branch information
nkysg authored Sep 13, 2022
1 parent fa99f3f commit e4389f2
Show file tree
Hide file tree
Showing 19 changed files with 335 additions and 269 deletions.
2 changes: 1 addition & 1 deletion abi/resolver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ mod tests {
data
}))
}
StateKey::TableItem { handle: _, key: _ } => {
StateKey::TableItem(_table_item) => {
// XXX FIXME YSG
unimplemented!()
}
Expand Down
2 changes: 1 addition & 1 deletion config/example/proxima/genesis_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"genesis_block_parameter": {
"Static": {
"parent_hash": "0xb9215327433b65d5f98f4155d39b06d9a74cc40886857ad510d753022b903f05",
"timestamp": 1659383200000,
"timestamp": 1661944080000,
"difficulty": "0x64"
}
},
Expand Down
2 changes: 1 addition & 1 deletion config/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -972,7 +972,7 @@ pub static G_PROXIMA_CONFIG: Lazy<GenesisConfig> = Lazy::new(|| {
GenesisConfig {
genesis_block_parameter: GenesisBlockParameterConfig::Static(GenesisBlockParameter {
parent_hash: HashValue::sha3_256_of(b"starcoin_proxima"),
timestamp: 1659383200000,
timestamp: 1661944080000,
difficulty: 100.into(),
}),
version: Version { major: 1 },
Expand Down
9 changes: 6 additions & 3 deletions etc/starcoin_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,8 @@ StateKey:
TYPENAME: AccessPath
1:
TableItem:
STRUCT:
- handle: U128
- key: BYTES
NEWTYPE:
TYPENAME: TableItem
StructTag:
STRUCT:
- address:
Expand All @@ -221,6 +220,10 @@ StructTag:
- type_args:
SEQ:
TYPENAME: TypeTag
TableItem:
STRUCT:
- handle: U128
- key: BYTES
Transaction:
ENUM:
0:
Expand Down
Binary file modified generated/proxima/genesis
Binary file not shown.
Binary file modified genesis/generated/proxima/genesis
Binary file not shown.
5 changes: 3 additions & 2 deletions network-rpc/api/src/remote_chain_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ impl StateView for RemoteChainStateReader {
let state_proof = self.get_with_proof(access_path)?;
Ok(state_proof.state)
}
StateKey::TableItem { handle, key } => {
let state_proof = self.get_with_table_item_proof(handle, key)?;
StateKey::TableItem(table_item) => {
let state_proof =
self.get_with_table_item_proof(&table_item.handle, &table_item.key)?;
Ok(state_proof.key_proof.0)
}
}
Expand Down
1 change: 0 additions & 1 deletion rpc/api/src/contract_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ pub trait ContractApi {
raw_txn: String,
sender_public_key: StrView<AccountPublicKey>,
) -> FutureResult<DryRunOutputView>;

#[rpc(name = "contract.resolve_function")]
fn resolve_function(&self, function_id: FunctionIdView) -> FutureResult<FunctionABI>;
#[rpc(name = "contract.resolve_module_function_index")]
Expand Down
100 changes: 73 additions & 27 deletions rpc/api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ use starcoin_accumulator::accumulator_info::AccumulatorInfo;
use starcoin_chain_api::{EventWithProof, TransactionInfoWithProof};
use starcoin_types::account_address::AccountAddress;
use starcoin_vm_types::move_resource::MoveResource;
use starcoin_vm_types::state_store::state_key::StateKey;
use starcoin_vm_types::state_store::state_key::{StateKey, TableItem};
pub use vm_status_translator::VmStatusExplainView;

#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
Expand All @@ -1097,52 +1097,63 @@ pub struct TransactionOutputView {
pub gas_used: StrView<u64>,
pub write_set: Vec<TransactionOutputAction>,
pub events: Vec<TransactionEventView>,
pub table_item_write_set: Vec<TransactionOutputTableItemAction>,
}

impl From<TransactionOutput> for TransactionOutputView {
fn from(txn_output: TransactionOutput) -> Self {
let (write_set, events, gas_used, status) = txn_output.into_inner();
let mut access_write_set = vec![];
let mut table_item_write_set = vec![];
for (state_key, op) in write_set {
match state_key {
StateKey::AccessPath(access_path) => {
access_write_set.push((access_path, op));
}
StateKey::TableItem(table_item) => {
table_item_write_set.push((table_item, op));
}
}
}
Self {
events: events.into_iter().map(Into::into).collect(),
gas_used: gas_used.into(),
status: status.into(),
write_set: write_set
write_set: access_write_set
.into_iter()
.map(TransactionOutputAction::from)
.collect(),
table_item_write_set: table_item_write_set
.into_iter()
.map(TransactionOutputTableItemAction::from)
.collect(),
}
}
}
impl From<(StateKey, WriteOp)> for TransactionOutputAction {
fn from((state_key, op): (StateKey, WriteOp)) -> Self {
impl From<(AccessPath, WriteOp)> for TransactionOutputAction {
fn from((access_path, op): (AccessPath, WriteOp)) -> Self {
let (action, value) = match op {
WriteOp::Deletion => (WriteOpView::Deletion, None),
WriteOp::Value(v) => (
WriteOpView::Value,
match &state_key {
StateKey::AccessPath(access_path) => Some(if access_path.path.is_resource() {
WriteOpValueView::Resource(v.into())
} else {
WriteOpValueView::Code(v.into())
}),
StateKey::TableItem { handle: _, key: _ } => {
Some(WriteOpValueView::Str(StrView(v)))
}
},
Some(if access_path.path.is_resource() {
WriteOpValueView::Resource(v.into())
} else {
WriteOpValueView::Code(v.into())
}),
),
};

TransactionOutputAction {
state_key: state_key.into(),
access_path,
action,
value,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct TransactionOutputAction {
// pub access_path: AccessPath,
pub state_key: StateKeyView,
pub access_path: AccessPath,
pub action: WriteOpView,
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<WriteOpValueView>,
Expand All @@ -1152,7 +1163,6 @@ pub struct TransactionOutputAction {
pub enum WriteOpValueView {
Code(CodeView),
Resource(ResourceView),
Str(StrView<Vec<u8>>),
}

#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
Expand All @@ -1161,6 +1171,29 @@ pub enum WriteOpView {
Value,
}

impl From<(TableItem, WriteOp)> for TransactionOutputTableItemAction {
fn from((table_item, op): (TableItem, WriteOp)) -> Self {
let (action, value) = match op {
WriteOp::Deletion => (WriteOpView::Deletion, None),
WriteOp::Value(v) => (WriteOpView::Value, Some(StrView(v))),
};

TransactionOutputTableItemAction {
table_item: table_item.into(),
action,
value,
}
}
}

#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct TransactionOutputTableItemAction {
pub table_item: TableItemView,
pub action: WriteOpView,
#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<StrView<Vec<u8>>>,
}

#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct ChainInfoView {
pub chain_id: u8,
Expand Down Expand Up @@ -1745,26 +1778,39 @@ impl From<BlockInfo> for BlockInfoView {
}
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(rename = "table_item")]
pub struct TableItemView {
handle: StrView<u128>,
#[schemars(with = "String")]
key: Vec<u8>,
}

impl From<TableItem> for TableItemView {
fn from(table_item: TableItem) -> Self {
Self {
handle: table_item.handle.into(),
key: table_item.key,
}
}
}

#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, JsonSchema)]
pub enum StateKeyView {
#[serde(rename = "access_path")]
AccessPath(AccessPath),
#[serde(rename = "table_item")]
TableItem {
handle: StrView<u128>,
#[schemars(with = "String")]
key: Vec<u8>,
},
TableItem(TableItemView),
}

impl From<StateKey> for StateKeyView {
fn from(state_key: StateKey) -> Self {
match state_key {
StateKey::AccessPath(access_path) => Self::AccessPath(access_path),
StateKey::TableItem { handle, key } => Self::TableItem {
handle: handle.into(),
key,
},
StateKey::TableItem(table_item) => Self::TableItem(TableItemView {
handle: table_item.handle.into(),
key: table_item.key,
}),
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions rpc/client/src/remote_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,13 @@ impl<'a> StateView for RemoteStateReader<'a> {
.state_get_with_proof_by_root(access_path.clone(), self.state_root())?
.state
.map(|v| v.0)),
StateKey::TableItem { handle, key } => Ok(self
StateKey::TableItem(table_item) => Ok(self
.client
.state_get_with_table_item_proof_by_root(*handle, key.clone(), self.state_root())?
.state_get_with_table_item_proof_by_root(
table_item.handle,
table_item.key.clone(),
self.state_root(),
)?
.key_proof
.0
.map(|v| v.0)),
Expand Down
Loading

0 comments on commit e4389f2

Please sign in to comment.