Fix init parameters#328
Merged
Merged
Conversation
henriqueaklein
commented
Jul 3, 2026
Contributor
- Removed parameters for the creation of the node. Migrated all of them to wither network_config.json or sgns_config.json.
- Reduced the creation methods to just a single one with a variant and the dev_config, to make it simpler for the SDK and therefore the final app
…d port-resolution Doxygen and test getters - Rename base_port -> port_seed in 3 public factories, private ctor, and InitNetwork (param names only; types/signatures unchanged) - Update @param Doxygen for all 5 declarations - Document pubsub_port > port_seed-derived port-resolution priority on InitNetwork (CONTEXT D-04) - Add GetPubsubPort() and IsAutodhtEnabled() read-only getters as test observables for the D-02 precedence test
…InitNetwork - Add port_seed (numeric IsUint) and auto_dht (bool) RapidJSON reads alongside existing keys - Config wins when present; constructor param is fallback (live override per CONTEXT D-01) - Reassign port_seed param and autodht_ member from config (auto_dht key -> autodht_ member, D-07) - Default-on-missing + WARN-log ill-typed values (CFG-04); INFO-log resolved overrides - port_seed numeric by design (diverges from legacy string pubsub_port, D-08) — code comment added - Document pubsub_port > port_seed-derived priority at port-selection block (D-04) - Define GetPubsubPort()/IsAutodhtEnabled() getters; rename base_port->port_seed throughout
…des constructor param - Scene A: config auto_dht=false overrides autodht=true param (EXPECT_FALSE IsAutodhtEnabled) - Scene B: config port_seed=49999 overrides param=40001 (resolved port >= 49999; param-only range [40001,40301] cannot reach it). Single construction per scene avoids port-bind flakiness. - Models account_management_test harness: temp dir, ofstream config write, NewFromPrivateKey. - Register via addtest + genius_node link + Apple -force_load whole-archive block
…v_config,AccountSource) factory + reordered ctor declarations - NodeType enum (Full/Light/Archive) co-located with NodeState/Error (CFG-02) - AccountSource = std::variant<NewAccount, FromPrivateKey, FromMnemonic, FromPublicKey> with owned std::string payloads (INTF-02, D-03) - New public New(dev_config, AccountSource) canonical factory overload (INTF-01) - New private ctor (dev_config, AccountSource) declaration — reordered, account via std::visit after LoadSgnsConfig (INTF-03) - node_type_ member (default Light); IsFullNode()/GetNodeType() test getters - Old factories + old private ctor RETAINED unchanged (D-01) for Phase 3 migration - Add #include <variant>
…g + IsFullNode/GetNodeType getters - NodeTypeFromString in anon namespace: case-insensitive (lowercase-normalize), returns std::optional<NodeType>, nullopt on unknown (CONTEXT D-02) - LoadSgnsConfig reads node_type -> node_type_ (default Light on missing/unknown + WARN); sets node_type_ ONLY, does NOT touch is_full_node_ (new ctor derives it, old ctor keeps param) - Define IsFullNode()/GetNodeType() test getters - #include <cctype> for std::tolower
…dev_config,AccountSource) factory - New private ctor (dev_config, AccountSource): LoadSgnsConfig -> derive is_full_node_ -> std::visit account creation (with is_full_node_ known) -> InitNetwork. Throws on null account (INTF-03 / CFG-03 / D-05) - std::visit visitor dispatches to GeniusAccount factories (New/NewFromPrivateKey/NewFromMnemonic/NewFromPublicKey) via if constexpr over the 4 AccountSource alternatives - New public New(dev_config, AccountSource): try/catch -> nullptr preserves the nullable contract (D-04) - is_full_node_ member gets defensive = false default (old ctor init-list still wins) - Old factories + old private ctor RETAINED unchanged (D-01)
…node_ + nullptr-on-failure
- Scene A: New(dev_config, FromPrivateKey{key}) with sgns_config {node_type:full} -> IsFullNode()==true, GetNodeType()==Full (proves case-insensitive D-02 + derivation CFG-03)
- Scene B: New(dev_config, FromPrivateKey{bad}) -> nullptr (proves D-04 nullptr-on-failure)
- Models network_config_precedence_test harness; registers via addtest + genius_node + Apple -force_load
…/std::string_view closed the comment early) The '*/' inside '(const char*/std::string_view)' terminated the /** block mid-comment, leaving the struct definitions outside any comment and causing 'unknown type NewAccount/ AccountSource/they' compile errors. Reworded to 'const char* or std::string_view'.
NodeType is nested in sgns::GeniusNode, not at sgns scope, so bare 'NodeType::Full' resolved to YAML::NodeType (yaml-cpp) via name lookup. 'using namespace sgns' exposes GeniusNode, so qualify as GeniusNode::NodeType::Full.
…omPrivateKey{...}) + helper configs
NodeExample.cpp, blockchain_genesis_test, multi_account_sync, node_initialization_progress,
child_tokens_test, full_node_test — each NewFromPrivateKey(dev_config,key,autodht,port_seed,is_full_node)
-> WriteNetworkConfig + WriteSgnsConfig(is_full_node?Full:Light) + New(dev_config, FromPrivateKey{key}).
full_node_test: replaced manual ofstream sgns_config.json write with WriteSgnsConfig (is_processor=false).
…ti (3), processing_nodes (3); reframe network_config_precedence - account_management_test: 3 sites -> New() + helper configs (is_full_node=true->Full, defaults->Light); replaced manual ofstream sgns_config writes with WriteSgnsConfig - processing_multi/processing_nodes: 3 sites each -> New() + helper configs; node_main is_processor=false, procs default true - network_config_precedence_test: REFRAMED (Phase-3 D-03) from 'config overrides param' to 'config drives value' — canonical factory has no autodht/port_seed params; assertions (EXPECT_FALSE IsAutodhtEnabled, EXPECT_GE port>=49999) preserved; removed conflicting local WriteNetworkConfig helper
…ites, transaction_sync 3, migration_sync 2) to New() + helper configs
All sites -> New(dev_config, FromPrivateKey{key}) + WriteNetworkConfig/WriteSgnsConfig; replaced
manual ofstream sgns_config writes with WriteSgnsConfig (is_processor=false preserved);
is_full_node=true->Full, false/defaults->Light.
…canonical New(dev_config,AccountSource) is sole entry point Removed (header + implementation): - Old New(autodht, port_seed, is_full_node) 4-arg overload - NewFromPrivateKey (GeniusNode factory) - NewFromMnemonic (GeniusNode factory) - Old private ctor (dev_config, account, autodht, port_seed, is_full_node) — had no callers after factory deletion Retained: canonical New(dev_config, AccountSource), new (dev_config, AccountSource) ctor (reordered, std::visit), WriteNetworkConfig/WriteSgnsConfig helpers, NodeType enum, all Phase 1/2 work. GeniusAccount::NewFromPrivateKey (different class) is NOT touched. Per CONTEXT D-03: migrate-then-delete.
…re ofstream processing_nodes_test failed: node2 ran with default config (full:false, is_processor:true) because WriteSgnsConfig's ofstream silently failed — node2/'s directory didn't exist yet (the original tests relied on New() creating per-node dirs internally; after migration the config writes happen before New). std::ofstream cannot create directories, so the write failed and LoadSgnsConfig read defaults. Fix: both helpers now std::filesystem::create_directories(base_path) before opening the ofstream. This fixes EVERY call site at once (processing_nodes, processing_multi, and any other migrated test whose per-node dir wasn't pre-created), and hardens the example app. Validation in WriteSgnsConfig still runs first (no dir created for an invalid node_type).
…fix 3 wrong is_processor values Root cause of the broader config concern: helpers truncated network_config.json/sgns_config.json, destroying pre-existing keys that some tests/example rely on: - example/node_test/sgns_config.json ships net_id, bootstrap_fullnodes, authorized_full_node — WriteSgnsConfig wiped them, breaking the example's bootstrap. - child_tokens_test writes pubsub_port (exact-port override) — WriteNetworkConfig wiped it. Fix 1 (merge): both helpers now read-modify-write via RapidJSON (ReadExistingJson + WriteJsonDoc anon helpers). Existing keys are preserved; the helper's keys are added/updated. This saves NodeExample's shipped config, child_tokens' pubsub_port, and any richer config. Fix 2 (wrong is_processor values I hardcoded): blockchain_genesis true->false (test wrote false); multi_account_sync true->isProcessor (param); child_tokens true->isProcessor (param). With merge, the tests' leftover is_processor ofstreams are now harmless (overwritten with the same value).
…_derivation_test uses shared helper - node_type_derivation_test: drop its local WriteSgnsConfig helper (Phase-2 leftover) + unused <fstream>; both scenes now call GeniusNode::WriteSgnsConfig (Scene A node_type='full' for case-insensitivity, Scene B 'Light' defaults). - Remove redundant manual ofstream is_processor writes in blockchain_genesis_test, multi_account_sync, child_tokens_test — the merge helpers now write is_processor; leaving them was dead code. KEPT child_tokens' pubsub_port ofstream (test-specific exact-port override; WriteNetworkConfig merges around it without dropping it).
… config write The test connects nodes via GetPubSub()->GetInterfaceAddress() (published addresses), not hardcoded ports, so pubsub_port (exact-port override) was unnecessary. port_seed=uniquePort (via WriteNetworkConfig) gives unique derived ports per node; peer discovery uses published addresses. ZERO manual ofstream config writes now remain in example/test — all flow through GeniusNode::WriteNetworkConfig/WriteSgnsConfig.
…ses shipped sgns_config.json Per design review: merge was over-engineering. Revert: - WriteNetworkConfig/WriteSgnsConfig TRUNCATE again (write exactly port_seed+auto_dht / node_type+is_processor; create parent dir; validate node_type). Removed ReadExistingJson/ WriteJsonDoc merge machinery. Tests pass correct values (no pubsub_port, no merge needed). - NodeExample no longer calls WriteSgnsConfig — node_type/is_processor come from the shipped example/node_test/sgns_config.json (operator-managed, like a real deployment). Added "node_type": "Light" to the shipped file (matches the original is_full_node=false default). Removed the now-dead is_full_node CLI flag + --full branch (node role is config-driven now, not a constructor param). Kept WriteNetworkConfig for port_seed/auto_dht (no shipped network_config.json).
The new Error::INVALID_NODE_TYPE = 16 (added in Plan 01) was missing a case in the OUTCOME_CPP_DEFINE_CATEGORY_3 message switch, triggering -Wswitch. Added the case with a descriptive message.
…nes/v1.0-REQUIREMENTS.md)
…teKey{...}) after develop merge
The develop merge brought bridge_e2e_test.cpp using the old NewFromPrivateKey factory
(deleted in Phase 3). Migrated its 3 call sites to the canonical API:
- node_main: WriteNetworkConfig(40001, false) + WriteSgnsConfig('Full', true) + New(DEV_CONFIG, FromPrivateKey{key})
- node_proc1/proc2: WriteNetworkConfig(40002/40003, false) + WriteSgnsConfig('Light', true) + New(DEV_CONFIGn, FromPrivateKey{key})
is_processor=true preserves the pre-merge default (the file wrote no sgns_config.json, so all
nodes ran with the LoadSgnsConfig default true).
… node_type_derivation tests Both Phase-1/2 tests construct GeniusNode without setting the secure-storage factory, so account creation hits the default (file/platform) backend. Added a UseMemorySecureStorage() helper (GeniusAccount::SetSecureStorageFactory -> MemorySecureStorage) called at the start of each TEST body, + linked json_secure_storage in CMake. Matches the pattern in multi_account_sync, bridge_e2e, processing_multi, transaction_sync.
… drop runtime WriteNetworkConfig NodeExample now reads BOTH config files from the shipped example/node_test/ files (sgns_config.json: net_id/is_processor/node_type/bootstrap_fullnodes/authorized_full_node; network_config.json: port_seed=40101, auto_dht=true) instead of writing network_config.json at runtime. The example is now fully operator-config-driven, like a real deployment.
EduMenges
requested changes
Jul 7, 2026
EduMenges
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.