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

neutrino: Added unban peer feature #270

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cb640ef
verification: mute taproot related err to dbg
guggero May 15, 2023
9813e2c
lru: add methods to range with orders
yyforyongyu Jun 14, 2023
9e7ab60
pushtx: add broadcast mapping function.
ziggie1984 Jun 22, 2023
74f6f2e
banman: add InvalidBlock ban reason
ellemouton May 3, 2023
f5637cc
query+blockmanager: add NumRetries optional param
ellemouton May 22, 2023
5469009
query+neutrino: create a WorkManager interface
ellemouton May 9, 2023
d309939
neutrino+query: use work dispatcher for GetBlock
ellemouton May 3, 2023
1901457
query: rename query variable
ellemouton May 4, 2023
dc8bf61
neutrino+query: use work dispatcher for GetCFilter
ellemouton May 5, 2023
bd101c4
query+neutrino: remove unused queryPeers function
ellemouton May 5, 2023
8a38db8
filterdb: lint and modernize the pkg
ellemouton May 4, 2023
16e3379
filterdb: add FilterData type
ellemouton May 5, 2023
fd19668
filterdb: update for batch filter writes
ellemouton May 5, 2023
621c98d
chanutils+log: add concurrent queue impl
ellemouton May 5, 2023
5addcf4
chanutils: add BatchWriter
ellemouton May 5, 2023
9f30f7f
neutrino+query: use BatchWriter for filter persistance
ellemouton May 5, 2023
1ced70d
rescan+refactor: use a rescanState struct for rescan variables
ellemouton May 5, 2023
45327d3
rescan+refactor: convert notifyBlock to rescanState method
ellemouton May 5, 2023
7d1fc5f
rescan: convert notifyBlockWithFilter to rescanState method
ellemouton May 5, 2023
0d714c7
rescan: refactor handleBlockDisconnected to be rescanState method
ellemouton May 5, 2023
c3d1d57
rescan: refactor handleBlockConnected to be rescanState method
ellemouton May 5, 2023
01eb349
rescan: add a waitForBlocks helper method to rescanState
ellemouton May 5, 2023
c521760
rescan: add IsCurrent to the ChainSource interface
ellemouton May 31, 2023
e7319ff
rescan: wait till current or end height reached
ellemouton May 5, 2023
05ddaa8
blockmanager: ensure received headers connect to each other
Crypt-iQ Jul 14, 2023
bdf0c9c
multi: use btcd libs to validate headers
Crypt-iQ Jul 14, 2023
4332177
blockmanager: remove now unused code
guggero Jul 14, 2023
929a080
blockmanager: clean up test, use require
guggero Jul 14, 2023
5bc6650
blockmanager: add test for non-connected headers
guggero Jul 14, 2023
bb96b18
banman: Added new method to banstore, UnbanIPNet
Chinwendu20 Apr 19, 2023
8a0eed9
neutrino: Added new method to ChainService, UnbanPeer
Chinwendu20 Apr 19, 2023
8fdbaf1
banman: Added test for Unban feature
Chinwendu20 Aug 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion banman/reason.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Reason uint8
// We prevent using `iota` to ensure the order does not have the value since
// these are serialized within the database.
const (
// ExcedeedBanThreshold signals that a peer exceeded its ban threshold.
// ExceededBanThreshold signals that a peer exceeded its ban threshold.
ExceededBanThreshold Reason = 1

// NoCompactFilters signals that a peer was unable to serve us compact
Expand All @@ -20,6 +20,9 @@ const (
// InvalidFilterHeaderCheckpoint signals that a peer served us an
// invalid filter header checkpoint.
InvalidFilterHeaderCheckpoint Reason = 4

// InvalidBlock signals that a peer served us a bad block.
InvalidBlock Reason = 5
)

// String returns a human-readable description for the reason a peer was banned.
Expand All @@ -37,6 +40,9 @@ func (r Reason) String() string {
case InvalidFilterHeaderCheckpoint:
return "peer served invalid filter header checkpoint"

case InvalidBlock:
return "peer served an invalid block"

default:
return "unknown reason"
}
Expand Down
31 changes: 31 additions & 0 deletions banman/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type Store interface {

// Status returns the ban status for a given IP network.
Status(*net.IPNet) (Status, error)

Copy link
Member

Choose a reason for hiding this comment

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

In commmit message: banmen -> banman

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh okay thanks.

// UnbanIPNet unbans previously banned peer
UnbanIPNet(ipNet *net.IPNet) error
}

// NewStore returns a Store backed by a database.
Expand Down Expand Up @@ -136,6 +139,34 @@ func (s *banStore) BanIPNet(ipNet *net.IPNet, reason Reason, duration time.Durat
})
}

// UnbanIPNet removes a ban record for the IP network within the store.
func (s *banStore) UnbanIPNet(ipNet *net.IPNet) error {
err := walletdb.Update(s.db, func(tx walletdb.ReadWriteTx) error {
banStore := tx.ReadWriteBucket(banStoreBucket)
if banStore == nil {
return ErrCorruptedStore
}
banIndex := banStore.NestedReadWriteBucket(banBucket)
if banIndex == nil {
return ErrCorruptedStore
}
reasonIndex := banStore.NestedReadWriteBucket(reasonBucket)
if reasonIndex == nil {
return ErrCorruptedStore
}

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

return removeBannedIPNet(banIndex, reasonIndex, k)
})

return err
}

// addBannedIPNet adds an entry to the ban store for the given IP network.
func addBannedIPNet(banIndex, reasonIndex walletdb.ReadWriteBucket,
ipNetKey []byte, reason Reason, duration time.Duration) error {
Expand Down
7 changes: 7 additions & 0 deletions banman/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,11 @@ 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
err = banStore.UnbanIPNet(ipNet1)

//IpNet1 should be unknown to the BanStore
checkBanStore(ipNet1, false, 0, 0)

}
Loading