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

feat: add support for configuring network protocol_id's #1093

Merged
merged 2 commits into from
Apr 17, 2024

Conversation

KolbyML
Copy link
Member

@KolbyML KolbyML commented Jan 11, 2024

What was wrong?

We aren't able to configure protocol_id in the case we want to support different networks like a testnet

How was it fixed?

This is basically the same thing we already did except we use a bidirectional map instead of trait conversions acting as a bidirectional map.

For storing mainnet/future network data we will use a folder structure I seen L1 clients use trin/mainnet/... trin/futurenetworkname/...

Now we can easily configure future networks

@KolbyML KolbyML self-assigned this Jan 11, 2024
@KolbyML KolbyML marked this pull request as ready for review January 12, 2024 16:21
@KolbyML KolbyML force-pushed the configure-testnet branch 2 times, most recently from 8976003 to ea72788 Compare January 12, 2024 16:40
Copy link
Collaborator

@njgheorghita njgheorghita left a comment

Choose a reason for hiding this comment

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

I appreciate the pr & work towards this direction. But imo we shouldn't merge any testnet implementation until ethereum/portal-network-specs#258 is approved by all client teams & merged

@KolbyML
Copy link
Member Author

KolbyML commented Jan 12, 2024

@njgheorghita
image
Piper seems to have the complete opposite view point. That clients should start doing stuff relating to this and only finalize it in spec, once we have figured shit out and are using it persumably.

By what is said between you and piper this PR and us even doing a testnet is in a deadlock now. This PR more has to do with configuring protocol ID's and I don't see how that a PR formalizing protocol_ids for a testnet blocks a pr allowing the option to configure protocol ID's.

Being able to configure network parameters is a standard feature in all L1 clients. I can comprehend how we wouldn't want to formalize the testnet protocol_ids in our code, but that is 15 lines of 200. This code could have been reviewed and we could have just removed the 15 line testnet part instead of a blanket ignore because the word testnet was mentioned.

