Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
af6a8fd
init from other pr, have some code up to client (not client db),
cheme Sep 23, 2019
4db0a7f
Dumb state_db implementation, mostly boiler plate, but cannot work as
cheme Sep 24, 2019
19df6e9
TODO2 variant for in memory
cheme Sep 25, 2019
3989fea
traits in place, still need to parameterized with blocknb &| branchix
cheme Sep 25, 2019
6a6606d
passing block hash as state in a convoluted way
cheme Sep 25, 2019
934c800
passing block hash as state in a convoluted way
cheme Sep 25, 2019
5d3d47e
Recover previous branch index code without persistence.
cheme Sep 25, 2019
aeab064
let's remove branch range set of changed and removed in next commit
cheme Sep 26, 2019
57e862e
removed delta in branch (not needed if no persistence)
cheme Sep 26, 2019
4edbf27
Before using range instead of hash (we move range to upper client on
cheme Sep 26, 2019
91b87d7
use also block number for query (when not in statedb we need number).
cheme Sep 26, 2019
966a09f
Fixing finalize state algo.
cheme Sep 27, 2019
a37a32f
remove keys from commit set, this likely indicates broken code, will
cheme Sep 27, 2019
4714b70
put a client test, for rest of test reset_storage and genesis build
cheme Sep 27, 2019
5e90b20
Get needed component from branch history-data
cheme Oct 1, 2019
f6956b1
use history from utils
cheme Oct 1, 2019
9ba8057
Test issue is that query on remove hash do not work
cheme Oct 1, 2019
31c1ee3
test commit set
cheme Oct 2, 2019
6209f4d
fix unpin gc
cheme Oct 2, 2019
70f69b6
missing offstate prunnig handling
cheme Oct 2, 2019
6803c86
previous pruning did not make sense, switch to only storing touched key
cheme Oct 2, 2019
2497575
Figure out pruning (see prune_one/prune_two tests).
cheme Oct 3, 2019
e86fdd2
end fixing pruning test, remainings root lib tests to adjust
cheme Oct 3, 2019
e48cf43
fix gc call block index.
cheme Oct 4, 2019
0e3c65e
state_db tests passing.
cheme Oct 4, 2019
13ea088
fix underflow
cheme Oct 4, 2019
92c699c
before switching to absolute indexing (option<u64> to u64).
cheme Oct 4, 2019
bf79879
complete first test in client db, new todo.
cheme Oct 4, 2019
3913ba7
Merge branch 'master' into chain-aux-merge
cheme Oct 4, 2019
4dc2c8d
serialized with default
cheme Oct 7, 2019
03080c4
serialized with default is useless
cheme Oct 7, 2019
8eb5e07
few warning fix
cheme Oct 7, 2019
c89274d
simplify state machine offstate traits, TODO2 will be simple hashmap
cheme Oct 7, 2019
249770b
further simplify
cheme Oct 7, 2019
69fef43
Remove stub state machine implementation.
cheme Oct 7, 2019
a547560
init offstate for tests, but tests will only be interesting with chil…
cheme Oct 7, 2019
397d510
rem todos
cheme Oct 7, 2019
c133a0b
compact casts
cheme Oct 7, 2019
f197d7d
compact casts
cheme Oct 7, 2019
9846613
quick prune test
cheme Oct 7, 2019
d51e98f
break some lines
cheme Oct 7, 2019
fff7cb5
fix
cheme Oct 7, 2019
d55211a
split commit set to have offstate pruning only when needed.
cheme Oct 8, 2019
27ca685
Fix logic of pruning in client (prior it did not take account of last
cheme Oct 8, 2019
64b4102
No need for special revert unless we create archive mode with pruning
cheme Oct 8, 2019
5072f85
Do not keep deletion in branch storage.
cheme Oct 8, 2019
8f8ecc9
sed renaming of offstate to more generic and less incorect 'kv' (as key
cheme Oct 8, 2019
35bc11e
switch overlay transaction to the inner hashmap storage, only change to
cheme Oct 8, 2019
d111288
Remove commit kv from revert.
cheme Oct 9, 2019
dd9dddb
test db better handling
cheme Oct 9, 2019
df950a5
cleaning pass.
cheme Oct 9, 2019
0ca6530
starting using keyspace, storing in the overlay next to the child trie
cheme Oct 9, 2019
0dd36d0
it is tricky, but clearly getting rid of keyspace in overlayed change
cheme Oct 9, 2019
34cf138
wrong approach (the overlay db code for kv is not strictly needed),
cheme Oct 9, 2019
a732231
a todo
cheme Oct 10, 2019
ae180ed
Slight change to 'into_committed' proto, to allow resolving
cheme Oct 10, 2019
c39385b
Merge branch 'chain-aux2' into kv-keyspace
cheme Oct 10, 2019
d53dbba
boilerplate changes.
cheme Oct 10, 2019
9a3d762
Change trie crate from child_trie_soft_min
cheme Oct 10, 2019
da23a0c
prepare change
cheme Oct 10, 2019
3931280
fix proof test
cheme Oct 10, 2019
f6268ab
need a kv_storage function in backend.
cheme Oct 11, 2019
431f93d
add 'kv_store' to state machine backend
cheme Oct 11, 2019
9ccf87f
Merge branch 'chain-aux2' into kv-keyspace
cheme Oct 11, 2019
2b4dad9
state machine missing functions.
cheme Oct 11, 2019
fc16bae
fix other modules compilation.
cheme Oct 11, 2019
ec10b6d
revert into_committed and TODO for caching that is major (child root
cheme Oct 11, 2019
1209ac7
apply renaming
cheme Oct 11, 2019
0eed411
Get and modify previous transaction test.
cheme Oct 11, 2019
42bbd9d
revert into_committed to previous implementation
cheme Oct 11, 2019
b06ec1b
Merge branch 'chain-aux2' into kv-keyspace
cheme Oct 11, 2019
b0dce4a
Merge branch 'master' into chain-aux2
cheme Oct 11, 2019
03e47c2
Merge branch 'chain-aux2' into kv-keyspace
cheme Oct 11, 2019
899e151
Add a place holder for child trie deletion in journals.
cheme Oct 16, 2019
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
fix gc call block index.
  • Loading branch information
cheme committed Oct 4, 2019
commit e48cf4335ecbe3fd79411f34f7b5df556c9e6c19
9 changes: 6 additions & 3 deletions core/state-db/src/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,18 @@ impl RangeSet {
full: bool,
) {

if branch_index <= self.treshold {
if branch_index < self.treshold {
return;
}
if branch_index == self.treshold && linear_index.is_none() {
return;
}
// range set update
let old_treshold = self.treshold;
// we do not finalize current branch cause it
// can contains other blocks
self.treshold = branch_index;
if branch_index == 0 || !full {
if (branch_index == 0 && linear_index.is_none()) || !full {
// remove cached value under treshold only
let new_storage = self.storage.split_off(&(self.treshold));
self.storage = new_storage;
Expand All @@ -321,7 +324,7 @@ impl RangeSet {
} else {
let new_storage = self.storage.split_off(&(self.treshold));
self.storage = new_storage;
self.finalize_full(branch_index, None);
self.finalize_full(branch_index, linear_index);
};
}

Expand Down
22 changes: 20 additions & 2 deletions core/state-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ pub struct ChangeSet<H: Hash> {
/// ),
/// but it just need to be build from client (no need to change
/// it here except to extract faster).
///
/// This assumes that we only commit block per block (otherwhise
/// we need to inclued block number value here).
pub type OffstateChangeSet<H> = Vec<(H, Option<DBValue>)>;

/// Info for pruning offstate: a last prune index and keys to prune.
Expand Down Expand Up @@ -259,6 +262,12 @@ impl<BlockHash: Hash, Key: Hash> StateDbSync<BlockHash, Key> {
Ok(CommitSet {
data: changeset,
meta: Default::default(),
// TODO EMCH no current support for archive all,
// this would require managing branch index at
// client level (was implemented in another branch:
// client-db-branch-ix)
// and use and ordered tuple (branchix, blocknumber)
// index to run.
offstate: offstate_changeset,
offstate_prune: None,
})
Expand All @@ -278,6 +287,9 @@ impl<BlockHash: Hash, Key: Hash> StateDbSync<BlockHash, Key> {
Ok(()) => {
if self.mode == PruningMode::ArchiveCanonical {
commit.data.deleted.clear();
// TODO EMCH use pruning mode in statedb to avoid feeding that
// in the first place.
commit.offstate_prune = None;
}
}
Err(e) => return Err(e),
Expand Down Expand Up @@ -618,15 +630,21 @@ mod tests {
fn full_archive_keeps_everything() {
let (db, sdb) = make_test_db(PruningMode::ArchiveAll);
assert!(db.data_eq(&make_db(&[1, 21, 22, 3, 4, 91, 921, 922, 93, 94])));
assert!(db.offstate_eq(&[1, 21, 22, 3, 4, 81, 821, 822, 83, 84]));

// TODO EMCH implement full for test db and test for offstate

assert!(!sdb.is_pruned(&H256::from_low_u64_be(0), 0));
}

#[test]
fn canonical_archive_keeps_canonical() {
let (db, _) = make_test_db(PruningMode::ArchiveCanonical);
assert!(db.data_eq(&make_db(&[1, 21, 3, 91, 921, 922, 93, 94])));
assert!(db.offstate_eq(&[1, 21, 3, 81, 821, 822, 83, 84]));
assert!(db.offstate_eq_at(&[81, 821, 822, 83, 84], Some(0)));
assert!(db.offstate_eq_at(&[1, 821, 822, 83, 84], Some(1)));
assert!(db.offstate_eq_at(&[21, 822, 83, 84], Some(2)));
assert!(db.offstate_eq_at(&[3, 21, 822, 84], Some(3)));
assert!(db.offstate_eq(&[3, 21, 822, 84]));
}

#[test]
Expand Down
24 changes: 19 additions & 5 deletions core/state-db/src/noncanonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,12 @@ impl OffstatePendingGC {
// TODO EMCH double get is rather inefficient, see if it is possible
// to reuse the hash of the hashset into the hashmap
for key in self.keys_pending_gc.drain() {
offstate_values.get_mut(&key).map(|historied_value| {
historied_value.gc(branches.reverse_iter_ranges());
});
match offstate_values.get_mut(&key).map(|historied_value| {
historied_value.gc(branches.reverse_iter_ranges())
}) {
Some(historied_data::PruneResult::Cleared) => { let _ = offstate_values.remove(&key); },
_ => (),
}
}

self.pending_canonicalisation_query = None;
Expand Down Expand Up @@ -572,12 +575,23 @@ impl<BlockHash: Hash, Key: Hash> NonCanonicalOverlay<BlockHash, Key> {
if let Some(range) = self.get_branch_range(hash, block_number) {
commit.offstate.extend(
overlay.offstate_inserted.iter()
.chain(overlay.offstate_deleted.iter())
.map(|k| (k.clone(), self.offstate_values.get(k)
.expect("For each key in overlays there's a value in values")
.get(&range)
.expect("For each key in overlays there's a historied entry in values")
.clone())));
// some deletion can be pruned if in first block so handle is
// a bit less restrictive
commit.offstate.extend(
overlay.offstate_deleted.iter()
.filter_map(|k| self.offstate_values.get(k)
.map(|v| (k.clone(), v.get(&range)
.expect("For each key in overlays there's a historied entry \
in values, and pruned empty value are cleared")
.clone())
)
)
);
}
}

Expand Down Expand Up @@ -633,7 +647,7 @@ impl<BlockHash: Hash, Key: Hash> NonCanonicalOverlay<BlockHash, Key> {
if let Some(branch_index_cannonicalize) = last_index {
// this needs to be call after parents update
// TODO EMCH may be needed in 'canonicalize', and restore or commit here
self.branches.update_finalize_treshold(branch_index_cannonicalize, Some(block_number), true);
self.branches.update_finalize_treshold(branch_index_cannonicalize, Some(block_number + 1), true);
// gc is at the right place
self.offstate_gc.set_pending_gc(branch_index_cannonicalize);
// try to run the garbage collection (can run later if there is
Expand Down
8 changes: 7 additions & 1 deletion core/state-db/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ pub struct TestDb {
pub data: HashMap<H256, DBValue>,
pub meta: HashMap<Vec<u8>, DBValue>,
pub offstate: HashMap<OffstateKey, DBValue>,
// big heuristic to increment this for canonicalize transaction only
// by checking if there is value in offstate change set.
// If empty change set needed, this need to be change manually.
// TODO EMCH consider changing commit fun to use last block number explicitely.
pub last_block: u64,
}

Expand Down Expand Up @@ -79,7 +83,9 @@ impl NodeDb for TestDb {

impl TestDb {
pub fn commit(&mut self, commit: &CommitSet<H256>) {
self.last_block += 1;
if commit.offstate.len() > 0 {
self.last_block += 1;
}
self.data.extend(commit.data.inserted.iter().cloned());
for k in commit.data.deleted.iter() {
self.data.remove(k);
Expand Down
36 changes: 27 additions & 9 deletions core/utils/historied-data/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use crate::linear::{
SerializedConfig,
};
use crate::HistoriedValue;
use crate::PruneResult;
use crate::{as_usize, as_i};
use rstd::rc::Rc;
use rstd::vec::Vec;
Expand Down Expand Up @@ -639,12 +640,13 @@ impl<V> History<V> {

/// Gc an historied value other its possible values.
/// Iterator need to be reversed ordered by branch index.
pub fn gc<IT, S, I>(&mut self, mut states: IT)
pub fn gc<IT, S, I>(&mut self, mut states: IT) -> PruneResult
where
IT: Iterator<Item = (S, I)>,
S: BranchStateTrait<bool, I>,
I: Copy + Eq + TryFrom<usize> + TryInto<usize>,
{
let mut changed = false;
// state is likely bigger than history.
let mut current_state = states.next();
for branch_index in (0..self.0.len()).rev() {
Expand All @@ -663,29 +665,45 @@ impl<V> History<V> {
if let Ok(node_index) = node_index.try_into() {
if !state.0.get_node(node_index) {
if history_index == len - 1 {
let _ = self.0[branch_index].history.pop();
changed = self.0[branch_index]
.history.pop().is_some() || changed;
} else {
let _ = self.0[branch_index].history.remove(history_index);
self.0[branch_index]
.history.remove(history_index);
changed = true;
}
}
}
}
if self.0[branch_index].history.len() == 0 {
let _ = self.0.remove(branch_index);
self.0.remove(branch_index);
changed = true;
}
break;
} else {
let _ = self.0.remove(branch_index);
self.0.remove(branch_index);
changed = true;
break;
}
}
self.0.remove(branch_index);
changed = true;
break;
} else {
break;
}
}
}
if changed {
if self.0.len() == 0 {
PruneResult::Cleared
} else {
PruneResult::Changed
}

} else {
PruneResult::Unchanged
}
}

/*
Expand Down Expand Up @@ -795,7 +813,7 @@ impl<'a, F: SerializedConfig> Serialized<'a, F> {
}

/// keep a single with value history before the state.
pub fn prune<I>(&mut self, index: I) -> crate::PruneResult
pub fn prune<I>(&mut self, index: I) -> PruneResult
where
I: Copy + Eq + TryFrom<usize> + TryInto<usize>,
{
Expand Down Expand Up @@ -845,14 +863,14 @@ impl<'a, F: SerializedConfig> Serialized<'a, F> {
if last_index_with_value > 0 {
println!("IN {}", last_index_with_value);
self.0.truncate_until(last_index_with_value);
return crate::PruneResult::Changed;
return PruneResult::Changed;
}
} else {
self.0.clear();
return crate::PruneResult::Cleared;
return PruneResult::Cleared;
}

crate::PruneResult::Unchanged
PruneResult::Unchanged
}

}
Expand Down