From 3fa6a23f7c8a8820a7b11b049f7e1e63d409aa9c Mon Sep 17 00:00:00 2001 From: SW van Heerden Date: Tue, 12 Sep 2023 11:25:18 +0200 Subject: [PATCH] docs: fix header sync diagrams (#5753) Description --- updates and fixes the header sync diagrams --- docs/src/diagrams/header_sync.md | 95 +++++++------------------------- 1 file changed, 19 insertions(+), 76 deletions(-) diff --git a/docs/src/diagrams/header_sync.md b/docs/src/diagrams/header_sync.md index 4567e3b9d8..378ea38eae 100644 --- a/docs/src/diagrams/header_sync.md +++ b/docs/src/diagrams/header_sync.md @@ -1,12 +1,13 @@ ## header sync ```mermaid flowchart TD + META[version: v0.1
commit: 45c20a] A -..- N1>header_sync.rs line 130] - A -..- N2>header_sync/synchronizer.rs line 105] + AB-..- N2>header_sync/synchronizer.rs line 107] A[synchronize] --> B[1. try sync from all peers] B --> C[2. connect and attempt sync] C --> D[3. attemp sync] - D -..- N3>header_sync/synchronizer.rs line 284] + D -..- N3>header_sync/synchronizer.rs line 231] D --> E[(get local tip header)] E --> F[["Determine sync status"]] F--> G{SyncStatus?} @@ -25,27 +26,30 @@ flowchart TD N1:::note N2:::note N3:::note + META:::meta classDef note fill:#eee,stroke:#ccc + classDef meta fill:#b11,stroke:#ccc ``` ## determine sync status ```mermaid flowchart TD - A -..- N1>header_sync/synchronizer.rs line 434] + META[version: v0.1
commit: 45c20a] + A -..- N1>header_sync/synchronizer.rs line 390] A[determine sync status] --> B[1. find chain split] - B -..- N2>header_sync/synchronizer.rs line 364] + B -..- N2>header_sync/synchronizer.rs line 311] B --> C[(fetch 500 headers back)] C --> D[2.Send headers to remote peer for matching] D --> E{Result back} E -->|RPC::RequestFailed|C - E -->|Some headers returned|F{3.Too much headers returned} + E -->|Some data returned|F{3.Too much headers returned} F --> |Yes| G[ban peer] F --> |No|I{4.bad data returned} I --> |Yes| G I --> |No|J{5.No headers returned} - J --> |Yes|K{6.returned forked inde > 0} + J --> |Yes|K{6.returned forked index > 0} K --> |Yes|L[return WereAhead] K --> |No|M[return Insync] - J --> |No|N[7.validater returned headers] + J --> |No|N[7.validate returned headers] N --> O{8. remote peer tip height < split height} O --> |Yes| G O --> |No|P[return Lagging] @@ -53,13 +57,16 @@ flowchart TD N1:::note N2:::note + META:::meta classDef note fill:#eee,stroke:#ccc + classDef meta fill:#b11,stroke:#ccc ``` ## synchronise headers ```mermaid flowchart TD - A -..- N1>header_sync/synchronizer.rs line 566] + META[version: v0.1
commit: 45c20a] + A -..- N1>header_sync/synchronizer.rs line 496] A[synchronie_headers] --> B{1. Compare PoW} B --> |Yes| C[2.Switch chain to pending chain] C --> D[Rewind chain if desired] @@ -69,9 +76,9 @@ flowchart TD F --> |Yes|G{4. Compare PoW} G --> |No|H[ban peer] F --> |No| I[5. Sync headers stream] - G --> |Yes| I + G --> |Yes| IA[return ok] I --> J[6. Stream get next header] - J -->|some header| K[(Get local chain metadata height)] + J -->|some header| K[Get local chain metadata height] K --> L{7.existing header?} L --> |Yes|J L --> |No|M[8. validate header] @@ -87,71 +94,7 @@ flowchart TD S --> |No| U[Return Ok] N1:::note + META:::meta classDef note fill:#eee,stroke:#ccc + classDef meta fill:#b11,stroke:#ccc ``` - -```mermaid -flowchart TD - A[attempt_sync] -->B[determine_sync_status] - A -..- DB>DB access featch last header] - B -..- N1>synchronizer.rs line 434] - - B --> C[fn find_chain_split] - C -..- N2>synchronizer.rs line 364] - - C -->|remote peer| D[fn find_chain_split] - D -..- N3>sync/rpc/service.rs line 364] - - D -->|GRAPH REMOTE|E[[fn determine_sync_status]] - E -..- N1>synchronizer.rs line 434] - - E -->|empty_headers|K[Is fork hash > 0] - K --> |true| L[Return we are ahread] - K --> |false|G[Return insync] - E -->|too many returned|F[ban peer] - E -->|index >= hashes returned|F[Return ban peer] - L --> |Check if our meta data has changed|M[ban peer on true] - G --> |Check if our meta data has changed|M[ban peer on true] - E -->|iterate over returned headers| H[Validate initial headers] - H --> I[is split height greater than claimed height] - I -->|No|F[Return ban peer] - I --> J[Lagging state] - J --> N[fn Synchroize_headers] - N -..- N4>synchronizer.rs line 566] - - N --> O[is intial headers pow's higher than current chain] - O --> |Yes|P[swap to chain to intial headers] - O --> |No|Q[Has peer sent max headers] - P --> Q[Has peer sent max headers] - Q --> |No|R[is intial headers pow's higher than current chain] - R --> |No|S[ban peer] - R --> |Yes|T[Exit header sync, go to block sync] - Q --> |Yes|U[iterate over header stream] - U --> V[Does it follow prev header] - V --> |No|W[ban peer] - V --> |Yes|X[Does it already exist in chain] - X --> |Yes|W[ban peer] - X --> |No|Y[validate] - Y --> |No|W[ban peer] - Y --> |Yes|Z[Have we swapped to new chain] - Z --> |Yes|AA[Add to main chain] - Z --> |No|AB[is the new temp chain's pow higher than the local chain] - AB --> |Yes|AC[Swap to new chain] - AC --> AD[End of header stream] - Z --> AD[End of header stream] - AD --> |No|U - AD --> |Yes|AE[Have we swapped chains] - AE --> |No|AF[is the temp chains'pow less than originally claimed by the peer] - AF --> |Yes|W - AF --> |No|AG[local chain is higher, exit sync] - AE --> AH[is new chains'pow less than originally claimed by the peer] - AH --> |Yes|W - AH --> |No|AI[Go on to block sync] - - N1:::note - N2:::note - N3:::note - N4:::note - DB:::note - classDef note fill:#eee,stroke:#ccc - ``` \ No newline at end of file