From 43e1d89067dff280d43eea0de3aaee333835ab75 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 27 Mar 2016 14:35:27 +0200 Subject: [PATCH] Fix State cloning. --- ethcore/src/state.rs | 19 +++++++++++++++++++ util/src/journaldb/archivedb.rs | 2 +- util/src/journaldb/earlymergedb.rs | 2 +- util/src/journaldb/overlayrecentdb.rs | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/ethcore/src/state.rs b/ethcore/src/state.rs index 83eb695fc..ad0cf4152 100644 --- a/ethcore/src/state.rs +++ b/ethcore/src/state.rs @@ -405,6 +405,25 @@ fn should_apply_create_transaction() { assert_eq!(result.trace, expected_trace); } +#[test] +fn should_work_when_cloned() { + init_log(); + + let a = Address::zero(); + + let temp = RandomTempPath::new(); + let mut state = { + let mut state = get_temp_state_in(temp.as_path()); + assert_eq!(state.exists(&a), false); + state.inc_nonce(&a); + state.commit(); + state.clone() + }; + + state.inc_nonce(&a); + state.commit(); +} + #[test] fn should_trace_failed_create_transaction() { init_log(); diff --git a/util/src/journaldb/archivedb.rs b/util/src/journaldb/archivedb.rs index 76f0ecc50..82d8a00ba 100644 --- a/util/src/journaldb/archivedb.rs +++ b/util/src/journaldb/archivedb.rs @@ -130,7 +130,7 @@ impl HashDB for ArchiveDB { impl JournalDB for ArchiveDB { fn spawn(&self) -> Box { Box::new(ArchiveDB { - overlay: MemoryDB::new(), + overlay: self.overlay.clone(), backing: self.backing.clone(), latest_era: self.latest_era, }) diff --git a/util/src/journaldb/earlymergedb.rs b/util/src/journaldb/earlymergedb.rs index 15dcacd6a..3e5252404 100644 --- a/util/src/journaldb/earlymergedb.rs +++ b/util/src/journaldb/earlymergedb.rs @@ -322,7 +322,7 @@ impl HashDB for EarlyMergeDB { impl JournalDB for EarlyMergeDB { fn spawn(&self) -> Box { Box::new(EarlyMergeDB { - overlay: MemoryDB::new(), + overlay: self.overlay.clone(), backing: self.backing.clone(), refs: self.refs.clone(), latest_era: self.latest_era.clone(), diff --git a/util/src/journaldb/overlayrecentdb.rs b/util/src/journaldb/overlayrecentdb.rs index 102e23407..236d1f177 100644 --- a/util/src/journaldb/overlayrecentdb.rs +++ b/util/src/journaldb/overlayrecentdb.rs @@ -85,7 +85,7 @@ impl HeapSizeOf for JournalEntry { impl Clone for OverlayRecentDB { fn clone(&self) -> OverlayRecentDB { OverlayRecentDB { - transaction_overlay: MemoryDB::new(), + transaction_overlay: self.transaction_overlay.clone(), backing: self.backing.clone(), journal_overlay: self.journal_overlay.clone(), }