Record CHECKOUT actions and actions without `block_hash` too
MODIFY
shell/tests/apply_and_verify_context_actions_from_file.rs
shell/tests/apply_and_verify_context_actions_from_file.rs
@@ -20,6 +20,22 @@ use storage::{
use tezos_context::channel::ContextAction;
use tezos_messages::p2p::encoding::prelude::BlockHeaderBuilder;
+pub fn get_tree_action(action: &ContextAction) -> String {
+ match action {
+ ContextAction::Get { .. } => "ContextAction::Get".to_string(),
+ ContextAction::Mem { .. } => "ContextAction::Mem".to_string(),
+ ContextAction::DirMem { .. } => "ContextAction::DirMem".to_string(),
+ ContextAction::Set { .. } => "ContextAction::Set".to_string(),
+ ContextAction::Copy { .. } => "ContextAction::Copy".to_string(),
+ ContextAction::Delete { .. } => "ContextAction::Delete".to_string(),
+ ContextAction::RemoveRecursively { .. } => "ContextAction::RemoveRecursively".to_string(),
+ ContextAction::Commit { .. } => "ContextAction::Commit".to_string(),
+ ContextAction::Fold { .. } => "ContextAction::Fold".to_string(),
+ ContextAction::Checkout { .. } => "ContextAction::Checkout".to_string(),
+ ContextAction::Shutdown { .. } => "ContextAction::Shutdown".to_string(),
+ }
+}
+
fn create_logger() -> Logger {
let drain = slog_async::Async::new(
slog_term::FullFormat::new(slog_term::TermDecorator::new().build())
@@ -207,7 +223,7 @@ fn feed_tezedge_context_with_actions() -> Result<(), Error> {
| ContextAction::Commit { .. }
| ContextAction::Checkout { .. } => {
if let Err(e) = perform_context_action(&action, &mut context) {
- panic!("cannot perform action {:?} error: '{}'", &action, e);
+ panic!("cannot perform action error: '{}'", e);
}
}
ContextAction::Get { .. }
@@ -217,6 +233,14 @@ fn feed_tezedge_context_with_actions() -> Result<(), Error> {
| ContextAction::Shutdown { .. } => {}
};
+ // verify context hashes after each block
+ if let ContextAction::Checkout { context_hash, .. } = action {
+ assert_eq!(
+ context_hash.as_slice(),
+ context.get_last_commit_hash().unwrap().as_slice()
+ );
+ }
+
if let Some(expected_hash) = get_new_tree_hash(&action) {
assert_eq!(context.get_merkle_root(), expected_hash);
}

MODIFY
storage/src/action_file_storage.rs
storage/src/action_file_storage.rs
use crate::action_file::*;
use crate::persistent::{ActionRecordError, ActionRecorder};
use crate::StorageError;
-use crypto::hash::BlockHash;
-use std::collections::HashMap;
-use std::convert::TryFrom;
use std::path::PathBuf;
use tezos_context::channel::ContextAction;
pub struct ActionFileStorage {
file: PathBuf,
- staging: HashMap<BlockHash, Vec<ContextAction>>,
+ staging: Vec<ContextAction>,
level: u32,
}
@@ -20,89 +17,68 @@ impl ActionFileStorage {
pub fn new(path: PathBuf) -> Self {
ActionFileStorage {
file: path,
- staging: HashMap::new(),
+ staging: Vec::new(),
level: 0,
}
}
- fn store_single_action(&mut self, block_hash: BlockHash, action: &ContextAction) {
- let block_actions = self.staging.entry(block_hash).or_default();
- block_actions.push(action.clone());
+ fn store_single_action(&mut self, action: &ContextAction) {
+ self.staging.push(action.clone());
}
- fn store_commit_action(
- &mut self,
- block_hash: BlockHash,
- action: &ContextAction,
- ) -> Result<(), StorageError> {
+ fn store_commit_action(&mut self, action: &ContextAction) -> Result<(), StorageError> {
self.level += 1;
- self.store_single_action(block_hash.clone(), action);
- self.flush_entries_to_file(block_hash)
+ self.store_single_action(action);
+ self.flush_entries_to_file()
}
- fn flush_entries_to_file(&mut self, block_hash: BlockHash) -> Result<(), StorageError> {
+ fn flush_entries_to_file(&mut self) -> Result<(), StorageError> {
let mut action_file_writer =
ActionsFileWriter::new(&self.file).map_err(|e| StorageError::ActionRecordError {
error: ActionRecordError::ActionFileError { error: e },
})?;
- let actions =
- self.staging
- .remove(&block_hash)
- .ok_or(ActionRecordError::MissingActions {
- hash: block_hash.to_base58_check(),
- })?;
-
action_file_writer
- .update(actions)
+ .update(self.staging.clone())
.map_err(ActionRecordError::from)?;
+ self.staging.clear();
Ok(())
}
}
+pub fn get_tree_action(action: &ContextAction) -> String {
+ match action {
+ ContextAction::Get { .. } => "ContextAction::Get".to_string(),
+ ContextAction::Mem { .. } => "ContextAction::Mem".to_string(),
+ ContextAction::DirMem { .. } => "ContextAction::DirMem".to_string(),
+ ContextAction::Set { .. } => "ContextAction::Set".to_string(),
+ ContextAction::Copy { .. } => "ContextAction::Copy".to_string(),
+ ContextAction::Delete { .. } => "ContextAction::Delete".to_string(),
+ ContextAction::RemoveRecursively { .. } => "ContextAction::RemoveRecursively".to_string(),
+ ContextAction::Commit { .. } => "ContextAction::Commit".to_string(),
+ ContextAction::Fold { .. } => "ContextAction::Fold".to_string(),
+ ContextAction::Checkout { .. } => "ContextAction::Checkout".to_string(),
+ ContextAction::Shutdown { .. } => "ContextAction::Shutdown".to_string(),
+ }
+}
+
impl ActionRecorder for ActionFileStorage {
fn record(&mut self, context_action: &ContextAction) -> std::result::Result<(), StorageError> {
match context_action {
- ContextAction::Set {
- block_hash: Some(block_hash),
- ..
- }
- | ContextAction::Copy {
- block_hash: Some(block_hash),
- ..
- }
- | ContextAction::Delete {
- block_hash: Some(block_hash),
- ..
- }
- | ContextAction::RemoveRecursively {
- block_hash: Some(block_hash),
- ..
- }
- | ContextAction::Mem {
- block_hash: Some(block_hash),
- ..
- }
- | ContextAction::DirMem {
- block_hash: Some(block_hash),
- ..
- }
- | ContextAction::Get {
- block_hash: Some(block_hash),
- ..
- }
- | ContextAction::Fold {
- block_hash: Some(block_hash),
- ..
- } => {
- self.store_single_action(BlockHash::try_from(block_hash.clone())?, context_action);
+ ContextAction::Set { .. }
+ | ContextAction::Copy { .. }
+ | ContextAction::Delete { .. }
+ | ContextAction::RemoveRecursively { .. }
+ | ContextAction::Mem { .. }
+ | ContextAction::DirMem { .. }
+ | ContextAction::Get { .. }
+ | ContextAction::Checkout { .. }
+ | ContextAction::Fold { .. } => {
+ self.store_single_action(context_action);
Ok(())
}
- ContextAction::Commit {
- block_hash: Some(block_hash),
- ..
- } => self.store_commit_action(BlockHash::try_from(block_hash.clone())?, context_action),
- _ => Ok(()),
+ ContextAction::Commit { .. } => self.store_commit_action(context_action),
+ ContextAction::Shutdown => Ok(()),
}
}
}

Record CHECKOUT actions and actions without `block_hash` too