Skip to content

Added option to send remote IP to peers #1326

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
merged 2 commits into from
Mar 23, 2022
Merged

Added option to send remote IP to peers #1326

merged 2 commits into from
Mar 23, 2022

Conversation

Psycho-Pirate
Copy link
Contributor

Fixes #1244

@Psycho-Pirate
Copy link
Contributor Author

I am new to this community and using rust in general.
Please have a look and suggest any corrections. @TheBlueMatt
How should I add the address to the init message?

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

For adding it to the message, you'll need to edit InitMessage and add a new field, then add it to the TLV encoding in msgs.rs as defined for InitMessage.

@Psycho-Pirate
Copy link
Contributor Author

For adding it to the message, you'll need to edit InitMessage and add a new field, then add it to the TLV encoding in msgs.rs as defined for InitMessage.

I am not able to find where InitMessage is defined in msg.rs. Where should I add the field exactly?

Also in peer_handler.rs, don't I have to use the newly stored NetAddress somewhere? probably in handle_message function?

@TheBlueMatt
Copy link
Collaborator

Oops sorry, its Init, not InitMessage.

@Psycho-Pirate
Copy link
Contributor Author

I was able to find this in msgs.rs

pub struct Init {
	/// The relevant features which the sender supports
	pub features: InitFeatures,
}

Do I have to add the field here or where InitFeatures is implemented?

@Psycho-Pirate
Copy link
Contributor Author

Also is there any documentation I can refer to? I did go through the ldk website but there wasn't much info present there on init messages.

@TheBlueMatt
Copy link
Collaborator

You should add it as a field in the Init struct. If you're not sure where to go, I recommend starting with the Rust book as an introduction to types and structs in Rust, see https://doc.rust-lang.org/stable/book/

@Psycho-Pirate
Copy link
Contributor Author

You should add it as a field in the Init struct. If you're not sure where to go, I recommend starting with the Rust book as an introduction to types and structs in Rust, see https://doc.rust-lang.org/stable/book/

Thanks, I have added the net_address as a field and resolved some of the errors. Please tell me what else needs to be done.

@Psycho-Pirate
Copy link
Contributor Author

I ran the following code in encoding_init and I am getting assertion error:

		assert_eq!(msgs::Init { features: InitFeatures::empty(),
			net_address: Some(msgs::NetAddress::IPv4 {
				addr: [127, 0, 0, 1],
				port: 1000,
			}),
		}.encode(), hex::decode("0307017f000103e8").unwrap());

Here is the assertion error

thread 'ln::msgs::tests::encoding_init' panicked at 'assertion failed: `(left == right)`
  left: `[3, 7, 1, 127, 0, 0, 1, 3, 232, 0, 0, 0, 0]`,
 right: `[3, 7, 1, 127, 0, 1, 3, 232]`'

How should I fix this?
@TheBlueMatt

@TheBlueMatt
Copy link
Collaborator

See the check_commits and benchmark CI passes - there are other parts of the code that still need updating.

@codecov-commenter
Copy link

codecov-commenter commented Feb 26, 2022

Codecov Report

Merging #1326 (f64383f) into main (74b9c1a) will increase coverage by 0.02%.
The diff coverage is 96.62%.

❗ Current head f64383f differs from pull request most recent head fc2f793. Consider uploading reports for the commit fc2f793 to get more accurate results

@@            Coverage Diff             @@
##             main    #1326      +/-   ##
==========================================
+ Coverage   90.75%   90.78%   +0.02%     
==========================================
  Files          73       73              
  Lines       41062    41002      -60     
  Branches    41062    41002      -60     
==========================================
- Hits        37266    37223      -43     
+ Misses       3796     3779      -17     
Impacted Files Coverage Δ
lightning-net-tokio/src/lib.rs 75.88% <66.66%> (-0.81%) ⬇️
lightning-background-processor/src/lib.rs 93.10% <100.00%> (ø)
lightning/src/ln/chanmon_update_fail_tests.rs 97.72% <100.00%> (ø)
lightning/src/ln/channelmanager.rs 84.79% <100.00%> (-0.06%) ⬇️
lightning/src/ln/functional_test_utils.rs 95.54% <100.00%> (ø)
lightning/src/ln/functional_tests.rs 97.07% <100.00%> (+0.01%) ⬆️
lightning/src/ln/msgs.rs 86.37% <100.00%> (+0.53%) ⬆️
lightning/src/ln/payment_tests.rs 99.15% <100.00%> (-0.08%) ⬇️
lightning/src/ln/peer_handler.rs 52.71% <100.00%> (+4.40%) ⬆️
lightning/src/ln/priv_short_conf_tests.rs 96.84% <100.00%> (ø)
... and 12 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74b9c1a...fc2f793. Read the comment docs.

