-
Notifications
You must be signed in to change notification settings - Fork 205
Sequence Diagrams
JamesPiechota edited this page Mar 13, 2023
·
20 revisions
Intent of these diagrams:
- Show how different modules fit together
- Map to specific functions/files in the codebase
- Be easily updatable to limit rot
That 3rd point forced some compromises, namely using Github's mermaid integration for diagrams rather than building the diagram in another tool and uploading an image. Adapting to mermaid's constraints:
- Vertical gray actors are distinct services
- Black "note" boxes reference specific functions in the codebase
- Horizontal arrows represent process-to-process communication or message passing
-
opt
dotted boxes group related functions and messages for understandability -
loop
dotted boxes are used for loops or repeated processes
%%{
init: {
'theme': 'neutral'
}
}%%
sequenceDiagram
participant ar_nonce_limiter
participant worker
participant ETS
participant ar_events
Note over ar_nonce_limiter: init/1
opt Query the last N blocks
Note over ar_nonce_limiter: ar_node:get_current_block/1
ETS->>ar_nonce_limiter: ets:lookup(node_state, current)
ETS->>ar_nonce_limiter: ets:lookup(node_state, {block, H})
Note over ar_nonce_limiter: ar_node:get_blocks/2
ETS->>ar_nonce_limiter: ets:lookup(node_state, {block, H})
end
Note over ar_nonce_limiter: start_worker/1
ar_nonce_limiter->>worker: spawn(worker/0)
loop Repeat every second (VDF delay)
Note over ar_nonce_limiter: schedule_step/1
ar_nonce_limiter->>ar_nonce_limiter worker: send(compute)
Note over worker: compute/2
Note over worker: ar_vdf:compute/3
Note over worker: ar_mine_randomx:vdf_sha2_nif/5
Note over worker: vdf.cpp:vdf_sha2(...)
worker->>ar_nonce_limiter: send(computed)
ar_nonce_limiter->>ar_events: send(nonce_limiter, computed_output)
end
%%{
init: {
'theme': 'neutral'
}
}%%
sequenceDiagram
participant ar_events
participant ar_mining_server
participant io thread
participant hashing thread
Note over ar_mining_server: init/1
ar_mining_server->>ar_events: subscribe(nonce_limiter)
ar_mining_server->>io thread: spawn(io thread) - 1 per storage_module
ar_mining_server->>hashing thread: spawn(hashing thread)
%%{
init: {
'theme': 'neutral'
}
}%%
sequenceDiagram
participant ar_events
participant ar_nonce_limiter_server_worker
participant VDF Client
loop 1 instance per configured VDF Client
Note over ar_nonce_limiter_server_worker: init/1
ar_nonce_limiter_server_worker->>ar_events: subscribe(nonce_limiter)
end
ar_events->>ar_nonce_limiter_server_worker: send(nonce_limiter, computed_output)
opt POST vdf to a registered client
Note over ar_nonce_limiter_server_worker: push_update/3
Note over ar_nonce_limiter_server_worker: ar_http_iface_cient:push_nonce_limiter_update/2
ar_nonce_limiter_server_worker->>VDF Client: POST /vdf
Note over ar_nonce_limiter_server_worker: push_session/2
Note over ar_nonce_limiter_server_worker: ar_http_iface_cient:push_nonce_limiter_update/2
ar_nonce_limiter_server_worker->>VDF Client: POST /vdf
end