Skip to content

Commit

Permalink
automation registry contract - addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nizam-supraoracles committed Jan 3, 2025
1 parent 709e928 commit 78b7b4f
Show file tree
Hide file tree
Showing 8 changed files with 384 additions and 306 deletions.
73 changes: 23 additions & 50 deletions aptos-move/framework/supra-framework/doc/automation_registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ This contract is part of the Supra Framework and is designed to manage automated
- [Function `cancel_task`](#0x1_automation_registry_cancel_task)
- [Function `refund_automation_task_fee`](#0x1_automation_registry_refund_automation_task_fee)
- [Function `update_epoch_interval_in_registry`](#0x1_automation_registry_update_epoch_interval_in_registry)
- [Function `update_last_reconfiguration_time_in_registry`](#0x1_automation_registry_update_last_reconfiguration_time_in_registry)
- [Function `get_next_task_index`](#0x1_automation_registry_get_next_task_index)
- [Function `get_active_task_ids`](#0x1_automation_registry_get_active_task_ids)
- [Function `get_task_details`](#0x1_automation_registry_get_task_details)
Expand Down Expand Up @@ -447,16 +446,6 @@ The default upper limit duration for automation task, specified in seconds (30 d



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

The default epoch interval in second


<pre><code><b>const</b> <a href="automation_registry.md#0x1_automation_registry_DEFAULT_EPOCH_INTERVAL">DEFAULT_EPOCH_INTERVAL</a>: u64 = 7200;
</code></pre>



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

Task is already cancelled.
Expand Down Expand Up @@ -567,6 +556,16 @@ Unauthorized access: the caller is not the owner of the task



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

Conversion factor between microseconds and second


<pre><code><b>const</b> <a href="automation_registry.md#0x1_automation_registry_MICROSECS_CONVERSION_FACTOR">MICROSECS_CONVERSION_FACTOR</a>: u64 = 1000000;
</code></pre>



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

Conversion factor between microseconds and millisecond || millisecond and second
Expand Down Expand Up @@ -613,7 +612,7 @@ The lenght of the transaction hash.



<pre><code><b>public</b> <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_initialize">initialize</a>(supra_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>)
<pre><code><b>public</b> <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_initialize">initialize</a>(supra_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, epoch_interval_microsecs: u64)
</code></pre>


Expand All @@ -622,7 +621,7 @@ The lenght of the transaction hash.
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_initialize">initialize</a>(supra_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>) {
<pre><code><b>public</b> <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_initialize">initialize</a>(supra_framework: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, epoch_interval_microsecs: u64) {
<a href="system_addresses.md#0x1_system_addresses_assert_supra_framework">system_addresses::assert_supra_framework</a>(supra_framework);

<b>move_to</b>(supra_framework, <a href="automation_registry.md#0x1_automation_registry_AutomationRegistryState">AutomationRegistryState</a> {
Expand All @@ -643,7 +642,7 @@ The lenght of the transaction hash.
automation_unit_price: <a href="automation_registry.md#0x1_automation_registry_DEFAULT_AUTOMATION_UNIT_PRICE">DEFAULT_AUTOMATION_UNIT_PRICE</a>,
registry_fee_address: <a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer_address_of">signer::address_of</a>(&registry_fee_resource_signer),
registry_fee_address_signer_cap,
epoch_interval: <a href="automation_registry.md#0x1_automation_registry_DEFAULT_EPOCH_INTERVAL">DEFAULT_EPOCH_INTERVAL</a>,
epoch_interval: epoch_interval_microsecs / <a href="automation_registry.md#0x1_automation_registry_MICROSECS_CONVERSION_FACTOR">MICROSECS_CONVERSION_FACTOR</a>,
last_reconfiguration_time: 0,
})
}
Expand All @@ -659,7 +658,7 @@ The lenght of the transaction hash.



<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_on_new_epoch">on_new_epoch</a>()
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_on_new_epoch">on_new_epoch</a>(last_reconfiguration_time: u64)
</code></pre>


Expand All @@ -668,11 +667,15 @@ The lenght of the transaction hash.
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_on_new_epoch">on_new_epoch</a>() <b>acquires</b> <a href="automation_registry.md#0x1_automation_registry_AutomationRegistryState">AutomationRegistryState</a>, <a href="automation_registry.md#0x1_automation_registry_AutomationRegistry">AutomationRegistry</a> {
<b>let</b> <a href="automation_registry.md#0x1_automation_registry">automation_registry</a> = <b>borrow_global</b>&lt;<a href="automation_registry.md#0x1_automation_registry_AutomationRegistry">AutomationRegistry</a>&gt;(@supra_framework);
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_on_new_epoch">on_new_epoch</a>(
last_reconfiguration_time: u64
) <b>acquires</b> <a href="automation_registry.md#0x1_automation_registry_AutomationRegistryState">AutomationRegistryState</a>, <a href="automation_registry.md#0x1_automation_registry_AutomationRegistry">AutomationRegistry</a> {
<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);
<b>let</b> state = <b>borrow_global_mut</b>&lt;<a href="automation_registry.md#0x1_automation_registry_AutomationRegistryState">AutomationRegistryState</a>&gt;(@supra_framework);
<b>let</b> ids = <a href="../../supra-stdlib/doc/enumerable_map.md#0x1_enumerable_map_get_map_list">enumerable_map::get_map_list</a>(&state.tasks);

<a href="automation_registry.md#0x1_automation_registry">automation_registry</a>.last_reconfiguration_time = last_reconfiguration_time;

<b>let</b> current_time = <a href="timestamp.md#0x1_timestamp_now_seconds">timestamp::now_seconds</a>();
<b>let</b> gas_committed_for_next_epoch = 0;

Expand Down Expand Up @@ -1064,35 +1067,7 @@ Refunds the automation task fee to the user who has removed their task registrat
Update epoch interval in registry while actually update happens in block module


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_update_epoch_interval_in_registry">update_epoch_interval_in_registry</a>(epoch_interval: u64)
</code></pre>



<details>
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_update_epoch_interval_in_registry">update_epoch_interval_in_registry</a>(epoch_interval: u64) <b>acquires</b> <a href="automation_registry.md#0x1_automation_registry_AutomationRegistry">AutomationRegistry</a> {
<b>if</b> (<b>exists</b>&lt;<a href="automation_registry.md#0x1_automation_registry_AutomationRegistry">AutomationRegistry</a>&gt;(@supra_framework)) {
<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">automation_registry</a>.epoch_interval = epoch_interval;
};
}
</code></pre>



</details>

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

## Function `update_last_reconfiguration_time_in_registry`

Update epoch interval in registry while actually update happens in block module


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_update_last_reconfiguration_time_in_registry">update_last_reconfiguration_time_in_registry</a>(last_reconfiguration_time: u64)
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_update_epoch_interval_in_registry">update_epoch_interval_in_registry</a>(epoch_interval_microsecs: u64)
</code></pre>


Expand All @@ -1101,12 +1076,10 @@ Update epoch interval in registry while actually update happens in block module
<summary>Implementation</summary>


<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_update_last_reconfiguration_time_in_registry">update_last_reconfiguration_time_in_registry</a>(
last_reconfiguration_time: u64
) <b>acquires</b> <a href="automation_registry.md#0x1_automation_registry_AutomationRegistry">AutomationRegistry</a> {
<pre><code><b>public</b>(<b>friend</b>) <b>fun</b> <a href="automation_registry.md#0x1_automation_registry_update_epoch_interval_in_registry">update_epoch_interval_in_registry</a>(epoch_interval_microsecs: u64) <b>acquires</b> <a href="automation_registry.md#0x1_automation_registry_AutomationRegistry">AutomationRegistry</a> {
<b>if</b> (<b>exists</b>&lt;<a href="automation_registry.md#0x1_automation_registry_AutomationRegistry">AutomationRegistry</a>&gt;(@supra_framework)) {
<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">automation_registry</a>.last_reconfiguration_time = last_reconfiguration_time;
<a href="automation_registry.md#0x1_automation_registry">automation_registry</a>.epoch_interval = epoch_interval_microsecs / <a href="automation_registry.md#0x1_automation_registry_MICROSECS_CONVERSION_FACTOR">MICROSECS_CONVERSION_FACTOR</a>;
};
}
</code></pre>
Expand Down
18 changes: 15 additions & 3 deletions aptos-move/framework/supra-framework/doc/block.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ Can only be called as part of the Supra governance proposal process established
block_resource.epoch_interval = new_epoch_interval;

// <b>update</b> epoch interval in registry contract
<a href="automation_registry.md#0x1_automation_registry_update_epoch_interval_in_registry">automation_registry::update_epoch_interval_in_registry</a>(new_epoch_interval / 1000000);
<a href="automation_registry.md#0x1_automation_registry_update_epoch_interval_in_registry">automation_registry::update_epoch_interval_in_registry</a>(new_epoch_interval);

<b>if</b> (std::features::module_event_migration_enabled()) {
<a href="event.md#0x1_event_emit">event::emit</a>(
Expand Down Expand Up @@ -669,7 +669,16 @@ The runtime always runs this before executing the transactions in a block.
previous_block_votes_bitvec: <a href="../../aptos-stdlib/../move-stdlib/doc/vector.md#0x1_vector">vector</a>&lt;u8&gt;,
<a href="timestamp.md#0x1_timestamp">timestamp</a>: u64
) <b>acquires</b> <a href="block.md#0x1_block_BlockResource">BlockResource</a>, <a href="block.md#0x1_block_CommitHistory">CommitHistory</a> {
<b>let</b> epoch_interval = <a href="block.md#0x1_block_block_prologue_common">block_prologue_common</a>(&vm, <a href="../../aptos-stdlib/../move-stdlib/doc/hash.md#0x1_hash">hash</a>, epoch, round, proposer, failed_proposer_indices, previous_block_votes_bitvec, <a href="timestamp.md#0x1_timestamp">timestamp</a>);
<b>let</b> epoch_interval = <a href="block.md#0x1_block_block_prologue_common">block_prologue_common</a>(
&vm,
<a href="../../aptos-stdlib/../move-stdlib/doc/hash.md#0x1_hash">hash</a>,
epoch,
round,
proposer,
failed_proposer_indices,
previous_block_votes_bitvec,
<a href="timestamp.md#0x1_timestamp">timestamp</a>
);
<a href="randomness.md#0x1_randomness_on_new_block">randomness::on_new_block</a>(&vm, epoch, round, <a href="../../aptos-stdlib/../move-stdlib/doc/option.md#0x1_option_none">option::none</a>());
<b>if</b> (<a href="timestamp.md#0x1_timestamp">timestamp</a> - <a href="reconfiguration.md#0x1_reconfiguration_last_reconfiguration_time">reconfiguration::last_reconfiguration_time</a>() &gt;= epoch_interval) {
<a href="reconfiguration.md#0x1_reconfiguration_reconfigure">reconfiguration::reconfigure</a>();
Expand Down Expand Up @@ -874,7 +883,10 @@ new block event for WriteSetPayload.
<summary>Implementation</summary>


<pre><code><b>public</b> <b>fun</b> <a href="block.md#0x1_block_emit_writeset_block_event">emit_writeset_block_event</a>(vm_signer: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>, fake_block_hash: <b>address</b>) <b>acquires</b> <a href="block.md#0x1_block_BlockResource">BlockResource</a>, <a href="block.md#0x1_block_CommitHistory">CommitHistory</a> {
<pre><code><b>public</b> <b>fun</b> <a href="block.md#0x1_block_emit_writeset_block_event">emit_writeset_block_event</a>(
vm_signer: &<a href="../../aptos-stdlib/../move-stdlib/doc/signer.md#0x1_signer">signer</a>,
fake_block_hash: <b>address</b>
) <b>acquires</b> <a href="block.md#0x1_block_BlockResource">BlockResource</a>, <a href="block.md#0x1_block_CommitHistory">CommitHistory</a> {
<a href="system_addresses.md#0x1_system_addresses_assert_vm">system_addresses::assert_vm</a>(vm_signer);
<b>let</b> block_metadata_ref = <b>borrow_global_mut</b>&lt;<a href="block.md#0x1_block_BlockResource">BlockResource</a>&gt;(@supra_framework);
block_metadata_ref.height = <a href="event.md#0x1_event_counter">event::counter</a>(&block_metadata_ref.new_block_events);
Expand Down
Loading

0 comments on commit 78b7b4f

Please sign in to comment.