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

A0-1323: Extend Runtime API to handle AlephBFT version #608

Merged
merged 48 commits into from
Oct 19, 2022

Conversation

maciejzelaszczyk
Copy link
Contributor

@maciejzelaszczyk maciejzelaszczyk commented Aug 31, 2022

Description

This extends the AlephSessionApi Runtime API, to handle the AlephBFT version. Storage items, getters, a setter and the declaration and implementation of appropriate methods are provided.

The solution is based on a u32 version. The scheduled version change is persisted as a StorageValue -> FinalityScheduledVersionChange. This value stores the information about a scheduled AlephBFT version change, where version_incoming is the version to be set and session is the session on which the new version will be set. A pallet_session::Session_Manager is implemented to check whether a scheduled version change has moved into the past and, if so, to record it as the current version StorageValue -> FinalityVersion. When a version change is recorded as the current version, FinalityScheduledVersionChange is cleared.

Importantly, we can always reschedule a version change, and an already set version change may move into the past as time goes by. The value of the current_session is needed to check whether the version change needs to be recorded as the current version.

In order to cancel a scheduled version change, we need to use the version change setter (scheduler) and schedule a version change which will actually not change the current version.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have added tests
  • I have created new documentation
  • I have bumped the spec_version and transaction_version

@maciejzelaszczyk maciejzelaszczyk marked this pull request as ready for review September 8, 2022 07:39
@maciejzelaszczyk maciejzelaszczyk marked this pull request as draft September 8, 2022 13:15
@maciejzelaszczyk
Copy link
Contributor Author

maciejzelaszczyk commented Sep 8, 2022

Based on a fruitful conversation with @fixxxedpoint and @kostekIV, I am converting this back to draft, as we have converged on an alternative and potentially more robust scheme to handle version updates. Will re-request review once a working version is ready.

Copy link
Contributor

@timorl timorl left a comment

Choose a reason for hiding this comment

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

LGTM.

Copy link
Contributor

@DamianStraszak DamianStraszak left a comment

Choose a reason for hiding this comment

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

My last doubt is regarding naming in this pallet. We want to use versioning not only for alephBFT but also for signature aggregation, and who knows what else in the future. I think its safe to use a more generic name here like schedule_finality_version_change or schedule_consensus_version_change instead of schedule_aleph_bft_version_change.

We ideally want to avoid changing the names ever, because it is in the runtime.

What do you think @timorl and @kostekIV ?

@kostekIV
Copy link
Contributor

kostekIV commented Oct 3, 2022

My last doubt is regarding naming in this pallet. We want to use versioning not only for alephBFT but also for signature aggregation, and who knows what else in the future. I think its safe to use a more generic name here like schedule_finality_version_change or schedule_consensus_version_change instead of schedule_aleph_bft_version_change.

We ideally want to avoid changing the names ever, because it is in the runtime.

What do you think @timorl and @kostekIV ?

Sounds good, either name is fine to me.

@timorl
Copy link
Contributor

timorl commented Oct 3, 2022

The names you propose sound good, although it's a bit strange that these two things (abft & justifications) get conflated – to be clear I don't have a better solution and this one seems alright, just the versioning will correspond to "official" versions in a strange way.

At the same time I'm worried about the arguments you use – changing names of functions in the runtime (or other changes there for that matter) shouldn't be that disastrous and we should probably spend some time figuring out how to do this better. I think I already mentioned this a long time ago, but it got forgotten... I'll add a task.

…ardinal-Cryptography/aleph-node into A0-1323-aleph-bft-version-coordination
@DamianStraszak
Copy link
Contributor

DamianStraszak commented Oct 3, 2022

Changing the names of runtime calls (=extrinsics) is fine (if these are sudo calls, because only we need to adapt), but changing the names in the runtime API is imho VERY non-trivial, because you need to add some compatibility layer in the host, otherwise a runtime update with new API would crash the node.

We should probably add this compatibility layer when writing the host part of update logic.

That being said -- let's avoid changing names anyway, and use consensus or finality here (I would vote for the latter, as this is the nomenclature used by substrate and nicely reflects what apehbft+aggregator do).

@maciejzelaszczyk
Copy link
Contributor Author

Changing the names of runtime calls (=extrinsics) is fine (if these are sudo calls, because only we need to adapt), but changing the names in the runtime API is imho VERY non-trivial, because you need to add some compatibility layer in the host, otherwise a runtime update with new API would crash the node.

We should probably add this compatibility layer when writing the host part of update logic.

That being said -- let's avoid changing names anyway, and use consensus or finality here (I would vote for the latter, as this is the nomenclature used by substrate and nicely reflects what apehbft+aggregator do).

finality it is :)

Copy link
Contributor

@DamianStraszak DamianStraszak left a comment

Choose a reason for hiding this comment

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

Awesome work!

Copy link
Contributor

@DamianStraszak DamianStraszak left a comment

Choose a reason for hiding this comment

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

Ehh. I approved but now I see that spec_version has not been bumped. Why is that?

@maciejzelaszczyk
Copy link
Contributor Author

Ehh. I approved but now I see that spec_version has not been bumped. Why is that?

First time working on anything in the runtime. Have corrected this just now.

@DamianStraszak
Copy link
Contributor

You must also bump transaction_version -- these things are in the PR checklist exactly because we don't want to miss them :/

@maciejzelaszczyk
Copy link
Contributor Author

You must also bump transaction_version -- these things are in the PR checklist exactly because we don't want to miss them :/

This should be OK now.

@maciejzelaszczyk
Copy link
Contributor Author

@DamianStraszak I have performed some final tests and there is one case that bothers me. Not a bug per se, but worth considering nonetheless. Whenever you use next_session_finality_version, you have to make sure that your call comes after the update_version_change_history call from the SessionManager. Otherwise, the returned version for the next session will not be correct for the session when the change takes hold. I can change this behavior to always return the correct version number at the cost of introducing a storage item. Any thoughts?

@maciejzelaszczyk
Copy link
Contributor Author

Actually, this bothered me too much, so I went and implemented the change.

@maciejzelaszczyk maciejzelaszczyk force-pushed the A0-1323-aleph-bft-version-coordination branch from df0c193 to 95a7fdd Compare October 19, 2022 11:56
@maciejzelaszczyk
Copy link
Contributor Author

Due to a discussion today with @mike1729 and @kostekIV and favorable testing so far I am merging this and will publish a separate PR with the requisite tests shortly.

@maciejzelaszczyk maciejzelaszczyk merged commit 3d1e0fd into main Oct 19, 2022
@maciejzelaszczyk maciejzelaszczyk deleted the A0-1323-aleph-bft-version-coordination branch October 19, 2022 13:03
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.

5 participants