-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrules.mk
More file actions
180 lines (158 loc) · 6.63 KB
/
Copy pathrules.mk
File metadata and controls
180 lines (158 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
EXTRACTOR_DIR ?= extractor
# tx-archive lives in the gnolang/gno monorepo under contribs/tx-archive.
# contribs/*/go.mod files use `replace github.com/gnolang/gno => ../..` so
# `go run <path>@version` does not work remotely — we must build from a
# local checkout.
#
# GNO_REF must match the build the target chain runs, so each chain Makefile
# pins its node's `chain/*` tag. tx-archive amino-decodes the node's block
# results with the gno types from this ref, and amino rejects unknown JSON
# fields: on `master` the fetch dies with `unknown JSON field "errors" for type
# vm.TypeCheckError` against gnoland1, whose build still carries that field
# (dropped from master in #5893).
GNO_REF ?= master
# Ref is part of the path so bumping GNO_REF re-clones instead of silently
# reusing a checkout of the previous ref.
GNO_REPO ?= $(HOME)/.cache/tx-exports/gno-$(subst /,-,$(GNO_REF))
TXARCHIVE ?= $(GNO_REPO)/contribs/tx-archive
.PHONY: all
all:
@echo 'use make fetch or make fetch-all to download blocks'
$(MAKE) join stats extractor
$(TXARCHIVE)/cmd/main.go:
@mkdir -p $(dir $(GNO_REPO))
@if [ ! -d $(GNO_REPO) ]; then \
git clone --depth=1 --branch $(GNO_REF) https://github.com/gnolang/gno.git $(GNO_REPO); \
else \
git -C $(GNO_REPO) fetch --depth=1 origin $(GNO_REF) && \
git -C $(GNO_REPO) checkout FETCH_HEAD; \
fi
.PHONY: tx-archive-ensure
tx-archive-ensure: $(TXARCHIVE)/cmd/main.go ## clone/update the gno repo so tx-archive is runnable
# Backup transport selection.
# Set USE_WS=1 in a chain Makefile to fetch over a WebSocket connection
# (wss://<host>/websocket) instead of HTTP(S). A single long-lived WS connection
# avoids the per-request rate limiting / WAF blocks that some RPC endpoints apply
# to high-volume HTTP batch fetches, at the cost of slower fetches (tx results are
# not batched over WS). REMOTE stays HTTP(S) so the latest-block curl still works.
ifeq ($(USE_WS),1)
WS_FLAG = -ws
BACKUP_REMOTE = $(shell echo $(REMOTE) | tr -d '"' | sed -e 's#^http://#ws://#' -e 's#^https://#wss://#')/websocket
else
WS_FLAG =
BACKUP_REMOTE = $(REMOTE)
endif
# --batch 100: the RPC nodes enforce a 10s WebSocket write deadline (tm2
# defaultWSWriteWait). Assembling a batch response for tx-archive's default
# 1000 blocks takes longer than that in tx-dense ranges, and the server
# drops the connection mid-fetch.
.PHONY: fetch
fetch: tx-archive-ensure
@echo "Backup from: $(FROM_BLOCK) to $(TO_BLOCK)"
cd $(TXARCHIVE) && go run ./cmd backup -verbose $(WS_FLAG) \
--batch 100 \
--remote $(BACKUP_REMOTE) \
--from-block $(FROM_BLOCK) \
--to-block $(TO_BLOCK) \
--output-path "$(shell pwd)/backup_$(shell printf '%07d' $(FROM_BLOCK))-$(shell printf '%07d' $(TO_BLOCK)).jsonl"
# Update metadata
@cat metadata.json | jq -a '.latest_block_height = $(TO_BLOCK)' > /tmp/aa.json
@mv /tmp/aa.json metadata.json
.PHONY: fetch-all
fetch-all:
@for i in `seq $(FROM_BLOCK) $(MAX_INTERVAL) $(LATEST_BLOCK_HEIGHT)`; do \
make -C . fetch FROM_BLOCK="$$i"; \
done
.PHONY: stats
stats:
echo "# $(REMOTE)" > README.md
echo >> README.md
echo "## TXs" >> README.md
echo '```' >> README.md
cat backup_*.jsonl | wc -l >> README.md
echo '```' >> README.md
echo >> README.md
echo "## addpkgs" >> README.md
echo '```' >> README.md
cat backup_*.jsonl | jq '.tx.msg[].package.Path | select( . != null )' | sort | uniq -c | sort --stable -nr >> README.md
echo '```' >> README.md
echo >> README.md
echo "## top realm calls" >> README.md
echo '```' >> README.md
cat backup_*.jsonl | jq '.tx.msg[].pkg_path | select( . != null )' | sort | uniq -c | sort --stable -nr >> README.md
echo '```' >> README.md
echo >> README.md
echo "## top faucet requesters" >> README.md
echo '```' >> README.md
cat backup_*.jsonl | jq -r '.tx.msg[] | select(.["@type"]=="/bank.MsgSend") | select(.["from_address"]=="g127jydsh6cms3lrtdenydxsckh23a8d6emqcvfa") | .to_address + " " + .amount' | sed 's/ugnot$$//' | awk 'NR == 1 {next} {a[$$1] += $$2} {b[$$1] += 1} END {for (i in a) {if (a[i] >= 500000000){printf "%-15s\t%s\t%s\n", i, b[i], a[i]}}}' | sort -rnk2 >> README.md
echo '```' >> README.md
echo >> README.md
stats-legacy:
echo "# $(REMOTE)" > README.md
echo >> README.md
echo "## TXs" >> README.md
echo '```' >> README.md
cat backup_*.jsonl | wc -l >> README.md
echo '```' >> README.md
echo >> README.md
echo "## addpkgs" >> README.md
echo '```' >> README.md
cat backup_*.jsonl | jq '.msg[].package.Path | select( . != null )' | sort | uniq -c | sort --stable -nr >> README.md
echo '```' >> README.md
echo >> README.md
echo "## top realm calls" >> README.md
echo '```' >> README.md
cat backup_*.jsonl | jq '.msg[].pkg_path | select( . != null )' | sort | uniq -c | sort --stable -nr >> README.md
echo '```' >> README.md
echo >> README.md
echo "## top faucet requesters" >> README.md
echo '```' >> README.md
cat backup_*.jsonl | jq -r '.msg[] | select(.["@type"]=="/bank.MsgSend") | select(.["from_address"]=="g127jydsh6cms3lrtdenydxsckh23a8d6emqcvfa") | .to_address + " " + .amount' | sed 's/ugnot$$//' | awk 'NR == 1 {next} {a[$$1] += $$2} {b[$$1] += 1} END {for (i in a) {if (a[i] >= 500000000){printf "%-15s\t%s\t%s\n", i, b[i], a[i]}}}' | sort -rnk2 >> README.md
echo '```' >> README.md
echo >> README.md
# Only files with contiguous block ranges may be merged: a coverage gap
# between two files must stay visible in the file names.
.PHONY: join
join:
@echo "Joining small backup files..."
@prev_file=""; \
for f in $$(ls backup_*.jsonl 2>/dev/null | sort); do \
size=$$(stat -c%s "$$f"); \
f_start=$$(echo "$$f" | sed 's/backup_0*\([0-9][0-9]*\)-.*/\1/'); \
if [ -n "$$prev_file" ]; then \
prev_size=$$(stat -c%s "$$prev_file"); \
prev_end=$$(echo "$$prev_file" | sed 's/backup_[0-9]*-0*\([0-9][0-9]*\)\..*/\1/'); \
if [ $$((prev_size + size)) -lt 102400 ] && [ "$$f_start" -eq $$((prev_end + 1)) ]; then \
start=$$(echo "$$prev_file" | sed 's/backup_\([0-9]*\)-.*/\1/'); \
end=$$(echo "$$f" | sed 's/backup_[0-9]*-\([0-9]*\)\..*/\1/'); \
new_file="backup_$${start}-$${end}.jsonl"; \
cat "$$prev_file" "$$f" > "$${new_file}.tmp"; \
rm "$$prev_file" "$$f"; \
mv "$${new_file}.tmp" "$$new_file"; \
prev_file="$$new_file"; \
echo " Joined -> $$new_file ($$(stat -c%s "$$new_file") bytes)"; \
continue; \
fi; \
fi; \
prev_file="$$f"; \
done
@echo "Done."
.PHONY: extractor
extractor:
go run -C "../$(EXTRACTOR_DIR)" . \
-source-path "$(shell pwd)" \
-output-dir "$(shell pwd)/extracted"
.PHONY: loop
loop:
while true; do \
( \
set -xe; \
make fetch; \
make stats; \
git add .; \
git commit . -sm "chore: update $(SHORTNAME)"; \
git push; \
); \
date; \
sleep $(LOOP_DURATION); \
done