Skip to content
Permalink
Browse files

fix: do not filter peers based on higher height

- If a bad peer has a height 50 blocks above the rest it is not returning any peer;
- This happens in devnet, which makes it impossible to select another peer.
  • Loading branch information...
luciorubeens committed Apr 22, 2019
1 parent 0573c64 commit 1d97bffcd4ff6dbe005b0520b9425428af128bb2
Showing with 13 additions and 11 deletions.
  1. +2 −2 __tests__/unit/store/modules/peer.spec.js
  2. +11 −9 src/renderer/store/modules/peer.js
@@ -39,7 +39,7 @@ describe('peer store module', () => {
it('should get one of the best peers', () => {
const bestPeer = store.getters['peer/best']()
expect(bestPeer).toBeOneOf(peers)
expect(bestPeer).not.toEqual(badPeer1)
// expect(bestPeer).not.toEqual(badPeer1)
})

it('should get peers in random order', () => {
@@ -133,7 +133,7 @@ describe('peer store module', () => {
const bestPeer = await store.dispatch('peer/connectToBest', { refresh: false })
expect(bestPeer).toEqual(store.getters['peer/current']())
expect(bestPeer.ip).toBeOneOf(peers.map(peer => peer.ip))
expect(bestPeer.ip).not.toEqual(badPeer1.ip)
// expect(bestPeer.ip).not.toEqual(badPeer1.ip)
})

it('should refresh peer list for v1', async () => {
@@ -174,15 +174,17 @@ export default {
return []
}

const highestHeight = peers[0].height
for (let i = 1; i < maxRandom; i++) {
if (!peers[i]) {
break
}
if (peers[i].height < highestHeight - 50) {
maxRandom = i - 1
}
}
// NOTE: Disabled because if a bad peer has a height 50 blocks above the rest it is not returning any peer

// const highestHeight = peers[0].height
// for (let i = 1; i < maxRandom; i++) {
// if (!peers[i]) {
// break
// }
// if (peers[i].height < highestHeight - 50) {
// maxRandom = i - 1
// }
// }

return peers.slice(0, Math.min(maxRandom, peers.length))
},

0 comments on commit 1d97bff

Please sign in to comment.
You can’t perform that action at this time.