2018-03-05 22:33:44 +03:00
|
|
|
// Copyright 2018 The Grin Developers
|
2017-09-05 08:50:25 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2018-12-08 02:59:40 +03:00
|
|
|
use env_logger;
|
|
|
|
use grin_core as core;
|
|
|
|
use grin_store as store;
|
2017-09-05 08:50:25 +03:00
|
|
|
|
|
|
|
use std::fs;
|
|
|
|
|
2018-10-18 13:40:58 +03:00
|
|
|
use chrono::prelude::Utc;
|
2018-06-18 18:18:38 +03:00
|
|
|
use croaring::Bitmap;
|
|
|
|
|
2019-02-15 16:41:19 +03:00
|
|
|
use crate::core::core::hash::DefaultHashable;
|
2018-12-08 02:59:40 +03:00
|
|
|
use crate::core::core::pmmr::{Backend, PMMR};
|
|
|
|
use crate::core::ser::{
|
2018-11-01 23:14:46 +03:00
|
|
|
Error, FixedLength, PMMRIndexHashable, PMMRable, Readable, Reader, Writeable, Writer,
|
|
|
|
};
|
2017-09-05 08:50:25 +03:00
|
|
|
|
|
|
|
#[test]
|
2018-02-22 16:45:13 +03:00
|
|
|
fn pmmr_append() {
|
2018-01-28 09:12:33 +03:00
|
|
|
let (data_dir, elems) = setup("append");
|
2019-02-10 00:14:27 +03:00
|
|
|
{
|
|
|
|
let mut backend = store::pmmr::PMMRBackend::new(data_dir.to_string(), true, None).unwrap();
|
2017-09-05 08:50:25 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// adding first set of 4 elements and sync
|
|
|
|
let mut mmr_size = load(0, &elems[0..4], &mut backend);
|
|
|
|
backend.sync().unwrap();
|
2017-09-05 08:50:25 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// adding the rest and sync again
|
|
|
|
mmr_size = load(mmr_size, &elems[4..9], &mut backend);
|
|
|
|
backend.sync().unwrap();
|
2017-09-05 08:50:25 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// check the resulting backend store and the computation of the root
|
|
|
|
let node_hash = elems[0].hash_with_index(0);
|
|
|
|
assert_eq!(backend.get_hash(1).unwrap(), node_hash);
|
2017-09-05 08:50:25 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// 0010012001001230
|
2018-03-16 17:45:58 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
let pos_0 = elems[0].hash_with_index(0);
|
|
|
|
let pos_1 = elems[1].hash_with_index(1);
|
|
|
|
let pos_2 = (pos_0, pos_1).hash_with_index(2);
|
2018-03-16 17:45:58 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
let pos_3 = elems[2].hash_with_index(3);
|
|
|
|
let pos_4 = elems[3].hash_with_index(4);
|
|
|
|
let pos_5 = (pos_3, pos_4).hash_with_index(5);
|
|
|
|
let pos_6 = (pos_2, pos_5).hash_with_index(6);
|
2018-03-16 17:45:58 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
let pos_7 = elems[4].hash_with_index(7);
|
|
|
|
let pos_8 = elems[5].hash_with_index(8);
|
|
|
|
let pos_9 = (pos_7, pos_8).hash_with_index(9);
|
2018-03-16 17:45:58 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
let pos_10 = elems[6].hash_with_index(10);
|
|
|
|
let pos_11 = elems[7].hash_with_index(11);
|
|
|
|
let pos_12 = (pos_10, pos_11).hash_with_index(12);
|
|
|
|
let pos_13 = (pos_9, pos_12).hash_with_index(13);
|
|
|
|
let pos_14 = (pos_6, pos_13).hash_with_index(14);
|
2018-03-16 17:45:58 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
let pos_15 = elems[8].hash_with_index(15);
|
2017-09-05 08:50:25 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
{
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
assert_eq!(pmmr.root(), (pos_14, pos_15).hash_with_index(16));
|
|
|
|
}
|
2017-09-05 08:50:25 +03:00
|
|
|
}
|
2018-01-28 09:12:33 +03:00
|
|
|
|
|
|
|
teardown(data_dir);
|
2017-09-05 08:50:25 +03:00
|
|
|
}
|
|
|
|
|
2018-03-13 21:22:34 +03:00
|
|
|
#[test]
|
|
|
|
fn pmmr_compact_leaf_sibling() {
|
|
|
|
let (data_dir, elems) = setup("compact_leaf_sibling");
|
|
|
|
|
|
|
|
// setup the mmr store with all elements
|
|
|
|
{
|
2019-02-10 00:14:27 +03:00
|
|
|
let mut backend = store::pmmr::PMMRBackend::new(data_dir.to_string(), true, None).unwrap();
|
|
|
|
let mmr_size = load(0, &elems[..], &mut backend);
|
|
|
|
backend.sync().unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// On far left of the MMR -
|
|
|
|
// pos 1 and 2 are leaves (and siblings)
|
|
|
|
// the parent is pos 3
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
let (pos_1_hash, pos_2_hash, pos_3_hash) = {
|
|
|
|
let pmmr = PMMR::at(&mut backend, mmr_size);
|
|
|
|
(
|
|
|
|
pmmr.get_hash(1).unwrap(),
|
|
|
|
pmmr.get_hash(2).unwrap(),
|
|
|
|
pmmr.get_hash(3).unwrap(),
|
|
|
|
)
|
|
|
|
};
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// prune pos 1
|
|
|
|
{
|
|
|
|
let mut pmmr = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.prune(1).unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// prune pos 8 as well to push the remove list past the cutoff
|
|
|
|
pmmr.prune(8).unwrap();
|
|
|
|
}
|
|
|
|
backend.sync().unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// // check pos 1, 2, 3 are in the state we expect after pruning
|
|
|
|
{
|
|
|
|
let pmmr = PMMR::at(&mut backend, mmr_size);
|
2018-03-15 20:12:30 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// check that pos 1 is "removed"
|
|
|
|
assert_eq!(pmmr.get_hash(1), None);
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// check that pos 2 and 3 are unchanged
|
|
|
|
assert_eq!(pmmr.get_hash(2).unwrap(), pos_2_hash);
|
|
|
|
assert_eq!(pmmr.get_hash(3).unwrap(), pos_3_hash);
|
|
|
|
}
|
2017-09-05 08:50:25 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// check we can still retrieve the "removed" element at pos 1
|
|
|
|
// from the backend hash file.
|
|
|
|
assert_eq!(backend.get_from_file(1).unwrap(), pos_1_hash);
|
2017-09-29 21:44:25 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// aggressively compact the PMMR files
|
[1.1.0] Merge master into 1.1.0 (#2720)
* cleanup legacy "3 dot" check (#2625)
* Allow to peers behind NAT to get up to preferred_max connections (#2543)
Allow to peers behind NAT to get up to preffered_max connections
If peer has only outbound connections it's mot likely behind NAT and we should not stop it from getting more outbound connections
* Reduce usage of unwrap in p2p crate (#2627)
Also change store crate a bit
* Simplify (and fix) output_pos cleanup during chain compaction (#2609)
* expose leaf pos iterator
use it for various things in txhashset when iterating over outputs
* fix
* cleanup
* rebuild output_pos index (and clear it out first) when compacting the chain
* fixup tests
* refactor to match on (output, proof) tuple
* add comments to compact() to explain what is going on.
* get rid of some boxing around the leaf_set iterator
* cleanup
* [docs] Add switch commitment documentation (#2526)
* remove references to no-longer existing switch commitment hash
(as switch commitments were removed in ca8447f3bd49e80578770da841e5fbbac2c23cde
and moved into the blinding factor of the Pedersen Commitment)
* some rewording (points vs curves) and fix of small formatting issues
* Add switch commitment documentation
* [docs] Documents in grin repo had translated in Korean. (#2604)
* Start to M/W intro translate in Korean
* translate in Korean
* add korean translation on intro
* table_of_content.md translate in Korean.
* table_of_content_KR.md finish translate in Korean, start to translate State_KR.md
* add state_KR.md & commit some translation in State_KR.md
* WIP stat_KR.md translation
* add build_KR.md && stratum_KR.md
* finish translate stratum_KR.md & table_of_content_KR.md
* rename intro.KR.md to intro_KR.md
* add intro_KR.md file path each language's intro.md
* add Korean translation file path to stratum.md & table_of_contents.md
* fix difference with grin/master
* Fix TxHashSet file filter for Windows. (#2641)
* Fix TxHashSet file filter for Windows.
* rustfmt
* Updating regexp
* Adding in test case
* Display the current download rate rather than the average when syncing the chain (#2633)
* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.
* Replace the explicitly ignored variables in the pattern with an implicit ignore
* remove root = true from editorconfig (#2655)
* Add Medium post to intro (#2654)
Spoke to @yeastplume who agreed it makes sense to add the "Grin Transactions Explained, Step-by-Step" Medium post to intro.md
Open for suggestions on a better location.
* add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files
* rustfmt
* use a constant instead of multiple 32
* rustfmt
* Fix the build warning of deprecated trim_right_matches (#2662)
* [DOC] state.md, build.md and chain directory documents translate in Korean. (#2649)
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* remove some useless md files for translation. this is rearrange set up translation order.
* add dot end of sentence & translate build.md in korean
* remove fast-sync_KR.md
* finish build_KR.md translation
* finish build_KR.md translation
* finish translation state_KR.md & add phrase in state.md to move other language md file
* translate blocks_and_headers.md && chain_sync.md in Korean
* add . in chain_sync.md , translation finished in doc/chain dir.
* fix some miss typos
* Api documentation fixes (#2646)
* Fix the API documentation for Chain Validate (v1/chain/validate). It was documented as a POST, but it is actually a GET request, which can be seen in its handler ChainValidationHandler
* Update the API V1 route list response to include the headers and merkleproof routes. Also clarify that for the chain/outputs route you must specify either byids or byheight to select outputs.
* refactor(ci): reorganize CI related code (#2658)
Break-down the CI related code into smaller more maintainable pieces.
* Specify grin or nanogrins in API docs where applicable (#2642)
* Set Content-Type in API client (#2680)
* Reduce number of unwraps in chain crate (#2679)
* fix: the restart of state sync doesn't work sometimes (#2687)
* let check_txhashset_needed return true on abnormal case (#2684)
* Reduce number of unwwaps in api crate (#2681)
* Reduce number of unwwaps in api crate
* Format use section
* Small QoL improvements for wallet developers (#2651)
* Small changes for wallet devs
* Move create_nonce into Keychain trait
* Replace match by map_err
* Add flag to Slate to skip fee check
* Fix secp dependency
* Remove check_fee flag in Slate
* Add Japanese edition of build.md (#2697)
* catch the panic to avoid peer thread quit early (#2686)
* catch the panic to avoid peer thread quit before taking the chance to ban
* move catch wrapper logic down into the util crate
* log the panic info
* keep txhashset.rs untouched
* remove a warning
* [DOC] dandelion.md, simulation.md ,fast-sync.md and pruning.md documents translate in Korean. (#2678)
* Show response code in API client error message (#2683)
It's hard to investigate what happens when an API client error is
printed out
* Add some better logging for get_outputs_by_id failure states (#2705)
* Switch commitment doc fixes (#2645)
Fix some typos and remove the use of parentheses in a
couple of places to make the reading flow a bit better.
* docs: update/add new README.md badges (#2708)
Replace existing badges with SVG counterparts and add a bunch of new ones.
* Update intro.md (#2702)
Add mention of censoring attack prevented by range proofs
* use sandbox folder for txhashset validation on state sync (#2685)
* use sandbox folder for txhashset validation on state sync
* rustfmt
* use temp directory as the sandbox instead actual db_root txhashset dir
* rustfmt
* move txhashset overwrite to the end of full validation
* fix travis-ci test
* rustfmt
* fix: hashset have 2 folders including txhashset and header
* rustfmt
*
(1)switch to rebuild_header_mmr instead of copy the sandbox header mmr
(2)lock txhashset when overwriting and opening and rebuild
* minor improve on sandbox_dir
* add Japanese edition of state.md (#2703)
* Attempt to fix broken TUI locale (#2713)
Can confirm that on the same machine 1.0.2 TUI looks great and is broken on
the current master. Bump of `cursive` version fixed it for me.
Fixes #2676
* clean the header folder in sandbox (#2716)
* forgot to clean the header folder in sandbox in #2685
* Reduce number of unwraps in servers crate (#2707)
It doesn't include stratum server which is sufficiently changed in 1.1
branch and adapters, which is big enough for a separate PR.
* rustfmt
* change version to beta
2019-04-01 13:47:48 +03:00
|
|
|
backend.check_compact(1, &Bitmap::create()).unwrap();
|
2017-09-05 08:50:25 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// check pos 1, 2, 3 are in the state we expect after compacting
|
|
|
|
{
|
|
|
|
let pmmr = PMMR::at(&mut backend, mmr_size);
|
2017-09-05 08:50:25 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// check that pos 1 is "removed"
|
|
|
|
assert_eq!(pmmr.get_hash(1), None);
|
2017-09-05 08:50:25 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// check that pos 2 and 3 are unchanged
|
|
|
|
assert_eq!(pmmr.get_hash(2).unwrap(), pos_2_hash);
|
|
|
|
assert_eq!(pmmr.get_hash(3).unwrap(), pos_3_hash);
|
|
|
|
}
|
2017-09-05 08:50:25 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// Check we can still retrieve the "removed" hash at pos 1 from the hash file.
|
|
|
|
// It should still be available even after pruning and compacting.
|
|
|
|
assert_eq!(backend.get_from_file(1).unwrap(), pos_1_hash);
|
2017-09-05 08:50:25 +03:00
|
|
|
}
|
2018-01-28 09:12:33 +03:00
|
|
|
|
|
|
|
teardown(data_dir);
|
2017-09-05 08:50:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2019-02-10 00:14:27 +03:00
|
|
|
fn pmmr_prune_compact() {
|
|
|
|
let (data_dir, elems) = setup("prune_compact");
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// setup the mmr store with all elements
|
2017-09-05 08:50:25 +03:00
|
|
|
{
|
2019-02-10 00:14:27 +03:00
|
|
|
let mut backend = store::pmmr::PMMRBackend::new(data_dir.to_string(), true, None).unwrap();
|
|
|
|
let mmr_size = load(0, &elems[..], &mut backend);
|
2017-09-05 08:50:25 +03:00
|
|
|
backend.sync().unwrap();
|
2017-09-29 21:44:25 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// save the root
|
|
|
|
let root = {
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.root()
|
|
|
|
};
|
|
|
|
|
|
|
|
// pruning some choice nodes
|
2017-09-05 08:50:25 +03:00
|
|
|
{
|
2018-12-08 02:59:40 +03:00
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
2018-06-18 18:18:38 +03:00
|
|
|
pmmr.prune(1).unwrap();
|
2019-02-10 00:14:27 +03:00
|
|
|
pmmr.prune(4).unwrap();
|
|
|
|
pmmr.prune(5).unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
}
|
|
|
|
backend.sync().unwrap();
|
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// check the root and stored data
|
2018-03-13 21:22:34 +03:00
|
|
|
{
|
2019-02-10 00:14:27 +03:00
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
assert_eq!(root, pmmr.root());
|
|
|
|
// check we can still retrieve same element from leaf index 2
|
|
|
|
assert_eq!(pmmr.get_data(2).unwrap(), TestElem(2));
|
|
|
|
// and the same for leaf index 7
|
|
|
|
assert_eq!(pmmr.get_data(11).unwrap(), TestElem(7));
|
2017-09-05 08:50:25 +03:00
|
|
|
}
|
2018-02-22 16:45:13 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// compact
|
[1.1.0] Merge master into 1.1.0 (#2720)
* cleanup legacy "3 dot" check (#2625)
* Allow to peers behind NAT to get up to preferred_max connections (#2543)
Allow to peers behind NAT to get up to preffered_max connections
If peer has only outbound connections it's mot likely behind NAT and we should not stop it from getting more outbound connections
* Reduce usage of unwrap in p2p crate (#2627)
Also change store crate a bit
* Simplify (and fix) output_pos cleanup during chain compaction (#2609)
* expose leaf pos iterator
use it for various things in txhashset when iterating over outputs
* fix
* cleanup
* rebuild output_pos index (and clear it out first) when compacting the chain
* fixup tests
* refactor to match on (output, proof) tuple
* add comments to compact() to explain what is going on.
* get rid of some boxing around the leaf_set iterator
* cleanup
* [docs] Add switch commitment documentation (#2526)
* remove references to no-longer existing switch commitment hash
(as switch commitments were removed in ca8447f3bd49e80578770da841e5fbbac2c23cde
and moved into the blinding factor of the Pedersen Commitment)
* some rewording (points vs curves) and fix of small formatting issues
* Add switch commitment documentation
* [docs] Documents in grin repo had translated in Korean. (#2604)
* Start to M/W intro translate in Korean
* translate in Korean
* add korean translation on intro
* table_of_content.md translate in Korean.
* table_of_content_KR.md finish translate in Korean, start to translate State_KR.md
* add state_KR.md & commit some translation in State_KR.md
* WIP stat_KR.md translation
* add build_KR.md && stratum_KR.md
* finish translate stratum_KR.md & table_of_content_KR.md
* rename intro.KR.md to intro_KR.md
* add intro_KR.md file path each language's intro.md
* add Korean translation file path to stratum.md & table_of_contents.md
* fix difference with grin/master
* Fix TxHashSet file filter for Windows. (#2641)
* Fix TxHashSet file filter for Windows.
* rustfmt
* Updating regexp
* Adding in test case
* Display the current download rate rather than the average when syncing the chain (#2633)
* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.
* Replace the explicitly ignored variables in the pattern with an implicit ignore
* remove root = true from editorconfig (#2655)
* Add Medium post to intro (#2654)
Spoke to @yeastplume who agreed it makes sense to add the "Grin Transactions Explained, Step-by-Step" Medium post to intro.md
Open for suggestions on a better location.
* add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files
* rustfmt
* use a constant instead of multiple 32
* rustfmt
* Fix the build warning of deprecated trim_right_matches (#2662)
* [DOC] state.md, build.md and chain directory documents translate in Korean. (#2649)
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* remove some useless md files for translation. this is rearrange set up translation order.
* add dot end of sentence & translate build.md in korean
* remove fast-sync_KR.md
* finish build_KR.md translation
* finish build_KR.md translation
* finish translation state_KR.md & add phrase in state.md to move other language md file
* translate blocks_and_headers.md && chain_sync.md in Korean
* add . in chain_sync.md , translation finished in doc/chain dir.
* fix some miss typos
* Api documentation fixes (#2646)
* Fix the API documentation for Chain Validate (v1/chain/validate). It was documented as a POST, but it is actually a GET request, which can be seen in its handler ChainValidationHandler
* Update the API V1 route list response to include the headers and merkleproof routes. Also clarify that for the chain/outputs route you must specify either byids or byheight to select outputs.
* refactor(ci): reorganize CI related code (#2658)
Break-down the CI related code into smaller more maintainable pieces.
* Specify grin or nanogrins in API docs where applicable (#2642)
* Set Content-Type in API client (#2680)
* Reduce number of unwraps in chain crate (#2679)
* fix: the restart of state sync doesn't work sometimes (#2687)
* let check_txhashset_needed return true on abnormal case (#2684)
* Reduce number of unwwaps in api crate (#2681)
* Reduce number of unwwaps in api crate
* Format use section
* Small QoL improvements for wallet developers (#2651)
* Small changes for wallet devs
* Move create_nonce into Keychain trait
* Replace match by map_err
* Add flag to Slate to skip fee check
* Fix secp dependency
* Remove check_fee flag in Slate
* Add Japanese edition of build.md (#2697)
* catch the panic to avoid peer thread quit early (#2686)
* catch the panic to avoid peer thread quit before taking the chance to ban
* move catch wrapper logic down into the util crate
* log the panic info
* keep txhashset.rs untouched
* remove a warning
* [DOC] dandelion.md, simulation.md ,fast-sync.md and pruning.md documents translate in Korean. (#2678)
* Show response code in API client error message (#2683)
It's hard to investigate what happens when an API client error is
printed out
* Add some better logging for get_outputs_by_id failure states (#2705)
* Switch commitment doc fixes (#2645)
Fix some typos and remove the use of parentheses in a
couple of places to make the reading flow a bit better.
* docs: update/add new README.md badges (#2708)
Replace existing badges with SVG counterparts and add a bunch of new ones.
* Update intro.md (#2702)
Add mention of censoring attack prevented by range proofs
* use sandbox folder for txhashset validation on state sync (#2685)
* use sandbox folder for txhashset validation on state sync
* rustfmt
* use temp directory as the sandbox instead actual db_root txhashset dir
* rustfmt
* move txhashset overwrite to the end of full validation
* fix travis-ci test
* rustfmt
* fix: hashset have 2 folders including txhashset and header
* rustfmt
*
(1)switch to rebuild_header_mmr instead of copy the sandbox header mmr
(2)lock txhashset when overwriting and opening and rebuild
* minor improve on sandbox_dir
* add Japanese edition of state.md (#2703)
* Attempt to fix broken TUI locale (#2713)
Can confirm that on the same machine 1.0.2 TUI looks great and is broken on
the current master. Bump of `cursive` version fixed it for me.
Fixes #2676
* clean the header folder in sandbox (#2716)
* forgot to clean the header folder in sandbox in #2685
* Reduce number of unwraps in servers crate (#2707)
It doesn't include stratum server which is sufficiently changed in 1.1
branch and adapters, which is big enough for a separate PR.
* rustfmt
* change version to beta
2019-04-01 13:47:48 +03:00
|
|
|
backend.check_compact(2, &Bitmap::create()).unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// recheck the root and stored data
|
2017-09-05 08:50:25 +03:00
|
|
|
{
|
2019-02-10 00:14:27 +03:00
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
assert_eq!(root, pmmr.root());
|
|
|
|
assert_eq!(pmmr.get_data(2).unwrap(), TestElem(2));
|
|
|
|
assert_eq!(pmmr.get_data(11).unwrap(), TestElem(7));
|
2017-09-05 08:50:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
teardown(data_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pmmr_reload() {
|
|
|
|
let (data_dir, elems) = setup("reload");
|
|
|
|
|
|
|
|
// set everything up with an initial backend
|
2017-09-05 08:50:25 +03:00
|
|
|
{
|
2018-07-05 05:31:08 +03:00
|
|
|
let mut backend = store::pmmr::PMMRBackend::new(data_dir.to_string(), true, None).unwrap();
|
2019-02-10 00:14:27 +03:00
|
|
|
|
|
|
|
let mmr_size = load(0, &elems[..], &mut backend);
|
|
|
|
|
|
|
|
// retrieve entries from the hash file for comparison later
|
|
|
|
let pos_3_hash = backend.get_hash(3).unwrap();
|
|
|
|
let pos_4_hash = backend.get_hash(4).unwrap();
|
|
|
|
let pos_5_hash = backend.get_hash(5).unwrap();
|
|
|
|
|
|
|
|
// save the root
|
|
|
|
let root = {
|
2018-12-08 02:59:40 +03:00
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
2019-02-10 00:14:27 +03:00
|
|
|
pmmr.root()
|
|
|
|
};
|
|
|
|
|
|
|
|
{
|
|
|
|
backend.sync().unwrap();
|
|
|
|
|
|
|
|
// prune a node so we have prune data
|
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.prune(1).unwrap();
|
|
|
|
}
|
|
|
|
backend.sync().unwrap();
|
|
|
|
|
|
|
|
// now check and compact the backend
|
[1.1.0] Merge master into 1.1.0 (#2720)
* cleanup legacy "3 dot" check (#2625)
* Allow to peers behind NAT to get up to preferred_max connections (#2543)
Allow to peers behind NAT to get up to preffered_max connections
If peer has only outbound connections it's mot likely behind NAT and we should not stop it from getting more outbound connections
* Reduce usage of unwrap in p2p crate (#2627)
Also change store crate a bit
* Simplify (and fix) output_pos cleanup during chain compaction (#2609)
* expose leaf pos iterator
use it for various things in txhashset when iterating over outputs
* fix
* cleanup
* rebuild output_pos index (and clear it out first) when compacting the chain
* fixup tests
* refactor to match on (output, proof) tuple
* add comments to compact() to explain what is going on.
* get rid of some boxing around the leaf_set iterator
* cleanup
* [docs] Add switch commitment documentation (#2526)
* remove references to no-longer existing switch commitment hash
(as switch commitments were removed in ca8447f3bd49e80578770da841e5fbbac2c23cde
and moved into the blinding factor of the Pedersen Commitment)
* some rewording (points vs curves) and fix of small formatting issues
* Add switch commitment documentation
* [docs] Documents in grin repo had translated in Korean. (#2604)
* Start to M/W intro translate in Korean
* translate in Korean
* add korean translation on intro
* table_of_content.md translate in Korean.
* table_of_content_KR.md finish translate in Korean, start to translate State_KR.md
* add state_KR.md & commit some translation in State_KR.md
* WIP stat_KR.md translation
* add build_KR.md && stratum_KR.md
* finish translate stratum_KR.md & table_of_content_KR.md
* rename intro.KR.md to intro_KR.md
* add intro_KR.md file path each language's intro.md
* add Korean translation file path to stratum.md & table_of_contents.md
* fix difference with grin/master
* Fix TxHashSet file filter for Windows. (#2641)
* Fix TxHashSet file filter for Windows.
* rustfmt
* Updating regexp
* Adding in test case
* Display the current download rate rather than the average when syncing the chain (#2633)
* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.
* Replace the explicitly ignored variables in the pattern with an implicit ignore
* remove root = true from editorconfig (#2655)
* Add Medium post to intro (#2654)
Spoke to @yeastplume who agreed it makes sense to add the "Grin Transactions Explained, Step-by-Step" Medium post to intro.md
Open for suggestions on a better location.
* add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files
* rustfmt
* use a constant instead of multiple 32
* rustfmt
* Fix the build warning of deprecated trim_right_matches (#2662)
* [DOC] state.md, build.md and chain directory documents translate in Korean. (#2649)
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* remove some useless md files for translation. this is rearrange set up translation order.
* add dot end of sentence & translate build.md in korean
* remove fast-sync_KR.md
* finish build_KR.md translation
* finish build_KR.md translation
* finish translation state_KR.md & add phrase in state.md to move other language md file
* translate blocks_and_headers.md && chain_sync.md in Korean
* add . in chain_sync.md , translation finished in doc/chain dir.
* fix some miss typos
* Api documentation fixes (#2646)
* Fix the API documentation for Chain Validate (v1/chain/validate). It was documented as a POST, but it is actually a GET request, which can be seen in its handler ChainValidationHandler
* Update the API V1 route list response to include the headers and merkleproof routes. Also clarify that for the chain/outputs route you must specify either byids or byheight to select outputs.
* refactor(ci): reorganize CI related code (#2658)
Break-down the CI related code into smaller more maintainable pieces.
* Specify grin or nanogrins in API docs where applicable (#2642)
* Set Content-Type in API client (#2680)
* Reduce number of unwraps in chain crate (#2679)
* fix: the restart of state sync doesn't work sometimes (#2687)
* let check_txhashset_needed return true on abnormal case (#2684)
* Reduce number of unwwaps in api crate (#2681)
* Reduce number of unwwaps in api crate
* Format use section
* Small QoL improvements for wallet developers (#2651)
* Small changes for wallet devs
* Move create_nonce into Keychain trait
* Replace match by map_err
* Add flag to Slate to skip fee check
* Fix secp dependency
* Remove check_fee flag in Slate
* Add Japanese edition of build.md (#2697)
* catch the panic to avoid peer thread quit early (#2686)
* catch the panic to avoid peer thread quit before taking the chance to ban
* move catch wrapper logic down into the util crate
* log the panic info
* keep txhashset.rs untouched
* remove a warning
* [DOC] dandelion.md, simulation.md ,fast-sync.md and pruning.md documents translate in Korean. (#2678)
* Show response code in API client error message (#2683)
It's hard to investigate what happens when an API client error is
printed out
* Add some better logging for get_outputs_by_id failure states (#2705)
* Switch commitment doc fixes (#2645)
Fix some typos and remove the use of parentheses in a
couple of places to make the reading flow a bit better.
* docs: update/add new README.md badges (#2708)
Replace existing badges with SVG counterparts and add a bunch of new ones.
* Update intro.md (#2702)
Add mention of censoring attack prevented by range proofs
* use sandbox folder for txhashset validation on state sync (#2685)
* use sandbox folder for txhashset validation on state sync
* rustfmt
* use temp directory as the sandbox instead actual db_root txhashset dir
* rustfmt
* move txhashset overwrite to the end of full validation
* fix travis-ci test
* rustfmt
* fix: hashset have 2 folders including txhashset and header
* rustfmt
*
(1)switch to rebuild_header_mmr instead of copy the sandbox header mmr
(2)lock txhashset when overwriting and opening and rebuild
* minor improve on sandbox_dir
* add Japanese edition of state.md (#2703)
* Attempt to fix broken TUI locale (#2713)
Can confirm that on the same machine 1.0.2 TUI looks great and is broken on
the current master. Bump of `cursive` version fixed it for me.
Fixes #2676
* clean the header folder in sandbox (#2716)
* forgot to clean the header folder in sandbox in #2685
* Reduce number of unwraps in servers crate (#2707)
It doesn't include stratum server which is sufficiently changed in 1.1
branch and adapters, which is big enough for a separate PR.
* rustfmt
* change version to beta
2019-04-01 13:47:48 +03:00
|
|
|
backend.check_compact(1, &Bitmap::create()).unwrap();
|
2019-02-10 00:14:27 +03:00
|
|
|
backend.sync().unwrap();
|
|
|
|
|
|
|
|
// prune another node to force compact to actually do something
|
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.prune(4).unwrap();
|
|
|
|
pmmr.prune(2).unwrap();
|
|
|
|
}
|
|
|
|
backend.sync().unwrap();
|
|
|
|
|
[1.1.0] Merge master into 1.1.0 (#2720)
* cleanup legacy "3 dot" check (#2625)
* Allow to peers behind NAT to get up to preferred_max connections (#2543)
Allow to peers behind NAT to get up to preffered_max connections
If peer has only outbound connections it's mot likely behind NAT and we should not stop it from getting more outbound connections
* Reduce usage of unwrap in p2p crate (#2627)
Also change store crate a bit
* Simplify (and fix) output_pos cleanup during chain compaction (#2609)
* expose leaf pos iterator
use it for various things in txhashset when iterating over outputs
* fix
* cleanup
* rebuild output_pos index (and clear it out first) when compacting the chain
* fixup tests
* refactor to match on (output, proof) tuple
* add comments to compact() to explain what is going on.
* get rid of some boxing around the leaf_set iterator
* cleanup
* [docs] Add switch commitment documentation (#2526)
* remove references to no-longer existing switch commitment hash
(as switch commitments were removed in ca8447f3bd49e80578770da841e5fbbac2c23cde
and moved into the blinding factor of the Pedersen Commitment)
* some rewording (points vs curves) and fix of small formatting issues
* Add switch commitment documentation
* [docs] Documents in grin repo had translated in Korean. (#2604)
* Start to M/W intro translate in Korean
* translate in Korean
* add korean translation on intro
* table_of_content.md translate in Korean.
* table_of_content_KR.md finish translate in Korean, start to translate State_KR.md
* add state_KR.md & commit some translation in State_KR.md
* WIP stat_KR.md translation
* add build_KR.md && stratum_KR.md
* finish translate stratum_KR.md & table_of_content_KR.md
* rename intro.KR.md to intro_KR.md
* add intro_KR.md file path each language's intro.md
* add Korean translation file path to stratum.md & table_of_contents.md
* fix difference with grin/master
* Fix TxHashSet file filter for Windows. (#2641)
* Fix TxHashSet file filter for Windows.
* rustfmt
* Updating regexp
* Adding in test case
* Display the current download rate rather than the average when syncing the chain (#2633)
* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.
* Replace the explicitly ignored variables in the pattern with an implicit ignore
* remove root = true from editorconfig (#2655)
* Add Medium post to intro (#2654)
Spoke to @yeastplume who agreed it makes sense to add the "Grin Transactions Explained, Step-by-Step" Medium post to intro.md
Open for suggestions on a better location.
* add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files
* rustfmt
* use a constant instead of multiple 32
* rustfmt
* Fix the build warning of deprecated trim_right_matches (#2662)
* [DOC] state.md, build.md and chain directory documents translate in Korean. (#2649)
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* remove some useless md files for translation. this is rearrange set up translation order.
* add dot end of sentence & translate build.md in korean
* remove fast-sync_KR.md
* finish build_KR.md translation
* finish build_KR.md translation
* finish translation state_KR.md & add phrase in state.md to move other language md file
* translate blocks_and_headers.md && chain_sync.md in Korean
* add . in chain_sync.md , translation finished in doc/chain dir.
* fix some miss typos
* Api documentation fixes (#2646)
* Fix the API documentation for Chain Validate (v1/chain/validate). It was documented as a POST, but it is actually a GET request, which can be seen in its handler ChainValidationHandler
* Update the API V1 route list response to include the headers and merkleproof routes. Also clarify that for the chain/outputs route you must specify either byids or byheight to select outputs.
* refactor(ci): reorganize CI related code (#2658)
Break-down the CI related code into smaller more maintainable pieces.
* Specify grin or nanogrins in API docs where applicable (#2642)
* Set Content-Type in API client (#2680)
* Reduce number of unwraps in chain crate (#2679)
* fix: the restart of state sync doesn't work sometimes (#2687)
* let check_txhashset_needed return true on abnormal case (#2684)
* Reduce number of unwwaps in api crate (#2681)
* Reduce number of unwwaps in api crate
* Format use section
* Small QoL improvements for wallet developers (#2651)
* Small changes for wallet devs
* Move create_nonce into Keychain trait
* Replace match by map_err
* Add flag to Slate to skip fee check
* Fix secp dependency
* Remove check_fee flag in Slate
* Add Japanese edition of build.md (#2697)
* catch the panic to avoid peer thread quit early (#2686)
* catch the panic to avoid peer thread quit before taking the chance to ban
* move catch wrapper logic down into the util crate
* log the panic info
* keep txhashset.rs untouched
* remove a warning
* [DOC] dandelion.md, simulation.md ,fast-sync.md and pruning.md documents translate in Korean. (#2678)
* Show response code in API client error message (#2683)
It's hard to investigate what happens when an API client error is
printed out
* Add some better logging for get_outputs_by_id failure states (#2705)
* Switch commitment doc fixes (#2645)
Fix some typos and remove the use of parentheses in a
couple of places to make the reading flow a bit better.
* docs: update/add new README.md badges (#2708)
Replace existing badges with SVG counterparts and add a bunch of new ones.
* Update intro.md (#2702)
Add mention of censoring attack prevented by range proofs
* use sandbox folder for txhashset validation on state sync (#2685)
* use sandbox folder for txhashset validation on state sync
* rustfmt
* use temp directory as the sandbox instead actual db_root txhashset dir
* rustfmt
* move txhashset overwrite to the end of full validation
* fix travis-ci test
* rustfmt
* fix: hashset have 2 folders including txhashset and header
* rustfmt
*
(1)switch to rebuild_header_mmr instead of copy the sandbox header mmr
(2)lock txhashset when overwriting and opening and rebuild
* minor improve on sandbox_dir
* add Japanese edition of state.md (#2703)
* Attempt to fix broken TUI locale (#2713)
Can confirm that on the same machine 1.0.2 TUI looks great and is broken on
the current master. Bump of `cursive` version fixed it for me.
Fixes #2676
* clean the header folder in sandbox (#2716)
* forgot to clean the header folder in sandbox in #2685
* Reduce number of unwraps in servers crate (#2707)
It doesn't include stratum server which is sufficiently changed in 1.1
branch and adapters, which is big enough for a separate PR.
* rustfmt
* change version to beta
2019-04-01 13:47:48 +03:00
|
|
|
backend.check_compact(4, &Bitmap::create()).unwrap();
|
2019-02-10 00:14:27 +03:00
|
|
|
backend.sync().unwrap();
|
|
|
|
|
|
|
|
assert_eq!(backend.unpruned_size(), mmr_size);
|
|
|
|
|
|
|
|
// prune some more to get rm log data
|
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.prune(5).unwrap();
|
|
|
|
}
|
|
|
|
backend.sync().unwrap();
|
|
|
|
assert_eq!(backend.unpruned_size(), mmr_size);
|
2017-09-05 08:50:25 +03:00
|
|
|
}
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// create a new backend referencing the data files
|
|
|
|
// and check everything still works as expected
|
|
|
|
{
|
|
|
|
let mut backend =
|
|
|
|
store::pmmr::PMMRBackend::new(data_dir.to_string(), true, None).unwrap();
|
|
|
|
assert_eq!(backend.unpruned_size(), mmr_size);
|
|
|
|
{
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
assert_eq!(root, pmmr.root());
|
|
|
|
}
|
|
|
|
|
|
|
|
// pos 1 and pos 2 are both removed (via parent pos 3 in prune list)
|
|
|
|
assert_eq!(backend.get_hash(1), None);
|
|
|
|
assert_eq!(backend.get_hash(2), None);
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// pos 3 is "removed" but we keep the hash around for root of pruned subtree
|
|
|
|
assert_eq!(backend.get_hash(3), Some(pos_3_hash));
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// pos 4 is removed (via prune list)
|
|
|
|
assert_eq!(backend.get_hash(4), None);
|
|
|
|
// pos 5 is removed (via leaf_set)
|
|
|
|
assert_eq!(backend.get_hash(5), None);
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// now check contents of the hash file
|
|
|
|
// pos 1 and pos 2 are no longer in the hash file
|
|
|
|
assert_eq!(backend.get_from_file(1), None);
|
|
|
|
assert_eq!(backend.get_from_file(2), None);
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// pos 3 is still in there
|
|
|
|
assert_eq!(backend.get_from_file(3), Some(pos_3_hash));
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// pos 4 and pos 5 are also still in there
|
|
|
|
assert_eq!(backend.get_from_file(4), Some(pos_4_hash));
|
|
|
|
assert_eq!(backend.get_from_file(5), Some(pos_5_hash));
|
|
|
|
}
|
2017-09-05 08:50:25 +03:00
|
|
|
}
|
2018-01-28 09:12:33 +03:00
|
|
|
|
|
|
|
teardown(data_dir);
|
2017-09-05 08:50:25 +03:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:32:23 +03:00
|
|
|
#[test]
|
2018-02-22 16:45:13 +03:00
|
|
|
fn pmmr_rewind() {
|
2018-01-28 09:12:33 +03:00
|
|
|
let (data_dir, elems) = setup("rewind");
|
2017-10-03 01:32:23 +03:00
|
|
|
{
|
2019-02-10 00:14:27 +03:00
|
|
|
let mut backend = store::pmmr::PMMRBackend::new(data_dir.clone(), true, None).unwrap();
|
2018-04-19 21:52:46 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// adding elements and keeping the corresponding root
|
|
|
|
let mut mmr_size = load(0, &elems[0..4], &mut backend);
|
|
|
|
backend.sync().unwrap();
|
|
|
|
let root1 = {
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.root()
|
|
|
|
};
|
2018-06-29 03:53:00 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
mmr_size = load(mmr_size, &elems[4..6], &mut backend);
|
|
|
|
backend.sync().unwrap();
|
|
|
|
let root2 = {
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
assert_eq!(pmmr.unpruned_size(), 10);
|
|
|
|
pmmr.root()
|
|
|
|
};
|
2017-11-01 02:32:33 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
mmr_size = load(mmr_size, &elems[6..9], &mut backend);
|
|
|
|
backend.sync().unwrap();
|
|
|
|
let root3 = {
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
assert_eq!(pmmr.unpruned_size(), 16);
|
|
|
|
pmmr.root()
|
|
|
|
};
|
2018-06-29 03:53:00 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// prune the first 4 elements (leaves at pos 1, 2, 4, 5)
|
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.prune(1).unwrap();
|
|
|
|
pmmr.prune(2).unwrap();
|
|
|
|
pmmr.prune(4).unwrap();
|
|
|
|
pmmr.prune(5).unwrap();
|
|
|
|
}
|
|
|
|
backend.sync().unwrap();
|
2018-06-29 03:53:00 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
println!("before compacting - ");
|
|
|
|
for x in 1..17 {
|
|
|
|
println!("pos {}, {:?}", x, backend.get_from_file(x));
|
|
|
|
}
|
2018-06-29 03:53:00 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// and compact the MMR to remove the pruned elements
|
[1.1.0] Merge master into 1.1.0 (#2720)
* cleanup legacy "3 dot" check (#2625)
* Allow to peers behind NAT to get up to preferred_max connections (#2543)
Allow to peers behind NAT to get up to preffered_max connections
If peer has only outbound connections it's mot likely behind NAT and we should not stop it from getting more outbound connections
* Reduce usage of unwrap in p2p crate (#2627)
Also change store crate a bit
* Simplify (and fix) output_pos cleanup during chain compaction (#2609)
* expose leaf pos iterator
use it for various things in txhashset when iterating over outputs
* fix
* cleanup
* rebuild output_pos index (and clear it out first) when compacting the chain
* fixup tests
* refactor to match on (output, proof) tuple
* add comments to compact() to explain what is going on.
* get rid of some boxing around the leaf_set iterator
* cleanup
* [docs] Add switch commitment documentation (#2526)
* remove references to no-longer existing switch commitment hash
(as switch commitments were removed in ca8447f3bd49e80578770da841e5fbbac2c23cde
and moved into the blinding factor of the Pedersen Commitment)
* some rewording (points vs curves) and fix of small formatting issues
* Add switch commitment documentation
* [docs] Documents in grin repo had translated in Korean. (#2604)
* Start to M/W intro translate in Korean
* translate in Korean
* add korean translation on intro
* table_of_content.md translate in Korean.
* table_of_content_KR.md finish translate in Korean, start to translate State_KR.md
* add state_KR.md & commit some translation in State_KR.md
* WIP stat_KR.md translation
* add build_KR.md && stratum_KR.md
* finish translate stratum_KR.md & table_of_content_KR.md
* rename intro.KR.md to intro_KR.md
* add intro_KR.md file path each language's intro.md
* add Korean translation file path to stratum.md & table_of_contents.md
* fix difference with grin/master
* Fix TxHashSet file filter for Windows. (#2641)
* Fix TxHashSet file filter for Windows.
* rustfmt
* Updating regexp
* Adding in test case
* Display the current download rate rather than the average when syncing the chain (#2633)
* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.
* Replace the explicitly ignored variables in the pattern with an implicit ignore
* remove root = true from editorconfig (#2655)
* Add Medium post to intro (#2654)
Spoke to @yeastplume who agreed it makes sense to add the "Grin Transactions Explained, Step-by-Step" Medium post to intro.md
Open for suggestions on a better location.
* add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files
* rustfmt
* use a constant instead of multiple 32
* rustfmt
* Fix the build warning of deprecated trim_right_matches (#2662)
* [DOC] state.md, build.md and chain directory documents translate in Korean. (#2649)
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* remove some useless md files for translation. this is rearrange set up translation order.
* add dot end of sentence & translate build.md in korean
* remove fast-sync_KR.md
* finish build_KR.md translation
* finish build_KR.md translation
* finish translation state_KR.md & add phrase in state.md to move other language md file
* translate blocks_and_headers.md && chain_sync.md in Korean
* add . in chain_sync.md , translation finished in doc/chain dir.
* fix some miss typos
* Api documentation fixes (#2646)
* Fix the API documentation for Chain Validate (v1/chain/validate). It was documented as a POST, but it is actually a GET request, which can be seen in its handler ChainValidationHandler
* Update the API V1 route list response to include the headers and merkleproof routes. Also clarify that for the chain/outputs route you must specify either byids or byheight to select outputs.
* refactor(ci): reorganize CI related code (#2658)
Break-down the CI related code into smaller more maintainable pieces.
* Specify grin or nanogrins in API docs where applicable (#2642)
* Set Content-Type in API client (#2680)
* Reduce number of unwraps in chain crate (#2679)
* fix: the restart of state sync doesn't work sometimes (#2687)
* let check_txhashset_needed return true on abnormal case (#2684)
* Reduce number of unwwaps in api crate (#2681)
* Reduce number of unwwaps in api crate
* Format use section
* Small QoL improvements for wallet developers (#2651)
* Small changes for wallet devs
* Move create_nonce into Keychain trait
* Replace match by map_err
* Add flag to Slate to skip fee check
* Fix secp dependency
* Remove check_fee flag in Slate
* Add Japanese edition of build.md (#2697)
* catch the panic to avoid peer thread quit early (#2686)
* catch the panic to avoid peer thread quit before taking the chance to ban
* move catch wrapper logic down into the util crate
* log the panic info
* keep txhashset.rs untouched
* remove a warning
* [DOC] dandelion.md, simulation.md ,fast-sync.md and pruning.md documents translate in Korean. (#2678)
* Show response code in API client error message (#2683)
It's hard to investigate what happens when an API client error is
printed out
* Add some better logging for get_outputs_by_id failure states (#2705)
* Switch commitment doc fixes (#2645)
Fix some typos and remove the use of parentheses in a
couple of places to make the reading flow a bit better.
* docs: update/add new README.md badges (#2708)
Replace existing badges with SVG counterparts and add a bunch of new ones.
* Update intro.md (#2702)
Add mention of censoring attack prevented by range proofs
* use sandbox folder for txhashset validation on state sync (#2685)
* use sandbox folder for txhashset validation on state sync
* rustfmt
* use temp directory as the sandbox instead actual db_root txhashset dir
* rustfmt
* move txhashset overwrite to the end of full validation
* fix travis-ci test
* rustfmt
* fix: hashset have 2 folders including txhashset and header
* rustfmt
*
(1)switch to rebuild_header_mmr instead of copy the sandbox header mmr
(2)lock txhashset when overwriting and opening and rebuild
* minor improve on sandbox_dir
* add Japanese edition of state.md (#2703)
* Attempt to fix broken TUI locale (#2713)
Can confirm that on the same machine 1.0.2 TUI looks great and is broken on
the current master. Bump of `cursive` version fixed it for me.
Fixes #2676
* clean the header folder in sandbox (#2716)
* forgot to clean the header folder in sandbox in #2685
* Reduce number of unwraps in servers crate (#2707)
It doesn't include stratum server which is sufficiently changed in 1.1
branch and adapters, which is big enough for a separate PR.
* rustfmt
* change version to beta
2019-04-01 13:47:48 +03:00
|
|
|
backend.check_compact(6, &Bitmap::create()).unwrap();
|
2019-02-10 00:14:27 +03:00
|
|
|
backend.sync().unwrap();
|
2018-06-18 18:18:38 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
println!("after compacting - ");
|
|
|
|
for x in 1..17 {
|
|
|
|
println!("pos {}, {:?}", x, backend.get_from_file(x));
|
|
|
|
}
|
2018-06-18 18:18:38 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
println!("root1 {:?}, root2 {:?}, root3 {:?}", root1, root2, root3);
|
2017-10-03 01:32:23 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// rewind and check the roots still match
|
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.rewind(9, &Bitmap::of(&vec![11, 12, 16])).unwrap();
|
|
|
|
assert_eq!(pmmr.unpruned_size(), 10);
|
2018-06-18 18:18:38 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// assert_eq!(pmmr.root(), root2);
|
|
|
|
}
|
|
|
|
println!("after rewinding - ");
|
|
|
|
for x in 1..17 {
|
|
|
|
println!("pos {}, {:?}", x, backend.get_from_file(x));
|
|
|
|
}
|
2018-06-18 18:18:38 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
println!("doing a sync after rewinding");
|
|
|
|
if let Err(e) = backend.sync() {
|
|
|
|
panic!("Err: {:?}", e);
|
|
|
|
}
|
2018-06-18 18:18:38 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
{
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, 10);
|
|
|
|
assert_eq!(pmmr.root(), root2);
|
|
|
|
}
|
2018-06-18 18:18:38 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// Also check the data file looks correct.
|
|
|
|
// pos 1, 2, 4, 5 are all leaves but these have been pruned.
|
|
|
|
for pos in vec![1, 2, 4, 5] {
|
|
|
|
assert_eq!(backend.get_data(pos), None);
|
|
|
|
}
|
|
|
|
// pos 3, 6, 7 are non-leaves so we have no data for these
|
|
|
|
for pos in vec![3, 6, 7] {
|
|
|
|
assert_eq!(backend.get_data(pos), None);
|
|
|
|
}
|
2018-04-19 21:52:46 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// pos 8 and 9 are both leaves and should be unaffected by prior pruning
|
2018-04-19 21:52:46 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
for x in 1..16 {
|
|
|
|
println!("data at {}, {:?}", x, backend.get_data(x));
|
|
|
|
}
|
2018-01-28 09:12:33 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
assert_eq!(backend.get_data(8), Some(elems[4]));
|
|
|
|
assert_eq!(backend.get_hash(8), Some(elems[4].hash_with_index(7)));
|
|
|
|
|
|
|
|
assert_eq!(backend.get_data(9), Some(elems[5]));
|
|
|
|
assert_eq!(backend.get_hash(9), Some(elems[5].hash_with_index(8)));
|
2018-04-19 21:52:46 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
assert_eq!(backend.data_size(), 2);
|
|
|
|
|
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, 10);
|
|
|
|
pmmr.rewind(5, &Bitmap::create()).unwrap();
|
|
|
|
assert_eq!(pmmr.root(), root1);
|
|
|
|
}
|
|
|
|
backend.sync().unwrap();
|
|
|
|
{
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, 7);
|
|
|
|
assert_eq!(pmmr.root(), root1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// also check the data file looks correct
|
|
|
|
// everything up to and including pos 7 should be pruned from the data file
|
|
|
|
// but we have rewound to pos 5 so everything after that should be None
|
|
|
|
for pos in 1..10 {
|
|
|
|
assert_eq!(backend.get_data(pos), None);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check we have no data in the backend after
|
|
|
|
// pruning, compacting and rewinding
|
|
|
|
assert_eq!(backend.data_size(), 0);
|
|
|
|
}
|
2018-04-19 21:52:46 +03:00
|
|
|
|
2018-01-28 09:12:33 +03:00
|
|
|
teardown(data_dir);
|
2017-10-03 01:32:23 +03:00
|
|
|
}
|
|
|
|
|
2018-03-13 21:22:34 +03:00
|
|
|
#[test]
|
|
|
|
fn pmmr_compact_single_leaves() {
|
|
|
|
let (data_dir, elems) = setup("compact_single_leaves");
|
|
|
|
{
|
2019-02-10 00:14:27 +03:00
|
|
|
let mut backend = store::pmmr::PMMRBackend::new(data_dir.clone(), true, None).unwrap();
|
|
|
|
let mmr_size = load(0, &elems[0..5], &mut backend);
|
|
|
|
backend.sync().unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.prune(1).unwrap();
|
|
|
|
pmmr.prune(4).unwrap();
|
|
|
|
}
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
backend.sync().unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// compact
|
[1.1.0] Merge master into 1.1.0 (#2720)
* cleanup legacy "3 dot" check (#2625)
* Allow to peers behind NAT to get up to preferred_max connections (#2543)
Allow to peers behind NAT to get up to preffered_max connections
If peer has only outbound connections it's mot likely behind NAT and we should not stop it from getting more outbound connections
* Reduce usage of unwrap in p2p crate (#2627)
Also change store crate a bit
* Simplify (and fix) output_pos cleanup during chain compaction (#2609)
* expose leaf pos iterator
use it for various things in txhashset when iterating over outputs
* fix
* cleanup
* rebuild output_pos index (and clear it out first) when compacting the chain
* fixup tests
* refactor to match on (output, proof) tuple
* add comments to compact() to explain what is going on.
* get rid of some boxing around the leaf_set iterator
* cleanup
* [docs] Add switch commitment documentation (#2526)
* remove references to no-longer existing switch commitment hash
(as switch commitments were removed in ca8447f3bd49e80578770da841e5fbbac2c23cde
and moved into the blinding factor of the Pedersen Commitment)
* some rewording (points vs curves) and fix of small formatting issues
* Add switch commitment documentation
* [docs] Documents in grin repo had translated in Korean. (#2604)
* Start to M/W intro translate in Korean
* translate in Korean
* add korean translation on intro
* table_of_content.md translate in Korean.
* table_of_content_KR.md finish translate in Korean, start to translate State_KR.md
* add state_KR.md & commit some translation in State_KR.md
* WIP stat_KR.md translation
* add build_KR.md && stratum_KR.md
* finish translate stratum_KR.md & table_of_content_KR.md
* rename intro.KR.md to intro_KR.md
* add intro_KR.md file path each language's intro.md
* add Korean translation file path to stratum.md & table_of_contents.md
* fix difference with grin/master
* Fix TxHashSet file filter for Windows. (#2641)
* Fix TxHashSet file filter for Windows.
* rustfmt
* Updating regexp
* Adding in test case
* Display the current download rate rather than the average when syncing the chain (#2633)
* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.
* Replace the explicitly ignored variables in the pattern with an implicit ignore
* remove root = true from editorconfig (#2655)
* Add Medium post to intro (#2654)
Spoke to @yeastplume who agreed it makes sense to add the "Grin Transactions Explained, Step-by-Step" Medium post to intro.md
Open for suggestions on a better location.
* add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files
* rustfmt
* use a constant instead of multiple 32
* rustfmt
* Fix the build warning of deprecated trim_right_matches (#2662)
* [DOC] state.md, build.md and chain directory documents translate in Korean. (#2649)
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* remove some useless md files for translation. this is rearrange set up translation order.
* add dot end of sentence & translate build.md in korean
* remove fast-sync_KR.md
* finish build_KR.md translation
* finish build_KR.md translation
* finish translation state_KR.md & add phrase in state.md to move other language md file
* translate blocks_and_headers.md && chain_sync.md in Korean
* add . in chain_sync.md , translation finished in doc/chain dir.
* fix some miss typos
* Api documentation fixes (#2646)
* Fix the API documentation for Chain Validate (v1/chain/validate). It was documented as a POST, but it is actually a GET request, which can be seen in its handler ChainValidationHandler
* Update the API V1 route list response to include the headers and merkleproof routes. Also clarify that for the chain/outputs route you must specify either byids or byheight to select outputs.
* refactor(ci): reorganize CI related code (#2658)
Break-down the CI related code into smaller more maintainable pieces.
* Specify grin or nanogrins in API docs where applicable (#2642)
* Set Content-Type in API client (#2680)
* Reduce number of unwraps in chain crate (#2679)
* fix: the restart of state sync doesn't work sometimes (#2687)
* let check_txhashset_needed return true on abnormal case (#2684)
* Reduce number of unwwaps in api crate (#2681)
* Reduce number of unwwaps in api crate
* Format use section
* Small QoL improvements for wallet developers (#2651)
* Small changes for wallet devs
* Move create_nonce into Keychain trait
* Replace match by map_err
* Add flag to Slate to skip fee check
* Fix secp dependency
* Remove check_fee flag in Slate
* Add Japanese edition of build.md (#2697)
* catch the panic to avoid peer thread quit early (#2686)
* catch the panic to avoid peer thread quit before taking the chance to ban
* move catch wrapper logic down into the util crate
* log the panic info
* keep txhashset.rs untouched
* remove a warning
* [DOC] dandelion.md, simulation.md ,fast-sync.md and pruning.md documents translate in Korean. (#2678)
* Show response code in API client error message (#2683)
It's hard to investigate what happens when an API client error is
printed out
* Add some better logging for get_outputs_by_id failure states (#2705)
* Switch commitment doc fixes (#2645)
Fix some typos and remove the use of parentheses in a
couple of places to make the reading flow a bit better.
* docs: update/add new README.md badges (#2708)
Replace existing badges with SVG counterparts and add a bunch of new ones.
* Update intro.md (#2702)
Add mention of censoring attack prevented by range proofs
* use sandbox folder for txhashset validation on state sync (#2685)
* use sandbox folder for txhashset validation on state sync
* rustfmt
* use temp directory as the sandbox instead actual db_root txhashset dir
* rustfmt
* move txhashset overwrite to the end of full validation
* fix travis-ci test
* rustfmt
* fix: hashset have 2 folders including txhashset and header
* rustfmt
*
(1)switch to rebuild_header_mmr instead of copy the sandbox header mmr
(2)lock txhashset when overwriting and opening and rebuild
* minor improve on sandbox_dir
* add Japanese edition of state.md (#2703)
* Attempt to fix broken TUI locale (#2713)
Can confirm that on the same machine 1.0.2 TUI looks great and is broken on
the current master. Bump of `cursive` version fixed it for me.
Fixes #2676
* clean the header folder in sandbox (#2716)
* forgot to clean the header folder in sandbox in #2685
* Reduce number of unwraps in servers crate (#2707)
It doesn't include stratum server which is sufficiently changed in 1.1
branch and adapters, which is big enough for a separate PR.
* rustfmt
* change version to beta
2019-04-01 13:47:48 +03:00
|
|
|
backend.check_compact(2, &Bitmap::create()).unwrap();
|
2019-02-10 00:14:27 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.prune(2).unwrap();
|
|
|
|
pmmr.prune(5).unwrap();
|
|
|
|
}
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
backend.sync().unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// compact
|
[1.1.0] Merge master into 1.1.0 (#2720)
* cleanup legacy "3 dot" check (#2625)
* Allow to peers behind NAT to get up to preferred_max connections (#2543)
Allow to peers behind NAT to get up to preffered_max connections
If peer has only outbound connections it's mot likely behind NAT and we should not stop it from getting more outbound connections
* Reduce usage of unwrap in p2p crate (#2627)
Also change store crate a bit
* Simplify (and fix) output_pos cleanup during chain compaction (#2609)
* expose leaf pos iterator
use it for various things in txhashset when iterating over outputs
* fix
* cleanup
* rebuild output_pos index (and clear it out first) when compacting the chain
* fixup tests
* refactor to match on (output, proof) tuple
* add comments to compact() to explain what is going on.
* get rid of some boxing around the leaf_set iterator
* cleanup
* [docs] Add switch commitment documentation (#2526)
* remove references to no-longer existing switch commitment hash
(as switch commitments were removed in ca8447f3bd49e80578770da841e5fbbac2c23cde
and moved into the blinding factor of the Pedersen Commitment)
* some rewording (points vs curves) and fix of small formatting issues
* Add switch commitment documentation
* [docs] Documents in grin repo had translated in Korean. (#2604)
* Start to M/W intro translate in Korean
* translate in Korean
* add korean translation on intro
* table_of_content.md translate in Korean.
* table_of_content_KR.md finish translate in Korean, start to translate State_KR.md
* add state_KR.md & commit some translation in State_KR.md
* WIP stat_KR.md translation
* add build_KR.md && stratum_KR.md
* finish translate stratum_KR.md & table_of_content_KR.md
* rename intro.KR.md to intro_KR.md
* add intro_KR.md file path each language's intro.md
* add Korean translation file path to stratum.md & table_of_contents.md
* fix difference with grin/master
* Fix TxHashSet file filter for Windows. (#2641)
* Fix TxHashSet file filter for Windows.
* rustfmt
* Updating regexp
* Adding in test case
* Display the current download rate rather than the average when syncing the chain (#2633)
* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.
* Replace the explicitly ignored variables in the pattern with an implicit ignore
* remove root = true from editorconfig (#2655)
* Add Medium post to intro (#2654)
Spoke to @yeastplume who agreed it makes sense to add the "Grin Transactions Explained, Step-by-Step" Medium post to intro.md
Open for suggestions on a better location.
* add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files
* rustfmt
* use a constant instead of multiple 32
* rustfmt
* Fix the build warning of deprecated trim_right_matches (#2662)
* [DOC] state.md, build.md and chain directory documents translate in Korean. (#2649)
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* remove some useless md files for translation. this is rearrange set up translation order.
* add dot end of sentence & translate build.md in korean
* remove fast-sync_KR.md
* finish build_KR.md translation
* finish build_KR.md translation
* finish translation state_KR.md & add phrase in state.md to move other language md file
* translate blocks_and_headers.md && chain_sync.md in Korean
* add . in chain_sync.md , translation finished in doc/chain dir.
* fix some miss typos
* Api documentation fixes (#2646)
* Fix the API documentation for Chain Validate (v1/chain/validate). It was documented as a POST, but it is actually a GET request, which can be seen in its handler ChainValidationHandler
* Update the API V1 route list response to include the headers and merkleproof routes. Also clarify that for the chain/outputs route you must specify either byids or byheight to select outputs.
* refactor(ci): reorganize CI related code (#2658)
Break-down the CI related code into smaller more maintainable pieces.
* Specify grin or nanogrins in API docs where applicable (#2642)
* Set Content-Type in API client (#2680)
* Reduce number of unwraps in chain crate (#2679)
* fix: the restart of state sync doesn't work sometimes (#2687)
* let check_txhashset_needed return true on abnormal case (#2684)
* Reduce number of unwwaps in api crate (#2681)
* Reduce number of unwwaps in api crate
* Format use section
* Small QoL improvements for wallet developers (#2651)
* Small changes for wallet devs
* Move create_nonce into Keychain trait
* Replace match by map_err
* Add flag to Slate to skip fee check
* Fix secp dependency
* Remove check_fee flag in Slate
* Add Japanese edition of build.md (#2697)
* catch the panic to avoid peer thread quit early (#2686)
* catch the panic to avoid peer thread quit before taking the chance to ban
* move catch wrapper logic down into the util crate
* log the panic info
* keep txhashset.rs untouched
* remove a warning
* [DOC] dandelion.md, simulation.md ,fast-sync.md and pruning.md documents translate in Korean. (#2678)
* Show response code in API client error message (#2683)
It's hard to investigate what happens when an API client error is
printed out
* Add some better logging for get_outputs_by_id failure states (#2705)
* Switch commitment doc fixes (#2645)
Fix some typos and remove the use of parentheses in a
couple of places to make the reading flow a bit better.
* docs: update/add new README.md badges (#2708)
Replace existing badges with SVG counterparts and add a bunch of new ones.
* Update intro.md (#2702)
Add mention of censoring attack prevented by range proofs
* use sandbox folder for txhashset validation on state sync (#2685)
* use sandbox folder for txhashset validation on state sync
* rustfmt
* use temp directory as the sandbox instead actual db_root txhashset dir
* rustfmt
* move txhashset overwrite to the end of full validation
* fix travis-ci test
* rustfmt
* fix: hashset have 2 folders including txhashset and header
* rustfmt
*
(1)switch to rebuild_header_mmr instead of copy the sandbox header mmr
(2)lock txhashset when overwriting and opening and rebuild
* minor improve on sandbox_dir
* add Japanese edition of state.md (#2703)
* Attempt to fix broken TUI locale (#2713)
Can confirm that on the same machine 1.0.2 TUI looks great and is broken on
the current master. Bump of `cursive` version fixed it for me.
Fixes #2676
* clean the header folder in sandbox (#2716)
* forgot to clean the header folder in sandbox in #2685
* Reduce number of unwraps in servers crate (#2707)
It doesn't include stratum server which is sufficiently changed in 1.1
branch and adapters, which is big enough for a separate PR.
* rustfmt
* change version to beta
2019-04-01 13:47:48 +03:00
|
|
|
backend.check_compact(2, &Bitmap::create()).unwrap();
|
2019-02-10 00:14:27 +03:00
|
|
|
}
|
2018-03-13 21:22:34 +03:00
|
|
|
|
|
|
|
teardown(data_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pmmr_compact_entire_peak() {
|
|
|
|
let (data_dir, elems) = setup("compact_entire_peak");
|
2019-02-10 00:14:27 +03:00
|
|
|
{
|
|
|
|
let mut backend = store::pmmr::PMMRBackend::new(data_dir.clone(), true, None).unwrap();
|
|
|
|
let mmr_size = load(0, &elems[0..5], &mut backend);
|
|
|
|
backend.sync().unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
let pos_7_hash = backend.get_hash(7).unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
let pos_8 = backend.get_data(8).unwrap();
|
|
|
|
let pos_8_hash = backend.get_hash(8).unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// prune all leaves under the peak at pos 7
|
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.prune(1).unwrap();
|
|
|
|
pmmr.prune(2).unwrap();
|
|
|
|
pmmr.prune(4).unwrap();
|
|
|
|
pmmr.prune(5).unwrap();
|
|
|
|
}
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
backend.sync().unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// compact
|
[1.1.0] Merge master into 1.1.0 (#2720)
* cleanup legacy "3 dot" check (#2625)
* Allow to peers behind NAT to get up to preferred_max connections (#2543)
Allow to peers behind NAT to get up to preffered_max connections
If peer has only outbound connections it's mot likely behind NAT and we should not stop it from getting more outbound connections
* Reduce usage of unwrap in p2p crate (#2627)
Also change store crate a bit
* Simplify (and fix) output_pos cleanup during chain compaction (#2609)
* expose leaf pos iterator
use it for various things in txhashset when iterating over outputs
* fix
* cleanup
* rebuild output_pos index (and clear it out first) when compacting the chain
* fixup tests
* refactor to match on (output, proof) tuple
* add comments to compact() to explain what is going on.
* get rid of some boxing around the leaf_set iterator
* cleanup
* [docs] Add switch commitment documentation (#2526)
* remove references to no-longer existing switch commitment hash
(as switch commitments were removed in ca8447f3bd49e80578770da841e5fbbac2c23cde
and moved into the blinding factor of the Pedersen Commitment)
* some rewording (points vs curves) and fix of small formatting issues
* Add switch commitment documentation
* [docs] Documents in grin repo had translated in Korean. (#2604)
* Start to M/W intro translate in Korean
* translate in Korean
* add korean translation on intro
* table_of_content.md translate in Korean.
* table_of_content_KR.md finish translate in Korean, start to translate State_KR.md
* add state_KR.md & commit some translation in State_KR.md
* WIP stat_KR.md translation
* add build_KR.md && stratum_KR.md
* finish translate stratum_KR.md & table_of_content_KR.md
* rename intro.KR.md to intro_KR.md
* add intro_KR.md file path each language's intro.md
* add Korean translation file path to stratum.md & table_of_contents.md
* fix difference with grin/master
* Fix TxHashSet file filter for Windows. (#2641)
* Fix TxHashSet file filter for Windows.
* rustfmt
* Updating regexp
* Adding in test case
* Display the current download rate rather than the average when syncing the chain (#2633)
* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.
* Replace the explicitly ignored variables in the pattern with an implicit ignore
* remove root = true from editorconfig (#2655)
* Add Medium post to intro (#2654)
Spoke to @yeastplume who agreed it makes sense to add the "Grin Transactions Explained, Step-by-Step" Medium post to intro.md
Open for suggestions on a better location.
* add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files
* rustfmt
* use a constant instead of multiple 32
* rustfmt
* Fix the build warning of deprecated trim_right_matches (#2662)
* [DOC] state.md, build.md and chain directory documents translate in Korean. (#2649)
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* remove some useless md files for translation. this is rearrange set up translation order.
* add dot end of sentence & translate build.md in korean
* remove fast-sync_KR.md
* finish build_KR.md translation
* finish build_KR.md translation
* finish translation state_KR.md & add phrase in state.md to move other language md file
* translate blocks_and_headers.md && chain_sync.md in Korean
* add . in chain_sync.md , translation finished in doc/chain dir.
* fix some miss typos
* Api documentation fixes (#2646)
* Fix the API documentation for Chain Validate (v1/chain/validate). It was documented as a POST, but it is actually a GET request, which can be seen in its handler ChainValidationHandler
* Update the API V1 route list response to include the headers and merkleproof routes. Also clarify that for the chain/outputs route you must specify either byids or byheight to select outputs.
* refactor(ci): reorganize CI related code (#2658)
Break-down the CI related code into smaller more maintainable pieces.
* Specify grin or nanogrins in API docs where applicable (#2642)
* Set Content-Type in API client (#2680)
* Reduce number of unwraps in chain crate (#2679)
* fix: the restart of state sync doesn't work sometimes (#2687)
* let check_txhashset_needed return true on abnormal case (#2684)
* Reduce number of unwwaps in api crate (#2681)
* Reduce number of unwwaps in api crate
* Format use section
* Small QoL improvements for wallet developers (#2651)
* Small changes for wallet devs
* Move create_nonce into Keychain trait
* Replace match by map_err
* Add flag to Slate to skip fee check
* Fix secp dependency
* Remove check_fee flag in Slate
* Add Japanese edition of build.md (#2697)
* catch the panic to avoid peer thread quit early (#2686)
* catch the panic to avoid peer thread quit before taking the chance to ban
* move catch wrapper logic down into the util crate
* log the panic info
* keep txhashset.rs untouched
* remove a warning
* [DOC] dandelion.md, simulation.md ,fast-sync.md and pruning.md documents translate in Korean. (#2678)
* Show response code in API client error message (#2683)
It's hard to investigate what happens when an API client error is
printed out
* Add some better logging for get_outputs_by_id failure states (#2705)
* Switch commitment doc fixes (#2645)
Fix some typos and remove the use of parentheses in a
couple of places to make the reading flow a bit better.
* docs: update/add new README.md badges (#2708)
Replace existing badges with SVG counterparts and add a bunch of new ones.
* Update intro.md (#2702)
Add mention of censoring attack prevented by range proofs
* use sandbox folder for txhashset validation on state sync (#2685)
* use sandbox folder for txhashset validation on state sync
* rustfmt
* use temp directory as the sandbox instead actual db_root txhashset dir
* rustfmt
* move txhashset overwrite to the end of full validation
* fix travis-ci test
* rustfmt
* fix: hashset have 2 folders including txhashset and header
* rustfmt
*
(1)switch to rebuild_header_mmr instead of copy the sandbox header mmr
(2)lock txhashset when overwriting and opening and rebuild
* minor improve on sandbox_dir
* add Japanese edition of state.md (#2703)
* Attempt to fix broken TUI locale (#2713)
Can confirm that on the same machine 1.0.2 TUI looks great and is broken on
the current master. Bump of `cursive` version fixed it for me.
Fixes #2676
* clean the header folder in sandbox (#2716)
* forgot to clean the header folder in sandbox in #2685
* Reduce number of unwraps in servers crate (#2707)
It doesn't include stratum server which is sufficiently changed in 1.1
branch and adapters, which is big enough for a separate PR.
* rustfmt
* change version to beta
2019-04-01 13:47:48 +03:00
|
|
|
backend.check_compact(2, &Bitmap::create()).unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// now check we have pruned up to and including the peak at pos 7
|
|
|
|
// hash still available in underlying hash file
|
|
|
|
assert_eq!(backend.get_hash(7), Some(pos_7_hash));
|
|
|
|
assert_eq!(backend.get_from_file(7), Some(pos_7_hash));
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// now check we still have subsequent hash and data where we expect
|
|
|
|
assert_eq!(backend.get_data(8), Some(pos_8));
|
|
|
|
assert_eq!(backend.get_hash(8), Some(pos_8_hash));
|
|
|
|
assert_eq!(backend.get_from_file(8), Some(pos_8_hash));
|
|
|
|
}
|
2018-03-13 21:22:34 +03:00
|
|
|
|
|
|
|
teardown(data_dir);
|
|
|
|
}
|
|
|
|
|
2018-03-01 00:15:29 +03:00
|
|
|
#[test]
|
|
|
|
fn pmmr_compact_horizon() {
|
|
|
|
let (data_dir, elems) = setup("compact_horizon");
|
2019-02-10 00:14:27 +03:00
|
|
|
{
|
|
|
|
let pos_1_hash;
|
|
|
|
let pos_2_hash;
|
|
|
|
let pos_3_hash;
|
|
|
|
let pos_6_hash;
|
|
|
|
let pos_7_hash;
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
let pos_8;
|
|
|
|
let pos_8_hash;
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
let pos_11;
|
|
|
|
let pos_11_hash;
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
let mmr_size;
|
2018-03-01 00:15:29 +03:00
|
|
|
{
|
2019-02-10 00:14:27 +03:00
|
|
|
let mut backend = store::pmmr::PMMRBackend::new(data_dir.clone(), true, None).unwrap();
|
|
|
|
mmr_size = load(0, &elems[..], &mut backend);
|
|
|
|
backend.sync().unwrap();
|
|
|
|
|
|
|
|
// 0010012001001230
|
|
|
|
// 9 leaves
|
|
|
|
assert_eq!(backend.data_size(), 19);
|
|
|
|
assert_eq!(backend.hash_size(), 35);
|
|
|
|
|
|
|
|
pos_1_hash = backend.get_hash(1).unwrap();
|
|
|
|
pos_2_hash = backend.get_hash(2).unwrap();
|
|
|
|
pos_3_hash = backend.get_hash(3).unwrap();
|
|
|
|
pos_6_hash = backend.get_hash(6).unwrap();
|
|
|
|
pos_7_hash = backend.get_hash(7).unwrap();
|
|
|
|
|
|
|
|
pos_8 = backend.get_data(8).unwrap();
|
|
|
|
pos_8_hash = backend.get_hash(8).unwrap();
|
|
|
|
|
|
|
|
pos_11 = backend.get_data(11).unwrap();
|
|
|
|
pos_11_hash = backend.get_hash(11).unwrap();
|
|
|
|
|
|
|
|
// pruning some choice nodes
|
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.prune(4).unwrap();
|
|
|
|
pmmr.prune(5).unwrap();
|
|
|
|
pmmr.prune(1).unwrap();
|
|
|
|
pmmr.prune(2).unwrap();
|
|
|
|
}
|
|
|
|
backend.sync().unwrap();
|
|
|
|
|
|
|
|
// check we can read hashes and data correctly after pruning
|
|
|
|
{
|
|
|
|
// assert_eq!(backend.get_hash(3), None);
|
|
|
|
assert_eq!(backend.get_from_file(3), Some(pos_3_hash));
|
|
|
|
|
|
|
|
// assert_eq!(backend.get_hash(6), None);
|
|
|
|
assert_eq!(backend.get_from_file(6), Some(pos_6_hash));
|
|
|
|
|
|
|
|
// assert_eq!(backend.get_hash(7), None);
|
|
|
|
assert_eq!(backend.get_from_file(7), Some(pos_7_hash));
|
|
|
|
|
|
|
|
assert_eq!(backend.get_hash(8), Some(pos_8_hash));
|
|
|
|
assert_eq!(backend.get_data(8), Some(pos_8));
|
|
|
|
assert_eq!(backend.get_from_file(8), Some(pos_8_hash));
|
|
|
|
|
|
|
|
assert_eq!(backend.get_hash(11), Some(pos_11_hash));
|
|
|
|
assert_eq!(backend.get_data(11), Some(pos_11));
|
|
|
|
assert_eq!(backend.get_from_file(11), Some(pos_11_hash));
|
|
|
|
}
|
|
|
|
|
|
|
|
// compact
|
[1.1.0] Merge master into 1.1.0 (#2720)
* cleanup legacy "3 dot" check (#2625)
* Allow to peers behind NAT to get up to preferred_max connections (#2543)
Allow to peers behind NAT to get up to preffered_max connections
If peer has only outbound connections it's mot likely behind NAT and we should not stop it from getting more outbound connections
* Reduce usage of unwrap in p2p crate (#2627)
Also change store crate a bit
* Simplify (and fix) output_pos cleanup during chain compaction (#2609)
* expose leaf pos iterator
use it for various things in txhashset when iterating over outputs
* fix
* cleanup
* rebuild output_pos index (and clear it out first) when compacting the chain
* fixup tests
* refactor to match on (output, proof) tuple
* add comments to compact() to explain what is going on.
* get rid of some boxing around the leaf_set iterator
* cleanup
* [docs] Add switch commitment documentation (#2526)
* remove references to no-longer existing switch commitment hash
(as switch commitments were removed in ca8447f3bd49e80578770da841e5fbbac2c23cde
and moved into the blinding factor of the Pedersen Commitment)
* some rewording (points vs curves) and fix of small formatting issues
* Add switch commitment documentation
* [docs] Documents in grin repo had translated in Korean. (#2604)
* Start to M/W intro translate in Korean
* translate in Korean
* add korean translation on intro
* table_of_content.md translate in Korean.
* table_of_content_KR.md finish translate in Korean, start to translate State_KR.md
* add state_KR.md & commit some translation in State_KR.md
* WIP stat_KR.md translation
* add build_KR.md && stratum_KR.md
* finish translate stratum_KR.md & table_of_content_KR.md
* rename intro.KR.md to intro_KR.md
* add intro_KR.md file path each language's intro.md
* add Korean translation file path to stratum.md & table_of_contents.md
* fix difference with grin/master
* Fix TxHashSet file filter for Windows. (#2641)
* Fix TxHashSet file filter for Windows.
* rustfmt
* Updating regexp
* Adding in test case
* Display the current download rate rather than the average when syncing the chain (#2633)
* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.
* Replace the explicitly ignored variables in the pattern with an implicit ignore
* remove root = true from editorconfig (#2655)
* Add Medium post to intro (#2654)
Spoke to @yeastplume who agreed it makes sense to add the "Grin Transactions Explained, Step-by-Step" Medium post to intro.md
Open for suggestions on a better location.
* add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files
* rustfmt
* use a constant instead of multiple 32
* rustfmt
* Fix the build warning of deprecated trim_right_matches (#2662)
* [DOC] state.md, build.md and chain directory documents translate in Korean. (#2649)
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* remove some useless md files for translation. this is rearrange set up translation order.
* add dot end of sentence & translate build.md in korean
* remove fast-sync_KR.md
* finish build_KR.md translation
* finish build_KR.md translation
* finish translation state_KR.md & add phrase in state.md to move other language md file
* translate blocks_and_headers.md && chain_sync.md in Korean
* add . in chain_sync.md , translation finished in doc/chain dir.
* fix some miss typos
* Api documentation fixes (#2646)
* Fix the API documentation for Chain Validate (v1/chain/validate). It was documented as a POST, but it is actually a GET request, which can be seen in its handler ChainValidationHandler
* Update the API V1 route list response to include the headers and merkleproof routes. Also clarify that for the chain/outputs route you must specify either byids or byheight to select outputs.
* refactor(ci): reorganize CI related code (#2658)
Break-down the CI related code into smaller more maintainable pieces.
* Specify grin or nanogrins in API docs where applicable (#2642)
* Set Content-Type in API client (#2680)
* Reduce number of unwraps in chain crate (#2679)
* fix: the restart of state sync doesn't work sometimes (#2687)
* let check_txhashset_needed return true on abnormal case (#2684)
* Reduce number of unwwaps in api crate (#2681)
* Reduce number of unwwaps in api crate
* Format use section
* Small QoL improvements for wallet developers (#2651)
* Small changes for wallet devs
* Move create_nonce into Keychain trait
* Replace match by map_err
* Add flag to Slate to skip fee check
* Fix secp dependency
* Remove check_fee flag in Slate
* Add Japanese edition of build.md (#2697)
* catch the panic to avoid peer thread quit early (#2686)
* catch the panic to avoid peer thread quit before taking the chance to ban
* move catch wrapper logic down into the util crate
* log the panic info
* keep txhashset.rs untouched
* remove a warning
* [DOC] dandelion.md, simulation.md ,fast-sync.md and pruning.md documents translate in Korean. (#2678)
* Show response code in API client error message (#2683)
It's hard to investigate what happens when an API client error is
printed out
* Add some better logging for get_outputs_by_id failure states (#2705)
* Switch commitment doc fixes (#2645)
Fix some typos and remove the use of parentheses in a
couple of places to make the reading flow a bit better.
* docs: update/add new README.md badges (#2708)
Replace existing badges with SVG counterparts and add a bunch of new ones.
* Update intro.md (#2702)
Add mention of censoring attack prevented by range proofs
* use sandbox folder for txhashset validation on state sync (#2685)
* use sandbox folder for txhashset validation on state sync
* rustfmt
* use temp directory as the sandbox instead actual db_root txhashset dir
* rustfmt
* move txhashset overwrite to the end of full validation
* fix travis-ci test
* rustfmt
* fix: hashset have 2 folders including txhashset and header
* rustfmt
*
(1)switch to rebuild_header_mmr instead of copy the sandbox header mmr
(2)lock txhashset when overwriting and opening and rebuild
* minor improve on sandbox_dir
* add Japanese edition of state.md (#2703)
* Attempt to fix broken TUI locale (#2713)
Can confirm that on the same machine 1.0.2 TUI looks great and is broken on
the current master. Bump of `cursive` version fixed it for me.
Fixes #2676
* clean the header folder in sandbox (#2716)
* forgot to clean the header folder in sandbox in #2685
* Reduce number of unwraps in servers crate (#2707)
It doesn't include stratum server which is sufficiently changed in 1.1
branch and adapters, which is big enough for a separate PR.
* rustfmt
* change version to beta
2019-04-01 13:47:48 +03:00
|
|
|
backend.check_compact(4, &Bitmap::of(&vec![1, 2])).unwrap();
|
2019-02-10 00:14:27 +03:00
|
|
|
backend.sync().unwrap();
|
|
|
|
|
|
|
|
// check we can read a hash by pos correctly after compaction
|
|
|
|
{
|
|
|
|
assert_eq!(backend.get_hash(1), None);
|
|
|
|
assert_eq!(backend.get_from_file(1), Some(pos_1_hash));
|
|
|
|
|
|
|
|
assert_eq!(backend.get_hash(2), None);
|
|
|
|
assert_eq!(backend.get_from_file(2), Some(pos_2_hash));
|
|
|
|
|
|
|
|
assert_eq!(backend.get_hash(3), Some(pos_3_hash));
|
|
|
|
|
|
|
|
assert_eq!(backend.get_hash(4), None);
|
|
|
|
assert_eq!(backend.get_hash(5), None);
|
|
|
|
assert_eq!(backend.get_hash(6), Some(pos_6_hash));
|
|
|
|
|
|
|
|
assert_eq!(backend.get_from_file(7), Some(pos_7_hash));
|
|
|
|
|
|
|
|
assert_eq!(backend.get_hash(8), Some(pos_8_hash));
|
|
|
|
assert_eq!(backend.get_from_file(8), Some(pos_8_hash));
|
|
|
|
}
|
2018-03-01 00:15:29 +03:00
|
|
|
}
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// recheck stored data
|
2018-03-13 21:22:34 +03:00
|
|
|
{
|
2019-02-10 00:14:27 +03:00
|
|
|
// recreate backend
|
|
|
|
let backend =
|
|
|
|
store::pmmr::PMMRBackend::<TestElem>::new(data_dir.to_string(), true, None)
|
|
|
|
.unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
assert_eq!(backend.data_size(), 19);
|
|
|
|
assert_eq!(backend.hash_size(), 35);
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// check we can read a hash by pos correctly from recreated backend
|
|
|
|
assert_eq!(backend.get_hash(7), Some(pos_7_hash));
|
2018-03-13 21:22:34 +03:00
|
|
|
assert_eq!(backend.get_from_file(7), Some(pos_7_hash));
|
|
|
|
|
2018-03-24 02:33:59 +03:00
|
|
|
assert_eq!(backend.get_hash(8), Some(pos_8_hash));
|
2018-03-13 21:22:34 +03:00
|
|
|
assert_eq!(backend.get_from_file(8), Some(pos_8_hash));
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2019-02-10 00:14:27 +03:00
|
|
|
let mut backend =
|
|
|
|
store::pmmr::PMMRBackend::<TestElem>::new(data_dir.to_string(), true, None)
|
|
|
|
.unwrap();
|
2018-06-18 18:18:38 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
pmmr.prune(8).unwrap();
|
|
|
|
pmmr.prune(9).unwrap();
|
|
|
|
}
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// compact some more
|
[1.1.0] Merge master into 1.1.0 (#2720)
* cleanup legacy "3 dot" check (#2625)
* Allow to peers behind NAT to get up to preferred_max connections (#2543)
Allow to peers behind NAT to get up to preffered_max connections
If peer has only outbound connections it's mot likely behind NAT and we should not stop it from getting more outbound connections
* Reduce usage of unwrap in p2p crate (#2627)
Also change store crate a bit
* Simplify (and fix) output_pos cleanup during chain compaction (#2609)
* expose leaf pos iterator
use it for various things in txhashset when iterating over outputs
* fix
* cleanup
* rebuild output_pos index (and clear it out first) when compacting the chain
* fixup tests
* refactor to match on (output, proof) tuple
* add comments to compact() to explain what is going on.
* get rid of some boxing around the leaf_set iterator
* cleanup
* [docs] Add switch commitment documentation (#2526)
* remove references to no-longer existing switch commitment hash
(as switch commitments were removed in ca8447f3bd49e80578770da841e5fbbac2c23cde
and moved into the blinding factor of the Pedersen Commitment)
* some rewording (points vs curves) and fix of small formatting issues
* Add switch commitment documentation
* [docs] Documents in grin repo had translated in Korean. (#2604)
* Start to M/W intro translate in Korean
* translate in Korean
* add korean translation on intro
* table_of_content.md translate in Korean.
* table_of_content_KR.md finish translate in Korean, start to translate State_KR.md
* add state_KR.md & commit some translation in State_KR.md
* WIP stat_KR.md translation
* add build_KR.md && stratum_KR.md
* finish translate stratum_KR.md & table_of_content_KR.md
* rename intro.KR.md to intro_KR.md
* add intro_KR.md file path each language's intro.md
* add Korean translation file path to stratum.md & table_of_contents.md
* fix difference with grin/master
* Fix TxHashSet file filter for Windows. (#2641)
* Fix TxHashSet file filter for Windows.
* rustfmt
* Updating regexp
* Adding in test case
* Display the current download rate rather than the average when syncing the chain (#2633)
* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.
* Replace the explicitly ignored variables in the pattern with an implicit ignore
* remove root = true from editorconfig (#2655)
* Add Medium post to intro (#2654)
Spoke to @yeastplume who agreed it makes sense to add the "Grin Transactions Explained, Step-by-Step" Medium post to intro.md
Open for suggestions on a better location.
* add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files
* rustfmt
* use a constant instead of multiple 32
* rustfmt
* Fix the build warning of deprecated trim_right_matches (#2662)
* [DOC] state.md, build.md and chain directory documents translate in Korean. (#2649)
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* remove some useless md files for translation. this is rearrange set up translation order.
* add dot end of sentence & translate build.md in korean
* remove fast-sync_KR.md
* finish build_KR.md translation
* finish build_KR.md translation
* finish translation state_KR.md & add phrase in state.md to move other language md file
* translate blocks_and_headers.md && chain_sync.md in Korean
* add . in chain_sync.md , translation finished in doc/chain dir.
* fix some miss typos
* Api documentation fixes (#2646)
* Fix the API documentation for Chain Validate (v1/chain/validate). It was documented as a POST, but it is actually a GET request, which can be seen in its handler ChainValidationHandler
* Update the API V1 route list response to include the headers and merkleproof routes. Also clarify that for the chain/outputs route you must specify either byids or byheight to select outputs.
* refactor(ci): reorganize CI related code (#2658)
Break-down the CI related code into smaller more maintainable pieces.
* Specify grin or nanogrins in API docs where applicable (#2642)
* Set Content-Type in API client (#2680)
* Reduce number of unwraps in chain crate (#2679)
* fix: the restart of state sync doesn't work sometimes (#2687)
* let check_txhashset_needed return true on abnormal case (#2684)
* Reduce number of unwwaps in api crate (#2681)
* Reduce number of unwwaps in api crate
* Format use section
* Small QoL improvements for wallet developers (#2651)
* Small changes for wallet devs
* Move create_nonce into Keychain trait
* Replace match by map_err
* Add flag to Slate to skip fee check
* Fix secp dependency
* Remove check_fee flag in Slate
* Add Japanese edition of build.md (#2697)
* catch the panic to avoid peer thread quit early (#2686)
* catch the panic to avoid peer thread quit before taking the chance to ban
* move catch wrapper logic down into the util crate
* log the panic info
* keep txhashset.rs untouched
* remove a warning
* [DOC] dandelion.md, simulation.md ,fast-sync.md and pruning.md documents translate in Korean. (#2678)
* Show response code in API client error message (#2683)
It's hard to investigate what happens when an API client error is
printed out
* Add some better logging for get_outputs_by_id failure states (#2705)
* Switch commitment doc fixes (#2645)
Fix some typos and remove the use of parentheses in a
couple of places to make the reading flow a bit better.
* docs: update/add new README.md badges (#2708)
Replace existing badges with SVG counterparts and add a bunch of new ones.
* Update intro.md (#2702)
Add mention of censoring attack prevented by range proofs
* use sandbox folder for txhashset validation on state sync (#2685)
* use sandbox folder for txhashset validation on state sync
* rustfmt
* use temp directory as the sandbox instead actual db_root txhashset dir
* rustfmt
* move txhashset overwrite to the end of full validation
* fix travis-ci test
* rustfmt
* fix: hashset have 2 folders including txhashset and header
* rustfmt
*
(1)switch to rebuild_header_mmr instead of copy the sandbox header mmr
(2)lock txhashset when overwriting and opening and rebuild
* minor improve on sandbox_dir
* add Japanese edition of state.md (#2703)
* Attempt to fix broken TUI locale (#2713)
Can confirm that on the same machine 1.0.2 TUI looks great and is broken on
the current master. Bump of `cursive` version fixed it for me.
Fixes #2676
* clean the header folder in sandbox (#2716)
* forgot to clean the header folder in sandbox in #2685
* Reduce number of unwraps in servers crate (#2707)
It doesn't include stratum server which is sufficiently changed in 1.1
branch and adapters, which is big enough for a separate PR.
* rustfmt
* change version to beta
2019-04-01 13:47:48 +03:00
|
|
|
backend.check_compact(9, &Bitmap::create()).unwrap();
|
2018-03-13 21:22:34 +03:00
|
|
|
}
|
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// recheck stored data
|
2018-03-13 21:22:34 +03:00
|
|
|
{
|
2019-02-10 00:14:27 +03:00
|
|
|
// recreate backend
|
|
|
|
let backend =
|
|
|
|
store::pmmr::PMMRBackend::<TestElem>::new(data_dir.to_string(), true, None)
|
|
|
|
.unwrap();
|
2018-03-01 00:15:29 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// 0010012001001230
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
assert_eq!(backend.data_size(), 13);
|
|
|
|
assert_eq!(backend.hash_size(), 27);
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// check we can read a hash by pos correctly from recreated backend
|
|
|
|
// get_hash() and get_from_file() should return the same value
|
|
|
|
// and we only store leaves in the leaf_set so pos 7 still has a hash in there
|
|
|
|
assert_eq!(backend.get_hash(7), Some(pos_7_hash));
|
|
|
|
assert_eq!(backend.get_from_file(7), Some(pos_7_hash));
|
2018-03-13 21:22:34 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
assert_eq!(backend.get_hash(11), Some(pos_11_hash));
|
|
|
|
assert_eq!(backend.get_data(11), Some(pos_11));
|
|
|
|
assert_eq!(backend.get_from_file(11), Some(pos_11_hash));
|
|
|
|
}
|
2018-03-01 00:15:29 +03:00
|
|
|
}
|
|
|
|
|
2018-06-07 00:46:21 +03:00
|
|
|
teardown(data_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compact_twice() {
|
|
|
|
let (data_dir, elems) = setup("compact_twice");
|
|
|
|
|
|
|
|
// setup the mmr store with all elements
|
2019-02-10 00:14:27 +03:00
|
|
|
// Scoped to allow Windows to teardown
|
|
|
|
{
|
|
|
|
let mut backend = store::pmmr::PMMRBackend::new(data_dir.to_string(), true, None).unwrap();
|
|
|
|
let mmr_size = load(0, &elems[..], &mut backend);
|
|
|
|
backend.sync().unwrap();
|
2018-06-07 00:46:21 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// save the root
|
|
|
|
let root = {
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.root()
|
|
|
|
};
|
2018-06-07 00:46:21 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// pruning some choice nodes
|
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.prune(1).unwrap();
|
|
|
|
pmmr.prune(2).unwrap();
|
|
|
|
pmmr.prune(4).unwrap();
|
|
|
|
}
|
|
|
|
backend.sync().unwrap();
|
2018-06-07 00:46:21 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// check the root and stored data
|
|
|
|
{
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
assert_eq!(root, pmmr.root());
|
|
|
|
assert_eq!(pmmr.get_data(5).unwrap(), TestElem(4));
|
|
|
|
assert_eq!(pmmr.get_data(11).unwrap(), TestElem(7));
|
|
|
|
}
|
2018-06-07 00:46:21 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// compact
|
[1.1.0] Merge master into 1.1.0 (#2720)
* cleanup legacy "3 dot" check (#2625)
* Allow to peers behind NAT to get up to preferred_max connections (#2543)
Allow to peers behind NAT to get up to preffered_max connections
If peer has only outbound connections it's mot likely behind NAT and we should not stop it from getting more outbound connections
* Reduce usage of unwrap in p2p crate (#2627)
Also change store crate a bit
* Simplify (and fix) output_pos cleanup during chain compaction (#2609)
* expose leaf pos iterator
use it for various things in txhashset when iterating over outputs
* fix
* cleanup
* rebuild output_pos index (and clear it out first) when compacting the chain
* fixup tests
* refactor to match on (output, proof) tuple
* add comments to compact() to explain what is going on.
* get rid of some boxing around the leaf_set iterator
* cleanup
* [docs] Add switch commitment documentation (#2526)
* remove references to no-longer existing switch commitment hash
(as switch commitments were removed in ca8447f3bd49e80578770da841e5fbbac2c23cde
and moved into the blinding factor of the Pedersen Commitment)
* some rewording (points vs curves) and fix of small formatting issues
* Add switch commitment documentation
* [docs] Documents in grin repo had translated in Korean. (#2604)
* Start to M/W intro translate in Korean
* translate in Korean
* add korean translation on intro
* table_of_content.md translate in Korean.
* table_of_content_KR.md finish translate in Korean, start to translate State_KR.md
* add state_KR.md & commit some translation in State_KR.md
* WIP stat_KR.md translation
* add build_KR.md && stratum_KR.md
* finish translate stratum_KR.md & table_of_content_KR.md
* rename intro.KR.md to intro_KR.md
* add intro_KR.md file path each language's intro.md
* add Korean translation file path to stratum.md & table_of_contents.md
* fix difference with grin/master
* Fix TxHashSet file filter for Windows. (#2641)
* Fix TxHashSet file filter for Windows.
* rustfmt
* Updating regexp
* Adding in test case
* Display the current download rate rather than the average when syncing the chain (#2633)
* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.
* Replace the explicitly ignored variables in the pattern with an implicit ignore
* remove root = true from editorconfig (#2655)
* Add Medium post to intro (#2654)
Spoke to @yeastplume who agreed it makes sense to add the "Grin Transactions Explained, Step-by-Step" Medium post to intro.md
Open for suggestions on a better location.
* add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files
* rustfmt
* use a constant instead of multiple 32
* rustfmt
* Fix the build warning of deprecated trim_right_matches (#2662)
* [DOC] state.md, build.md and chain directory documents translate in Korean. (#2649)
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* remove some useless md files for translation. this is rearrange set up translation order.
* add dot end of sentence & translate build.md in korean
* remove fast-sync_KR.md
* finish build_KR.md translation
* finish build_KR.md translation
* finish translation state_KR.md & add phrase in state.md to move other language md file
* translate blocks_and_headers.md && chain_sync.md in Korean
* add . in chain_sync.md , translation finished in doc/chain dir.
* fix some miss typos
* Api documentation fixes (#2646)
* Fix the API documentation for Chain Validate (v1/chain/validate). It was documented as a POST, but it is actually a GET request, which can be seen in its handler ChainValidationHandler
* Update the API V1 route list response to include the headers and merkleproof routes. Also clarify that for the chain/outputs route you must specify either byids or byheight to select outputs.
* refactor(ci): reorganize CI related code (#2658)
Break-down the CI related code into smaller more maintainable pieces.
* Specify grin or nanogrins in API docs where applicable (#2642)
* Set Content-Type in API client (#2680)
* Reduce number of unwraps in chain crate (#2679)
* fix: the restart of state sync doesn't work sometimes (#2687)
* let check_txhashset_needed return true on abnormal case (#2684)
* Reduce number of unwwaps in api crate (#2681)
* Reduce number of unwwaps in api crate
* Format use section
* Small QoL improvements for wallet developers (#2651)
* Small changes for wallet devs
* Move create_nonce into Keychain trait
* Replace match by map_err
* Add flag to Slate to skip fee check
* Fix secp dependency
* Remove check_fee flag in Slate
* Add Japanese edition of build.md (#2697)
* catch the panic to avoid peer thread quit early (#2686)
* catch the panic to avoid peer thread quit before taking the chance to ban
* move catch wrapper logic down into the util crate
* log the panic info
* keep txhashset.rs untouched
* remove a warning
* [DOC] dandelion.md, simulation.md ,fast-sync.md and pruning.md documents translate in Korean. (#2678)
* Show response code in API client error message (#2683)
It's hard to investigate what happens when an API client error is
printed out
* Add some better logging for get_outputs_by_id failure states (#2705)
* Switch commitment doc fixes (#2645)
Fix some typos and remove the use of parentheses in a
couple of places to make the reading flow a bit better.
* docs: update/add new README.md badges (#2708)
Replace existing badges with SVG counterparts and add a bunch of new ones.
* Update intro.md (#2702)
Add mention of censoring attack prevented by range proofs
* use sandbox folder for txhashset validation on state sync (#2685)
* use sandbox folder for txhashset validation on state sync
* rustfmt
* use temp directory as the sandbox instead actual db_root txhashset dir
* rustfmt
* move txhashset overwrite to the end of full validation
* fix travis-ci test
* rustfmt
* fix: hashset have 2 folders including txhashset and header
* rustfmt
*
(1)switch to rebuild_header_mmr instead of copy the sandbox header mmr
(2)lock txhashset when overwriting and opening and rebuild
* minor improve on sandbox_dir
* add Japanese edition of state.md (#2703)
* Attempt to fix broken TUI locale (#2713)
Can confirm that on the same machine 1.0.2 TUI looks great and is broken on
the current master. Bump of `cursive` version fixed it for me.
Fixes #2676
* clean the header folder in sandbox (#2716)
* forgot to clean the header folder in sandbox in #2685
* Reduce number of unwraps in servers crate (#2707)
It doesn't include stratum server which is sufficiently changed in 1.1
branch and adapters, which is big enough for a separate PR.
* rustfmt
* change version to beta
2019-04-01 13:47:48 +03:00
|
|
|
backend.check_compact(2, &Bitmap::create()).unwrap();
|
2018-06-07 00:46:21 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// recheck the root and stored data
|
|
|
|
{
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
assert_eq!(root, pmmr.root());
|
|
|
|
assert_eq!(pmmr.get_data(5).unwrap(), TestElem(4));
|
|
|
|
assert_eq!(pmmr.get_data(11).unwrap(), TestElem(7));
|
|
|
|
}
|
2018-06-07 00:46:21 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// now prune some more nodes
|
|
|
|
{
|
|
|
|
let mut pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
pmmr.prune(5).unwrap();
|
|
|
|
pmmr.prune(8).unwrap();
|
|
|
|
pmmr.prune(9).unwrap();
|
|
|
|
}
|
|
|
|
backend.sync().unwrap();
|
2018-06-07 00:46:21 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// recheck the root and stored data
|
|
|
|
{
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
assert_eq!(root, pmmr.root());
|
|
|
|
assert_eq!(pmmr.get_data(11).unwrap(), TestElem(7));
|
|
|
|
}
|
2018-06-07 00:46:21 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// compact
|
[1.1.0] Merge master into 1.1.0 (#2720)
* cleanup legacy "3 dot" check (#2625)
* Allow to peers behind NAT to get up to preferred_max connections (#2543)
Allow to peers behind NAT to get up to preffered_max connections
If peer has only outbound connections it's mot likely behind NAT and we should not stop it from getting more outbound connections
* Reduce usage of unwrap in p2p crate (#2627)
Also change store crate a bit
* Simplify (and fix) output_pos cleanup during chain compaction (#2609)
* expose leaf pos iterator
use it for various things in txhashset when iterating over outputs
* fix
* cleanup
* rebuild output_pos index (and clear it out first) when compacting the chain
* fixup tests
* refactor to match on (output, proof) tuple
* add comments to compact() to explain what is going on.
* get rid of some boxing around the leaf_set iterator
* cleanup
* [docs] Add switch commitment documentation (#2526)
* remove references to no-longer existing switch commitment hash
(as switch commitments were removed in ca8447f3bd49e80578770da841e5fbbac2c23cde
and moved into the blinding factor of the Pedersen Commitment)
* some rewording (points vs curves) and fix of small formatting issues
* Add switch commitment documentation
* [docs] Documents in grin repo had translated in Korean. (#2604)
* Start to M/W intro translate in Korean
* translate in Korean
* add korean translation on intro
* table_of_content.md translate in Korean.
* table_of_content_KR.md finish translate in Korean, start to translate State_KR.md
* add state_KR.md & commit some translation in State_KR.md
* WIP stat_KR.md translation
* add build_KR.md && stratum_KR.md
* finish translate stratum_KR.md & table_of_content_KR.md
* rename intro.KR.md to intro_KR.md
* add intro_KR.md file path each language's intro.md
* add Korean translation file path to stratum.md & table_of_contents.md
* fix difference with grin/master
* Fix TxHashSet file filter for Windows. (#2641)
* Fix TxHashSet file filter for Windows.
* rustfmt
* Updating regexp
* Adding in test case
* Display the current download rate rather than the average when syncing the chain (#2633)
* When syncing the chain, calculate the displayed download speed using the current rate from the most recent iteration, rather than the average download speed from the entire syncing process.
* Replace the explicitly ignored variables in the pattern with an implicit ignore
* remove root = true from editorconfig (#2655)
* Add Medium post to intro (#2654)
Spoke to @yeastplume who agreed it makes sense to add the "Grin Transactions Explained, Step-by-Step" Medium post to intro.md
Open for suggestions on a better location.
* add a new configure item for log_max_files (#2601)
* add a new configure item for log_max_files
* rustfmt
* use a constant instead of multiple 32
* rustfmt
* Fix the build warning of deprecated trim_right_matches (#2662)
* [DOC] state.md, build.md and chain directory documents translate in Korean. (#2649)
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* add md files for translation.
* start to translation fast-sync, code_structure. add file build_KR.md, states_KR.md
* add dandelion_KR.md && simulation_KR.md for Korean translation.
* remove some useless md files for translation. this is rearrange set up translation order.
* add dot end of sentence & translate build.md in korean
* remove fast-sync_KR.md
* finish build_KR.md translation
* finish build_KR.md translation
* finish translation state_KR.md & add phrase in state.md to move other language md file
* translate blocks_and_headers.md && chain_sync.md in Korean
* add . in chain_sync.md , translation finished in doc/chain dir.
* fix some miss typos
* Api documentation fixes (#2646)
* Fix the API documentation for Chain Validate (v1/chain/validate). It was documented as a POST, but it is actually a GET request, which can be seen in its handler ChainValidationHandler
* Update the API V1 route list response to include the headers and merkleproof routes. Also clarify that for the chain/outputs route you must specify either byids or byheight to select outputs.
* refactor(ci): reorganize CI related code (#2658)
Break-down the CI related code into smaller more maintainable pieces.
* Specify grin or nanogrins in API docs where applicable (#2642)
* Set Content-Type in API client (#2680)
* Reduce number of unwraps in chain crate (#2679)
* fix: the restart of state sync doesn't work sometimes (#2687)
* let check_txhashset_needed return true on abnormal case (#2684)
* Reduce number of unwwaps in api crate (#2681)
* Reduce number of unwwaps in api crate
* Format use section
* Small QoL improvements for wallet developers (#2651)
* Small changes for wallet devs
* Move create_nonce into Keychain trait
* Replace match by map_err
* Add flag to Slate to skip fee check
* Fix secp dependency
* Remove check_fee flag in Slate
* Add Japanese edition of build.md (#2697)
* catch the panic to avoid peer thread quit early (#2686)
* catch the panic to avoid peer thread quit before taking the chance to ban
* move catch wrapper logic down into the util crate
* log the panic info
* keep txhashset.rs untouched
* remove a warning
* [DOC] dandelion.md, simulation.md ,fast-sync.md and pruning.md documents translate in Korean. (#2678)
* Show response code in API client error message (#2683)
It's hard to investigate what happens when an API client error is
printed out
* Add some better logging for get_outputs_by_id failure states (#2705)
* Switch commitment doc fixes (#2645)
Fix some typos and remove the use of parentheses in a
couple of places to make the reading flow a bit better.
* docs: update/add new README.md badges (#2708)
Replace existing badges with SVG counterparts and add a bunch of new ones.
* Update intro.md (#2702)
Add mention of censoring attack prevented by range proofs
* use sandbox folder for txhashset validation on state sync (#2685)
* use sandbox folder for txhashset validation on state sync
* rustfmt
* use temp directory as the sandbox instead actual db_root txhashset dir
* rustfmt
* move txhashset overwrite to the end of full validation
* fix travis-ci test
* rustfmt
* fix: hashset have 2 folders including txhashset and header
* rustfmt
*
(1)switch to rebuild_header_mmr instead of copy the sandbox header mmr
(2)lock txhashset when overwriting and opening and rebuild
* minor improve on sandbox_dir
* add Japanese edition of state.md (#2703)
* Attempt to fix broken TUI locale (#2713)
Can confirm that on the same machine 1.0.2 TUI looks great and is broken on
the current master. Bump of `cursive` version fixed it for me.
Fixes #2676
* clean the header folder in sandbox (#2716)
* forgot to clean the header folder in sandbox in #2685
* Reduce number of unwraps in servers crate (#2707)
It doesn't include stratum server which is sufficiently changed in 1.1
branch and adapters, which is big enough for a separate PR.
* rustfmt
* change version to beta
2019-04-01 13:47:48 +03:00
|
|
|
backend.check_compact(2, &Bitmap::create()).unwrap();
|
2018-06-07 00:46:21 +03:00
|
|
|
|
2019-02-10 00:14:27 +03:00
|
|
|
// recheck the root and stored data
|
|
|
|
{
|
|
|
|
let pmmr: PMMR<'_, TestElem, _> = PMMR::at(&mut backend, mmr_size);
|
|
|
|
assert_eq!(root, pmmr.root());
|
|
|
|
assert_eq!(pmmr.get_data(11).unwrap(), TestElem(7));
|
|
|
|
}
|
2018-06-07 00:46:21 +03:00
|
|
|
}
|
|
|
|
|
2018-03-01 00:15:29 +03:00
|
|
|
teardown(data_dir);
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:35:25 +03:00
|
|
|
#[test]
|
|
|
|
fn cleanup_rewind_files_test() {
|
|
|
|
let expected = 10;
|
|
|
|
let prefix_to_delete = "foo";
|
|
|
|
let prefix_to_save = "bar";
|
|
|
|
let seconds_to_delete_after = 100;
|
|
|
|
|
|
|
|
// create the scenario
|
|
|
|
let (data_dir, _) = setup("cleanup_rewind_files_test");
|
|
|
|
// create some files with the delete prefix that aren't yet old enough to delete
|
|
|
|
create_numbered_files(&data_dir, expected, prefix_to_delete, 0, 0);
|
|
|
|
// create some files with the delete prefix that are old enough to delete
|
|
|
|
create_numbered_files(
|
|
|
|
&data_dir,
|
|
|
|
expected,
|
|
|
|
prefix_to_delete,
|
|
|
|
seconds_to_delete_after,
|
|
|
|
expected,
|
|
|
|
);
|
|
|
|
// create some files with the save prefix that are old enough to delete, but will be saved because they don't start
|
|
|
|
// with the right prefix
|
|
|
|
create_numbered_files(
|
|
|
|
&data_dir,
|
|
|
|
expected,
|
|
|
|
prefix_to_save,
|
|
|
|
seconds_to_delete_after,
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
|
|
|
|
// run the cleaner
|
|
|
|
let actual =
|
|
|
|
store::pmmr::clean_files_by_prefix(&data_dir, prefix_to_delete, seconds_to_delete_after)
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(
|
|
|
|
actual, expected,
|
|
|
|
"the clean files by prefix function did not report the correct number of files deleted"
|
|
|
|
);
|
|
|
|
|
|
|
|
// check that the reported number is actually correct, the block is to borrow data_dir for the closure
|
|
|
|
{
|
|
|
|
// this function simply counts the number of files in the directory based on the prefix
|
|
|
|
let count_fn = |prefix| {
|
|
|
|
let mut remaining_count = 0;
|
|
|
|
for entry in fs::read_dir(&data_dir).unwrap() {
|
|
|
|
if entry
|
|
|
|
.unwrap()
|
|
|
|
.file_name()
|
|
|
|
.into_string()
|
|
|
|
.unwrap()
|
|
|
|
.starts_with(prefix)
|
|
|
|
{
|
|
|
|
remaining_count += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
remaining_count
|
|
|
|
};
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
count_fn(prefix_to_delete),
|
|
|
|
expected, // we expect this many to be left because they weren't old enough to be deleted yet
|
|
|
|
"it should delete all of the files it is supposed to delete"
|
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
count_fn(prefix_to_save),
|
|
|
|
expected,
|
|
|
|
"it should delete none of the files it is not supposed to"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown(data_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create some files for testing with, for example
|
|
|
|
///
|
|
|
|
/// ```text
|
|
|
|
/// create_numbered_files(".", 3, "hello.txt.", 100, 2)
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// will create files
|
|
|
|
///
|
|
|
|
/// ```text
|
|
|
|
/// hello.txt.2
|
|
|
|
/// hello.txt.3
|
|
|
|
/// hello.txt.4
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// in the current working directory that are all 100 seconds old (modified and accessed time)
|
|
|
|
///
|
|
|
|
fn create_numbered_files(
|
|
|
|
data_dir: &str,
|
|
|
|
num_files: u32,
|
|
|
|
prefix: &str,
|
|
|
|
last_accessed_delay_seconds: u64,
|
|
|
|
start_index: u32,
|
|
|
|
) {
|
|
|
|
let now = std::time::SystemTime::now();
|
|
|
|
let time_to_set = now - std::time::Duration::from_secs(last_accessed_delay_seconds);
|
|
|
|
let time_to_set_ft = filetime::FileTime::from_system_time(time_to_set);
|
|
|
|
|
|
|
|
for rewind_file_num in 0..num_files {
|
|
|
|
let path = std::path::Path::new(&data_dir).join(format!(
|
|
|
|
"{}.{}",
|
|
|
|
prefix,
|
|
|
|
start_index + rewind_file_num
|
|
|
|
));
|
2019-01-02 02:29:16 +03:00
|
|
|
let file = fs::File::create(path.clone()).unwrap();
|
2019-01-10 23:18:25 +03:00
|
|
|
let _metadata = file.metadata().unwrap();
|
2019-01-02 02:29:16 +03:00
|
|
|
filetime::set_file_times(path, time_to_set_ft, time_to_set_ft).unwrap();
|
2018-12-10 12:35:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-28 09:12:33 +03:00
|
|
|
fn setup(tag: &str) -> (String, Vec<TestElem>) {
|
2018-06-15 01:59:53 +03:00
|
|
|
match env_logger::try_init() {
|
|
|
|
Ok(_) => println!("Initializing env logger"),
|
|
|
|
Err(e) => println!("env logger already initialized: {:?}", e),
|
|
|
|
};
|
2018-07-30 11:33:28 +03:00
|
|
|
let t = Utc::now();
|
2018-10-18 13:40:58 +03:00
|
|
|
let data_dir = format!(
|
|
|
|
"./target/tmp/{}.{}-{}",
|
|
|
|
t.timestamp(),
|
|
|
|
t.timestamp_subsec_nanos(),
|
|
|
|
tag
|
|
|
|
);
|
2017-09-05 08:50:25 +03:00
|
|
|
fs::create_dir_all(data_dir.clone()).unwrap();
|
|
|
|
|
2018-03-13 21:22:34 +03:00
|
|
|
let mut elems = vec![];
|
|
|
|
for x in 1..20 {
|
|
|
|
elems.push(TestElem(x));
|
|
|
|
}
|
2017-09-05 08:50:25 +03:00
|
|
|
(data_dir, elems)
|
|
|
|
}
|
|
|
|
|
2018-12-10 12:35:25 +03:00
|
|
|
/// note that taking ownership of the data_dir is a feature
|
|
|
|
/// because it will not be able to be used after teardown as intended
|
2018-01-28 09:12:33 +03:00
|
|
|
fn teardown(data_dir: String) {
|
|
|
|
fs::remove_dir_all(data_dir).unwrap();
|
|
|
|
}
|
|
|
|
|
2018-02-22 16:45:13 +03:00
|
|
|
fn load(pos: u64, elems: &[TestElem], backend: &mut store::pmmr::PMMRBackend<TestElem>) -> u64 {
|
2017-09-05 08:50:25 +03:00
|
|
|
let mut pmmr = PMMR::at(backend, pos);
|
|
|
|
for elem in elems {
|
2018-12-02 22:59:24 +03:00
|
|
|
pmmr.push(elem).unwrap();
|
2017-09-05 08:50:25 +03:00
|
|
|
}
|
|
|
|
pmmr.unpruned_size()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
2018-03-13 21:22:34 +03:00
|
|
|
struct TestElem(u32);
|
2018-02-22 16:45:13 +03:00
|
|
|
|
2019-02-15 16:41:19 +03:00
|
|
|
impl DefaultHashable for TestElem {}
|
|
|
|
|
2018-11-01 23:14:46 +03:00
|
|
|
impl FixedLength for TestElem {
|
|
|
|
const LEN: usize = 4;
|
2017-09-05 08:50:25 +03:00
|
|
|
}
|
|
|
|
|
2018-11-27 15:32:39 +03:00
|
|
|
impl PMMRable for TestElem {
|
|
|
|
type E = Self;
|
|
|
|
|
2018-12-02 22:59:24 +03:00
|
|
|
fn as_elmt(&self) -> Self::E {
|
|
|
|
self.clone()
|
2018-11-27 15:32:39 +03:00
|
|
|
}
|
|
|
|
}
|
2018-11-01 23:14:46 +03:00
|
|
|
|
2017-09-05 08:50:25 +03:00
|
|
|
impl Writeable for TestElem {
|
|
|
|
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), Error> {
|
2018-03-13 21:22:34 +03:00
|
|
|
writer.write_u32(self.0)
|
2017-09-05 08:50:25 +03:00
|
|
|
}
|
|
|
|
}
|
2018-02-22 16:45:13 +03:00
|
|
|
impl Readable for TestElem {
|
2018-12-08 02:59:40 +03:00
|
|
|
fn read(reader: &mut dyn Reader) -> Result<TestElem, Error> {
|
2018-03-13 21:22:34 +03:00
|
|
|
Ok(TestElem(reader.read_u32()?))
|
2018-02-22 16:45:13 +03:00
|
|
|
}
|
|
|
|
}
|