|
5 | 5 | IRankingBlockSent, |
6 | 6 | IRankingBlockReceived, |
7 | 7 | IEndorserBlockSent, |
| 8 | + IEndorserBlockReceived, |
8 | 9 | } from "@/components/Sim/types"; |
9 | 10 | import { useRef } from "react"; |
10 | 11 |
|
@@ -209,6 +210,53 @@ const parseEndorserBlockSent = ( |
209 | 210 | return null; |
210 | 211 | }; |
211 | 212 |
|
| 213 | +const parseEndorserBlockReceived = ( |
| 214 | + streamLabels: any, |
| 215 | + timestamp: number, |
| 216 | + logLine: string, |
| 217 | +): IServerMessage | null => { |
| 218 | + try { |
| 219 | + const log = JSON.parse(logLine); |
| 220 | + |
| 221 | + // From cardano-node ns=LeiosFetch.Remote.Receive.Block |
| 222 | + // {"mux_at":"2025-12-05T12:45:21.98320066Z","peer":{"connectionId":"127.0.0.1:3003 127.0.0.1:3002"},"kind":"Recv","msg":{"kind":"MsgLeiosBlock","eb":"\u003celided\u003e","ebBytesSize":27471}} |
| 223 | + if (log.kind === "Recv" && log.msg && log.msg.kind === "MsgLeiosBlock") { |
| 224 | + const recipient = streamLabels.process; |
| 225 | + const connectionId = log.peer?.connectionId; |
| 226 | + let sender = "Node0"; |
| 227 | + |
| 228 | + if (connectionId) { |
| 229 | + const endpoints = connectionId.split(" "); |
| 230 | + if (endpoints.length === 2) { |
| 231 | + const senderEndpoint = endpoints[1]; |
| 232 | + sender = HOST_PORT_TO_NODE[senderEndpoint] || sender; |
| 233 | + } |
| 234 | + } |
| 235 | + |
| 236 | + const message: IEndorserBlockReceived = { |
| 237 | + type: EServerMessageType.EBReceived, |
| 238 | + slot: 0, // FIXME: use correct slot |
| 239 | + id: `eb-${log.msg.eb}`, // FIXME: msg.eb is always elided |
| 240 | + sender, |
| 241 | + recipient, |
| 242 | + }; |
| 243 | + |
| 244 | + return { |
| 245 | + time_s: timestamp, |
| 246 | + message, |
| 247 | + }; |
| 248 | + } |
| 249 | + } catch (error) { |
| 250 | + console.warn( |
| 251 | + "Failed to parse EndorserBlockReceived log line:", |
| 252 | + logLine, |
| 253 | + error, |
| 254 | + ); |
| 255 | + } |
| 256 | + |
| 257 | + return null; |
| 258 | +}; |
| 259 | + |
212 | 260 | function connectLokiWebSocket(lokiHost: string, dispatch: any): () => void { |
213 | 261 | // NOTE: Single websocket is essential because: |
214 | 262 | // 1. Timeline aggregation assumes events are chronologically ordered |
@@ -247,7 +295,8 @@ function connectLokiWebSocket(lokiHost: string, dispatch: any): () => void { |
247 | 295 | const event = |
248 | 296 | parseRankingBlockSent(stream.stream, ts, logLine) || |
249 | 297 | parseRankingBlockReceived(stream.stream, ts, logLine) || |
250 | | - parseEndorserBlockSent(stream.stream, ts, logLine); |
| 298 | + parseEndorserBlockSent(stream.stream, ts, logLine) || |
| 299 | + parseEndorserBlockReceived(stream.stream, ts, logLine); |
251 | 300 | if (event) { |
252 | 301 | console.warn("Parsed", event.time_s, event.message); |
253 | 302 | events.push(event); |
|
0 commit comments