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

Validate the ChainConfig struct at construction time #1845

Merged
merged 14 commits into from
Sep 2, 2022
Merged

Conversation

tyshko5
Copy link
Contributor

@tyshko5 tyshko5 commented Aug 22, 2022

Summary of changes
Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes #1579

Other information and links

@tyshko5 tyshko5 marked this pull request as ready for review August 22, 2022 10:48
forest/src/daemon.rs Outdated Show resolved Hide resolved
types/networks/src/lib.rs Outdated Show resolved Hide resolved
types/networks/src/lib.rs Outdated Show resolved Hide resolved
types/networks/src/lib.rs Outdated Show resolved Hide resolved
types/networks/src/lib.rs Outdated Show resolved Hide resolved
types/networks/src/lib.rs Outdated Show resolved Hide resolved
@tyshko5 tyshko5 requested review from lemmih and LesnyRumcajs August 31, 2022 08:15
types/networks/src/lib.rs Outdated Show resolved Hide resolved
types/networks/src/lib.rs Outdated Show resolved Hide resolved
types/networks/src/lib.rs Outdated Show resolved Hide resolved
@tyshko5 tyshko5 requested a review from LesnyRumcajs September 1, 2022 10:07
@lemmih
Copy link
Contributor

lemmih commented Sep 1, 2022

@tyshko5 You can write a From<Height> for NetworkVersion. It would be a total function and guaranteed to never fail.

@tyshko5
Copy link
Contributor Author

tyshko5 commented Sep 1, 2022

@tyshko5 You can write a From<Height> for NetworkVersion. It would be a total function and guaranteed to never fail.

I've already added a compile-time check

@lemmih
Copy link
Contributor

lemmih commented Sep 1, 2022

@tyshko5 You can write a From<Height> for NetworkVersion. It would be a total function and guaranteed to never fail.

I've already added a compile-time check

Right but you can't use #![feature(variant_count)] (we want to avoid +unstable as soon as possible) and you can't assume Height is in the same order as NetworkVersion. A trait implementation that maps from Height to NetworkVersion would be stable rust and free of magic.

types/networks/src/lib.rs Outdated Show resolved Hide resolved
@tyshko5 tyshko5 requested a review from lemmih September 1, 2022 11:57
types/networks/src/lib.rs Show resolved Hide resolved
@tyshko5 tyshko5 requested a review from lemmih September 1, 2022 15:36
Comment on lines 45 to 64
pub const HEIGHT_VEC: [Height; 17] = [
Height::Breeze,
Height::Smoke,
Height::Ignition,
Height::ActorsV2,
Height::Tape,
Height::Liftoff,
Height::Kumquat,
Height::Calico,
Height::Persian,
Height::Orange,
Height::Trust,
Height::Norwegian,
Height::Turbo,
Height::Hyperdrive,
Height::Chocolate,
Height::OhSnap,
Height::Skyr,
];

Copy link
Contributor

Choose a reason for hiding this comment

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

This is unused.

types/networks/src/lib.rs Show resolved Hide resolved
Comment on lines 74 to 78
Height::Breeze => NetworkVersion::V0,
Height::Smoke => NetworkVersion::V1,
Height::Ignition => NetworkVersion::V2,
Height::ActorsV2 => NetworkVersion::V3,
Height::Tape => NetworkVersion::V4,
Copy link
Contributor

Choose a reason for hiding this comment

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

Bump everything such that Breeze is V1 and Tape is V5. See the deleted UPGRADE_INFOS for ground truth.

Comment on lines 109 to 113
pub fn sort_by_epoch(mut height_info_vec: Vec<HeightInfo>) -> Vec<HeightInfo> {
height_info_vec.sort_by(|a, b| a.epoch.cmp(&b.epoch));
height_info_vec
}

Copy link
Contributor

Choose a reason for hiding this comment

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

If this function takes a slice of HeightInfo (and turns it into a Vec) then the rest of the code will become simpler.

@tyshko5 tyshko5 requested a review from lemmih September 2, 2022 10:49
Comment on lines 205 to 206
let height_infos = sort_by_epoch(&self.height_infos);
let height = height_infos
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 height_infos = sort_by_epoch(&self.height_infos);
let height = height_infos
let height = sort_by_epoch(&self.height_infos)

Comment on lines 238 to 239
let height_infos = sort_by_epoch(&self.height_infos);
height_infos
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 height_infos = sort_by_epoch(&self.height_infos);
height_infos
sort_by_epoch(&self.height_infos)

self.name == other.name
&& self.bootstrap_peers == other.bootstrap_peers
&& self.block_delay_secs == other.block_delay_secs
&& self.version_schedule == other.version_schedule
&& self.height_infos == other.height_infos
&& height_infos == other_height_infos
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
&& height_infos == other_height_infos
&& sort_by_epoch(&self.height_infos) == sort_by_epoch(&other.height_infos)

Copy link
Contributor

@lemmih lemmih left a comment

Choose a reason for hiding this comment

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

Good. Only a few style suggestions.

@elmattic
Copy link
Contributor

elmattic commented Sep 2, 2022

@tyshko5 Could you update the delegate consensus code that is still using Claus height in its toml settings file?

types/networks/src/lib.rs Outdated Show resolved Hide resolved
@tyshko5
Copy link
Contributor Author

tyshko5 commented Sep 2, 2022

@tyshko5 Could you update the delegate consensus code that is still using Claus height in its toml settings file?

Done

@tyshko5 tyshko5 merged commit 0f78aa4 into main Sep 2, 2022
@tyshko5 tyshko5 deleted the tyshko5/issue-1579 branch September 2, 2022 15:07
tyshko5 added a commit that referenced this pull request Sep 5, 2022
* most changes

* requested change

* fix fmt

* new ways: delete claus, version_schedule, sort

* fix lint

* requested changes

* compile time check

* from implementation

* requested changes

* requested changes

* requested changes

* requested changes

* requested changes

* delete Claus from deleg cns config
tyshko5 added a commit that referenced this pull request Sep 7, 2022
* most changes

* requested change

* fix fmt

* new ways: delete claus, version_schedule, sort

* fix lint

* requested changes

* compile time check

* from implementation

* requested changes

* requested changes

* requested changes

* requested changes

* requested changes

* delete Claus from deleg cns config
tyshko5 added a commit that referenced this pull request Sep 7, 2022
* most changes

* requested change

* fix fmt

* new ways: delete claus, version_schedule, sort

* fix lint

* requested changes

* compile time check

* from implementation

* requested changes

* requested changes

* requested changes

* requested changes

* requested changes

* delete Claus from deleg cns config
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.

Validate the ChainConfig struct at construction time
4 participants