From 5f3f42e875084dfc2b411cc1b69a49cd72e846bc Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 1 Nov 2024 15:40:35 +0200 Subject: [PATCH 1/3] FEAT: Trust mode: createNotifierWSReceiverServicesIfNeeded --- cmd/sovereignnode/config/sovereignConfig.toml | 7 ++ cmd/sovereignnode/sovereignNodeRunner.go | 69 ++++++++++++------- config/sovereignConfig.go | 1 + 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/cmd/sovereignnode/config/sovereignConfig.toml b/cmd/sovereignnode/config/sovereignConfig.toml index 2f8d009f686..d8d333750a1 100644 --- a/cmd/sovereignnode/config/sovereignConfig.toml +++ b/cmd/sovereignnode/config/sovereignConfig.toml @@ -45,6 +45,13 @@ Hasher = "sha256" [NotifierConfig] + # This flag indicates whether the node will establish a WebSocket receiver connection from a light node or observer. + # Running an additional main chain light node as a notifier requires extra hardware resources. + # When disabled, the node will rely on and trust incoming headers from the main chain proposed by other leaders. + # Disabling this flag can be useful in scenarios where additional validation infrastructure isn't necessary, + # such as for a CEX observer setup that only requires balance checks on various addresses. + Enabled = true + SubscribedEvents = [ { Identifier = "deposit", Addresses = ["erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"] }, { Identifier = "execute", Addresses = ["erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th"] } diff --git a/cmd/sovereignnode/sovereignNodeRunner.go b/cmd/sovereignnode/sovereignNodeRunner.go index c20fc77add4..98aba1852bb 100644 --- a/cmd/sovereignnode/sovereignNodeRunner.go +++ b/cmd/sovereignnode/sovereignNodeRunner.go @@ -529,44 +529,27 @@ func (snr *sovereignNodeRunner) executeOneComponentCreationCycle( return true, err } - sovereignNotifier, err := createSovereignNotifier(&configs.SovereignExtraConfig.NotifierConfig) - if err != nil { - return true, err - } - - sovereignWsReceiver, err := createSovereignWsReceiver( + notifierServices, err := createNotifierWSReceiverServicesIfNeeded( &configs.SovereignExtraConfig.NotifierConfig, - sovereignNotifier, - ) - if err != nil { - return true, err - } - - sovereignNotifierBootstrapper, err := startSovereignNotifierBootstrapper( incomingHeaderHandler, - sovereignNotifier, managedCoreComponents.GenesisNodesSetup().GetRoundDuration(), managedProcessComponents.ForkDetector(), managedConsensusComponents.Bootstrapper(), ) - if err != nil { - return true, err - } log.Debug("creating node structure") - extraOptionNotifierReceiver := func(n *node.Node) error { - n.AddClosableComponent(sovereignWsReceiver) + extraOptionsNotifier := func(n *node.Node) error { + for _, notifierService := range notifierServices { + n.AddClosableComponent(notifierService) + } + return nil } extraOptionOutGoingBridgeSender := func(n *node.Node) error { n.AddClosableComponent(outGoingBridgeOpHandler) return nil } - extraOptionNotifierBootstrapper := func(n *node.Node) error { - n.AddClosableComponent(sovereignNotifierBootstrapper) - return nil - } nodeHandler, err := node.CreateNode( configs.GeneralConfig, @@ -585,9 +568,8 @@ func (snr *sovereignNodeRunner) executeOneComponentCreationCycle( flagsConfig.BootstrapRoundIndex, configs.ImportDbConfig.IsImportDBMode, node.NewSovereignNodeFactory(configs.GeneralConfig.SovereignConfig.GenesisConfig.NativeESDT), - extraOptionNotifierReceiver, + extraOptionsNotifier, extraOptionOutGoingBridgeSender, - extraOptionNotifierBootstrapper, ) if err != nil { return true, err @@ -1904,6 +1886,43 @@ func createWhiteListerVerifiedTxs(generalConfig *config.Config) (process.WhiteLi return interceptors.NewWhiteListDataVerifier(whiteListCacheVerified) } +func createNotifierWSReceiverServicesIfNeeded( + config *config.NotifierConfig, + incomingHeaderHandler process.IncomingHeaderSubscriber, + roundDuration uint64, + forkDetector process.ForkDetector, + bootstrapper process.Bootstrapper, +) ([]mainFactory.Closer, error) { + if !config.Enabled { + return make([]mainFactory.Closer, 0), nil + } + + sovereignNotifier, err := createSovereignNotifier(config) + if err != nil { + return nil, err + } + + sovereignWsReceiver, err := createSovereignWsReceiver( + config, + sovereignNotifier, + ) + if err != nil { + return nil, err + } + sovereignNotifierBootstrapper, err := startSovereignNotifierBootstrapper( + incomingHeaderHandler, + sovereignNotifier, + roundDuration, + forkDetector, + bootstrapper, + ) + if err != nil { + return nil, err + } + + return []mainFactory.Closer{sovereignWsReceiver, sovereignNotifierBootstrapper}, nil +} + func createSovereignWsReceiver( config *config.NotifierConfig, sovereignNotifier notifierProcess.SovereignNotifier, diff --git a/config/sovereignConfig.go b/config/sovereignConfig.go index 0461bd8e0ba..04ad37b9cd0 100644 --- a/config/sovereignConfig.go +++ b/config/sovereignConfig.go @@ -38,6 +38,7 @@ type OutGoingBridgeCertificate struct { // NotifierConfig holds sovereign notifier configuration type NotifierConfig struct { + Enabled bool `toml:"Enabled"` SubscribedEvents []SubscribedEvent `toml:"SubscribedEvents"` WebSocketConfig WebSocketConfig `toml:"WebSocket"` } From a54a94ccc8db93d6af7102b9abbcb6650ad07005 Mon Sep 17 00:00:00 2001 From: MariusC Date: Mon, 4 Nov 2024 17:30:35 +0200 Subject: [PATCH 2/3] FEAT: Add info log when notifier is disabled --- cmd/sovereignnode/sovereignNodeRunner.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/sovereignnode/sovereignNodeRunner.go b/cmd/sovereignnode/sovereignNodeRunner.go index 98aba1852bb..2855c18c0e0 100644 --- a/cmd/sovereignnode/sovereignNodeRunner.go +++ b/cmd/sovereignnode/sovereignNodeRunner.go @@ -1894,6 +1894,7 @@ func createNotifierWSReceiverServicesIfNeeded( bootstrapper process.Bootstrapper, ) ([]mainFactory.Closer, error) { if !config.Enabled { + log.Info("running without any notifier attached") return make([]mainFactory.Closer, 0), nil } From 5bdc0417fd38396019c89dd334d5aae5418d1bf2 Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 8 Nov 2024 12:22:24 +0200 Subject: [PATCH 3/3] FIX: After merge --- cmd/sovereignnode/sovereignNodeRunner.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/cmd/sovereignnode/sovereignNodeRunner.go b/cmd/sovereignnode/sovereignNodeRunner.go index b3ea56e8727..53fe17cea58 100644 --- a/cmd/sovereignnode/sovereignNodeRunner.go +++ b/cmd/sovereignnode/sovereignNodeRunner.go @@ -529,25 +529,20 @@ func (snr *sovereignNodeRunner) executeOneComponentCreationCycle( return true, err } - notifierServices, err := createNotifierWSReceiverServicesIfNeeded( - &configs.SovereignExtraConfig.NotifierConfig, - sovereignNotifier, - ) - if err != nil { - return true, err - } - - sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) - sovereignNotifierBootstrapper, err := startSovereignNotifierBootstrapper( + notifierServices, err := createNotifierWSReceiverServicesIfNeeded( + &configs.SovereignExtraConfig.NotifierConfig, incomingHeaderHandler, managedCoreComponents.GenesisNodesSetup().GetRoundDuration(), managedProcessComponents.ForkDetector(), managedConsensusComponents.Bootstrapper(), sigs, ) + if err != nil { + return true, err + } log.Debug("creating node structure") @@ -1901,6 +1896,7 @@ func createNotifierWSReceiverServicesIfNeeded( roundDuration uint64, forkDetector process.ForkDetector, bootstrapper process.Bootstrapper, + sigStopNode chan os.Signal, ) ([]mainFactory.Closer, error) { if !config.Enabled { log.Info("running without any notifier attached") @@ -1925,6 +1921,7 @@ func createNotifierWSReceiverServicesIfNeeded( roundDuration, forkDetector, bootstrapper, + sigStopNode, ) if err != nil { return nil, err