Skip to content

Commit

Permalink
[refactoring] Remove unused genesis check from StateView (#9589)
Browse files Browse the repository at this point in the history
`is_genesis()` was defined in `StateView` but never used apart
from a single test with `MockVM`. But the test set it to false
always...

Removing it to have better view interfaces.
  • Loading branch information
georgemitenkov authored Aug 10, 2023
1 parent 262d264 commit a87492b
Show file tree
Hide file tree
Showing 14 changed files with 0 additions and 85 deletions.
4 changes: 0 additions & 4 deletions aptos-move/aptos-aggregator/src/delta_change_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -567,10 +567,6 @@ mod test {
)))
}

fn is_genesis(&self) -> bool {
unreachable!()
}

fn get_usage(&self) -> anyhow::Result<StateStorageUsage> {
unreachable!()
}
Expand Down
4 changes: 0 additions & 4 deletions aptos-move/aptos-validator-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,6 @@ impl TStateView for DebuggerStateView {
self.get_state_value_internal(state_key, self.version)
}

fn is_genesis(&self) -> bool {
false
}

fn get_usage(&self) -> Result<StateStorageUsage> {
unimplemented!()
}
Expand Down
4 changes: 0 additions & 4 deletions aptos-move/aptos-vm/src/move_vm_ext/respawned_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@ impl<'r> TStateView for ChangeSetStateView<'r> {
}
}

fn is_genesis(&self) -> bool {
unreachable!("Unexpected access to is_genesis()")
}

fn get_usage(&self) -> Result<StateStorageUsage> {
bail!("Unexpected access to get_usage()")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,6 @@ impl<'a, S: StateView + Sync + Send> TStateView for CrossShardStateView<'a, S> {
self.base_view.get_state_value(state_key)
}

fn is_genesis(&self) -> bool {
unimplemented!("is_genesis is not implemented for InMemoryStateView")
}

fn get_usage(&self) -> Result<StateStorageUsage> {
Ok(StateStorageUsage::new_untracked())
}
Expand Down
8 changes: 0 additions & 8 deletions aptos-move/block-executor/src/proptest_types/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ where
StateViewId::Miscellaneous
}

fn is_genesis(&self) -> bool {
unreachable!();
}

fn get_usage(&self) -> anyhow::Result<StateStorageUsage> {
unreachable!();
}
Expand All @@ -92,10 +88,6 @@ where
StateViewId::Miscellaneous
}

fn is_genesis(&self) -> bool {
unreachable!();
}

fn get_usage(&self) -> anyhow::Result<StateStorageUsage> {
unreachable!();
}
Expand Down
4 changes: 0 additions & 4 deletions aptos-move/block-executor/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,6 @@ impl<'a, T: Transaction, S: TStateView<Key = T::Key>, X: Executable> TStateView
self.base_view.id()
}

fn is_genesis(&self) -> bool {
self.base_view.is_genesis()
}

fn get_usage(&self) -> Result<StateStorageUsage> {
self.base_view.get_usage()
}
Expand Down
4 changes: 0 additions & 4 deletions aptos-move/e2e-tests/src/data_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ impl TStateView for FakeDataStore {
Ok(self.state_data.get(state_key).cloned())
}

fn is_genesis(&self) -> bool {
self.state_data.is_empty()
}

fn get_usage(&self) -> Result<StateStorageUsage> {
let mut usage = StateStorageUsage::new_untracked();
for (k, v) in self.state_data.iter() {
Expand Down
4 changes: 0 additions & 4 deletions aptos-move/vm-genesis/src/genesis_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ impl TStateView for GenesisStateView {
.map(StateValue::new_legacy))
}

fn is_genesis(&self) -> bool {
true
}

fn get_usage(&self) -> Result<StateStorageUsage> {
Ok(StateStorageUsage::zero())
}
Expand Down
4 changes: 0 additions & 4 deletions execution/executor/src/mock_vm/mock_vm_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ impl TStateView for MockStateView {
Ok(None)
}

fn is_genesis(&self) -> bool {
false
}

fn get_usage(&self) -> Result<StateStorageUsage> {
Ok(StateStorageUsage::new_untracked())
}
Expand Down
21 changes: 0 additions & 21 deletions execution/executor/src/mock_vm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,27 +81,6 @@ impl VMExecutor for MockVM {
state_view: &impl StateView,
_maybe_block_gas_limit: Option<u64>,
) -> Result<Vec<TransactionOutput>, VMStatus> {
if state_view.is_genesis() {
assert_eq!(
transactions.len(),
1,
"Genesis block should have only one transaction."
);
let output = TransactionOutput::new(
gen_genesis_writeset(),
// mock the validator set event
vec![ContractEvent::new(
new_epoch_event_key(),
0,
TypeTag::Bool,
bcs::to_bytes(&0).unwrap(),
)],
0,
KEEP_STATUS.clone(),
);
return Ok(vec![output]);
}

// output_cache is used to store the output of transactions so they are visible to later
// transactions.
let mut output_cache = HashMap::new();
Expand Down
4 changes: 0 additions & 4 deletions storage/state-view/src/in_memory_state_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ impl TStateView for InMemoryStateView {
Ok(self.state_data.get(state_key).cloned())
}

fn is_genesis(&self) -> bool {
unimplemented!("is_genesis is not implemented for InMemoryStateView")
}

fn get_usage(&self) -> Result<StateStorageUsage> {
Ok(StateStorageUsage::new_untracked())
}
Expand Down
8 changes: 0 additions & 8 deletions storage/state-view/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ pub trait TStateView {
/// Gets the state value for a given state key.
fn get_state_value(&self, state_key: &Self::Key) -> Result<Option<StateValue>>;

/// VM needs this method to know whether the current state view is for genesis state creation.
/// Currently TransactionPayload::WriteSet is only valid for genesis state creation.
fn is_genesis(&self) -> bool;

/// Get state storage usage info at epoch ending.
fn get_usage(&self) -> Result<StateStorageUsage>;

Expand Down Expand Up @@ -88,10 +84,6 @@ where
self.deref().get_state_value(state_key)
}

fn is_genesis(&self) -> bool {
self.deref().is_genesis()
}

fn get_usage(&self) -> Result<StateStorageUsage> {
self.deref().get_usage()
}
Expand Down
8 changes: 0 additions & 8 deletions storage/storage-interface/src/cached_state_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ impl TStateView for CachedStateView {
Ok(value_opt.clone())
}

fn is_genesis(&self) -> bool {
self.snapshot.is_none()
}

fn get_usage(&self) -> Result<StateStorageUsage> {
Ok(self.speculative_state.usage())
}
Expand Down Expand Up @@ -267,10 +263,6 @@ impl TStateView for CachedDbStateView {
Ok(new_value.clone())
}

fn is_genesis(&self) -> bool {
self.db_state_view.is_genesis()
}

fn get_usage(&self) -> Result<StateStorageUsage> {
self.db_state_view.get_usage()
}
Expand Down
4 changes: 0 additions & 4 deletions storage/storage-interface/src/state_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ impl TStateView for DbStateView {
self.get(state_key)
}

fn is_genesis(&self) -> bool {
self.version.is_none()
}

fn get_usage(&self) -> Result<StateStorageUsage> {
self.db.get_state_storage_usage(self.version)
}
Expand Down

0 comments on commit a87492b

Please sign in to comment.