Skip to content

Commit a992541

Browse files
author
Seulgi Kim
authored
Merge branch 'master' into feature/cleanups
2 parents c407403 + fc6fec0 commit a992541

File tree

28 files changed

+90
-2134
lines changed

28 files changed

+90
-2134
lines changed

Cargo.lock

Lines changed: 9 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ parking_lot = "0.6.0"
3535
primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" }
3636
rand = "0.6.1"
3737
rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" }
38-
rlp_compress = { path = "../util/rlp_compress" }
39-
rlp_derive = { path = "../util/rlp_derive" }
38+
rlp_compress = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.2" }
39+
rlp_derive = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.2" }
4040
snap = "0.2"
4141
table = { path = "../util/table" }
4242
util-error = { path = "../util/error" }

core/src/consensus/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ pub trait ConsensusEngine: Sync + Send {
201201
}
202202

203203
/// Phase 3 verification. Check block information against parent. Returns either a null `Ok` or a general error detailing the problem with import.
204+
/// The verification must be conducted only with the two headers' information because it does not guarantee whether the two corresponding bodies have been imported.
204205
fn verify_block_family(&self, _header: &Header, _parent: &Header) -> Result<(), Error> {
205206
Ok(())
206207
}

core/src/scheme/scheme.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::sync::Arc;
2020
use ccrypto::{blake256, BLAKE_NULL_RLP};
2121
use cjson;
2222
use ckey::Address;
23-
use cmerkle::TrieFactory;
23+
use cmerkle::{TrieFactory, TrieMut};
2424
use cstate::{Metadata, MetadataAddress, Shard, ShardAddress, StateDB, StateResult, StateWithCache, TopLevelState};
2525
use ctypes::errors::SyntaxError;
2626
use ctypes::{BlockHash, CommonParams, Header, ShardId};

network/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ never-type = "0.1.0"
2020
parking_lot = "0.6.0"
2121
rand = "0.6.1"
2222
rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" }
23-
rlp_derive = { path = "../util/rlp_derive" }
23+
rlp_derive = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.2" }
2424
table = { path = "../util/table" }
2525
time = "0.1"
2626
token-generator = "0.1.0"

state/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ lru-cache = "0.1.1"
2020
parking_lot = "0.6.0"
2121
primitives = { git = "https://github.com/CodeChain-io/rust-codechain-primitives.git", version = "0.4" }
2222
rlp = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.4" }
23-
rlp_derive = { path = "../util/rlp_derive" }
23+
rlp_derive = { git = "https://github.com/CodeChain-io/rlp.git", version = "0.2" }
2424
rustc-hex = "1.0"
2525
util-error = { path = "../util/error" }

state/src/cache/shard_cache.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
use std::cell::RefMut;
1818

19-
use cmerkle::{Result as TrieResult, TrieDB, TrieMut};
19+
use cmerkle::{Result as TrieResult, Trie, TrieMut};
2020

2121
use super::WriteBack;
2222
use crate::{AssetScheme, AssetSchemeAddress, OwnedAsset, OwnedAssetAddress};
@@ -58,11 +58,11 @@ impl ShardCache {
5858
Ok(())
5959
}
6060

