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

SYS-4002: Fix primary validator for summary operations #385

Merged

Conversation

micaelffrancoAV
Copy link
Contributor

@micaelffrancoAV micaelffrancoAV commented Apr 19, 2024

Proposed changes

  • PR to change avn primary validator to be calculated based on the block number.

Type of change/Merge

🚨What type of change is this PR?

Put an x in the boxes that apply

  • Release
    • Increase versions
    • Baseline tests passed
    • Release type:
      • Major release
      • Minor release
      • Patch release

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR.

  • You describe the purpose of the PR, e.g.:
    • What does it do?
    • Highlight what important points reviewers should know about;
    • Indicates if there is something left for follow-up PRs.
  • Documentation updated
  • Business logic tested successfully
  • Verify First, Write Last: In Substrate development, it is important that you always ensure preconditions are met and return errors at the beginning. After these checks have completed, then you may begin the function's computation.

Further comments

@@ -181,20 +175,14 @@ pub mod pallet {

#[pallet::storage]
#[pallet::getter(fn get_primary_collator)]
pub type PrimaryCollator<T: Config> = StorageValue<_, PrimaryCollatorData, ValueQuery>;
pub type PrimaryCollator<T: Config> = StorageValue<_, u8, ValueQuery>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename this to make it more explicit? Something like primaryCollatorIndexForEth? I also think we should use a large type for the value. u8 give 255 only and its possible we will end up sending more than that. Perhaps a u32?

let is_primary =
AVN::<T>::is_primary(OperationType::Ethereum, &this_validator.account_id);
if is_primary.is_err() {
let is_primary_validator_for_sending =
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let is_primary_validator_for_sending =
let is_primary =

@@ -836,7 +835,7 @@ pub mod pallet {
return InvalidTransaction::Custom(ERROR_CODE_INVALID_EVENT_DATA).into()
}

if AVN::<T>::is_primary(OperationType::Ethereum, &result.checked_by)
if AVN::<T>::is_primary_validator_for_sending(&result.checked_by)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if AVN::<T>::is_primary_validator_for_sending(&result.checked_by)
if AVN::<T>::is_primary_for_block(&result.checked_by)

validator: &AccountId,
) -> Result<bool, avn_error<TestRuntime>> {
return AVN::is_primary(op_type, validator)
return AVN::is_primary_validator_for_sending(validator)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return AVN::is_primary_validator_for_sending(validator)
return AVN::is_primary_for_block(validator)

@@ -190,7 +190,7 @@ fn test_is_primary_blocknumber_3() {
ext.execute_with(|| {
let block_number = 3;
let expected_primary = account_id_1();
let result = EthereumEvents::is_primary(OperationType::Ethereum, &expected_primary);
let result = EthereumEvents::is_primary_validator_for_sending(&expected_primary);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let result = EthereumEvents::is_primary_validator_for_sending(&expected_primary);
let result = EthereumEvents::is_primary_for_block(&expected_primary);

@@ -312,7 +312,7 @@ fn is_primary_fails_with_no_validators() {
let mut ext = ExtBuilder::build_default().as_externality();
ext.execute_with(|| {
let block_number = 1;
let result = EthereumEvents::is_primary(OperationType::Ethereum, &account_id_1());
let result = EthereumEvents::is_primary_validator_for_sending(&account_id_1());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let result = EthereumEvents::is_primary_validator_for_sending(&account_id_1());
let result = EthereumEvents::is_primary_for_block(&account_id_1());

@@ -751,7 +751,7 @@ pub mod pallet {
safe_add_block_numbers::<BlockNumberFor<T>>(Self::current_slot(), 1u32.into())
.map_err(|_| Error::<T>::Overflow)?;

let new_validator_account_id = AVN::<T>::advance_primary_validator(OperationType::Avn)?;
let new_validator_account_id = AVN::<T>::advance_primary_validator_for_sending()?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should be doing that here. The index is only incremented when sending I think.

@@ -152,19 +159,20 @@ mod challenge_slot_if_required {
assert!(pool_state.read().transactions.is_empty());

System::set_block_number(context.block_after_grace_period);
// let challenge = get_valid_challenge(&context);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// let challenge = get_valid_challenge(&context);

@@ -897,7 +897,7 @@ mod end_voting_period {
Summary::set_previous_summary_slot(5);

let primary_validator_id =
AVN::<TestRuntime>::advance_primary_validator(OperationType::Avn)
AVN::<TestRuntime>::advance_primary_validator_for_sending()
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to advance here? I think only sending should advance.

@@ -131,13 +58,13 @@ mod calling_is_primary_validator_for_ethereum {
let mut ext = ExtBuilder::build_default().with_validators().as_externality();
ext.execute_with(|| {
let expected_primary = 1;
let eth_index_before: u8 = get_index_based_on_operation_type(&OperationType::Ethereum);
let eth_index_before: u8 = AVN::get_primary_collator();
Copy link
Contributor

Choose a reason for hiding this comment

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

where is this defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its the getter for the primary collator storage index.

@@ -143,7 +141,7 @@ fn generate_msg_hash<T: pallet::Config>(
}

fn assign_sender<T: Config>() -> Result<T::AccountId, Error<T>> {
match AVN::<T>::advance_primary_validator(OperationType::Ethereum) {
match AVN::<T>::advance_primary_validator_for_sending() {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Cargo.toml Outdated
@@ -12,7 +12,7 @@ lto = "fat"
codegen-units = 1

[workspace.package]
version = "5.2.3"
version = "5.2.4"
Copy link
Contributor

Choose a reason for hiding this comment

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

and this

@@ -174,7 +174,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("avn-parachain"),
impl_name: create_runtime_str!("avn-parachain"),
authoring_version: 1,
spec_version: 62,
spec_version: 63,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we revert this change please?

@@ -169,7 +169,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("avn-test-parachain"),
impl_name: create_runtime_str!("avn-test-parachain"),
authoring_version: 1,
spec_version: 62,
spec_version: 63,
Copy link
Contributor

Choose a reason for hiding this comment

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

and this too

@micaelffrancoAV micaelffrancoAV merged commit 95e9252 into main Apr 22, 2024
5 checks passed
@micaelffrancoAV micaelffrancoAV deleted the SYS-4002_Fix_primary_validator_for_summary_operations branch April 22, 2024 13:11
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.

4 participants