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

[Merged by Bors] - Improve ergonomics of adding a new network config #2489

Closed
wants to merge 12 commits into from

Conversation

paulhauner
Copy link
Member

@paulhauner paulhauner commented Aug 2, 2021

Issue Addressed

NA

Proposed Changes

This PR adds some more fancy macro magic to make it easier to add a new built-in (aka "baked-in") testnet config to the lighthouse binary.

Previously, a user needed to modify several files and repeat themselves several times. Now, they only need to add a single definition in the eth2_config crate. No repetition 🎉

@paulhauner paulhauner added work-in-progress PR is a work-in-progress v1.5.1 To be included in the v1.5.1 relase labels Aug 2, 2021
@paulhauner paulhauner added ready-for-review The code is ready for review and removed work-in-progress PR is a work-in-progress labels Aug 2, 2021
paulhauner added a commit that referenced this pull request Aug 4, 2021
commit e22b271
Author: Paul Hauner <[email protected]>
Date:   Wed Aug 4 10:55:15 2021 +1000

    Separate name_ident and name_str

commit d7e8408
Author: Paul Hauner <[email protected]>
Date:   Tue Aug 3 10:58:54 2021 +1000

    Naming consistency fix

commit cd73518
Author: Paul Hauner <[email protected]>
Date:   Tue Aug 3 10:44:26 2021 +1000

    Refactor for a single source of truth

commit 83280d6
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 18:27:51 2021 +1000

    Add test for name consistency

commit 99be2ea
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:55:40 2021 +1000

    Switch define_nets to lower case

commit 777b419
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:52:41 2021 +1000

    Add instructional comments

commit 33dda79
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:36:14 2021 +1000

    Use hardcoded list in CLI

commit 892efe4
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:34:58 2021 +1000

    Add paste to eth2_config mod

commit 03d6e49
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:23:06 2021 +1000

    Add hardcoded net names

commit d3dadc8
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:10:01 2021 +1000

    Use paste in eth2_network_config

commit 5053f53
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:03:15 2021 +1000

    Add define_nets!
@paulhauner paulhauner mentioned this pull request Aug 4, 2021
paulhauner added a commit that referenced this pull request Aug 4, 2021
commit e22b271
Author: Paul Hauner <[email protected]>
Date:   Wed Aug 4 10:55:15 2021 +1000

    Separate name_ident and name_str

commit d7e8408
Author: Paul Hauner <[email protected]>
Date:   Tue Aug 3 10:58:54 2021 +1000

    Naming consistency fix

commit cd73518
Author: Paul Hauner <[email protected]>
Date:   Tue Aug 3 10:44:26 2021 +1000

    Refactor for a single source of truth

commit 83280d6
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 18:27:51 2021 +1000

    Add test for name consistency

commit 99be2ea
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:55:40 2021 +1000

    Switch define_nets to lower case

commit 777b419
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:52:41 2021 +1000

    Add instructional comments

commit 33dda79
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:36:14 2021 +1000

    Use hardcoded list in CLI

commit 892efe4
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:34:58 2021 +1000

    Add paste to eth2_config mod

commit 03d6e49
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:23:06 2021 +1000

    Add hardcoded net names

commit d3dadc8
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:10:01 2021 +1000

    Use paste in eth2_network_config

commit 5053f53
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:03:15 2021 +1000

    Add define_nets!
paulhauner added a commit that referenced this pull request Aug 6, 2021
commit e22b271
Author: Paul Hauner <[email protected]>
Date:   Wed Aug 4 10:55:15 2021 +1000

    Separate name_ident and name_str

commit d7e8408
Author: Paul Hauner <[email protected]>
Date:   Tue Aug 3 10:58:54 2021 +1000

    Naming consistency fix

commit cd73518
Author: Paul Hauner <[email protected]>
Date:   Tue Aug 3 10:44:26 2021 +1000

    Refactor for a single source of truth

commit 83280d6
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 18:27:51 2021 +1000

    Add test for name consistency

commit 99be2ea
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:55:40 2021 +1000

    Switch define_nets to lower case

commit 777b419
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:52:41 2021 +1000

    Add instructional comments

commit 33dda79
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:36:14 2021 +1000

    Use hardcoded list in CLI

commit 892efe4
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:34:58 2021 +1000

    Add paste to eth2_config mod

commit 03d6e49
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:23:06 2021 +1000

    Add hardcoded net names

