Skip to content

Commit 1518fe3

Browse files
authored
docs: add d2 tool to repo and mempool arch diagram (#597)
* add mempool draft * add svg * update readme * add missing edge * make tx handler two lines * make ext mempool interface impl two lines
1 parent 8156e38 commit 1518fe3

File tree

4 files changed

+370
-1
lines changed

4 files changed

+370
-1
lines changed

Makefile

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,3 +395,73 @@ mocks:
395395
@go get github.com/vektra/mockery/v2
396396
@go generate ./...
397397
@make format-go
398+
399+
###############################################################################
400+
### D2 Diagrams ###
401+
###############################################################################
402+
403+
D2_THEME=300
404+
D2_DARK_THEME=200
405+
D2_LAYOUT=tala
406+
407+
D2_ENV_VARS=D2_THEME=$(D2_THEME) \
408+
D2_DARK_THEME=$(D2_DARK_THEME) \
409+
D2_LAYOUT=$(D2_LAYOUT)
410+
411+
.PHONY: d2check d2watch d2gen d2gen-all
412+
413+
d2check:
414+
@echo "🔍 checking if d2 is installed..."
415+
@which d2 > /dev/null 2>&1 || { \
416+
echo "🔴 d2 is not installed, see installation docs: https://d2lang.com/tour/install/"; \
417+
exit 1; \
418+
}
419+
@echo "🟢 d2 is installed"
420+
@echo "🔍 checking if $(D2_LAYOUT) layout is installed..."
421+
@d2 layout | grep $(D2_LAYOUT) > /dev/null 2>&1 || { \
422+
echo "🔴 $(D2_LAYOUT) layout is not installed, see docs: https://d2lang.com/tour/layouts/"; \
423+
exit 1; \
424+
}
425+
@echo "🟢 $(D2_LAYOUT) layout is installed"
426+
427+
d2watch: d2check
428+
@if [ -z "$(FILE)" ]; then \
429+
echo "🔴 missing required parameter FILE, the correct usage is: make d2watch FILE=path/to/file.d2"; \
430+
exit 1; \
431+
fi
432+
@if [ ! -f "$(FILE)" ]; then \
433+
echo "🔴 file $(FILE) does not exist"; \
434+
exit 1; \
435+
fi
436+
@echo "🔄 watching $(FILE) for changes..."
437+
@dir=$$(dirname "$(FILE)"); \
438+
basename=$$(basename "$(FILE)" .d2); \
439+
svgfile="$$dir/$$basename.svg"; \
440+
printf "📊 generating $$svgfile from $(FILE)... "; \
441+
$(D2_ENV_VARS) d2 --watch "$(FILE)" "$$svgfile"
442+
443+
d2gen: d2check
444+
@if [ -z "$(FILE)" ]; then \
445+
echo "🔴 missing required parameter FILE, the correct usage is: make d2gen FILE=path/to/file.d2"; \
446+
exit 1; \
447+
fi
448+
@if [ ! -f "$(FILE)" ]; then \
449+
echo "🔴 file $(FILE) does not exist"; \
450+
exit 1; \
451+
fi
452+
@dir=$$(dirname "$(FILE)"); \
453+
basename=$$(basename "$(FILE)" .d2); \
454+
svgfile="$$dir/$$basename.svg"; \
455+
printf "📊 generating $$svgfile from $(FILE)... "; \
456+
$(D2_ENV_VARS) d2 "$(FILE)" "$$svgfile" > /dev/null 2>&1 && echo "done ✅" || echo "failed ❌";
457+
458+
d2gen-all: d2check
459+
@echo "🟢 generating svg files for all d2 diagrams..."
460+
@find . -name "*.d2" -type f | while read d2file; do \
461+
dir=$$(dirname "$$d2file"); \
462+
basename=$$(basename "$$d2file" .d2); \
463+
svgfile="$$dir/$$basename.svg"; \
464+
printf "📊 generating $$svgfile from $$d2file... "; \
465+
$(D2_ENV_VARS) d2 "$$d2file" "$$svgfile" > /dev/null 2>&1 && echo "done ✅" || echo "failed ❌"; \
466+
done
467+
@echo "✅ svg files generated for all d2 diagrams"

mempool/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ The following diagrams illustrate the complete transaction flow architecture, sh
411411

412412
### Architecture Overview
413413

414-
![EVM Mempool Architecture](img/mempool_architecture.jpg)
414+
![EVM Mempool Architecture](img/mempool_architecture.svg)
415415

416416
### Transaction Flow
417417

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
direction: right
2+
3+
# entities
4+
prepare proposal
5+
check tx\nhandler
6+
comet bft
7+
rpc call
8+
broadcast
9+
rebroadcast\ncallback: { shape: diamond }
10+
evm mempool: {
11+
direction: up
12+
13+
# entities
14+
ext mempool\ninterface impl
15+
cosmos priority\nnonce mempool
16+
tx pool: {
17+
direction: up
18+
19+
# entities
20+
queued\ntransactions
21+
pending\ntransactions
22+
tx pool\ninterface
23+
reset loop\n(evicts from\nqueued and\npending txs)
24+
promotion: {shape: diamond }
25+
filter: { shape: diamond }
26+
27+
# edges
28+
filter -> queued\ntransactions: add nonce\ngapped txs
29+
filter -> pending\ntransactions: add\nexecutable txs
30+
promotion -> pending\ntransactions: promote tx
31+
queued\ntransactions -> promotion: check closed gap\nand promote tx
32+
pending\ntransactions -> tx pool\ninterface: get txs for\nblock building
33+
tx pool\ninterface -> filter: add valid txs
34+
}
35+
36+
# edges
37+
tx pool.tx pool\ninterface -> ext mempool\ninterface impl: get txs for\nblock building
38+
39+
cosmos priority\nnonce mempool -> ext mempool\ninterface impl: get txs for\nblock building
40+
41+
ext mempool\ninterface impl -> tx pool.tx pool\ninterface: success/nonce gap failure:\nadd valid evm txs
42+
ext mempool\ninterface impl -> tx pool.tx pool\ninterface: recheck tx\neviction
43+
ext mempool\ninterface impl -> cosmos priority\nnonce mempool: add\ncosmos txs
44+
}
45+
46+
# edges
47+
rebroadcast\ncallback -> comet bft: rebroadcast\nrebuilt tx
48+
49+
evm mempool.tx pool.promotion -> rebroadcast\ncallback: call rebroadcast\ncallback
50+
evm mempool.ext mempool\ninterface impl -> prepare proposal: get txs for\nblock building
51+
52+
comet bft -> broadcast: success:\nbroadcast tx
53+
comet bft -> check tx\nhandler: send tx for validation
54+
comet bft -> check tx\nhandler: send tx again\nfor recheck
55+
56+
check tx\nhandler -> rpc call: queued\nsuccess response
57+
check tx\nhandler -> comet bft: success: broadcast\nand add to mempool
58+
check tx\nhandler -> comet bft: recheck tx complete\nfailure: discard from pool
59+
check tx\nhandler -> evm mempool.ext mempool\ninterface impl: complete failure:\nremove from pending
60+
check tx\nhandler -> evm mempool.ext mempool\ninterface impl: nonce gap failure:\nadd transaction
61+
check tx\nhandler -> evm mempool.ext mempool\ninterface impl: success:\nadd txs
62+
check tx\nhandler -> evm mempool.ext mempool\ninterface impl: recheck tx complete\nfailure: eviction

0 commit comments

Comments
 (0)