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

P2P: Inform peer if not accepting transactions #1020

Merged
merged 2 commits into from
Apr 12, 2023
Merged

Conversation

heifner
Copy link
Member

@heifner heifner commented Apr 12, 2023

Optimize network traffic by informing peers when node is configured for p2p-accept-transactions=false. Since the transactions will be immediately dropped, no reason for the peer to send them.
If configured to not accept transactions, p2p-accept-transactions=false, then inform peer the node is a blocks only connection.

Resolves #767

…ons=false, then inform peer the node is blocks only
@heifner heifner added the OCI Work exclusive to OCI team label Apr 12, 2023
@heifner heifner added this to the Leap v5.0.0-rc1 milestone Apr 12, 2023
@@ -3598,7 +3598,8 @@ namespace eosio {
hello.token = sha256();
hello.p2p_address = my_impl->p2p_address;
if( is_transactions_only_connection() ) hello.p2p_address += ":trx";
if( is_blocks_only_connection() ) hello.p2p_address += ":blk";
// if we are not accepting transactions tell peer we are blocks only
if( is_blocks_only_connection() || !my_impl->p2p_accept_transactions ) hello.p2p_address += ":blk";
Copy link
Member

Choose a reason for hiding this comment

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

Can !my_impl->p2p_accept_transactions be folded inside is_blocks_only_connection()?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, as other places is_blocks_only_connection() is called we don't want it to be true. For example is_blocks_only_connection() is called in the loop to send out trxs. If it was true we would not send out a trx to our peer. We want to send trxs out, just not allow transactions to flow in.

Copy link
Member

@linh2931 linh2931 Apr 12, 2023

Choose a reason for hiding this comment

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

Thanks. Maybe you can add a comment here because hello.p2p_address += ":blk"; makes the node like a block only node.

@@ -3598,7 +3598,8 @@ namespace eosio {
hello.token = sha256();
hello.p2p_address = my_impl->p2p_address;
if( is_transactions_only_connection() ) hello.p2p_address += ":trx";
if( is_blocks_only_connection() ) hello.p2p_address += ":blk";
// if we are not accepting transactions tell peer we are blocks only
if( is_blocks_only_connection() || !my_impl->p2p_accept_transactions ) hello.p2p_address += ":blk";
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this might be better because it also updates connection_type and logs the change.

       if(hello.sig == chain::signature_type())
          hello.token = sha256();
       hello.p2p_address = my_impl->p2p_address;
+      if (!my_impl->p2p_accept_transactions && !is_blocks_only_connection()) {
+         fc_dlog( logger, "Setting connection ${c} type for: ${peer} to transactions only", ("c", connection_id)("peer", peer_addr) );
+         connection_type = blocks_only;
+      }
       if( is_transactions_only_connection() ) hello.p2p_address += ":trx";
       if( is_blocks_only_connection() ) hello.p2p_address += ":blk";
       hello.p2p_address += " - " + hello.node_id.str().substr(0,7);

Copy link
Member Author

Choose a reason for hiding this comment

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

We do not want to set connection_type = blocks_only see my comment to Lin above.
Adding a log statement we are doing it is a good idea.

Copy link
Contributor

@greg7mdp greg7mdp Apr 12, 2023

Choose a reason for hiding this comment

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

@heifner I see in your comment above why we don't want to change connection_type (so we keep sending transactions).
Still, this seems a little bit hacky to me. I think I'd recommend changing connection_type to be an something like an uint32_t which can contain 4 non-exclusive flags:

  • send_transactions
  • receive_transactions
  • send_blocks
  • receive_blocks

Copy link
Member Author

Choose a reason for hiding this comment

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

Keeping track of receive_transactions is already tracked via p2p_accept_transaction. I don't think we want to track that state in two different places. net_plugin already has the concept blk block only connection (do not send transactions to the peer). All we are doing here is telling the peer that from its perspective we are blocks only.

Copy link
Contributor

@greg7mdp greg7mdp Apr 12, 2023

Choose a reason for hiding this comment

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

Right now, we are keeping state describing what the connection permits in two places, connection_type and p2p_accept_transaction.

I am suggesting keeping it only in one place: connection_type . I think it would be cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

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

That is not how I see it. connection_type is the type of connection I have with my peer. That does not imply it is the same connection they have with me. p2p_accept_transaction is an indication of what I allow. A peer might not honor my request for what they send me, so I need to enforce it myself. In my mind these are two separate concepts.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, I understand this is how it is setup today. However, if you just consider what you allow on your connection to your peer:

  • send_transactions
  • accept_transactions
  • send_blocks
  • accept_blocks

I don't see why these capabilities should not be stored together in one field. It is certainly less confusing than the current way imho.

Copy link
Contributor

Choose a reason for hiding this comment

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

However I'm fine approving as-is.

@heifner heifner merged commit be11e4f into main Apr 12, 2023
@heifner heifner deleted the GH-767-p2p-net-opt branch April 12, 2023 18:49
@heifner heifner added the documentation Improvements or additions to documentation label May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation OCI Work exclusive to OCI team
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

nodeos is sending extra p2p traffic when not required - need new configuration option(s)
3 participants