commit d3dadc8
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:10:01 2021 +1000

    Use paste in eth2_network_config

commit 5053f53
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:03:15 2021 +1000

    Add define_nets!
paulhauner added a commit that referenced this pull request Aug 9, 2021
commit e22b271
Author: Paul Hauner <[email protected]>
Date:   Wed Aug 4 10:55:15 2021 +1000

    Separate name_ident and name_str

commit d7e8408
Author: Paul Hauner <[email protected]>
Date:   Tue Aug 3 10:58:54 2021 +1000

    Naming consistency fix

commit cd73518
Author: Paul Hauner <[email protected]>
Date:   Tue Aug 3 10:44:26 2021 +1000

    Refactor for a single source of truth

commit 83280d6
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 18:27:51 2021 +1000

    Add test for name consistency

commit 99be2ea
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:55:40 2021 +1000

    Switch define_nets to lower case

commit 777b419
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:52:41 2021 +1000

    Add instructional comments

commit 33dda79
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:36:14 2021 +1000

    Use hardcoded list in CLI

commit 892efe4
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:34:58 2021 +1000

    Add paste to eth2_config mod

commit 03d6e49
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:23:06 2021 +1000

    Add hardcoded net names

commit d3dadc8
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:10:01 2021 +1000

    Use paste in eth2_network_config

commit 5053f53
Author: Paul Hauner <[email protected]>
Date:   Mon Aug 2 15:03:15 2021 +1000

    Add define_nets!
Copy link
Member

@realbigsean realbigsean left a comment

Choose a reason for hiding this comment

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

This looks sweet! Quite the macro rabbit hole here, didn't realize how much one can do. Just found some small things.

/// perform the final step of using `std::include_bytes` to bake the files (bytes) into the binary.
macro_rules! define_hardcoded_nets {
($(($name_ident: ident, $name_str: tt, $genesis_is_known: ident)),+) => {
paste! {
Copy link
Member

Choose a reason for hiding this comment

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

I don't see any paste! identifiers [< .. >] in the macro so not sure it's necessary here

/// Creates a `HardcodedNet` definition for some network.
#[macro_export]
macro_rules! define_net {
($this_crate: tt, $mod: ident, $include_file: tt) => {{
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
($this_crate: tt, $mod: ident, $include_file: tt) => {{
($this_crate: ident, $mod: ident, $include_file: tt) => {{

Seems like this works as is, but should this be ident?


/// Defines an `Eth2NetArchiveAndDirectory` for some network.
///
/// It also defines a `include_<title>_bytes!` macro which provides a wrapper around
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// It also defines a `include_<title>_bytes!` macro which provides a wrapper around
/// It also defines a `include_<title>_file!` macro which provides a wrapper around

@realbigsean realbigsean added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Aug 10, 2021
@michaelsproul michaelsproul added v1.5.2 The release after v1.5.1 v2.0.0 Altair on mainnet release (v2.0.0) and removed v1.5.1 To be included in the v1.5.1 relase v1.5.2 The release after v1.5.1 labels Aug 26, 2021
@paulhauner
Copy link
Member Author

Thanks @realbigsean, great suggestions. Ready for review!

@paulhauner paulhauner removed the waiting-on-author The reviewer has suggested changes and awaits thier implementation. label Aug 30, 2021
@paulhauner paulhauner added ready-for-review The code is ready for review v1.5.2 The release after v1.5.1 and removed v2.0.0 Altair on mainnet release (v2.0.0) labels Aug 30, 2021
Copy link
Member

@realbigsean realbigsean left a comment

Choose a reason for hiding this comment

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

LGTM!

@paulhauner paulhauner added ready-for-merge This PR is ready to merge. and removed ready-for-review The code is ready for review labels Aug 30, 2021
@paulhauner
Copy link
Member Author

bors r+

bors bot pushed a commit that referenced this pull request Aug 30, 2021
## Issue Addressed

NA

## Proposed Changes

This PR adds some more fancy macro magic to make it easier to add a new built-in (aka "baked-in") testnet config to the `lighthouse` binary.

Previously, a user needed to modify several files and repeat themselves several times. Now, they only need to add a single definition in the `eth2_config` crate. No repetition 🎉
@bors bors bot changed the title Improve ergonomics of adding a new network config [Merged by Bors] - Improve ergonomics of adding a new network config Aug 31, 2021
@bors bors bot closed this Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge This PR is ready to merge. v1.5.2 The release after v1.5.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants