From ccdb0b494249ebeb2563c517d4995c3c98aa6b95 Mon Sep 17 00:00:00 2001 From: Enrique Lacal Date: Wed, 19 Jun 2024 18:08:20 +0100 Subject: [PATCH] fix: do not start multiple blockchain plugin on retry of namespace start Signed-off-by: Enrique Lacal --- internal/orchestrator/orchestrator.go | 62 +++++++++++++++------------ 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/internal/orchestrator/orchestrator.go b/internal/orchestrator/orchestrator.go index 0b6746d32..5909aeaa8 100644 --- a/internal/orchestrator/orchestrator.go +++ b/internal/orchestrator/orchestrator.go @@ -191,33 +191,34 @@ type Config struct { } type orchestrator struct { - ctx context.Context - cancelCtx context.CancelFunc - started bool - startedLock sync.Mutex - namespace *core.Namespace - config Config - plugins *Plugins - multiparty multiparty.Manager // only for multiparty - batch batch.Manager // only for multiparty - broadcast broadcast.Manager // only for multiparty - messaging privatemessaging.Manager // only for multiparty - sharedDownload shareddownload.Manager // only for multiparty - identity identity.Manager - events events.EventManager - networkmap networkmap.Manager - defhandler definitions.Handler - defsender definitions.Sender - data data.Manager - syncasync syncasync.Bridge - assets assets.Manager - bc boundCallbacks - contracts contracts.Manager - metrics metrics.Manager - cacheManager cache.Manager - operations operations.Manager - txHelper txcommon.Helper - txWriter txwriter.Writer + ctx context.Context + cancelCtx context.CancelFunc + started bool + startedBlockchainPlugin bool + startedLock sync.Mutex + namespace *core.Namespace + config Config + plugins *Plugins + multiparty multiparty.Manager // only for multiparty + batch batch.Manager // only for multiparty + broadcast broadcast.Manager // only for multiparty + messaging privatemessaging.Manager // only for multiparty + sharedDownload shareddownload.Manager // only for multiparty + identity identity.Manager + events events.EventManager + networkmap networkmap.Manager + defhandler definitions.Handler + defsender definitions.Sender + data data.Manager + syncasync syncasync.Bridge + assets assets.Manager + bc boundCallbacks + contracts contracts.Manager + metrics metrics.Manager + cacheManager cache.Manager + operations operations.Manager + txHelper txcommon.Helper + txWriter txwriter.Writer } func NewOrchestrator(ns *core.Namespace, config Config, plugins *Plugins, metrics metrics.Manager, cacheManager cache.Manager) Orchestrator { @@ -568,11 +569,16 @@ func (or *orchestrator) initManagers(ctx context.Context) (err error) { } func (or *orchestrator) initComponents(ctx context.Context) (err error) { - if or.blockchain() != nil { + // The blockchain plugin doesn't return a manager or struct that we can check for + // nil like all the other mangagers to see if it has been initialised before! + // So we have a boolean to check so that when the retry wrapper initialises these components + // again we do have multiple ones running + if or.blockchain() != nil && !or.startedBlockchainPlugin { err = or.blockchain().StartNamespace(ctx, or.namespace.Name) if err != nil { return err } + or.startedBlockchainPlugin = true } if or.data == nil {