Process flow

The following main threads are spawned when Trin is started via ./src/main.rs.

trin

UTP listener

main()

sub-protocol handler

sub-protocol network task

portal events handler

JSON-RPC server

Where for each sub-protocol implemented (History, State, Etc.,), a new thread is started.

Here are some of the major components that are called on startup within ./src/lib.rs.

trin
portalnet
utp
validation

configs and services

main()

from_cli()

run_trin()

discovery()

utp_listener()

header_oracle()

portalnet_config

storage_config

Once the initial collection of important configs and services have been aggregated, they are passed to the crates for each sub-protocol (trin-history shown here). The received data structures are then used to start the JSON-RPC server.

An events listener awaits network activity that can be actioned.

trin-history
trin
rpc
portalnet
jsonrpc

JSON-RPC History details

History handler

configs and services

initialize_history_network()

HistoryRequestHandler

launch_jsonrpc_server()

events()

Then ./portalnet/events.rs is handles events at the level of the Portal Wire Protocol. These are defined messages that are compliant with the Discv5 protocol, and specific to the Portal Network.