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 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ pub enum EntryFunctionCall {
cap_update_table: Vec<u8>,
},

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

Expand Down Expand Up @@ -1202,7 +1203,7 @@ impl EntryFunctionCall {
new_public_key_bytes,
cap_update_table,
),
AutomationRegistryRemoveTask { id } => automation_registry_remove_task(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 @@ -2148,8 +2149,9 @@ pub fn account_rotate_authentication_key_with_rotation_capability(
))
}

/// Remove Automatioon task entry.
pub fn automation_registry_remove_task(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 @@ -2158,7 +2160,7 @@ pub fn automation_registry_remove_task(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(&id).unwrap()],
))
Expand Down Expand Up @@ -5379,11 +5381,11 @@ 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 {
Some(EntryFunctionCall::AutomationRegistryCancelTask {
id: bcs::from_bytes(script.args().get(0)?).ok()?,
})
} else {
Expand Down Expand Up @@ -7288,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
33 changes: 23 additions & 10 deletions aptos-move/framework/supra-framework/doc/automation_registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This contract is part of the Supra Framework and is designed to manage automated
- [Function `charge_automation_fee_from_user`](#0x1_automation_registry_charge_automation_fee_from_user)
- [Function `get_last_epoch_time_second`](#0x1_automation_registry_get_last_epoch_time_second)
- [Function `register`](#0x1_automation_registry_register)
- [Function `remove_task`](#0x1_automation_registry_remove_task)
- [Function `cancel_task`](#0x1_automation_registry_cancel_task)
- [Function `refund_automation_task_fee`](#0x1_automation_registry_refund_automation_task_fee)
- [Function `get_next_task_index`](#0x1_automation_registry_get_next_task_index)
- [Function `get_active_task_ids`](#0x1_automation_registry_get_active_task_ids)
Expand Down Expand Up @@ -200,6 +200,16 @@ Update duration upper limit event
## Constants


<a id="0x1_automation_registry_EINVALID_EXPIRY_TIME"></a>

Invalid expiry time: it cannot be earlier than the current time


<pre><code><b>const</b> <a href="automation_registry.md#0x1_automation_registry_EINVALID_EXPIRY_TIME">EINVALID_EXPIRY_TIME</a>: u64 = 1;
</code></pre>



<a id="0x1_automation_registry_DEFAULT_AUTOMATION_GAS_LIMIT"></a>

The default automation task gas limit
Expand Down Expand Up @@ -235,7 +245,7 @@ The default upper limit duration for automation task, specified in seconds (30 d
Expiry time must be after the start of the next epoch


<pre><code><b>const</b> <a href="automation_registry.md#0x1_automation_registry_EEXPIRY_BEFORE_NEXT_EPOCH">EEXPIRY_BEFORE_NEXT_EPOCH</a>: u64 = 2;
<pre><code><b>const</b> <a href="automation_registry.md#0x1_automation_registry_EEXPIRY_BEFORE_NEXT_EPOCH">EEXPIRY_BEFORE_NEXT_EPOCH</a>: u64 = 3;
</code></pre>


Expand All @@ -245,7 +255,7 @@ Expiry time must be after the start of the next epoch
Expiry time does not go beyond upper cap duration


<pre><code><b>const</b> <a href="automation_registry.md#0x1_automation_registry_EEXPIRY_TIME_UPPER">EEXPIRY_TIME_UPPER</a>: u64 = 1;
<pre><code><b>const</b> <a href="automation_registry.md#0x1_automation_registry_EEXPIRY_TIME_UPPER">EEXPIRY_TIME_UPPER</a>: u64 = 2;
</code></pre>


Expand Down Expand Up @@ -512,9 +522,11 @@ Registers a new automation task entry.
//Well formedness check of payload_tx is done in <b>native</b> layer beforehand.

<b>let</b> current_time = <a href="timestamp.md#0x1_timestamp_now_seconds">timestamp::now_seconds</a>();
<b>assert</b>!(expiry_time &gt; current_time, <a href="automation_registry.md#0x1_automation_registry_EINVALID_EXPIRY_TIME">EINVALID_EXPIRY_TIME</a>);
<b>let</b> task_duration = expiry_time - current_time;
<b>assert</b>!(task_duration &lt; registry_data.duration_upper_limit, <a href="automation_registry.md#0x1_automation_registry_EEXPIRY_TIME_UPPER">EEXPIRY_TIME_UPPER</a>);

// Check that task is valid at least in the next epoch
<b>let</b> epoch_interval = <a href="block.md#0x1_block_get_epoch_interval_secs">block::get_epoch_interval_secs</a>();
<b>let</b> last_epoch_time = <a href="automation_registry.md#0x1_automation_registry_get_last_epoch_time_second">get_last_epoch_time_second</a>();
<b>assert</b>!(expiry_time &gt; (last_epoch_time + epoch_interval), <a href="automation_registry.md#0x1_automation_registry_EEXPIRY_BEFORE_NEXT_EPOCH">EEXPIRY_BEFORE_NEXT_EPOCH</a>);
Expand All @@ -541,14 +553,15 @@ Registers a new automation task entry.

</details>

<a id="0x1_automation_registry_remove_task"></a>
<a id="0x1_automation_registry_cancel_task"></a>

## Function `remove_task`
## Function `cancel_task`

Remove Automatioon task entry.
Cancel Automation task with specified id.
Only existing task can be cancled and only by task onwer.


<pre><code><b>public</b> entry <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_remove_task">remove_task</a>(owner: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, id: u64)
<pre><code><b>public</b> entry <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_cancel_task">cancel_task</a>(owner: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, id: u64)
</code></pre>


Expand All @@ -557,8 +570,8 @@ Remove Automatioon task entry.
<summary>Implementation</summary>


<pre><code><b>public</b> entry <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_remove_task">remove_task</a>(owner: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, id: u64) <b>acquires</b> <a href="automation_registry.md#0x1_automation_registry_AutomationRegistry">AutomationRegistry</a> {
<b>let</b> automation_task_metadata = <a href="automation_registry_state.md#0x1_automation_registry_state_remove_task">automation_registry_state::remove_task</a>(owner, id);
<pre><code><b>public</b> entry <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_cancel_task">cancel_task</a>(owner: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, id: u64) <b>acquires</b> <a href="automation_registry.md#0x1_automation_registry_AutomationRegistry">AutomationRegistry</a> {
<b>let</b> automation_task_metadata = <a href="automation_registry_state.md#0x1_automation_registry_state_cancel_task">automation_registry_state::cancel_task</a>(owner, id);
<b>let</b> <a href="automation_registry.md#0x1_automation_registry">automation_registry</a> = <b>borrow_global_mut</b>&lt;<a href="automation_registry.md#0x1_automation_registry_AutomationRegistry">AutomationRegistry</a>&gt;(@supra_framework);
<a href="automation_registry.md#0x1_automation_registry_refund_automation_task_fee">refund_automation_task_fee</a>(<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(owner), automation_task_metadata, <a href="automation_registry.md#0x1_automation_registry">automation_registry</a>.automation_unit_price);
}
Expand Down Expand Up @@ -737,7 +750,7 @@ Get registry fee resource account address

## Function `get_gas_committed_for_next_epoch`

Ge gas committed for next epoch
Get gas committed for next epoch


<pre><code>#[view]
Expand Down
Loading
Loading