Эх сурвалжийг харах

explorer: incorporate no-sync mode into respective explorer Makefiles

This commit adds targets to the explorer's Makefiles for starting the explorer in no-sync mode. This allows node environments to launch without connecting to a Darkfi blockchain network, relying instead on existing explorer databases. A `check-contracts` target was added to ensure required WASM files are built to start explorerd in no-sync mode. This setup enhances the mode implementation by simplifying the process of starting environments without sync.

Summary of Updates:
- Introduced `start-no-sync-%` targets in `explorer/Makefile` and `explorer/explorerd/Makefile`
- Added `await-startup-no-sync-%` in `explorer/explorerd/Makefile` to wait for explorerd startup while skipping the Darkfid connection and sync
- Implemented a `check-contracts` target to verify the presence of required contract artifacts and build them if necessary
kalm 1 жил өмнө
parent
commit
a9939f47e9

+ 12 - 0
bin/explorer/Makefile

@@ -24,6 +24,18 @@ start-%:
 		while true; do sleep 1; done; \
 	'
 
+# Start no-sync explorer (localnet/testnet/mainnet) without connecting to or syncing with the Darkfi blockchain
+start-no-sync-%:
+	@echo "Starting $* environment (no sync)..."
+	@sh -c ' \
+		trap "echo Interrupt detected; make stop; exit 0" INT; \
+		$(MAKE) -C ./explorerd start-no-sync-$*; \
+		$(MAKE) -C ./explorerd await-startup-no-sync-$*; \
+		$(MAKE) -C ./site start-$*; \
+		echo "Started $* environment in no sync mode. Press Ctrl-C to stop."; \
+		while true; do sleep 1; done; \
+	'
+
 # Stop the running network
 stop:
 	@$(MAKE) -C ./explorerd stop || true; \

+ 33 - 1
bin/explorer/explorerd/Makefile

@@ -132,6 +132,25 @@ start-%: check-darkfid check-explorerd
 		$(call wait_for_explorerd_startup, $$LOG_DIR) \
 	'
 
+# Starts an explorer node in no-sync mode for `localnet`, `testnet`, or `mainnet` networks.
+# In no-sync mode, no connections are made with the Darkfi blockchain network and the explorer
+# relies solely on a local database without attempting synchronization. As with the `start-%`
+# target, inputs are verified, any running nodes are stopped, the log directory is initialized,
+# and the node is started.
+start-no-sync-%: check-contracts check-explorerd
+	@if [ "$*" != "localnet" ] && [ "$*" != "testnet" ] && [ "$*" != "mainnet" ]; then \
+		echo "Error: Unsupported network '$*'. Use 'localnet', 'testnet', or 'mainnet'."; \
+		exit 1; \
+	fi
+	@$(MAKE) stop suppress_not_running=1
+	@echo "Starting explorer node environment (no sync) $*..."
+	@sh -c ' \
+		LOG_DIR=$(LOG_HOME)/$*; \
+		mkdir -p "$$LOG_DIR"; \
+		./$(EXPLORERD_BIN) --log "$$LOG_DIR/explorerd.log" -c $(EXPLORERD_CONFIG) --network $* --no-sync & echo $$! >> PIDs.txt; \
+		$(call wait_for_explorerd_startup, $$LOG_DIR) \
+	'
+
 # Check and build darkfid if it does not exist
 check-darkfid:
 	@if [ ! -f "$(DARKFID_BIN)" ]; then \
@@ -153,6 +172,15 @@ check-minerd:
 		$(MAKE) -C "$(PROJECT_ROOT)" minerd; \
 	fi
 
+# Check and build contracts if they do not exist
+check-contracts:
+	@if [ ! -f "$(PROJECT_ROOT)/src/contract/money/darkfi_money_contract.wasm" ] \
+	  || [ ! -f "$(PROJECT_ROOT)/contract/dao/darkfi_dao_contract.wasm" ] \
+	  || [ ! -f "$(PROJECT_ROOT)/contract/deployooor/darkfi_deployooor_contract.wasm" ]; then \
+		echo "Building contracts..."; \
+		$(MAKE) -C "$(PROJECT_ROOT)" contracts; \
+	fi
+
 # Stop the running network
 # Usage: make stop [suppress_not_running=1]
 stop:
@@ -172,11 +200,15 @@ stop:
 		fi; \
 	fi
 
-# Wait for the network to start from another Makefile
+# Wait for the network to start
 await-startup-%:
 	@$(call wait_for_darkfid_startup,$(LOG_HOME)/$*)
 	@$(call wait_for_explorerd_startup,$(LOG_HOME)/$*)
 
+# Wait for the explorer node environment to start in no-sync mode (skip waiting for darkfid startup)
+await-startup-no-sync-%:
+	@$(call wait_for_explorerd_startup,$(LOG_HOME)/$*)
+
 # Waits for Darkfid to start
 define wait_for_darkfid_startup
   log_dir=$(strip $(1)); \