@Psycho-Pirate
Copy link
Contributor Author

See the check_commits and benchmark CI passes - there are other parts of the code that still need updating.

How can I fix the check_commits test? It is failing because of some previous commit.

@TheBlueMatt
Copy link
Collaborator

You can rebase and squash intermediate commits to rewrite the history to make the code pass at each commit.

@Psycho-Pirate
Copy link
Contributor Author

Please have a look at the fuzz test as well

@Psycho-Pirate
Copy link
Contributor Author

This is the error I am getting

error: failed to run LLVM passes: unknown pass name 'sancov'

I am not sure how to fix this.

@TheBlueMatt
Copy link
Collaborator

The fuzz failure is an upstream regression, see #1335, you can ignore it here.

@Psycho-Pirate
Copy link
Contributor Author

I have fixed the warnings, is there anything else that needs to be done?
@TheBlueMatt

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

  • should we open an issue to support this in net-tokio?
  • do we care to expose our remote IP in the future, from the Init messages we receive?

I'm pretty fine to address all feedback in follow-up, since it's an external contributor PR and the code looks fine :)

@Psycho-Pirate
Copy link
Contributor Author

Is there anything else that needs to be done here?
@TheBlueMatt
@valentinewallace
@jkczyz

@jkczyz
Copy link
Contributor

jkczyz commented Mar 4, 2022

You'll need to get your branch in order still as per: https://github.com/lightningdevkit/rust-lightning/pull/1326/files#r817983366

@Psycho-Pirate
Copy link
Contributor Author

You'll need to get your branch in order still as per: https://github.com/lightningdevkit/rust-lightning/pull/1326/files#r817983366

I have rebased it now. Is this alright?

@TheBlueMatt
Copy link
Collaborator

You should rename the commits to describe the changes that are happening in each, instead of "squashed commits".

Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

One real comment and some style nits, thanks for sticking with it, this is looking great now!

fn filter_addresses(ip_address: Option<NetAddress>) -> Option<NetAddress> {
match ip_address{
// For IPv4 range 10.0.0.0 - 10.255.255.255 (10/8)
Some(NetAddress::IPv4{addr: [0xA, 0x00..=0xFF, _, _], port: _}) => None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this would be more readable if you replace all the 0x00..=0xff places with just _. Also, for IPv4, not using hex is more readable, since the traditional representation is decimal, my previous nit about hex was just for v6, where the traditional representation is hex.

@Psycho-Pirate
Copy link
Contributor Author

One real comment and some style nits, thanks for sticking with it, this is looking great now!

Thank you so much! I couldn't have done this without your guidance!

@TheBlueMatt
Copy link
Collaborator

See #1326 (comment) please feel free to squash the last fixup commit down (I already checked with @jkczyz ).

@TheBlueMatt
Copy link
Collaborator

Looks like this is now randomly including one commit from upstream?

@Psycho-Pirate
Copy link
Contributor Author

Looks like this is now randomly including one commit from upstream?

I'm not really sure how to remove that, i used git rebase -i HEAD~3 and then squashed the commits.

@TheBlueMatt
Copy link
Collaborator

Take a look at the Bitcoin Core contributors guide, it has a section on how to do git rebases.

@Psycho-Pirate
Copy link
Contributor Author

Is there anything else that needs to be done?

TheBlueMatt
TheBlueMatt previously approved these changes Mar 21, 2022
Copy link
Collaborator

@TheBlueMatt TheBlueMatt left a comment

Choose a reason for hiding this comment

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

Oops sorry, github didn't tag the PR as unread when you pushed...A few minor nits, needs a second review.

@TheBlueMatt
Copy link
Collaborator

Can you squash down the two new commits into the first commit? Then LGTM.

@Psycho-Pirate
Copy link
Contributor Author

Can you squash down the two new commits into the first commit? Then LGTM.

Sure

Copy link
Contributor

@valentinewallace valentinewallace left a comment

Choose a reason for hiding this comment

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

Needs rebase. Some optional nits but I'm ACK!

@TheBlueMatt do we care to expose our remote IP in the future or to use this for our node_announcements, from the Init messages we receive?

@TheBlueMatt
Copy link
Collaborator

@TheBlueMatt do we care to expose our remote IP in the future or to use this for our node_announcements, from the Init messages we receive?

Yea, its something to consider using, totally, Its kinda nice cause we can completely automate it without our users having to care, I opened #1377 for the followup.

@TheBlueMatt
Copy link
Collaborator

Oops, this now needs rebase, sorry about that!

@TheBlueMatt TheBlueMatt merged commit b010aeb into lightningdevkit:main Mar 23, 2022
@Psycho-Pirate
Copy link
Contributor Author

Thank you so much! This was a great learning experience for me! @TheBlueMatt

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.

Send peers the remote IP we see on the connection
5 participants