Skip to content

Commit

Permalink
remove payer from StateValueMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
msmouse committed Aug 11, 2023
1 parent 8edbf73 commit 4dad7ff
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 41 deletions.
20 changes: 2 additions & 18 deletions aptos-move/aptos-vm/src/move_vm_ext/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,35 +123,23 @@ impl SessionId {
pub fn as_uuid(&self) -> HashValue {
self.hash()
}

pub fn sender(&self) -> Option<AccountAddress> {
match self {
SessionId::Txn { sender, .. }
| SessionId::Prologue { sender, .. }
| SessionId::Epilogue { sender, .. } => Some(*sender),
SessionId::BlockMeta { .. } | SessionId::Genesis { .. } | SessionId::Void => None,
}
}
}

pub struct SessionExt<'r, 'l> {
inner: Session<'r, 'l>,
remote: &'r dyn MoveResolverExt,
new_slot_payer: Option<AccountAddress>,
features: Arc<Features>,
}

impl<'r, 'l> SessionExt<'r, 'l> {
pub fn new(
inner: Session<'r, 'l>,
remote: &'r dyn MoveResolverExt,
new_slot_payer: Option<AccountAddress>,
features: Arc<Features>,
) -> Self {
Self {
inner,
remote,
new_slot_payer,
features,
}
}
Expand All @@ -178,7 +166,6 @@ impl<'r, 'l> SessionExt<'r, 'l> {

let change_set = Self::convert_change_set(
self.remote,
self.new_slot_payer,
self.features.is_storage_slot_metadata_enabled(),
current_time.as_ref(),
change_set,
Expand Down Expand Up @@ -306,7 +293,6 @@ impl<'r, 'l> SessionExt<'r, 'l> {

pub fn convert_change_set<C: AccessPathCache>(
remote: &dyn MoveResolverExt,
new_slot_payer: Option<AccountAddress>,
is_storage_slot_metadata_enabled: bool,
current_time: Option<&CurrentTimeMicroseconds>,
change_set: MoveChangeSet,
Expand All @@ -319,10 +305,8 @@ impl<'r, 'l> SessionExt<'r, 'l> {
) -> Result<VMChangeSet, VMStatus> {
let mut new_slot_metadata: Option<StateValueMetadata> = None;
if is_storage_slot_metadata_enabled {
if let Some(payer) = new_slot_payer {
if let Some(current_time) = current_time {
new_slot_metadata = Some(StateValueMetadata::new(payer, 0, current_time));
}
if let Some(current_time) = current_time {
new_slot_metadata = Some(StateValueMetadata::new(0, current_time));
}
}
let woc = WriteOpConverter {
Expand Down
2 changes: 0 additions & 2 deletions aptos-move/aptos-vm/src/move_vm_ext/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ impl MoveVmExt {
extensions.add(AlgebraContext::new());
extensions.add(NativeAggregatorContext::new(txn_hash, remote));

let sender_opt = session_id.sender();
let script_hash = match session_id {
SessionId::Txn {
sender: _,
Expand Down Expand Up @@ -196,7 +195,6 @@ impl MoveVmExt {
SessionExt::new(
self.inner.new_session_with_extensions(remote, extensions),
remote,
sender_opt,
self.features.clone(),
)
}
Expand Down
14 changes: 7 additions & 7 deletions aptos-move/e2e-move-tests/src/tests/state_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use aptos_types::{
use move_core_types::{account_address::AccountAddress, parser::parse_struct_tag};

#[test]
fn test_track_slot_payer() {
fn test_metadata_tracking() {
let mut harness = MoveHarness::new();
harness.new_epoch(); // so that timestamp is not 0 (rather, 7200000001)
let timestamp = CurrentTimeMicroseconds {
Expand All @@ -25,30 +25,30 @@ fn test_track_slot_payer() {
// create and fund account1
let account1 = harness.new_account_at(address1);

// Disable storage slot payer tracking
// Disable storage slot metadata tracking
harness.enable_features(vec![], vec![FeatureFlag::STORAGE_SLOT_METADATA]);
// Create and fund account2
harness.run_transaction_payload(
&account1,
aptos_cached_packages::aptos_stdlib::aptos_account_transfer(address2, 100),
);
// Observe that the payer is not tracked for address2 resources
// Observe that metadata is not tracked for address2 resources
assert_eq!(
harness.read_resource_metadata(&address2, coin_store.clone()),
Some(None),
);

// Enable storage slot payer tracking
// Enable storage slot metadata tracking
harness.enable_features(vec![FeatureFlag::STORAGE_SLOT_METADATA], vec![]);
// Create and fund account3
harness.run_transaction_payload(
&account1,
aptos_cached_packages::aptos_stdlib::aptos_account_transfer(address3, 100),
);
// Observe that the payer is tracked for address3 resources
// Observe that metadata is tracked for address3 resources
assert_eq!(
harness.read_resource_metadata(&address3, coin_store.clone()),
Some(Some(StateValueMetadata::new(address1, 0, &timestamp))),
Some(Some(StateValueMetadata::new(0, &timestamp))),
);

// Bump the timestamp and modify the resources, observe that metadata doesn't change.
Expand All @@ -67,6 +67,6 @@ fn test_track_slot_payer() {
);
assert_eq!(
harness.read_resource_metadata(&address3, coin_store),
Some(Some(StateValueMetadata::new(address1, 0, &timestamp))),
Some(Some(StateValueMetadata::new(0, &timestamp))),
);
}
2 changes: 0 additions & 2 deletions testsuite/generate-format/tests/staged/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,6 @@ StateValueMetadata:
0:
V0:
STRUCT:
- payer:
TYPENAME: AccountAddress
- deposit: U64
- creation_time_usecs: U64
StructTag:
Expand Down
2 changes: 0 additions & 2 deletions testsuite/generate-format/tests/staged/aptos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ StateValueMetadata:
0:
V0:
STRUCT:
- payer:
TYPENAME: AccountAddress
- deposit: U64
- creation_time_usecs: U64
StructTag:
Expand Down
2 changes: 0 additions & 2 deletions testsuite/generate-format/tests/staged/consensus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,6 @@ StateValueMetadata:
0:
V0:
STRUCT:
- payer:
TYPENAME: AccountAddress
- deposit: U64
- creation_time_usecs: U64
StructTag:
Expand Down
9 changes: 1 addition & 8 deletions types/src/state_store/state_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use aptos_crypto::{
HashValue,
};
use aptos_crypto_derive::{BCSCryptoHash, CryptoHasher};
use move_core_types::account_address::AccountAddress;
use once_cell::sync::OnceCell;
#[cfg(any(test, feature = "fuzzing"))]
use proptest::{arbitrary::Arbitrary, prelude::*};
Expand All @@ -31,20 +30,14 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
)]
pub enum StateValueMetadata {
V0 {
payer: AccountAddress,
deposit: u64,
creation_time_usecs: u64,
},
}

impl StateValueMetadata {
pub fn new(
payer: AccountAddress,
deposit: u64,
creation_time_usecs: &CurrentTimeMicroseconds,
) -> Self {
pub fn new(deposit: u64, creation_time_usecs: &CurrentTimeMicroseconds) -> Self {
Self::V0 {
payer,
deposit,
creation_time_usecs: creation_time_usecs.microseconds,
}
Expand Down

0 comments on commit 4dad7ff

Please sign in to comment.