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

support move language v6 and new gas meter #3838

Merged
merged 72 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
5de1500
[compiler] update move
LemonHX Jun 2, 2022
8e321b4
Merge branch 'master' into update_move
LemonHX Jun 6, 2022
11eaff5
gen new stdlib
LemonHX Jun 6, 2022
d9fabca
fix warning: add phantom for merkle distributor
LemonHX Jun 9, 2022
3f50159
update move version
LemonHX Jun 22, 2022
e03b64b
fix Identifier merge
LemonHX Jun 23, 2022
a8bd54b
Update module_upgrade_test.rs
LemonHX Jun 25, 2022
fcb85fc
update script
LemonHX Jun 30, 2022
d26b12e
Merge branch 'master' into update_move
LemonHX Jun 30, 2022
5c4d0b3
check commit
LemonHX Jun 30, 2022
76d7894
1.add table native functions
nkysg Jul 7, 2022
1fd0799
1.add StateKey,MoveExt, SessionId,MoveResolveExt
nkysg Jul 7, 2022
71ed0a5
Merge branch 'master' into update_move
nkysg Jul 7, 2022
70786de
add contract_api.json
nkysg Jul 7, 2022
ab68cbc
1.add halley genesis
nkysg Jul 7, 2022
a86860a
gen new stdlib
nkysg Jul 7, 2022
50ee42a
Merge branch 'master' into update_move
LemonHX Jul 11, 2022
91da2b2
Merge branch 'master' into update_move
LemonHX Jul 11, 2022
532470c
fix lock
LemonHX Jul 11, 2022
38b1122
update move repo
nkysg Jul 11, 2022
ad56d3e
add move table extension flush
nkysg Jul 11, 2022
0c50094
add statedb support move table extension with commit and flush
nkysg Jul 12, 2022
c89762d
remove WriteAccessPathSet and refactor code
nkysg Jul 12, 2022
7abd16f
Merge branch 'master' into update_move
nkysg Jul 12, 2022
0924d4d
remove unused code
nkysg Jul 12, 2022
df4c523
add halley genesis
nkysg Jul 13, 2022
3529979
add halley genesis
nkysg Jul 13, 2022
f2e99da
remove file
nkysg Jul 13, 2022
e0c0e95
fix bug
nkysg Jul 13, 2022
8090bd2
add halley genesis
nkysg Jul 13, 2022
8d46608
add table item test code
nkysg Jul 13, 2022
c48e5d2
fix warnings
nkysg Jul 13, 2022
a9dbbae
update move repo
nkysg Jul 20, 2022
5f99371
Merge branch 'master' into update_move
nkysg Jul 20, 2022
34fdbe3
fix fmt
nkysg Jul 20, 2022
ecd9d5f
reset proxima
nkysg Jul 20, 2022
f555439
add proxima genesis_config.json
nkysg Jul 20, 2022
83f1192
branch update_move add docker build
nkysg Jul 20, 2022
5c0af6a
add table_info storage
nkysg Jul 21, 2022
b56d0ff
update starcoin-framework repo
nkysg Jul 21, 2022
eba3f68
fix clippy warnings
nkysg Jul 21, 2022
21d6667
reset proxima genesis
nkysg Jul 21, 2022
bdac32f
update docker build
nkysg Jul 21, 2022
35e2e72
Merge branch 'master' into update_move
nkysg Jul 26, 2022
7dfe6df
update starcoin_framework
nkysg Aug 1, 2022
91d9073
gen new stdlib, reset proxima genesis
nkysg Aug 1, 2022
141532d
gen new stdlib, reset proxima genesis
nkysg Aug 1, 2022
9c16d31
gen new stdlib, reset proxima genesis
nkysg Aug 1, 2022
e8e00f0
gen new stdlib, reset proxima genesis
nkysg Aug 1, 2022
9c05929
add TableItemProof
nkysg Jul 29, 2022
62a9085
add TableItemProof
nkysg Aug 3, 2022
ee94b3b
fmt Cargo.toml
nkysg Aug 5, 2022
ff67c97
add TableItemProof unit_test
nkysg Aug 8, 2022
4de7967
change StateKeyView serde Field attributes
nkysg Aug 9, 2022
084a3e1
fix pre_lib
nkysg Aug 12, 2022
6a2d5ac
[Feature]Add string module (#3626)
WGB5445 Aug 16, 2022
dd85be3
add manual dispatch to workflow build and test
nkysg Aug 17, 2022
12f9416
add pr build_test
nkysg Sep 1, 2022
dabeb6f
fix execute script (#3705)
nkysg Sep 2, 2022
fa99f3f
fix mpm package table test (#3715)
nkysg Sep 5, 2022
e4389f2
[dev branch]table extension compatible dry run (#3706)
nkysg Sep 13, 2022
0c095dc
close #3732
LemonHX Sep 14, 2022
60ec947
mpm: remove tmp code
nanne007 Sep 22, 2022
a367145
Merge branch 'master' into dev
nkysg Oct 13, 2022
2708122
[dev]Update docker_build.yml docker/setup-buildx-action to 2, Docker…
jiangying000 Oct 8, 2022
8eba92a
[dev] remove starcoin-x package,update script and config (#3772)
jiangying000 Oct 9, 2022
40acaa0
use BAD_TRANSACTION_FEE_CURRENCY for test
nkysg Oct 13, 2022
c5e39a1
Merge branch 'master' into dev
nkysg Feb 6, 2023
edba7d7
Merge branch 'master' into dev
nkysg Feb 7, 2023
c6fb713
abi support u16, u32, u256
nkysg Feb 10, 2023
bbb514e
abi support u16, u32, u256
nkysg Feb 10, 2023
07ba45d
update rpc schema
nkysg Feb 10, 2023
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
Prev Previous commit
Next Next commit
add statedb support move table extension with commit and flush
  • Loading branch information
nkysg committed Jul 12, 2022
commit 0c50094e9260fc4b6f51ae73dec8e1f2232b3587
8 changes: 8 additions & 0 deletions network-rpc/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,11 @@ pub trait NetworkRpc: Sized + Send + Sync + 'static {
ids: Vec<HashValue>,
) -> BoxFuture<Result<Vec<Option<Block>>>>;
}

/// XXX FIXME YSG
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GetTableItemStateWithProof {
pub state_root: HashValue,
pub table_item: u128,
pub key: Vec<u8>,
}
5 changes: 5 additions & 0 deletions network-rpc/api/src/remote_chain_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ impl ChainStateReader for RemoteChainStateReader {
fn dump_iter(&self) -> Result<AccountStateSetIterator> {
unimplemented!()
}

fn get_table_item_with_proof(&self, _handle: u128, _key: &[u8]) -> Result<StateWithProof> {
// XXX FIXME YSG
todo!()
}
}

impl StateView for RemoteChainStateReader {
Expand Down
5 changes: 5 additions & 0 deletions rpc/client/src/remote_state_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ impl<'a> ChainStateReader for RemoteStateReader<'a> {
fn dump_iter(&self) -> Result<AccountStateSetIterator> {
unimplemented!()
}

fn get_table_item_with_proof(&self, _handle: u128, _key: &[u8]) -> Result<StateWithProof> {
// XXX FIXME YSG
todo!()
}
}

impl<'a> StateView for RemoteStateReader<'a> {
Expand Down
2 changes: 2 additions & 0 deletions state/api/src/chain_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ pub trait ChainStateReader: StateView {
fn dump(&self) -> Result<ChainStateSet>;

fn dump_iter(&self) -> Result<AccountStateSetIterator>;

fn get_table_item_with_proof(&self, _handle: u128, _key: &[u8]) -> Result<StateWithProof>;
}

pub trait ChainStateWriter {
Expand Down
4 changes: 4 additions & 0 deletions state/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ impl ChainStateReader for Inner {
fn dump_iter(&self) -> Result<AccountStateSetIterator> {
unimplemented!()
}

fn get_table_item_with_proof(&self, handle: u128, key: &[u8]) -> Result<StateWithProof> {
self.state_db.get_table_item_with_proof(handle, key)
}
}

impl StateView for Inner {
Expand Down
107 changes: 63 additions & 44 deletions state/statedb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,15 @@ pub struct ChainStateDB {
updates: RwLock<HashSet<AccountAddress>>,
updates_table_handle: RwLock<HashSet<TableHandle>>,
cache_table_handle: Mutex<LruCache<TableHandle, Arc<TableHandleStateObject>>>,
state_tree_table_handle: StateTree<TableHandleKey>,
// SMT save TableHandle -> TableHandleState.root_hash
state_tree_table_handles: StateTree<TableHandleKey>,
}

static G_DEFAULT_CACHE_SIZE: usize = 10240;

static TABLE_PATH: Lazy<DataPath> = Lazy::new(|| {
let str = format!(
"{}/1/{}::TableHandle::TableHandle",
"{}/1/{}::TableHandles::TableHandles",
table_handle_address(),
table_handle_address()
);
Expand All @@ -250,7 +251,7 @@ impl ChainStateDB {
updates: RwLock::new(HashSet::new()),
updates_table_handle: RwLock::new(HashSet::new()),
cache_table_handle: Mutex::new(LruCache::new(G_DEFAULT_CACHE_SIZE)),
state_tree_table_handle: StateTree::new(store.clone(), None),
state_tree_table_handles: StateTree::new(store.clone(), None),
};
let account_state_object = chain_statedb
.get_account_state_object(&table_handle_address(), true)
Expand All @@ -259,7 +260,7 @@ impl ChainStateDB {
// XXX FIXME YSG
if let Some(state_root) = state_root {
let hash = HashValue::from_slice(state_root.as_slice()).unwrap();
chain_statedb.state_tree_table_handle = StateTree::new(store, Some(hash));
chain_statedb.state_tree_table_handles = StateTree::new(store, Some(hash));
}
chain_statedb
}
Expand Down Expand Up @@ -347,13 +348,17 @@ impl ChainStateDB {
Some(item) => item.clone(),
None => {
let val = self
.state_tree_table_handle
.state_tree_table_handles
.get(&TableHandleKey(handle.0))?;
let hash = match val {
Some(val) => HashValue::from_slice(val)?,
None => *SPARSE_MERKLE_PLACEHOLDER_HASH,
};
let obj = Arc::new(TableHandleStateObject::new(hash, self.store.clone()));
let obj = Arc::new(TableHandleStateObject::new(
*handle,
hash,
self.store.clone(),
));
cache.put(*handle, obj.clone());
obj
}
Expand All @@ -374,10 +379,10 @@ impl StateView for ChainStateDB {
None => Ok(None),
})
}
StateKey::TableItem { handle: _, key: _ } => {
// XXX FIXME YSG
// unimplemented!()
Ok(None)
StateKey::TableItem { handle, key } => {
let table_handle_state_object =
self.get_table_handle_state_object(&TableHandle(*handle))?;
table_handle_state_object.get(key)
}
}
}
Expand Down Expand Up @@ -488,6 +493,11 @@ impl ChainStateReader for ChainStateDB {
let iter = AccountStateSetIterator::new(self.store.clone(), jmt_into_iter);
Ok(iter)
}

fn get_table_item_with_proof(&self, _handle: u128, _key: &[u8]) -> Result<StateWithProof> {
// XXX FIXME YSG
todo!()
}
}

impl ChainStateWriter for ChainStateDB {
Expand Down Expand Up @@ -540,7 +550,6 @@ impl ChainStateWriter for ChainStateDB {
}

fn apply_write_set(&self, write_set: WriteSet) -> Result<()> {
// XXX FIXME YSG
let mut locks = self.updates.write();
for (state_key, write_op) in write_set {
//update self updates record
Expand All @@ -561,18 +570,36 @@ impl ChainStateWriter for ChainStateDB {
}
}
}
StateKey::TableItem { handle: _, key: _ } => {
// XXX FIXME YSG
// unimplemented!()
}
StateKey::TableItem { handle: _, key: _ } => {}
}
}
Ok(())
}
/// Commit
fn commit(&self) -> Result<HashValue> {
// cache commit
// XXX FIXME YSG
for handle in self.updates_table_handle.read().iter() {
let table_handle_state_object = self.get_table_handle_state_object(handle)?;
table_handle_state_object.commit()?;
// put table_handle_state_object commit
self.state_tree_table_handles.put(
TableHandleKey(handle.0),
table_handle_state_object.root_hash().to_vec(),
);
}
self.state_tree_table_handles.commit()?;

// update table_handle_address state
let mut locks = self.updates.write();
locks.insert(table_handle_address());
let table_handle_account_state_object =
self.get_account_state_object(&table_handle_address(), true)?;
table_handle_account_state_object.set(
TABLE_PATH.clone(),
self.state_tree_table_handles.root_hash().to_vec(),
);
locks.clear();

for address in self.updates.read().iter() {
let account_state_object = self.get_account_state_object(address, false)?;
let state = account_state_object.commit()?;
Expand All @@ -584,24 +611,24 @@ impl ChainStateWriter for ChainStateDB {
/// flush data to db.
fn flush(&self) -> Result<()> {
//cache flush
let mut locks = self.updates.write();
for address in locks.iter() {
let account_state_object = self.get_account_state_object(address, false)?;
account_state_object.flush()?;
}
locks.clear();
let mut locks_table_handle = self.updates_table_handle.write();
for h in locks_table_handle.iter() {
let table_handle_state_object = self.get_table_handle_state_object(h)?;
table_handle_state_object.flush()?;
let _root_hash = table_handle_state_object.root_hash();
// self.state_tree_table_handle.lock().
}
locks_table_handle.clear();

self.state_tree_table_handles.flush()?;

let mut locks = self.updates.write();
for address in locks.iter() {
let account_state_object = self.get_account_state_object(address, false)?;
account_state_object.flush()?;
}
locks.clear();

// self tree flush
// self.state_tree.update state_tree_table_handle_root
self.state_tree.flush()
// XXX FIXME STATE_ROOT
}

fn apply_write_set_and_change_set(
Expand All @@ -610,8 +637,8 @@ impl ChainStateWriter for ChainStateDB {
table_change_set: TableChangeSet,
) -> Result<()> {
let TableChangeSet {
new_tables,
removed_tables,
new_tables: _,
removed_tables: _,
changes,
} = table_change_set;
let mut lock_table_handle = self.updates_table_handle.write();
Expand All @@ -627,33 +654,22 @@ impl ChainStateWriter for ChainStateDB {
}
}
self.apply_write_set(write_set)

/*
let mut table_updates = self.tables.write();
table_updates.extend(new_tables.into_iter().map(|h|(h, BTreeMap::default())));
let state_root = self.state_root();
for (h, c) in changes {
assert!(table_updates.contains_key(&h), "inconsistent table change set: stale table handle");
let table = table_updates.get_mut(&h).unwrap();
for (key, val) in c.entries {
table.insert(key, val);
}
} */
}
}

/// represent TableHandleState in runtime memory.
/// TableHandle's SMT Save (table.key, table.value)
struct TableHandleStateObject {
_handle: TableHandle,
state_tree: Mutex<StateTree<Vec<u8>>>,
// store: Arc<dyn StateNodeStore>,
}

impl TableHandleStateObject {
pub fn new(root: HashValue, store: Arc<dyn StateNodeStore>) -> Self {
pub fn new(_handle: TableHandle, root: HashValue, store: Arc<dyn StateNodeStore>) -> Self {
let state_tree = StateTree::<Vec<u8>>::new(store.clone(), Some(root));
Self {
_handle,
state_tree: Mutex::new(state_tree),
//store,
}
}

Expand All @@ -666,7 +682,6 @@ impl TableHandleStateObject {
}

pub fn commit(&self) -> Result<()> {
// XXX FIXME YSG
let state_tree = self.state_tree.lock();
if state_tree.is_dirty() {
state_tree.commit()?;
Expand All @@ -682,6 +697,10 @@ impl TableHandleStateObject {
pub fn root_hash(&self) -> HashValue {
self.state_tree.lock().root_hash()
}

pub fn get(&self, key: &Vec<u8>) -> Result<Option<Vec<u8>>> {
self.state_tree.lock().get(key)
}
}

#[cfg(test)]
Expand Down
12 changes: 9 additions & 3 deletions vm/starcoin-transactional-test-harness/src/remote_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,16 @@ where
fn apply_write_set_and_change_set(
&self,
write_set: WriteSet,
_table_change_set: TableChangeSet,
table_change_set: TableChangeSet,
) -> Result<()> {
// XXX FIXME YSG
self.apply_write_set(write_set)
match self {
SelectableStateView::A(a) => {
a.apply_write_set_and_change_set(write_set, table_change_set)
}
SelectableStateView::B(b) => {
b.apply_write_set_and_change_set(write_set, table_change_set)
}
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions vm/types/src/unit_tests/access_path_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::access_path::{AccessPath, DataType};
use crate::account_address::AccountAddress;
use crate::account_config::table_handle_address;
#[cfg(any(test, feature = "fuzzing"))]
use proptest::prelude::*;
use std::str::FromStr;
Expand All @@ -18,8 +17,7 @@ fn test_data_type() {
fn test_access_path_str_valid() {
let r1 = format!(
"{}/1/0x00000000000000000000000000000001::Account::Account",
//AccountAddress::random()
table_handle_address()
AccountAddress::random()
);
let test_cases = vec!["0x00000000000000000000000000000000/0/Account",
"0x00000000000000000000000000000001/0/Account",
Expand All @@ -28,7 +26,6 @@ fn test_access_path_str_valid() {
r1.as_str()];
for case in test_cases {
let access_path = AccessPath::from_str(case).unwrap();
println!("{:?} {}", access_path.path.data_type(), access_path);
assert_eq!(case.to_owned(), access_path.to_string())
}
}
Expand Down