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-1435] Enable epoch-interval and last-configuration-time properties in registry #158

Open
wants to merge 7 commits into
base: feature/automation-networks
Choose a base branch
from

Conversation

nizam-supraoracles
Copy link

@nizam-supraoracles nizam-supraoracles self-assigned this Jan 1, 2025
@nizam-supraoracles nizam-supraoracles changed the title [AN-Issue-1434] Enable epoch-interval and last-configuration-time properties in registry [AN-Issue-1435] Enable epoch-interval and last-configuration-time properties in registry Jan 1, 2025
tasks: EnumerableMap<u64, AutomationTaskMetaData>,
current_index: u64,
gas_committed_for_next_epoch: u64,
automation_gas_limit: u64,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to keep AutomationRegistryState as separate struct then I would suggest to remove automation_gas_limit from it's context, otherwise we can flatten and have it embedded in AutomationRegistry.

@@ -51,6 +82,33 @@ module supra_framework::automation_registry {
registry_fee_address: address,
/// Resource account signature capability
registry_fee_address_signer_cap: SignerCapability,
/// Time period between epochs.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is acceptable I would suggest to have a struct enclosing all the properties related to epochs to make the AutomationRegistry more compact

EpochState {
   /// Epoch expected duration at the beginning of the new epoch, Based on this and actual 
   /// epoch-duration which will be (current-time - last_reconfiguration_time) automation tasks 
   /// refunds will be calculated.
   /// it will be updated upon each new epoch start with epoch_interval value. 
   /// Although we should be careful with refunds if block production interval is quite high.
   expected_epoch_duration: u64
   /// Epoch interval that can be updated any moment of the time
   epoch_interval: u64,
  /// Current epoch start time which is the same as last_reconfiguration_time
   start_time: u64,
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we are going to introduce AutomationRegistryConfig as mentioned in the https://github.com/Entropy-Foundation/smr-moonshot/issues/1436 , I have plan to do this with the different PR, if it's okay.

let state = borrow_global_mut<AutomationRegistryState>(@supra_framework);
let ids = enumerable_map::get_map_list(&state.tasks);

automation_registry.last_reconfiguration_time = last_reconfiguration_time;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last_reconfiguration_time should be updated at the very end of this function.
also we can avoid passing it as input parameter as it is going to be the same as timestamp::now_seconds()

let automation_base_fee = task_duration * automation_unit_price;
// todo : dynamic price calculation is pending
supra_account::transfer(owner, registry_fee_address, automation_base_fee);
}

/// Get last epoch time in second
fun get_last_epoch_time_second(): u64 {
let last_epoch_time_ms = reconfiguration::last_reconfiguration_time() / MILLISECOND_CONVERSION_FACTOR;
fun get_last_epoch_time_second(last_reconfiguration_time: u64): u64 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function can be removed already.

let registry_state_data = borrow_global_mut<AutomationRegistryState>(@supra_framework);
let registration_time = timestamp::now_seconds();

assert!(expiry_time > registration_time, EINVALID_EXPIRY_TIME);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's have similar checks close to each other.

… field + remove `last_reconfiguration_time` from on_new_epoch + remove `get_last_epoch_time_second` unused function + update testcases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants