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

Added unban peer feature #286

Merged
merged 2 commits into from
May 23, 2024
Merged

Added unban peer feature #286

merged 2 commits into from
May 23, 2024

Conversation

Chinwendu20
Copy link
Contributor

@Chinwendu20 Chinwendu20 commented Aug 22, 2023

Changes:

  • Added unbanpeer method to chainservice.
  • Added unbanipnet method to banstore

Link to issue: #253
Link to previous PR for context:
#270

@Chinwendu20
Copy link
Contributor Author

Hello @Roasbeef and @positiveblue . I have added the test

@@ -123,4 +123,10 @@ func TestBanStore(t *testing.T) {
// We'll query for second IP network again as it should now be unknown
// to the BanStore. We should expect not to find anything regarding it.
checkBanStore(ipNet2, false, 0, 0)

//Unban ipNet1
Copy link
Member

Choose a reason for hiding this comment

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

Style nit: comments should be complete sentences.

neutrino.go Outdated
}
s.connManager.Connect(&connmgr.ConnReq{
Addr: tcpAddr,
Permanent: true,
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this should be optional? So a bool that controls if we'll try to permanently connecvt to them after banning.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this defer is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you saying we should skip the defer function and just connect the peer that has just been unbanned?

banman/store.go Show resolved Hide resolved
banman/store.go Outdated

var ipNetBuf bytes.Buffer
if err := encodeIPNet(&ipNetBuf, ipNet); err != nil {
return fmt.Errorf("unable to encode %v: %v", ipNet, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: line length

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it has the right line length?

Copy link
Member

Choose a reason for hiding this comment

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

Should be wrapped to 80 columns.

neutrino.go Outdated
}
s.connManager.Connect(&connmgr.ConnReq{
Addr: tcpAddr,
Permanent: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this defer is necessary?

@Roasbeef
Copy link
Member

@Chinwendu20 still interested in finishing this up?

@Chinwendu20
Copy link
Contributor Author

Thanks @Roasbeef wow, did not notice the comments

@Chinwendu20 Chinwendu20 force-pushed the UBPeer branch 3 times, most recently from c4ac8ac to e420c11 Compare May 1, 2024 16:47
@Chinwendu20 Chinwendu20 requested review from Roasbeef and Crypt-iQ May 1, 2024 17:47
@lightninglabs-deploy
Copy link

@Roasbeef: review reminder
@Crypt-iQ: review reminder

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 👑

banman/store.go Outdated

var ipNetBuf bytes.Buffer
if err := encodeIPNet(&ipNetBuf, ipNet); err != nil {
return fmt.Errorf("unable to encode %v: %v", ipNet, err)
Copy link
Member

Choose a reason for hiding this comment

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

Should be wrapped to 80 columns.

Copy link
Contributor

@Crypt-iQ Crypt-iQ left a comment

Choose a reason for hiding this comment

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

looks really close, some comments

banman/store_test.go Show resolved Hide resolved
return fmt.Errorf("unable to unban peer: %v", err)
}

return s.ConnectNode(addr, parmanent)
Copy link
Contributor

Choose a reason for hiding this comment

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

sorry for my earlier suggestion, I think this should be in a goroutine so we aren't blocking?

cc @Roasbeef

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the blocking you are referring to might emanate from here?

neutrino/notifications.go

Lines 351 to 360 in 9130a5e

select {
case s.query <- connectNodeMsg{
addr: addr,
permanent: permanent,
reply: replyChan,
}:
return <-replyChan
case <-s.quit:
return nil
}

From what I have seen from other exported functions on the chainservice, I do not think they take into account this blocking?

Copy link
Contributor

Choose a reason for hiding this comment

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

See above in BanPeer, the disconnect is in a goroutine

Copy link
Contributor Author

@Chinwendu20 Chinwendu20 May 20, 2024

Choose a reason for hiding this comment

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

Thanks for pointing this out. The Disconnect in that function is quite different as it is not a chain service method like what I was referring to. I was referring to other exported chainservice methods just like the ConnectNode function used in UnbanPeer that send a message to the query channel and how I have seen that they do not take into account a potential blocking.

I am not sure if we should continue with that practice.

Copy link
Contributor

Choose a reason for hiding this comment

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

It depends on how it's used in practice, which it's not here. So I'm fine with it as-is and we can adjust it later based on usage

Signed-off-by: Ononiwu Maureen <amaka013@gmail.com>
Signed-off-by: Ononiwu Maureen <amaka013@gmail.com>
@Chinwendu20
Copy link
Contributor Author

@guggero I think we can merge this now?
Here is the upstream PR for lnd: lightningnetwork/lnd#7606

@guggero guggero added this pull request to the merge queue May 23, 2024
Merged via the queue into lightninglabs:master with commit 1ea6f52 May 23, 2024
4 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.

5 participants