Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

BREAKING Overlay transaction support. #3263

Closed
wants to merge 203 commits into from
Closed
Show file tree
Hide file tree
Changes from 143 commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
ef20f40
init some bench
cheme Jul 9, 2019
a218162
Init implementing.
cheme Jul 9, 2019
4e8f6a7
Initial implementation of prospective with unbound layer.
cheme Jul 11, 2019
917e26b
Remove size counter
cheme Jul 11, 2019
8b93ab7
fix ix.
cheme Jul 11, 2019
ae8e880
code for transactional layers: TODO testing!!
cheme Jul 12, 2019
c716f95
Regain perfs (-15%) by using a couple of static memory for
cheme Jul 30, 2019
808a409
Fix tx logic and basic tx test.
cheme Jul 30, 2019
e481952
with_transaction function and high level test.
cheme Jul 30, 2019
d9f3e50
state was useless in overlayed change (allways the last ix of history).
cheme Jul 30, 2019
cc0aa37
Cleaning comments and names.
cheme Jul 30, 2019
2bc2af0
Merge branch 'master' into overlay_change
cheme Jul 30, 2019
0c8235e
Rename Externalities primitives to 'storage_' + old name.
cheme Jul 31, 2019
5b98b4b
Merge branch 'master' into overlay_change
cheme Jul 31, 2019
cade913
name fields instead of tuble.
cheme Jul 31, 2019
fd26b2a
Update srml/support/src/storage/mod.rs
cheme Jul 31, 2019
3245968
Use more efficient smallvec.
cheme Aug 1, 2019
8550ad9
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Aug 1, 2019
41483b5
Missing spaces.
cheme Aug 1, 2019
44f5173
slice and slice to_vec from ptr to vec.
cheme Aug 1, 2019
00326b2
Init some fuzzing (only look for panic).
cheme Aug 1, 2019
fc2100d
Implement simplier inefficient overlay to fuzz compare.
cheme Aug 1, 2019
e38fc7b
Update core/state-machine/src/overlayed_changes.rs
cheme Aug 1, 2019
b8564e6
implement overlay garbage collection.
cheme Aug 5, 2019
21aa65d
Trigger gc based on constant rule.
cheme Aug 5, 2019
c8938d3
Managing a configuration for gc of overlay. This commit will be revert
cheme Aug 5, 2019
d1d947b
Revert "Managing a configuration for gc of overlay. This commit will …
cheme Aug 5, 2019
f4fb1e1
Merge branch 'master' into overlay_change
cheme Aug 6, 2019
2836808
Merge branch 'master' into overlay_change
cheme Aug 8, 2019
968ba35
Merge branch 'master' into overlay_change
cheme Aug 8, 2019
d703ee4
Merge branch 'master' into overlay_change
cheme Aug 15, 2019
ee52917
Direct iterator on children, not that the fact that it is owned does not
cheme Aug 15, 2019
249675e
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Aug 15, 2019
0100d70
Merge branch 'master' into overlay_change
cheme Aug 22, 2019
da093d5
Merge branch 'master' into overlay_change
cheme Aug 26, 2019
af4cceb
warning fix
cheme Aug 26, 2019
4e68123
Extracting transaction history and states plus logics to its own
cheme Aug 26, 2019
75fd798
Make history buffer parametric (to allow encoding efficient
cheme Aug 26, 2019
1fb154e
Removed history trait, to go to the more pragmatic macro approach (after
cheme Aug 27, 2019
46de531
macroed code (trait would be better but not at this point).
cheme Aug 28, 2019
80f4c2b
Fix basis code.
cheme Aug 28, 2019
8dbd48d
Remove serialized variant.
cheme Aug 28, 2019
9203e25
change some variables name, try to document gc.
cheme Aug 28, 2019
ea028ec
Change operation cost proto, add into_pending method and few formatting
cheme Aug 28, 2019
c69e258
Merge branch 'master' into overlay_change
cheme Aug 28, 2019
0ab789e
Doc and renaming 'force_push' to 'unsafe_push' (this function being
cheme Aug 29, 2019
8d45d31
Merge branch 'master' into overlay_change
cheme Aug 29, 2019
9488ca1
Merge branch 'master' into overlay_change
cheme Sep 2, 2019
09a24e0
Merge branch 'overlay_change' of github.com:cheme/substrate into over…
cheme Sep 2, 2019
b596b52
Merge branch 'master' into overlay_change
cheme Sep 4, 2019
5cc5fd0
Merge branch 'master' into overlay_change
cheme Sep 5, 2019
117388e
bump spec version
cheme Sep 5, 2019
1647084
Merge branch 'master' into overlay_change
cheme Sep 11, 2019
838cd3b
Addressing some nits, adding fuzz check into ci benches target.
cheme Sep 12, 2019
5437981
Merge branch 'master' into overlay_change
cheme Sep 12, 2019
fe38b30
Update iter docs, bump runtime version.
cheme Sep 13, 2019
b7dcd6d
Merge branch 'master' into overlay_change
cheme Sep 13, 2019
616fc2a
Simplify top and child iter into a single function.
cheme Sep 13, 2019
7001e8c
Restore access to iter for fuzzer.
cheme Sep 13, 2019
b534b3d
Merge branch 'master' into overlay_change
cheme Sep 16, 2019
a84b8db
rename gc for liner to get_mut_pruning, rename unsafe_push to
cheme Sep 16, 2019
9787a97
switch tuple to historiedvalue struct.
cheme Sep 16, 2019
d9d2118
use len instead of internal_item_counts
cheme Sep 16, 2019
887f95b
historied value on get and get mut to.
cheme Sep 17, 2019
1074c8c
Merge branch 'master' into overlay_change
Demi-Marie Sep 17, 2019
076623d
Merge branch 'master' into overlay_change
cheme Sep 18, 2019
937655f
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Sep 18, 2019
ff4bcb0
proper rand on bench
cheme Sep 18, 2019
45dc935
Update core/utils/historied-data/README.md
cheme Sep 20, 2019
d7c9f8a
Update core/utils/historied-data/src/lib.rs
cheme Sep 20, 2019
6c9abda
Update core/utils/historied-data/src/linear.rs
cheme Sep 20, 2019
89b4f26
Switching runtime test to panic instead of returning result.
cheme Sep 20, 2019
2ab0da3
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Sep 20, 2019
6673ce1
Merge branch 'master' into overlay_change
cheme Oct 2, 2019
cdd1c3e
Merge branch 'master' into overlay_change
cheme Oct 10, 2019
e076d12
Avoid clone explicitely in some case (the clone with this PR is
cheme Oct 10, 2019
b877213
remove it from parameter.
cheme Oct 10, 2019
fc66ecd
Merge branch 'master' into overlay_change
cheme Oct 18, 2019
dcdd32c
Merge branch 'master' into overlay_change
cheme Oct 21, 2019
6a153e5
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Oct 21, 2019
32e6268
fix merge.
cheme Oct 21, 2019
cf943e2
Apply suggestions from code review
cheme Oct 21, 2019
4a439af
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Oct 21, 2019
c71e2c5
Smallvec is compatible with no_std.
cheme Oct 21, 2019
71c4012
fix fuzz, rename 'test' feature to more substratish 'test-helpers'.
cheme Oct 21, 2019
4ca0b40
Implement with less state.
cheme Oct 21, 2019
47b8867
revert to no gc of commited data
cheme Oct 23, 2019
d9a0fb5
renaming some history variables and field to states.
cheme Oct 23, 2019
1c06ce1
satisfactory get_mut, pruning need changes.
cheme Oct 23, 2019
c399c58
Fix gc (fuzz seems ok), a bit more work on avoiding redundancy in
cheme Oct 23, 2019
106d84b
remove a bit of code redundancy.
cheme Oct 24, 2019
6b5aeea
rename historied to historical
cheme Oct 24, 2019
8738b30
Merge branch 'master' into overlay_change
cheme Oct 24, 2019
594ce64
removing dubious as_ref_mut method (intermediate tuple is not optimized
cheme Oct 24, 2019
7546e6a
Named field for States.
cheme Oct 24, 2019
2e6fa4c
change find_previous_transaction to use an in memory state.
cheme Oct 24, 2019
cd7113b
update runtime versions.
cheme Oct 24, 2019
a995150
Merge branch 'master' into overlay_change
cheme Oct 24, 2019
789af78
Merge branch 'master' into overlay_change, and few english nits.
cheme Oct 28, 2019
1a12715
Merge branch 'master' into overlay_change
cheme Oct 30, 2019
6625ab8
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Oct 30, 2019
2d91b89
fix some documentation nits.
cheme Oct 30, 2019
61dba1e
Documentation.
cheme Nov 1, 2019
6334c10
favor for expression when possible.
cheme Nov 1, 2019
1b9ff7b
use 'get_unchecked_pending' for a recurrent pattern matching.
cheme Nov 1, 2019
55cacc1
Reorganize historical crate and documentation.
cheme Nov 1, 2019
4920da4
fix import.
cheme Nov 1, 2019
4a1fb7f
Preparing refactor.
cheme Nov 11, 2019
a995e18
setting up linear synch historical data.
cheme Nov 12, 2019
fb01856
quick implementation before fuzzing.
cheme Nov 12, 2019
ef0bcda
code fix and overlay implemetation, before deletion of old code.
cheme Nov 13, 2019
e265ad1
New implementation accounts for a 17 and 20% lost on existing bench.
cheme Nov 13, 2019
9904c4f
Remove unuse code. Test failings.
cheme Nov 14, 2019
0a98033
Merge branch 'master' into overlay_change
cheme Nov 14, 2019
5f82305
Fix broken tests (obviously cloning only state do not work anymore).
cheme Nov 14, 2019
494ad42
Removing trailing spaces.
cheme Nov 14, 2019
f7b9594
rename 'ensure_runing' to 'finalize_discard' as it is only really needed
cheme Nov 14, 2019
55d112a
renaming PruneResult to CleaningResult.
cheme Nov 14, 2019
741d420
fix compilation issue
cheme Nov 14, 2019
19b1014
Field name for states.
cheme Nov 15, 2019
a2bab20
Merge branch 'master' into overlay_change
cheme Nov 15, 2019
4b90775
Fix conflicts.
cheme Nov 15, 2019
a81fb12
fix ci for checking fuzz
cheme Nov 15, 2019
d9ff813
No sense in having new ext in deprecated interface.
cheme Nov 19, 2019
fa0ec93
Ensure discard prospective.
cheme Nov 19, 2019
e0b580e
Merge branch 'master' into overlay_change
cheme Nov 21, 2019
efa05f1
Merge branch 'master' into overlay_change
cheme Nov 23, 2019
e0a6243
Merge branch 'master' into overlay_change
cheme Nov 27, 2019
281344b
Merge branch 'master' into overlay_change
cheme Nov 29, 2019
2676397
Merge branch 'master' into overlay_change
cheme Nov 29, 2019
fbdbd34
Merge branch 'master' into overlay_change
cheme Dec 2, 2019
80c55c6
Merge branch 'overlay_change' of github.com:cheme/substrate into over…
cheme Dec 2, 2019
5597bf3
update cargo.lock
cheme Dec 2, 2019
9c09b78
fix crate names for bench and fuzz
cheme Dec 6, 2019
28413a7
Merge branch 'master' into overlay_change
cheme Dec 8, 2019
1e1e790
Address nits: remove test-helpers specific derive, make 'len' function
cheme Dec 9, 2019
827441c
Merge branch 'master' into overlay_change
cheme Dec 9, 2019
ac424ac
Merge branch 'master' into overlay_change
cheme Dec 10, 2019
6d3e10f
Merge branch 'master' into overlay_change
cheme Dec 11, 2019
19733c5
fix merge (runtime-io to sp-io)
cheme Dec 11, 2019
f7a1193
Merge branch 'master' into overlay_change
cheme Dec 11, 2019
0f8bee6
Move historical-data crate to primitives.
cheme Dec 11, 2019
106b1f7
Merge branch 'master' into overlay_change
cheme Dec 13, 2019
fd262d9
Historical values documentation update.
cheme Dec 14, 2019
8f79592
Merge branch 'master' into overlay_change
cheme Dec 14, 2019
d1554ec
Documentation change on overlay_change
cheme Dec 14, 2019
92d5184
Merge branch 'master' into overlay_change
cheme Dec 17, 2019
81f5c90
adding cargo.lock to overlay fuzzing
cheme Dec 17, 2019
57a2ddd
Merge branch 'master' into overlay_change
cheme Jan 1, 2020
70946d1
rewrite readme, rename historicalvalue to historicalentry
cheme Jan 2, 2020
dc4462a
spelling an slight documentation change.
cheme Jan 2, 2020
0004cf4
Merge branch 'master' into overlay_change
cheme Jan 6, 2020
2a5b816
Merge branch 'overlay_change' of github.com:cheme/polkadot into overl…
cheme Jan 6, 2020
d00f3e8
Merge branch 'master' into overlay_change
cheme Jan 6, 2020
7bc1c6c
Fix runtime tests.
cheme Jan 6, 2020
7a99509
apply update-copyright.sh
cheme Jan 7, 2020
256f3a5
move transaction to its own transaction runtime module.
cheme Jan 7, 2020
80f3d38
synch_linear_transaction renamed to sync_linear_transaction
cheme Jan 7, 2020
c9873b8
unused dependency to sp-std
cheme Jan 7, 2020
4f0c633
nits.
cheme Jan 7, 2020
b3014ae
Comments for `apply_commit_transaction` internals.
cheme Jan 7, 2020
412fba4
Use 'COMMITTED_LAYER' const to make code clearer.
cheme Jan 7, 2020
4f4fed6
Fix refacto error.
cheme Jan 7, 2020
9dee523
Discard transaction is same as truncate.
cheme Jan 7, 2020
f055f3b
Move helpers implementations.
cheme Jan 7, 2020
441d5ca
Declare transaction host function for wasm
cheme Jan 8, 2020
96f9662
renaming prior to removal of historical-data
cheme Jan 10, 2020
b3078a7
Flattern historical data crate & fix discard transaction latest commit
cheme Jan 10, 2020
9f01802
Move transaction code in its own module.
cheme Jan 10, 2020
92c99af
Move fuzzer base code to sp-state-machine to add non regression
cheme Jan 10, 2020
5614176
Merge branch 'master' into overlay_change
cheme Jan 10, 2020
f18f4d3
Merge branch 'master' into overlay_change
cheme Jan 13, 2020
26cfd0f
fix `where` formatting and some documentation from pr review.
cheme Jan 13, 2020
ab272e3
Simplify logic for commit transaction.
cheme Jan 14, 2020
e93097e
Merge branch 'master' into overlay_change
cheme Jan 15, 2020
2970099
provious lazy design for transaction.
cheme Jan 15, 2020
ec7f683
Switch overlay_change primitives.
cheme Jan 16, 2020
68b9678
Switch to mutable for storage, child storage and similar.
cheme Jan 16, 2020
6b14213
Merge branch 'master' into overlay_change
cheme Jan 16, 2020
8cc64bb
Merge branch 'overlay_change' into overlay_change_lazy
cheme Jan 16, 2020
6227baf
Merge branch 'overlay_change_lazy' into overlay_change_lazy_mut
cheme Jan 16, 2020
be9811d
Merge branch 'master' into overlay_change
cheme Jan 20, 2020
e69fd24
Merge branch 'overlay_change' into overlay_change_lazy_mut
cheme Jan 20, 2020
47f117a
Fix some doc, mark loop enhancement to test.
cheme Jan 20, 2020
5f26869
best loop condition, and manage deleted offset out of actual deletion.
cheme Jan 20, 2020
09539d4
fix benches.
cheme Jan 21, 2020
ea1fe4f
Merge branch 'master' into overlay_change
cheme Jan 27, 2020
b109130
Fixing line lengths.
cheme Jan 30, 2020
2533b04
Merge branch 'master' into overlay_change
cheme Jan 30, 2020
1db0bec
increment spec version
cheme Jan 30, 2020
121e64b
storage transaction host module name.
cheme Jan 30, 2020
1e2497a
3 new function, switching index of missing one in wasmtime test.
cheme Jan 30, 2020
46e54c8
another hardcoded wasmtime index in test.
cheme Jan 30, 2020
1e8cd7b
Merge branch 'master' into overlay_change
cheme Feb 5, 2020
1667f18
Merge branch 'master' into overlay_change
cheme Feb 12, 2020
5df5e51
Merge branch 'master' into overlay_change
cheme Feb 12, 2020
0d29a09
Merge branch 'master' into overlay_change
cheme Feb 28, 2020
4d6af74
Added a descriptive test of internal state. This does not intend to
cheme Mar 2, 2020
6242ebc
Merge branch 'master' into overlay_change
cheme Mar 10, 2020
683abcb
update fuzzer cargo.lock
cheme Mar 10, 2020
0c8d9e7
Merge branch 'master' into overlay_change
cheme Mar 17, 2020
e620a05
Merge branch 'master' into overlay_change
cheme Apr 14, 2020
45d5c7c
fix bench
cheme Apr 14, 2020
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
3 changes: 3 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ cargo-check-benches:
<<: *docker-env
script:
- BUILD_DUMMY_WASM_BINARY=1 time cargo +nightly check --benches --all
- cd ./primitives/state-machine/fuzz
- time cargo check
- sccache -s
pepyakin marked this conversation as resolved.
Show resolved Hide resolved



cargo-check-subkey:
stage: test
<<: *docker-env
Expand Down
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ members = [
"primitives/api/proc-macro",
"primitives/api/test",
"primitives/arithmetic",
"primitives/historical-data",
"primitives/io",
"primitives/runtime",
"primitives/sandbox",
Expand Down
16 changes: 16 additions & 0 deletions frame/support/src/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ pub mod hashed;
pub mod child;
pub mod generator;

/// Execute under a transactional layer.
///
/// If the result of execution is an error,
/// the transactional layer get reverted; otherwhise
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// the transactional layer get reverted; otherwhise
/// the transactional layer get reverted; otherwise

/// it is committed.
pub fn with_transaction<R, E>(f: impl FnOnce() -> Result<R, E>) -> Result<R, E> {
sp_io::storage::start_transaction();
let r = f();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cheme what do you expect to gain by assigning from one single-letter-function call to a single-letter-variable?

Suggested change
let r = f();
let result = f();

if r.is_ok() {
Copy link
Member

@gavofyork gavofyork Dec 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to use a match here: fewer {s.

sp_io::storage::commit_transaction();
} else {
sp_io::storage::discard_transaction();
}
r
}

/// A trait for working with macro-generated storage values under the substrate storage API.
///
/// Details on implementation can be found at
Expand Down
18 changes: 17 additions & 1 deletion primitives/api/test/tests/runtime_calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ fn calling_with_both_strategy_and_fail_on_native_should_work() {
assert_eq!(runtime_api.fail_on_native(&block_id).unwrap(), 1);
}


#[test]
fn calling_with_native_else_wasm_and_fail_on_wasm_should_work() {
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeElseWasm).build();
Expand All @@ -131,6 +130,23 @@ fn use_trie_function() {
assert_eq!(runtime_api.use_trie(&block_id).unwrap(), 2);
}

#[test]
fn use_history_data() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are not really belonging here.

You could put them here: https://github.com/paritytech/substrate/blob/master/test-utils/runtime/src/lib.rs#L950

let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::AlwaysWasm).build();
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.info().chain.best_number);
assert!(runtime_api.use_history_data(&block_id).is_ok());
}

#[test]
fn test_transactions() {
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::AlwaysWasm).build();
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.info().chain.best_number);
assert_eq!(runtime_api.use_transactions(&block_id).unwrap(), 1);
}


#[test]
fn initialize_block_works() {
let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build();
Expand Down
10 changes: 10 additions & 0 deletions primitives/externalities/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ pub trait Externalities: ExtensionStore {
///
/// Returns the SCALE encoded hash.
fn storage_changes_root(&mut self, parent: &[u8]) -> Result<Option<Vec<u8>>, ()>;

/// Create a new transactional layer.
fn storage_start_transaction(&mut self);

/// Discard a transactional layer, pending changes of every transaction behind this layer are
/// dropped (including committed changes) .
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// dropped (including committed changes) .
/// dropped (including committed changes).

please pay attention to detail.

fn storage_discard_transaction(&mut self);

/// Commit a transactional layer. The changes stay attached to parent transaction layer.
fn storage_commit_transaction(&mut self);
}

/// Extension for the [`Externalities`] trait.
Expand Down
18 changes: 18 additions & 0 deletions primitives/historical-data/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "sp-historical-data"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Data associated with its history"
edition = "2018"

[dependencies]
rstd = { package = "sp-std", path = "../std", default-features = false }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to use renames anymore for internal crates, so please use sp-std directly.

smallvec = { version = "0.6", default-features = false }

[features]
default = ["std"]
std = [
"rstd/std",
"smallvec/std",
]
test-helpers = []
18 changes: 18 additions & 0 deletions primitives/historical-data/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Historical data

Crate with functionality to manage data that stores its own history.

This covers:
- linear history driven data, eg. transactional layers for overlay.
- long term storage with multiple branch, eg. offchain storage.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- long term storage with multiple branch, eg. offchain storage.
- long term storage with multiple branches, eg. off-chain storage.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that even the intended meaning?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am removing this line, it is something that is implemented in another PR, but since the code is currently not in the crate it does not make sense to keep it.


General design is container where query and update requires global
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
General design is container where query and update requires global
General design is to be a container where query and update both require a global

i'm changing this from non-english to english. i've no idea if what i'm writing is what you were meaning @cheme .

history context.

History is serialize as a per item basis.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not english.


This crates is `no_std` compatible as long as the `std` feature is not enabled.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This crates is `no_std` compatible as long as the `std` feature is not enabled.
This crate is `no_std` compatible as long as the `std` feature is not enabled.


For more information see <https://crates.io/historical-data>

License: GPL-3.0
92 changes: 92 additions & 0 deletions primitives/historical-data/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// Copyright 2019 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Substrate is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.

//! Data storage containing multiple states for a value.
//! This is used to store historical information for an item.

#![cfg_attr(not(feature = "std"), no_std)]

pub mod synch_linear_transaction;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would use sync. Or do you mean something different?


/// An entry at a given history index.
#[derive(Debug, Clone, PartialEq)]
pub struct HistoricalValue<V, I> {
/// The stored value.
pub value: V,
/// The moment in history when the value got set.
pub index: I,
}

impl<V, I> From<(V, I)> for HistoricalValue<V, I> {
fn from(input: (V, I)) -> HistoricalValue<V, I> {
HistoricalValue { value: input.0, index: input.1 }
}
}

impl<V, I: Clone> HistoricalValue<V, I> {
fn as_mut(&mut self) -> HistoricalValue<&mut V, I> {
HistoricalValue { value: &mut self.value, index: self.index.clone() }
}
}

#[derive(Debug, PartialEq)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put it above the type.

/// Results from cleaning a data with history.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Results from cleaning a data with history.
/// The results from cleaning a data with history.

???

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea what you mean by "a data". This is not english.

/// It should be used to update from the calling context,
Copy link
Member

@gavofyork gavofyork Dec 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea what this is intended to mean.

/// for instance remove this data from a map if it was cleared.
pub enum CleaningResult {
Unchanged,
pepyakin marked this conversation as resolved.
Show resolved Hide resolved
Changed,
Cleared,
}

/// History of value and their state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// History of value and their state.
/// History of value and its state.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, but what is the context in which is it used? This documentation is completely useless for a newcomer to the codebase.

#[derive(Debug, Clone, PartialEq)]
pub struct History<V, I>(pub(crate) smallvec::SmallVec<[HistoricalValue<V, I>; ALLOCATED_HISTORY]>);

impl<V, I> Default for History<V, I> {
fn default() -> Self {
History(Default::default())
}
}

/// Size of preallocated history per element.
/// Currently at two for committed and prospective only.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No idea what you mean here @cheme

/// It means that using transaction in a module got a direct allocation cost.
const ALLOCATED_HISTORY: usize = 2;

impl<V, I> History<V, I> {
#[cfg(any(test, feature = "test-helpers"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But above the function.

/// Get current number of stored historical values.
pub fn len(&self) -> usize {
self.0.len()
}

#[cfg(any(test, feature = "test-helpers"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

/// Create an history from an existing history.
pub fn from_iter(input: impl IntoIterator<Item = HistoricalValue<V, I>>) -> Self {
let mut history = History::default();
for v in input {
history.push_unchecked(v);
}
history
}

/// Push a value without checking if it can overwrite the current
/// state.
pub fn push_unchecked(&mut self, item: HistoricalValue<V, I>) {
self.0.push(item);
}
}
Loading