Skip to content

Commit

Permalink
update storage len
Browse files Browse the repository at this point in the history
  • Loading branch information
sambley authored and mvines committed Jun 18, 2019
1 parent 8b41a5d commit 44967ab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
11 changes: 10 additions & 1 deletion net/net.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ while [[ -n $1 ]]; do
fi
done

while getopts "h?T:t:o:f:rD:c:Fn:x:s:" opt "${shortArgs[@]}"; do
while getopts "h?T:t:o:f:rD:c:Fn:i:x:s:" opt "${shortArgs[@]}"; do
case $opt in
h | \?)
usage
Expand Down Expand Up @@ -205,6 +205,9 @@ while getopts "h?T:t:o:f:rD:c:Fn:x:s:" opt "${shortArgs[@]}"; do
s)
stakeNodesInGenesisBlock=$OPTARG
;;
i)
nodeAddress=$OPTARG
;;
*)
usage "Error: unhandled option: $opt"
;;
Expand Down Expand Up @@ -684,6 +687,12 @@ sanity)
stop)
stop
;;
stopnode)
stopNode "$nodeAddress" true
;;
startnode)
startNode "$nodeAddress" validator
;;
logs)
fetchRemoteLog() {
declare ipAddress=$1
Expand Down
35 changes: 21 additions & 14 deletions runtime/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ impl Serialize for AccountStorage {
where
S: Serializer,
{
let mut map = serializer.serialize_map(Some(self.0.len()))?;
let mut len: usize = 0;
for storage in self.0.values() {
len += storage.len();
}
let mut map = serializer.serialize_map(Some(len))?;
for fork_storage in self.0.values() {
for (storage_id, account_storage_entry) in fork_storage {
map.serialize_entry(storage_id, &**account_storage_entry)?;
Expand Down Expand Up @@ -323,7 +327,7 @@ impl AccountsDB {
.map_err(|_| AccountsDB::get_io_error("accounts index deserialize error"))?;
let storage: AccountStorage = deserialize_from(&mut stream)
.map_err(|_| AccountsDB::get_io_error("storage deserialize error"))?;
let version: usize = deserialize_from(&mut stream)
let version: u64 = deserialize_from(&mut stream)
.map_err(|_| AccountsDB::get_io_error("write version deserialize error"))?;

let mut ids: Vec<usize> = storage
Expand All @@ -336,7 +340,6 @@ impl AccountsDB {

{
let mut index = self.accounts_index.write().unwrap();
index.account_maps.extend(accounts_index.account_maps);
let union = index.roots.union(&accounts_index.roots);
index.roots = union.cloned().collect();
index.last_root = accounts_index.last_root;
Expand All @@ -345,7 +348,8 @@ impl AccountsDB {
}
self.next_id
.store(ids[ids.len() - 1] + 1, Ordering::Relaxed);
self.write_version.store(version, Ordering::Relaxed);
self.write_version
.fetch_add(version as usize, Ordering::Relaxed);
self.generate_index();
Ok(())
}
Expand Down Expand Up @@ -662,18 +666,17 @@ impl Serialize for AccountsDB {
S: serde::ser::Serializer,
{
use serde::ser::Error;
let len = serialized_size(&self.accounts_index).unwrap()
+ serialized_size(&self.storage).unwrap()
+ std::mem::size_of::<usize>() as u64;
let accounts_index = self.accounts_index.read().unwrap();
let storage = self.storage.read().unwrap();
let len = serialized_size(&*accounts_index).unwrap()
+ serialized_size(&*storage).unwrap()
+ std::mem::size_of::<u64>() as u64;
let mut buf = vec![0u8; len as usize];
let mut wr = Cursor::new(&mut buf[..]);
serialize_into(&mut wr, &self.accounts_index).map_err(Error::custom)?;
serialize_into(&mut wr, &self.storage).map_err(Error::custom)?;
serialize_into(
&mut wr,
&(self.write_version.load(Ordering::Relaxed) as u64),
)
.map_err(Error::custom)?;
let version: u64 = self.write_version.load(Ordering::Relaxed) as u64;
serialize_into(&mut wr, &*accounts_index).map_err(Error::custom)?;
serialize_into(&mut wr, &*storage).map_err(Error::custom)?;
serialize_into(&mut wr, &version).map_err(Error::custom)?;
let len = wr.position() as usize;
serializer.serialize_bytes(&wr.into_inner()[..len])
}
Expand Down Expand Up @@ -1243,6 +1246,10 @@ mod tests {
let mut reader = BufReader::new(&buf[..]);
let daccounts = AccountsDB::new(&paths.paths);
assert!(daccounts.update_from_stream(&mut reader).is_ok());
assert_eq!(
daccounts.write_version.load(Ordering::Relaxed),
accounts.write_version.load(Ordering::Relaxed)
);
check_accounts(&daccounts, &pubkeys, 0, 100, 2);
check_accounts(&daccounts, &pubkeys1, 1, 10, 1);
}
Expand Down
1 change: 1 addition & 0 deletions runtime/src/accounts_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct AccountsIndex<T> {
pub roots: HashSet<Fork>,

//This value that needs to be stored to recover the index from AppendVec
#[serde(skip)]
pub last_root: Fork,
}

Expand Down

0 comments on commit 44967ab

Please sign in to comment.