From bd85dd4074503b42a2a8443c5c3b7ebd9e8cc807 Mon Sep 17 00:00:00 2001 From: Alessandro De Blasis Date: Mon, 9 Jan 2023 16:40:48 +0000 Subject: [PATCH] refactor(P2P): DebugMode handling --- Makefile | 2 +- app/client/cli/debug.go | 2 +- build/config/config1.json | 1 - p2p/raintree/network.go | 13 +------------ runtime/manager.go | 6 ++++++ 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 43dd7261a..e2d1476f6 100644 --- a/Makefile +++ b/Makefile @@ -130,7 +130,7 @@ rebuild_client_start: docker_check ## Rebuild and run a client daemon which is o .PHONY: client_connect client_connect: docker_check ## Connect to the running client debugging daemon - docker exec -it client /bin/bash -c "POCKET_CLIENT_DEBUG_MODE=true go run -tags=debug app/client/*.go debug" + docker exec -it client /bin/bash -c "go run -tags=debug app/client/*.go debug" .PHONY: build_and_watch build_and_watch: ## Continous build Pocket's main entrypoint as files change diff --git a/app/client/cli/debug.go b/app/client/cli/debug.go index dc112a77e..e873882dc 100644 --- a/app/client/cli/debug.go +++ b/app/client/cli/debug.go @@ -58,7 +58,7 @@ func NewDebugCommand() *cobra.Command { Args: cobra.ExactArgs(0), PersistentPreRun: func(cmd *cobra.Command, args []string) { var err error - runtimeMgr := runtime.NewManagerFromFiles(defaultConfigPath, defaultGenesisPath, runtime.WithRandomPK()) + runtimeMgr := runtime.NewManagerFromFiles(defaultConfigPath, defaultGenesisPath, runtime.WithClientDebugMode(), runtime.WithRandomPK()) // HACK(#416): this is a temporary solution that guarantees backward compatibility while we implement peer discovery. validators = runtimeMgr.GetGenesis().Validators diff --git a/build/config/config1.json b/build/config/config1.json index 419a16f1c..80cc9c1f0 100644 --- a/build/config/config1.json +++ b/build/config/config1.json @@ -1,7 +1,6 @@ { "root_directory": "/go/src/github.com/pocket-network", "private_key": "6fd0bc54cc2dd205eaf226eebdb0451629b321f11d279013ce6fdd5a33059256b2eda2232ffb2750bf761141f70f75a03a025f65b2b2b417c7f8b3c9ca91e8e4", - "client_debug_mode": false, "consensus": { "max_mempool_bytes": 500000000, "pacemaker_config": { diff --git a/p2p/raintree/network.go b/p2p/raintree/network.go index 89838870c..b492158b9 100644 --- a/p2p/raintree/network.go +++ b/p2p/raintree/network.go @@ -154,13 +154,7 @@ func (n *rainTreeNetwork) networkSendInternal(data []byte, address cryptoPocket. return err } - // this is because in client mode there's no bus - bus := n.GetBus() - if bus == nil { - return nil - } - - bus. + n.GetBus(). GetTelemetryModule(). GetEventMetricsAgent(). EmitEvent( @@ -258,11 +252,6 @@ func (n *rainTreeNetwork) SetBus(bus modules.Bus) { } func (n *rainTreeNetwork) GetBus() modules.Bus { - // TODO: Do we need this if? - // if n.bus == nil { - // log.Printf("[WARN] PocketBus is not initialized in rainTreeNetwork") - // return nil - // } return n.bus } diff --git a/runtime/manager.go b/runtime/manager.go index 9c574b7cb..4b3faa051 100644 --- a/runtime/manager.go +++ b/runtime/manager.go @@ -158,3 +158,9 @@ func WithClock(clockMgr clock.Clock) func(*Manager) { b.clock = clockMgr } } + +func WithClientDebugMode() func(*Manager) { + return func(b *Manager) { + b.config.ClientDebugMode = true + } +}