61-
pub fn asset_scheme(&self, a: &AssetSchemeAddress, db: &TrieDB) -> TrieResult<Option<AssetScheme>> {
61+
pub fn asset_scheme(&self, a: &AssetSchemeAddress, db: &dyn Trie) -> TrieResult<Option<AssetScheme>> {
6262
self.asset_scheme.get(a, db)
6363
}
6464

65-
pub fn asset_scheme_mut(&self, a: &AssetSchemeAddress, db: &TrieDB) -> TrieResult<RefMut<AssetScheme>> {
65+
pub fn asset_scheme_mut(&self, a: &AssetSchemeAddress, db: &dyn Trie) -> TrieResult<RefMut<AssetScheme>> {
6666
self.asset_scheme.get_mut(a, db)
6767
}
6868

@@ -72,7 +72,7 @@ impl ShardCache {
7272
self.asset_scheme.create(a, f)
7373
}
7474

75-
pub fn asset(&self, a: &OwnedAssetAddress, db: &TrieDB) -> TrieResult<Option<OwnedAsset>> {
75+
pub fn asset(&self, a: &OwnedAssetAddress, db: &dyn Trie) -> TrieResult<Option<OwnedAsset>> {
7676
self.asset.get(a, db)
7777
}
7878

state/src/cache/top_cache.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use std::cell::RefMut;
1818

1919
use ckey::Address;
20-
use cmerkle::{Result as TrieResult, TrieDB, TrieMut};
20+
use cmerkle::{Result as TrieResult, Trie, TrieMut};
2121
use primitives::H256;
2222

2323
use super::WriteBack;
@@ -90,43 +90,43 @@ impl TopCache {
9090
Ok(())
9191
}
9292

93-
pub fn account(&self, a: &Address, db: &TrieDB) -> TrieResult<Option<Account>> {
93+
pub fn account(&self, a: &Address, db: &dyn Trie) -> TrieResult<Option<Account>> {
9494
self.account.get(a, db)
9595
}
9696

97-
pub fn account_mut(&self, a: &Address, db: &TrieDB) -> TrieResult<RefMut<Account>> {
97+
pub fn account_mut(&self, a: &Address, db: &dyn Trie) -> TrieResult<RefMut<Account>> {
9898
self.account.get_mut(a, db)
9999
}
100100

101101
pub fn remove_account(&self, address: &Address) {
102102
self.account.remove(address)
103103
}
104104

105-
pub fn regular_account(&self, a: &RegularAccountAddress, db: &TrieDB) -> TrieResult<Option<RegularAccount>> {
105+
pub fn regular_account(&self, a: &RegularAccountAddress, db: &dyn Trie) -> TrieResult<Option<RegularAccount>> {
106106
self.regular_account.get(a, db)
107107
}
108108

109-
pub fn regular_account_mut(&self, a: &RegularAccountAddress, db: &TrieDB) -> TrieResult<RefMut<RegularAccount>> {
109+
pub fn regular_account_mut(&self, a: &RegularAccountAddress, db: &dyn Trie) -> TrieResult<RefMut<RegularAccount>> {
110110
self.regular_account.get_mut(a, db)
111111
}
112112

113113
pub fn remove_regular_account(&self, address: &RegularAccountAddress) {
114114
self.regular_account.remove(address)
115115
}
116116

117-
pub fn metadata(&self, a: &MetadataAddress, db: &TrieDB) -> TrieResult<Option<Metadata>> {
117+
pub fn metadata(&self, a: &MetadataAddress, db: &dyn Trie) -> TrieResult<Option<Metadata>> {
118118
self.metadata.get(a, db)
119119
}
120120

121-
pub fn metadata_mut(&self, a: &MetadataAddress, db: &TrieDB) -> TrieResult<RefMut<Metadata>> {
121+
pub fn metadata_mut(&self, a: &MetadataAddress, db: &dyn Trie) -> TrieResult<RefMut<Metadata>> {
122122
self.metadata.get_mut(a, db)
123123
}
124124

125-
pub fn shard(&self, a: &ShardAddress, db: &TrieDB) -> TrieResult<Option<Shard>> {
125+
pub fn shard(&self, a: &ShardAddress, db: &dyn Trie) -> TrieResult<Option<Shard>> {
126126
self.shard.get(a, db)
127127
}
128128

129-
pub fn shard_mut(&self, a: &ShardAddress, db: &TrieDB) -> TrieResult<RefMut<Shard>> {
129+
pub fn shard_mut(&self, a: &ShardAddress, db: &dyn Trie) -> TrieResult<RefMut<Shard>> {
130130
self.shard.get_mut(a, db)
131131
}
132132

@@ -135,23 +135,23 @@ impl TopCache {
135135
self.shard.remove(address)
136136
}
137137

138-
pub fn text(&self, a: &H256, db: &TrieDB) -> TrieResult<Option<Text>> {
138+
pub fn text(&self, a: &H256, db: &dyn Trie) -> TrieResult<Option<Text>> {
139139
self.text.get(a, db)
140140
}
141141

142-
pub fn text_mut(&self, a: &H256, db: &TrieDB) -> TrieResult<RefMut<Text>> {
142+
pub fn text_mut(&self, a: &H256, db: &dyn Trie) -> TrieResult<RefMut<Text>> {
143143
self.text.get_mut(a, db)
144144
}
145145

146146
pub fn remove_text(&self, address: &H256) {
147147
self.text.remove(address);
148148
}
149149

150-
pub fn action_data(&self, a: &H256, db: &TrieDB) -> TrieResult<Option<ActionData>> {
150+
pub fn action_data(&self, a: &H256, db: &dyn Trie) -> TrieResult<Option<ActionData>> {
151151
self.action_data.get(a, db)
152152
}
153153

154-
pub fn action_data_mut(&self, a: &H256, db: &TrieDB) -> TrieResult<RefMut<ActionData>> {
154+
pub fn action_data_mut(&self, a: &H256, db: &dyn Trie) -> TrieResult<RefMut<ActionData>> {
155155
self.action_data.get_mut(a, db)
156156
}
157157

state/src/cache/write_back.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::fmt;
2222
use std::sync::atomic::{AtomicUsize, Ordering};
2323
use std::vec::Vec;
2424

25-
use cmerkle::{self, Result as TrieResult, Trie, TrieDB, TrieMut};
25+
use cmerkle::{self, Result as TrieResult, Trie, TrieMut};
2626

2727
use super::CacheableItem;
2828

@@ -195,25 +195,25 @@ where
195195
/// Check caches for required data
196196
/// First searches for account in the local, then the shared cache.
197197
/// Populates local cache if nothing found.
198-
pub fn get(&self, a: &Item::Address, db: &TrieDB) -> cmerkle::Result<Option<Item>> {
198+
pub fn get(&self, a: &Item::Address, db: &dyn Trie) -> cmerkle::Result<Option<Item>> {
199199
// check local cache first
200200
if let Some(cached_item) = self.cache.borrow_mut().get_mut(a) {
201201
cached_item.touched = touched_count();
202202
return Ok(cached_item.item.clone())
203203
}
204204

205205
// not found in the cache, get from the DB and insert into cache
206-
let maybe_item = db.get_with(a.as_ref(), &|bytes| ::rlp::decode::<Item>(bytes).unwrap())?;
206+
let maybe_item = db.get(a.as_ref())?.map(|bytes| ::rlp::decode::<Item>(&bytes).unwrap());
207207
self.insert(a, Entry::<Item>::new_clean(maybe_item.clone()));
208208
Ok(maybe_item)
209209
}
210210

211211
/// Pull item `a` in our cache from the trie DB.
212212
/// If it doesn't exist, make item equal the evaluation of `default`.
213-
pub fn get_mut(&self, a: &Item::Address, db: &TrieDB) -> cmerkle::Result<RefMut<Item>> {
213+
pub fn get_mut(&self, a: &Item::Address, db: &dyn Trie) -> cmerkle::Result<RefMut<Item>> {
214214
let contains_key = self.cache.borrow().contains_key(a);
215215
if !contains_key {
216-
let maybe_item = db.get_with(a.as_ref(), &|bytes| ::rlp::decode::<Item>(bytes).unwrap())?;
216+
let maybe_item = db.get(a.as_ref())?.map(|bytes| ::rlp::decode::<Item>(&bytes).unwrap());
217217
self.insert(a, Entry::<Item>::new_clean(maybe_item));
218218
}
219219
self.note(a);

state/src/impls/top_level.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ impl StateWithCache for TopLevelState {
173173

174174
let shard_cache = self.shard_caches.get_mut(&shard_id).expect("Shard must exist");
175175

176-
shard_cache.commit(&mut *trie)?;
176+
shard_cache.commit(&mut trie)?;
177177
}
178178
self.set_shard_root(shard_id, shard_root)?;
179179
}
180180
{
181181
let mut db = self.db.borrow_mut();
182182
let mut trie = TrieFactory::from_existing(db.as_hashdb_mut(), &mut self.root)?;
183-
self.top_cache.commit(&mut *trie)?;
183+
self.top_cache.commit(&mut trie)?;
184184
}
185185
Ok(self.root)
186186
}

0 commit comments

Comments
 (0)