Skip to content
Snippets Groups Projects
Unverified Commit 3a026fb4 authored by Levente Pap's avatar Levente Pap Committed by GitHub
Browse files

Make syncPercentage configurable (#675)

* Make syncPercentage configurable

 - Use `syncbeaconfollower.syncPercentage` in config.json to specify
   the desired percentage of nodes (being followed) that we need to be
   synced compared to in order to consider the node synced.
 - syncPercentage has to be in [0.5, 1.0] interval.
 - Use default value of 0.5 in case of invalid config.

* Add syncPercentage to config.default.json

* Fix syncbeaconfollower configure order
parent fb3d15c4
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
"followNodes": [ "followNodes": [
"Gm7W191NDnqyF7KJycZqK7V6ENLwqxTwoKQN4SmpkB24", "Gm7W191NDnqyF7KJycZqK7V6ENLwqxTwoKQN4SmpkB24",
"9DB3j9cWYSuEEtkvanrzqkzCQMdH1FGv3TawJdVbDxkd" "9DB3j9cWYSuEEtkvanrzqkzCQMdH1FGv3TawJdVbDxkd"
] ],
"syncPercentage": 0.5
}, },
"dashboard": { "dashboard": {
"bindAddress": "127.0.0.1:8081", "bindAddress": "127.0.0.1:8081",
......
...@@ -37,8 +37,8 @@ const ( ...@@ -37,8 +37,8 @@ const (
// CfgSyncBeaconCleanupInterval defines the interval that old beacon status are cleaned up. // CfgSyncBeaconCleanupInterval defines the interval that old beacon status are cleaned up.
CfgSyncBeaconCleanupInterval = "syncbeaconfollower.cleanupInterval" CfgSyncBeaconCleanupInterval = "syncbeaconfollower.cleanupInterval"
// syncPercentage defines the percentage of following nodes that have to be synced. // CfgSyncBeaconSyncPercentage defines the percentage of following nodes that have to be synced.
syncPercentage = 0.5 CfgSyncBeaconSyncPercentage = "syncbeaconfollower.syncPercentage"
) )
// Status represents the status of a beacon node consisting of latest messageID, sentTime and sync status. // Status represents the status of a beacon node consisting of latest messageID, sentTime and sync status.
...@@ -54,6 +54,7 @@ func init() { ...@@ -54,6 +54,7 @@ func init() {
flag.Int(CfgSyncBeaconMaxTimeWindowSec, 10, "the maximum time window for which a sync payload would be considerable") flag.Int(CfgSyncBeaconMaxTimeWindowSec, 10, "the maximum time window for which a sync payload would be considerable")
flag.Int(CfgSyncBeaconMaxTimeOfflineSec, 70, "the maximum time the node should stay synced without receiving updates") flag.Int(CfgSyncBeaconMaxTimeOfflineSec, 70, "the maximum time the node should stay synced without receiving updates")
flag.Int(CfgSyncBeaconCleanupInterval, 10, "the interval at which cleanups are done") flag.Int(CfgSyncBeaconCleanupInterval, 10, "the interval at which cleanups are done")
flag.Float64(CfgSyncBeaconSyncPercentage, 0.5, "percentage of nodes being followed that need to be synced in order to consider the node synced")
} }
var ( var (
...@@ -66,6 +67,7 @@ var ( ...@@ -66,6 +67,7 @@ var (
mutex sync.RWMutex mutex sync.RWMutex
beaconMaxTimeOfflineSec float64 beaconMaxTimeOfflineSec float64
beaconMaxTimeWindowSec float64 beaconMaxTimeWindowSec float64
syncPercentage float64
// tells whether the node is synced or not. // tells whether the node is synced or not.
synced atomic.Bool synced atomic.Bool
...@@ -126,10 +128,18 @@ func OverwriteSyncedState(syncedOverwrite bool) { ...@@ -126,10 +128,18 @@ func OverwriteSyncedState(syncedOverwrite bool) {
// configure plugin // configure plugin
func configure(_ *node.Plugin) { func configure(_ *node.Plugin) {
log = logger.NewLogger(PluginName)
pubKeys := config.Node().GetStringSlice(CfgSyncBeaconFollowNodes) pubKeys := config.Node().GetStringSlice(CfgSyncBeaconFollowNodes)
beaconMaxTimeOfflineSec = float64(config.Node().GetInt(CfgSyncBeaconMaxTimeOfflineSec)) beaconMaxTimeOfflineSec = float64(config.Node().GetInt(CfgSyncBeaconMaxTimeOfflineSec))
beaconMaxTimeWindowSec = float64(config.Node().GetInt(CfgSyncBeaconMaxTimeWindowSec)) beaconMaxTimeWindowSec = float64(config.Node().GetInt(CfgSyncBeaconMaxTimeWindowSec))
log = logger.NewLogger(PluginName) syncPercentage = config.Node().GetFloat64(CfgSyncBeaconSyncPercentage)
if syncPercentage < 0.5 || syncPercentage > 1.0 {
log.Warnf("invalid syncPercentage: %f, syncPercentage has to be in [0.5, 1.0] interval", syncPercentage)
// set it to default
log.Warnf("setting syncPercentage to default value of 0.5")
syncPercentage = 0.5
}
currentBeacons = make(map[ed25519.PublicKey]*Status) currentBeacons = make(map[ed25519.PublicKey]*Status)
currentBeaconPubKeys = make(map[ed25519.PublicKey]string) currentBeaconPubKeys = make(map[ed25519.PublicKey]string)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment