Class BlockchainNode
BlockchainNode orchestrates all subsystems — chain management, mempool,
event bus, P2P networking — through a well-defined lifecycle
(start() / stop()).
Minimum example (FR-CFG-02)
BlockchainNode node = BlockchainConfig.builder().build().start();
System.out.println(node.status().chainHeight());
node.stop();
Milestone 8 changes (T-066)
TransactionMempoolis now a first-class dependency, started and stopped with the node lifecycle.status()correctly reports livemempoolSize.- All event listeners from
BlockchainConfig.getEventListeners()are wired onto the sharedBlockchainEventBusduring construction. - Network subsystem setters are now
publicso thatblockchain-networkcan wire inNodeServerLifecycle,PeerManagerLifecycle, andChainSyncerfrom outside this package.
- Since:
- 1.0.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordImmutable snapshot of a node's operational status (NFR-UX-04). -
Constructor Summary
ConstructorsConstructorDescriptionBlockchainNode(BlockchainConfig config) Constructs aBlockchainNodefrom the given configuration. -
Method Summary
Modifier and TypeMethodDescriptiongetChain()Returns the underlyingBlockchainfor direct chain access.Returns the transaction mempool managed by this node.voidsetNodeServer(NodeServerLifecycle nodeServer) Wires the node server into this node.voidsetPeerManager(PeerManagerLifecycle peerManager) Wires the peer manager into this node.voidsetSyncManager(ChainSyncer syncManager) Wires the chain syncer into this node.start()Starts the blockchain node.status()Returns a snapshot of the current node status (NFR-UX-04).voidstop()Stops the blockchain node and cleanly releases all subsystems.voidsubmitTransaction(Transaction transaction) Validates and submits a transaction through the configured validator chain.
-
Constructor Details
-
BlockchainNode
Constructs aBlockchainNodefrom the given configuration.Construction is lightweight — it does not start networking or mine blocks. Call
start()to begin operations. The event bus is always non-null becauseBlockchainConfig.Builderinitialises it unconditionally.- Parameters:
config- the fully built configuration (non-null)- Throws:
NullPointerException- if config is null
-
-
Method Details
-
setNodeServer
Wires the node server into this node.Called by
blockchain-networkduring assembly. Applications should not call this directly.- Parameters:
nodeServer- the server to bind onstart(); may benullfor standalone mode
-
setPeerManager
Wires the peer manager into this node.Called by
blockchain-networkduring assembly.- Parameters:
peerManager- the peer manager to start/stop with this node; may benullfor standalone mode
-
setSyncManager
Wires the chain syncer into this node.Called by
blockchain-networkduring assembly.- Parameters:
syncManager- the syncer to invoke on startup; may benullfor standalone mode
-
start
Starts the blockchain node.Steps in order:
- Genesis block if chain is empty (FR-CORE-07).
- Mempool TTL eviction scheduler (Milestone 8).
PeerManagerLifecycleheartbeat (Milestone 7).NodeServerLifecycleTCP bind (Milestone 7).- Initial chain sync via
ChainSyncer(Milestone 7).
- Returns:
- this node (for fluent use)
- Throws:
IllegalStateException- if already started
-
stop
public void stop()Stops the blockchain node and cleanly releases all subsystems.Shutdown order (reverse of startup):
- Stop
NodeServerLifecycle - Stop
PeerManagerLifecycle - Stop mempool eviction scheduler (Milestone 8)
- Shutdown
BlockchainEventBus
- Throws:
IllegalStateException- if not yet started
- Stop
-
submitTransaction
Validates and submits a transaction through the configured validator chain.Each registered
TransactionValidatoris applied in sequence. On success the transaction is added to the mempool which publishes aBlockchainEvent.TransactionSubmittedEvent(T-066).- Parameters:
transaction- the transaction to submit (non-null)- Throws:
NullPointerException- if transaction is nullTransactionValidationException- if any validator rejects the transactionIllegalStateException- if the node has not been started
-
getChain
Returns the underlyingBlockchainfor direct chain access.- Returns:
- non-null
Blockchain
-
getMempool
Returns the transaction mempool managed by this node.- Returns:
- non-null
TransactionMempool
-
status
Returns a snapshot of the current node status (NFR-UX-04).The
mempoolSizefield is populated from the liveTransactionMempool(fixed in Milestone 8; was always0before).- Returns:
- non-null
BlockchainNode.NodeStatus - Throws:
IllegalStateException- if the node has not been started
-