Shouldn't by the same logic we should have blocked TraceGossip till it was merged into the spec and reviewed by all client teams? I don't see why 95% (configure protocol id's) of this PR is being blocked for 5% (15 lines of testnet parameters)

I have removed the code relating to "testnet" from the PR so hopefully the code can be reviewed now

@KolbyML KolbyML changed the title feat: support multiple network MAINNET/TESTNET etc feat: support multiple network MAINNET and for future networks Jan 12, 2024
@KolbyML KolbyML requested a review from njgheorghita January 12, 2024 19:33
@KolbyML KolbyML changed the title feat: support multiple network MAINNET and for future networks feat: add support for configuring network protocol_id's Jan 12, 2024
@pipermerriam
Copy link
Member

I wouldn't categorize my opinion as "strong". Only that since we haven't done "testnet" yet my intuition is that actually doing the implementation will likely uncovers somes "unknown unknown" types of learning... but feel free to proceed however you guys feel is best.

I think the only thing I have a "strong" opinion on is that we should not write the spec and then blindly implement the clients to follow the spec. Lets make sure that client implementation learnings are actively used to influence the specification because things don't always unfold the way we expect them to.

Copy link
Collaborator

@njgheorghita njgheorghita left a comment

Choose a reason for hiding this comment

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

I think kurtosis could be useful in testing this.
Something like...

  • Spin up 3 trin nodes running testnet
  • Spin up 3 trin nodes running mainnet
  • Send a ping between the testnet & mainnet clients
  • Spin up a bridge gossiping testnet data (eg epoch # 1)
  • Spin up a bridge gossiping mainnet data (eg epoch # 2)

Test that the mainnet nodes only store epoch # 2 data, and testnet nodes only have epoch # 1 data.

@KolbyML
Copy link
Member Author

KolbyML commented Feb 26, 2024

I think kurtosis could be useful in testing this. Something like...

  • Send a ping between the testnet & mainnet clients

We can test it with that and also add a test for it in peer tests.

If you try to ping a testnet history node to a mainnet history node the ping will fail because the networks have different Discv5 TalkReq ids which is what we use to route messages with

Assuming we use this proposal for running testnets*

So the test could look like in peertests

  1. Start a history testnet node
  2. Start a history mainnet node
  3. send a ping
  4. expect no result

@KolbyML KolbyML force-pushed the configure-testnet branch 5 times, most recently from 55967aa to e34e9b6 Compare April 12, 2024 23:48
@KolbyML KolbyML force-pushed the configure-testnet branch from e34e9b6 to 0a25f79 Compare April 13, 2024 01:29
@KolbyML KolbyML requested a review from njgheorghita April 13, 2024 02:41
@KolbyML
Copy link
Member Author

KolbyML commented Apr 13, 2024

@njgheorghita @ogenev ready for a review

I added the small peertest I talked about in the call and comment above

Copy link
Collaborator

@njgheorghita njgheorghita left a comment

Choose a reason for hiding this comment

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

Looks pretty good, just a few comments on fn naming. But, I'd also like to hold off on merging this until after the db update is deployed, since this will require some changes to the cluster repo, and it'd be better to do the 2 somewhat significant changes in separate goes to isolate their effects/bugs from each other

match network_string {
"mainnet" => Ok(MAINNET.clone()),
"testnet" => Ok(TESTNET.clone()),
_ => Err(format!("Not a valid network: {network_string}")),
Copy link
Collaborator

Choose a reason for hiding this comment

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

"Not a valid network: {network_string}, must be 'testnet' or 'mainnet'"

let mut portal_networks = BiHashMap::new();
portal_networks.insert(ProtocolId::State, "0x501A".to_string());
portal_networks.insert(ProtocolId::History, "0x501B".to_string());
portal_networks.insert(ProtocolId::TransactionGossip, "0x501C".to_string());
Copy link
Collaborator

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 reason to include TransactionGossip & CanonicalIndices?

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean it is included in our mainnet code

}

#[test]
fn protocol_id_encoding() {
let hex = "0x500A";
let protocol_id = ProtocolId::from_str(hex).unwrap();
let expected_hex = hex_encode_upper(Vec::try_from(protocol_id).unwrap());
let protocol_id = MAINNET.portal_networks.get_by_right(hex).unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not a huge fan of using the native BiHashMap api. It's not obvious (without looking up the map &/or BiHashMap source code), what these functions do (aka left vs. right)... Could you impl something more intuitive, like get_protocol_id / get_protocol_id_hex (or whatever fn name makes the most sense here)?

let protocol_id = self
.network_spec
.portal_networks
.get_by_right(&hex_encode_upper(request.protocol()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here. Some custom impl that has a more intuitive name would be better

@@ -100,7 +111,11 @@ pub async fn run_trin(
beacon_event_tx,
beacon_jsonrpc_tx,
beacon_event_stream,
) = if trin_config.networks.iter().any(|val| val == BEACON_NETWORK) {
) = if trin_config
.portal_subnetworks
Copy link
Collaborator

Choose a reason for hiding this comment

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

Think we could also do a custom trin_config.portal_subnetwork.contains() or something similar

@@ -206,13 +206,22 @@ async fn peertest_state_offer_contract_bytecode() {
#[tokio::test(flavor = "multi_thread")]
#[serial]
async fn peertest_state_recursive_gossip() {
let (peertest, target, handle) = setup_peertest().await;
let (peertest, target, handle) = setup_peertest(None).await;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would be a bit better to get rid of the Option and just use "mainnet" as the arg here

@KolbyML
Copy link
Member Author

KolbyML commented Apr 15, 2024

since this will require some changes to the cluster repo,

This PR requires 0 changes to the cluster repo, to my knowledge? Would it be possible to provide an explanation on how that conclusion was achieved? Maybe I am misunderstanding something.

@KolbyML
Copy link
Member Author

KolbyML commented Apr 15, 2024

ready for another look

@njgheorghita
Copy link
Collaborator

Well, it's not a major change, but we'll need to update the --networks flag to --portal-subnetworks. Anyways, I guess it's not a huge blocker for this pr, just something that we'll make sure we want to do in parallel. And if we forget to do it, the nodes will crash, so the problem will be pretty obvious. So, I guess nvm let's go ahead with the merge here.

@KolbyML KolbyML merged commit 492f1d8 into ethereum:master Apr 17, 2024
8 checks passed
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.

3 participants