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

Add getnodeaddresses JSON-RPC support (rpc client & server) #1590

Merged
merged 1 commit into from
Sep 14, 2020

Conversation

lindlof
Copy link
Contributor

@lindlof lindlof commented May 31, 2020

Add NodeAddresses function to rpcserverConnManager
interface for fetching known node addresses.

rpcserver.go Outdated
Comment on lines 2496 to 2499
if int32(len(nodes)) < count {
count = int32(len(nodes))
}
Copy link
Contributor

@onyb onyb Jun 29, 2020

Choose a reason for hiding this comment

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

Will an extra assignment be better than traversing nodes twice?

Suggested change
if int32(len(nodes)) < count {
count = int32(len(nodes))
}
if numOfNodes := int32(len(nodes)); numOfNodes < count {
count = numOfNodes
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implementations of len should be fast because slice knows its length. I do like the reduced repetition of your suggestion especially since int32 conversion is duplicated here. I'm keen to name this variable something short like nn given its narrow scope.

}

// GetNodeAddresses returns data about known node addresses.
func (c *Client) GetNodeAddresses(count *int32) ([]btcjson.GetNodeAddressesResult, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There are plenty of examples in rpcclient where each optional parameter has its own dedicated method. For example, instead of GetNodeAddresses(count *int32), we can have the following:

  • GetNodeAddresses()
  • GetNodeAddressesCount(count int32)

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for bringing this up. After getting similar feedback in another PR I was looking around rpcclient. In RPC calls that take a single optional variable I can see many examples where a single function which takes a pointer is provided - similarly to GetNodeAddresses(count *int32)

Trying to be consistent is the best solution I think. I can change it to the non-pointer style that you're suggesting if you think that's better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine with me as long as we are consistent. 👍

@lindlof lindlof force-pushed the getnodeaddresses branch 2 times, most recently from 4270f15 to 1954064 Compare July 5, 2020 14:11
Copy link
Contributor

@onyb onyb left a comment

Choose a reason for hiding this comment

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

Looks good! 🚀

@onyb onyb added this to the 0.22.0 milestone Sep 7, 2020
@onyb
Copy link
Contributor

onyb commented Sep 7, 2020

@lindlof Could you please rebase this? Will have this merged tomorrow. 🙂

@jcvernaleo
Copy link
Member

Rebase/conflict fix and then this is good to go in.

Add NodeAddresses function to rpcserverConnManager
interface for fetching known node addresses.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 245431911

  • 6 of 54 (11.11%) changed or added relevant lines in 4 files are covered.
  • 4 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.07%) to 53.633%

Changes Missing Coverage Covered Lines Changed/Added Lines %
rpcadapters.go 0 3 0.0%
rpcclient/net.go 0 18 0.0%
rpcserver.go 0 27 0.0%
Files with Coverage Reduction New Missed Lines %
database/ffldb/blockio.go 4 92.62%
Totals Coverage Status
Change from base Build 245421206: -0.07%
Covered Lines: 20638
Relevant Lines: 38480

💛 - Coveralls

@lindlof
Copy link
Contributor Author

lindlof commented Sep 9, 2020

@onyb @jcvernaleo Sweet, rebased

Copy link
Member

@jcvernaleo jcvernaleo left a comment

Choose a reason for hiding this comment

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

OK

@jcvernaleo jcvernaleo merged commit fff9661 into btcsuite:master Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants