Storage chains part 1 (#7868)

* CLI options and DB upgrade

* Transaction storage

* Block pruning

* Block pruning test

* Style

* Naming

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Style

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Arkadiy Paronyan
2021-01-14 21:55:41 +03:00
committed by GitHub
parent 086c7946ca
commit b59c3297cc
13 changed files with 347 additions and 41 deletions
@@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use crate::error;
use sc_service::{PruningMode, Role};
use sc_service::{PruningMode, Role, KeepBlocks};
use structopt::StructOpt;
/// Parameters to define the pruning mode
@@ -30,11 +30,16 @@ pub struct PruningParams {
/// 256 blocks.
#[structopt(long = "pruning", value_name = "PRUNING_MODE")]
pub pruning: Option<String>,
/// Specify the number of finalized blocks to keep in the database.
///
/// Default is to keep all blocks.
#[structopt(long, value_name = "COUNT")]
pub keep_blocks: Option<u32>,
}
impl PruningParams {
/// Get the pruning value from the parameters
pub fn pruning(&self, unsafe_pruning: bool, role: &Role) -> error::Result<PruningMode> {
pub fn state_pruning(&self, unsafe_pruning: bool, role: &Role) -> error::Result<PruningMode> {
// by default we disable pruning if the node is an authority (i.e.
// `ArchiveAll`), otherwise we keep state for the last 256 blocks. if the
// node is an authority and pruning is enabled explicitly, then we error
@@ -58,4 +63,12 @@ impl PruningParams {
}
})
}
/// Get the block pruning value from the parameters
pub fn keep_blocks(&self) -> error::Result<KeepBlocks> {
Ok(match self.keep_blocks {
Some(n) => KeepBlocks::Some(n),
None => KeepBlocks::All,
})
}
}