Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AN-Issue-1409] Handled automation-registry state update on new epoch #144

Merged
merged 9 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ impl AptosVM {
traversal_context,
txn_data.sender(),
registration_params,
txn_data
)
})?;

Expand Down Expand Up @@ -958,6 +959,7 @@ impl AptosVM {
traversal_context: &mut TraversalContext,
sender: AccountAddress,
registration_params: &RegistrationParams,
txn_metadata: &TransactionMetadata,
) -> Result<(), VMStatus> {
// Note: Feature gating is needed here because the traversal of the dependencies could
// result in shallow-loading of the modules and therefore subtle changes in
Expand All @@ -972,7 +974,8 @@ impl AptosVM {
[(module_id.address(), module_id.name())],
)?;
}
let args = registration_params.serialized_args_with_sender(sender);
let args = registration_params
.serialized_args_with_sender_and_parent_hash(sender, txn_metadata.txn_app_hash.clone());

session.execute_function_bypass_visibility(
registration_params.module_id(),
Expand Down
1 change: 0 additions & 1 deletion aptos-move/aptos-vm/src/transaction_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ impl TransactionMetadata {
self.gas_unit_price.into(),
self.chain_id.id(),
payload_type_reference,
self.txn_app_hash.clone(),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn check_successful_registration() {
let result = view_output.values.expect("Valid result");
assert_eq!(result.len(), 1);
let next_task_id = bcs::from_bytes::<u64>(&result[0]).unwrap();
assert_eq!(next_task_id, 2);
assert_eq!(next_task_id, 1);
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ pub enum EntryFunctionCall {
cap_update_table: Vec<u8>,
},

/// Remove Automatioon task entry.
AutomationRegistryRemoveTask {
registry_id: u64,
/// Cancel Automation task with specified id.
/// Only existing task can be cancled and only by task onwer.
AutomationRegistryCancelTask {
id: u64,
},

/// Update Automation gas limit
Expand Down Expand Up @@ -1202,9 +1203,7 @@ impl EntryFunctionCall {
new_public_key_bytes,
cap_update_table,
),
AutomationRegistryRemoveTask { registry_id } => {
automation_registry_remove_task(registry_id)
},
AutomationRegistryCancelTask { id } => automation_registry_cancel_task(id),
AutomationRegistryUpdateAutomationGasLimit {
automation_gas_limit,
} => automation_registry_update_automation_gas_limit(automation_gas_limit),
Expand Down Expand Up @@ -2150,8 +2149,9 @@ pub fn account_rotate_authentication_key_with_rotation_capability(
))
}

/// Remove Automatioon task entry.
pub fn automation_registry_remove_task(registry_id: u64) -> TransactionPayload {
/// Cancel Automation task with specified id.
/// Only existing task can be cancled and only by task onwer.
pub fn automation_registry_cancel_task(id: u64) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
Expand All @@ -2160,9 +2160,9 @@ pub fn automation_registry_remove_task(registry_id: u64) -> TransactionPayload {
]),
ident_str!("automation_registry").to_owned(),
),
ident_str!("remove_task").to_owned(),
ident_str!("cancel_task").to_owned(),
vec![],
vec![bcs::to_bytes(&registry_id).unwrap()],
vec![bcs::to_bytes(&id).unwrap()],
))
}

Expand Down Expand Up @@ -5381,12 +5381,12 @@ mod decoder {
}
}

pub fn automation_registry_remove_task(
pub fn automation_registry_cancel_task(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::AutomationRegistryRemoveTask {
registry_id: bcs::from_bytes(script.args().get(0)?).ok()?,
Some(EntryFunctionCall::AutomationRegistryCancelTask {
id: bcs::from_bytes(script.args().get(0)?).ok()?,
})
} else {
None
Expand Down Expand Up @@ -7290,8 +7290,8 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
Box::new(decoder::account_rotate_authentication_key_with_rotation_capability),
);
map.insert(
"automation_registry_remove_task".to_string(),
Box::new(decoder::automation_registry_remove_task),
"automation_registry_cancel_task".to_string(),
Box::new(decoder::automation_registry_cancel_task),
);
map.insert(
"automation_registry_update_automation_gas_limit".to_string(),
Expand Down
26 changes: 0 additions & 26 deletions aptos-move/framework/src/natives/transaction_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,31 +238,6 @@ fn native_chain_id_internal(
}
}

/***************************************************************************************************
* native fun get_txn_app_hash
*
* gas cost: base_cost
*
**************************************************************************************************/
fn native_txn_app_hash_internal(
context: &mut SafeNativeContext,
_ty_args: Vec<Type>,
_args: VecDeque<Value>,
) -> SafeNativeResult<SmallVec<[Value; 1]>> {
context.charge(TRANSACTION_CONTEXT_GET_TXN_APP_HASH_BASE)?;

let user_transaction_context_opt = get_user_transaction_context_opt_from_context(context);
if let Some(transaction_context) = user_transaction_context_opt {
Ok(smallvec![Value::vector_u8(
transaction_context.txn_app_hash()
)])
} else {
Err(SafeNativeError::Abort {
abort_code: error::invalid_state(abort_codes::ETRANSACTION_CONTEXT_NOT_AVAILABLE),
})
}
}

fn create_option_some_value(value: Value) -> Value {
Value::struct_(Struct::pack(vec![create_singleton_vector(value)]))
}
Expand Down Expand Up @@ -431,7 +406,6 @@ pub fn make_all(
"multisig_payload_internal",
native_multisig_payload_internal,
),
("txn_app_hash_internal", native_txn_app_hash_internal),
];

builder.make_named_natives(natives)
Expand Down
Loading
Loading