Limit sync candidates (#407)

This commit is contained in:
petricadaipegsp 2024-12-08 04:21:03 +01:00 committed by GitHub
parent 9a09dc904b
commit a329bdab3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 5 deletions

View File

@ -94,6 +94,8 @@ type EngineConfig struct {
AutoMergeCoins bool `yaml:"autoMergeCoins"`
// Maximum wait time for a frame to be downloaded from a peer.
SyncTimeout time.Duration `yaml:"syncTimeout"`
// Number of candidate peers per category to sync with.
SyncCandidates int `yaml:"syncCandidates"`
// Values used only for testing do not override these in production, your
// node will get kicked out

View File

@ -20,7 +20,10 @@ import (
"source.quilibrium.com/quilibrium/monorepo/node/protobufs"
)
const defaultSyncTimeout = 4 * time.Second
const (
defaultSyncTimeout = 4 * time.Second
defaultSyncCandidates = 8
)
func (e *DataClockConsensusEngine) syncWithMesh() error {
e.logger.Info("collecting vdf proofs")
@ -304,11 +307,16 @@ func (e *DataClockConsensusEngine) GetAheadPeers(frameNumber uint64) []internal.
}
}
syncCandidates := e.config.Engine.SyncCandidates
if syncCandidates == 0 {
syncCandidates = defaultSyncCandidates
}
return slices.Concat(
internal.WeightedSampleWithoutReplacement(nearCandidates, len(nearCandidates)),
internal.WeightedSampleWithoutReplacement(reachableCandidates, len(reachableCandidates)),
internal.WeightedSampleWithoutReplacement(unknownCandidates, len(unknownCandidates)),
internal.WeightedSampleWithoutReplacement(unreachableCandidates, len(unreachableCandidates)),
internal.WeightedSampleWithoutReplacement(nearCandidates, min(len(nearCandidates), syncCandidates)),
internal.WeightedSampleWithoutReplacement(reachableCandidates, min(len(reachableCandidates), syncCandidates)),
internal.WeightedSampleWithoutReplacement(unknownCandidates, min(len(unknownCandidates), syncCandidates)),
internal.WeightedSampleWithoutReplacement(unreachableCandidates, min(len(unreachableCandidates), syncCandidates)),
)
}