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

Move append into AccountStorageEntry #3172

Closed
Closed
Changes from all commits
Commits
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
16 changes: 9 additions & 7 deletions runtime/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,14 @@ impl AccountStorageEntry {
self.status.load(Ordering::Relaxed).into()
}

fn add_account(&self) {
self.count.fetch_add(1, Ordering::Relaxed);
fn append_account(&self, account: &Account) -> Option<u64> {
let res = self.accounts.read().unwrap().append_account(account);
if res.is_some() {
self.count.fetch_add(1, Ordering::Relaxed);
} else {
self.set_status(AccountStorageStatus::StorageFull);
}
res
}

fn remove_account(&self) {
Expand Down Expand Up @@ -377,8 +383,6 @@ impl AccountsDB {
if stores[id].get_status() == AccountStorageStatus::StorageAvailable {
return id;
}
} else {
stores[id].set_status(AccountStorageStatus::StorageFull);
}

loop {
Expand Down Expand Up @@ -419,8 +423,7 @@ impl AccountsDB {
loop {
let result: Option<u64>;
{
let av = &self.storage.read().unwrap()[id].accounts;
result = av.read().unwrap().append_account(acc);
result = self.storage.read().unwrap()[id].append_account(acc);
}
if let Some(val) = result {
offset = val;
Expand Down Expand Up @@ -478,7 +481,6 @@ impl AccountsDB {
fn insert_account_entry(&self, fork: Fork, id: AppendVecId, offset: u64, map: &AccountMap) {
let mut forks = map.write().unwrap();
let stores = self.storage.read().unwrap();
stores[id].add_account();
if let Some((old_id, _)) = forks.insert(fork, (id, offset)) {
stores[old_id].remove_account();
}
Expand Down