Skip to content

Commit 91447b0

Browse files
committed
Merge remote-tracking branch 'NYBACHOK/quick-fix-caching' into joneskm/staking3
2 parents 47927f0 + 5a0664d commit 91447b0

4 files changed

Lines changed: 34 additions & 1 deletion

File tree

gears/src/baseapp/abci.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ impl<DB: Database, PSK: ParamsSubspaceKey, H: ABCIHandler, AI: ApplicationInfo>
278278
let consensus_params = self.baseapp_params_keeper.consensus_params(&ctx);
279279

280280
state.replace_meter(Gas::from(max_gas));
281+
state.take_block_cache(&mut multi_store);
281282

282283
let mut ctx = BlockContext::new(
283284
&mut multi_store,

gears/src/baseapp/state.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ impl<DB: Database, AH: ABCIHandler> ApplicationState<DB, AH> {
4949
.append_block_cache(multi_store);
5050
}
5151

52+
pub fn take_block_cache(&mut self, multi_store: &mut ApplicationMultiBank<DB, AH::StoreKey>) {
53+
let list = self.deliver_mode.multi_store.take_block_cache();
54+
55+
for (key, (insert_list, delete_list)) in list {
56+
let kv_store = multi_store.kv_store_mut(&key);
57+
58+
delete_list.into_iter().for_each(|this| {
59+
kv_store.delete(&this);
60+
});
61+
insert_list
62+
.into_iter()
63+
.for_each(|(key, value)| kv_store.set(key, value));
64+
}
65+
}
66+
5267
pub fn commit(&mut self, multi_store: &mut ApplicationMultiBank<DB, AH::StoreKey>) -> [u8; 32] {
5368
self.check_mode.multi_store.tx_cache_clear();
5469
self.check_mode.multi_store.block_cache_clear();

kv_store/src/bank/kv/transaction.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
borrow::Cow,
3-
collections::HashMap,
3+
collections::{BTreeMap, HashMap, HashSet},
44
ops::RangeBounds,
55
sync::{Arc, RwLock},
66
};
@@ -61,6 +61,10 @@ impl<DB: Database> TransactionKVBank<DB> {
6161
}
6262
}
6363

64+
pub fn take_block_cache(&mut self) -> (BTreeMap<Vec<u8>, Vec<u8>>, HashSet<Vec<u8>>) {
65+
self.block.take()
66+
}
67+
6468
/// Delete value from storage
6569
#[inline]
6670
pub fn delete(&mut self, k: &[u8]) -> Option<Vec<u8>> {

kv_store/src/bank/multi/transaction.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::collections::{BTreeMap, HashSet};
2+
13
use database::{prefix::PrefixDB, Database};
24

35
use crate::{bank::kv::transaction::TransactionKVBank, StoreKey};
@@ -43,4 +45,15 @@ impl<DB: Database, SK: StoreKey> MultiBank<DB, SK, TransactionStore<DB, SK>> {
4345
store.append_block_cache(other.kv_store_mut(sk))
4446
}
4547
}
48+
49+
pub fn take_block_cache(
50+
&mut self,
51+
) -> HashMap<SK, (BTreeMap<Vec<u8>, Vec<u8>>, HashSet<Vec<u8>>)> {
52+
let mut set = HashMap::with_capacity(self.backend.0.len());
53+
for (sk, store) in &mut self.backend.0 {
54+
set.insert(sk.clone(), store.take_block_cache());
55+
}
56+
57+
set
58+
}
4659
}

0 commit comments

Comments
 (0)