mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-21 10:27:26 +08:00
Limit sync candidates (#407)
This commit is contained in:
parent
9a09dc904b
commit
a329bdab3a
@ -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
|
||||
|
||||
@ -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)),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user