-
Notifications
You must be signed in to change notification settings - Fork 7
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
Remove refute v2 #351
Draft
BelfordZ
wants to merge
10
commits into
1.15.4
Choose a base branch
from
remove-refute-v2
base: 1.15.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+555
−20
Draft
Remove refute v2 #351
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
f179d17
feat: remove nodes that refute regularility
BelfordZ 1396e20
feat: stats based refute limits
BelfordZ ec90b2b
fix: count problematic+expired properly
BelfordZ 7c92ae3
wip
BelfordZ a4cea36
fix: improved testing
BelfordZ 4da7a35
feat: refactor to be easier to reason through
BelfordZ 5c63b00
fix: implement feedback from andrew
BelfordZ 6170d90
fix: use a rotation-safe feature flag
BelfordZ 1f27cb9
fix: update tests after refactoring
BelfordZ a27ebe0
fix: tests passing now
BelfordZ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { P2P } from '@shardus/types' | ||
import * as NodeList from './NodeList' | ||
import { config } from './Context' | ||
import { NodeWithRefuteCycles } from './NodeList'; | ||
|
||
export function isNodeProblematic(node: NodeWithRefuteCycles, currentCycle: number): boolean { | ||
if (!node.refuteCycles) return false; | ||
|
||
// Check consecutive refutes | ||
const refuteCyclesArray = Array.from(node.refuteCycles as Set<number>).sort((a: number, b: number) => a - b); | ||
const consecutiveRefutes = getConsecutiveRefutes(refuteCyclesArray, currentCycle); | ||
if (consecutiveRefutes >= config.p2p.problematicNodeConsecutiveRefuteThreshold) { | ||
return true; | ||
} | ||
|
||
// Check refute percentage in recent history | ||
const refutePercentage = getRefutePercentage(node.refuteCycles, currentCycle); | ||
if (refutePercentage >= config.p2p.problematicNodeRefutePercentageThreshold) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
export function getConsecutiveRefutes(refuteCycles: number[], currentCycle: number): number { | ||
return refuteCycles[refuteCycles.length - 1] !== currentCycle ? 0 : | ||
refuteCycles.filter((cycle, index) => { | ||
return index === 0 || cycle === refuteCycles[index - 1] + 1; | ||
}).length; | ||
} | ||
|
||
export function getRefutePercentage(refuteCycles: Set<number>, currentCycle: number): number { | ||
const windowStart = Math.max(1, currentCycle - config.p2p.problematicNodeHistoryLength + 1); | ||
const windowSize = Math.min(config.p2p.problematicNodeHistoryLength, currentCycle); | ||
const recentRefutes = Array.from(refuteCycles) | ||
.filter(cycle => cycle >= windowStart && cycle <= currentCycle).length; | ||
|
||
return recentRefutes / windowSize; | ||
} | ||
|
||
export function getProblematicNodes(prevRecord: P2P.CycleCreatorTypes.CycleRecord): string[] { | ||
const problematicNodes = new Set<string>(); | ||
|
||
for (const node of NodeList.activeByIdOrder) { | ||
if (isNodeProblematic(node as NodeWithRefuteCycles, prevRecord.counter)) { | ||
problematicNodes.add(node.id); | ||
} | ||
} | ||
|
||
// Sort by refute percentage | ||
return Array.from(problematicNodes).sort((a, b) => { | ||
const nodeA = NodeList.nodes.get(a) as NodeWithRefuteCycles; | ||
const nodeB = NodeList.nodes.get(b) as NodeWithRefuteCycles; | ||
const percentageA = getRefutePercentage(nodeA.refuteCycles, prevRecord.counter); | ||
const percentageB = getRefutePercentage(nodeB.refuteCycles, prevRecord.counter); | ||
return percentageB - percentageA; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be in the if statement below as it can impact the hash of a node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or at least inside of config.p2p.enableProblematicNodeRemoval