mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-08-30 17:01:30 +00:00
Merge pull request #778 from Roasbeef/fix-pruned-peer-filter
chain: fix peer selection for the pruned block dispatcher
This commit is contained in:
commit
559f6eff0e
2 changed files with 42 additions and 3 deletions
|
@ -417,10 +417,12 @@ func filterNodeAddrs(nodeAddrs []btcjson.GetNodeAddressesResult) []string {
|
|||
}
|
||||
|
||||
// satisfiesRequiredServices determines whether the services signaled by a peer
|
||||
// satisfy our requirements for retrieving pruned blocks from them.
|
||||
// satisfy our requirements for retrieving pruned blocks from them. We need the
|
||||
// full chain, and witness data as well. Note that we ignore the limited
|
||||
// (pruned bit) as nodes can have the full data and set that as well. Pure
|
||||
// pruned nodes won't set the network bit.
|
||||
func satisfiesRequiredServices(services wire.ServiceFlag) bool {
|
||||
return services&requiredServices == requiredServices &&
|
||||
services&prunedNodeService != prunedNodeService
|
||||
return services&requiredServices == requiredServices
|
||||
}
|
||||
|
||||
// newQueryPeer creates a new peer instance configured to relay any received
|
||||
|
|
|
@ -620,3 +620,40 @@ func TestPrunedBlockDispatcherInvalidBlock(t *testing.T) {
|
|||
h.assertPeerQueried()
|
||||
h.assertPeerReplied(blockChan, errChan, true)
|
||||
}
|
||||
|
||||
func TestSatisfiesRequiredServices(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
services wire.ServiceFlag
|
||||
ok bool
|
||||
}{
|
||||
{
|
||||
name: "full node, segwit",
|
||||
services: wire.SFNodeWitness | wire.SFNodeNetwork,
|
||||
ok: true,
|
||||
},
|
||||
{
|
||||
name: "full node segwit, signals limited",
|
||||
services: wire.SFNodeWitness | wire.SFNodeNetwork | prunedNodeService,
|
||||
ok: true,
|
||||
},
|
||||
{
|
||||
name: "full node, no segwit",
|
||||
services: wire.SFNodeNetwork,
|
||||
ok: false,
|
||||
},
|
||||
{
|
||||
name: "segwit, pure pruned",
|
||||
services: wire.SFNodeWitness | prunedNodeService,
|
||||
ok: false,
|
||||
},
|
||||
}
|
||||
for _, testCase := range testCases {
|
||||
ok := satisfiesRequiredServices(testCase.services)
|
||||
require.Equal(
|
||||
t, testCase.ok, ok, fmt.Sprintf("test case: %v", testCase.name),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue