Skip to content
Snippets Groups Projects
Select Git revision
  • 308b76e8896af0a123b3404ce8cd4e1568f5e863
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

plugin.go

Blame
  • plugin.go 12.00 KiB
    package sync
    
    import (
    	"sync"
    	"time"
    
    	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/message"
    	"github.com/iotaledger/goshimmer/packages/binary/messagelayer/tangle"
    	"github.com/iotaledger/goshimmer/packages/shutdown"
    	"github.com/iotaledger/goshimmer/plugins/autopeering/local"
    	"github.com/iotaledger/goshimmer/plugins/config"
    	"github.com/iotaledger/goshimmer/plugins/gossip"
    	"github.com/iotaledger/goshimmer/plugins/messagelayer"
    	"github.com/iotaledger/hive.go/autopeering/peer"
    	"github.com/iotaledger/hive.go/daemon"
    	"github.com/iotaledger/hive.go/events"
    	"github.com/iotaledger/hive.go/logger"
    	"github.com/iotaledger/hive.go/node"
    	"github.com/iotaledger/hive.go/types"
    	"github.com/pkg/errors"
    	flag "github.com/spf13/pflag"
    	"go.uber.org/atomic"
    )
    
    const (
    	// PluginName is the plugin name of the sync plugin.
    	PluginName = "Sync"
    	// CfgSyncAnchorPointsCount defines the amount of anchor points to use to determine
    	// whether a node is synchronized.
    	CfgSyncAnchorPointsCount = "sync.anchorPointsCount"
    	// CfgSyncAnchorPointsCleanupAfterSec defines the amount of time which is allowed to pass between setting an anchor
    	// point and it not becoming solid (to clean its slot for another anchor point). It basically defines the expectancy
    	// of how long it should take for an anchor point to become solid. Even if this value is set too low, usually a node
    	// would eventually solidify collected anchor points.
    	CfgSyncAnchorPointsCleanupAfterSec = "sync.anchorPointsCleanupAfterSec"
    	// CfgSyncAnchorPointsCleanupIntervalSec defines the interval at which it is checked whether anchor points fall
    	// into the cleanup window.
    	CfgSyncAnchorPointsCleanupIntervalSec = "sync.anchorPointsCleanupIntervalSec"
    	// CfgSyncDesyncedIfNoMessageAfterSec defines the time period in which new messages must be received and if not
    	// the node is marked as desynced.
    	CfgSyncDesyncedIfNoMessageAfterSec = "sync.desyncedIfNoMessagesAfterSec"
    )
    
    func init() {
    	flag.Int(CfgSyncAnchorPointsCount, 3, "the amount of anchor points to use to determine whether a node is synchronized")
    	flag.Int(CfgSyncDesyncedIfNoMessageAfterSec, 300, "the time period in seconds which sets the node as desynced if no new messages are received")
    	flag.Int(CfgSyncAnchorPointsCleanupIntervalSec, 10, "the interval at which it is checked whether anchor points fall into the cleanup window")
    	flag.Int(CfgSyncAnchorPointsCleanupAfterSec, 60, "the amount of time which is allowed to pass between setting an anchor point and it not becoming solid (to clean its slot for another anchor point)")
    }
    
    var (
    	// Plugin is the plugin instance of the sync plugin.
    	Plugin = node.NewPlugin(PluginName, node.Enabled, configure, run)
    	// ErrNodeNotSynchronized is returned when an operation can't be executed because
    	// the node is not synchronized.
    	ErrNodeNotSynchronized = errors.New("node is not synchronized")
    	// tells whether the node is synced or not.
    	synced atomic.Bool
    	log    *logger.Logger
    )
    
    // Synced tells whether the node is in a state we consider synchronized, meaning
    // it has the relevant past and present message data.
    func Synced() bool {
    	return synced.Load()
    }
    
    // OverwriteSyncedState overwrites the synced state with the given value.
    func OverwriteSyncedState(syncedOverwrite bool) {
    	synced.Store(syncedOverwrite)