Skip to content

Commit cb658a9

Browse files
authored
Merge pull request #1694 from hirosystems/feat/event-replay-parquet-based
event-replay optimizations
2 parents 76df6a0 + 52323b8 commit cb658a9

24 files changed

+3562
-349
lines changed

.env

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,15 @@ STACKS_NODE_TYPE=L1
172172
# STACKS_ADDRESS_CACHE_SIZE=10000
173173

174174
# Specify a URL to redirect from /doc. If this URL is not provided, server renders local documentation
175-
# of openapi.yaml for test / development NODE_ENV.
175+
# of openapi.yaml for test / development NODE_ENV.
176176
# For production, /doc is not served if this env var is not provided.
177-
# API_DOCS_URL="https://docs.hiro.so/api"
177+
# API_DOCS_URL="https://docs.hiro.so/api"
178178

179-
# For use while syncing. Places the API into an "Initial Block Download(IBD)" mode,
180-
# forcing it to stop any redundant processing until the node is fully synced up to its peers.
181-
# Some examples of processing that are avoided are:
179+
# For use while syncing. Places the API into an "Initial Block Download(IBD)" mode,
180+
# forcing it to stop any redundant processing until the node is fully synced up to its peers.
181+
# Some examples of processing that are avoided are:
182182
# REFRESH MATERIALIZED VIEW SQLs that are extremely CPU intensive on the PG instance, Mempool messages, etc.,
183183
# IBD_MODE_UNTIL_BLOCK=
184+
185+
# Folder with events to be imported by the event-replay.
186+
STACKS_EVENTS_DIR=./eventssds

Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,18 @@ RUN echo "GIT_TAG=$(git tag --points-at HEAD)" >> .env
88
RUN npm config set unsafe-perm true && npm ci && npm run build && npm run build:docs && npm prune --production
99
RUN apk del .build-deps
1010

11+
# As no pre-built binaries of duckdb can be found for Alpine (musl based),
12+
# a rebuild of duckdb package is need.
13+
#
14+
# Library used by the event-replay based on parquet files.
15+
ARG DUCKDB_VERSION=0.8.1
16+
WORKDIR /duckdb
17+
RUN apk add --no-cache --virtual .duckdb-build-deps python3 git g++ make
18+
RUN git clone https://github.com/duckdb/duckdb.git -b v${DUCKDB_VERSION} --depth 1 \
19+
&& cd duckdb/tools/nodejs \
20+
&& ./configure && make all
21+
WORKDIR /app
22+
RUN npm uninstall duckdb && npm install /duckdb/duckdb/tools/nodejs
23+
RUN apk del .duckdb-build-deps
24+
1125
CMD ["node", "./lib/index.js"]

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,23 @@ The feature can be used via program args. For example, if there are breaking cha
111111
SQL schema, like adding a new column that requires events to be re-played, the following steps
112112
could be run:
113113

114-
### Event Replay Instructions
114+
### Event Replay V2
115115

116-
#### V1 BNS Data
116+
This version of the replay process relies on parquet files processing instead of TSV files.
117+
118+
There are some improvements on the replay process and this version is is, around, 10x times faster than the previous (V1) one.
119+
120+
__Note: the previous event-replay version is still available and can be used as well, for the same purpose.__
121+
122+
#### Instructions
123+
124+
To run the new event-replay, please follow the instructions at [stacks-event-replay](https://github.com/hirosystems/stacks-event-replay#installation) repository.
125+
126+
### Event Replay V1
127+
128+
#### Instructions
129+
130+
##### V1 BNS Data
117131

118132
**Optional but recommended** - If you want the V1 BNS data, there are going to be a few extra steps:
119133

@@ -139,7 +153,7 @@ could be run:
139153
```
140154
1. Set the data's location as the value of `BNS_IMPORT_DIR` in your `.env` file.
141155
142-
#### Export and Import
156+
##### Export and Import
143157
144158
1. Ensure the API process is not running. When stopping the API, let the process exit gracefully so
145159
that any in-progress SQL writes can finish.

migrations/1620937804009_microblocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ exports.up = pgm => {
2626
type: 'integer',
2727
notNull: true,
2828
},
29-
// For the first microblock (sequence number 0), this points to the parent/anchor block hash,
29+
// For the first microblock (sequence number 0), this points to the parent/anchor block hash,
3030
// for subsequent microblocks it points to the previous microblock's hash.
3131
microblock_parent_hash: {
3232
type: 'bytea',

migrations/1621511823381_nft_metadata.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ exports.up = pgm => {
2020
image_uri: {
2121
type: 'string',
2222
notNull: true,
23-
},
23+
},
2424
image_canonical_uri: {
25-
type: 'string',
25+
type: 'string',
2626
notNull: true,
27-
},
27+
},
2828
contract_id: {
29-
type: 'string',
30-
notNull: true,
29+
type: 'string',
30+
notNull: true,
3131
unique: true,
3232
},
3333
tx_id: {
3434
type: 'bytea',
3535
notNull: true,
3636
},
3737
sender_address: {
38-
type: 'string',
39-
notNull: true,
38+
type: 'string',
39+
notNull: true,
4040
}
4141
});
4242

migrations/1621511832113_ft_metadata.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,31 @@ exports.up = pgm => {
2020
image_uri: {
2121
type: 'string',
2222
notNull: true,
23-
},
23+
},
2424
image_canonical_uri: {
25-
type: 'string',
25+
type: 'string',
2626
notNull: true,
27-
},
27+
},
2828
contract_id: {
29-
type: 'string',
30-
notNull: true,
29+
type: 'string',
30+
notNull: true,
3131
unique: true,
3232
},
3333
symbol: {
34-
type: 'string',
35-
notNull: true,
34+
type: 'string',
35+
notNull: true,
3636
},
3737
decimals: {
38-
type: 'integer',
39-
notNull: true,
38+
type: 'integer',
39+
notNull: true,
4040
},
4141
tx_id: {
4242
type: 'bytea',
4343
notNull: true,
4444
},
4545
sender_address: {
46-
type: 'string',
47-
notNull: true,
46+
type: 'string',
47+
notNull: true,
4848
}
4949
});
5050

migrations/1666703991492_pox_events.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -132,46 +132,46 @@ exports.up = pgm => {
132132
});
133133

134134
pgm.addConstraint('pox2_events', 'valid_event_specific_columns', `CHECK (
135-
CASE name
136-
WHEN 'handle-unlock' THEN
137-
first_cycle_locked IS NOT NULL AND
135+
CASE name
136+
WHEN 'handle-unlock' THEN
137+
first_cycle_locked IS NOT NULL AND
138138
first_unlocked_cycle IS NOT NULL
139139
WHEN 'stack-stx' THEN
140-
lock_period IS NOT NULL AND
141-
lock_amount IS NOT NULL AND
142-
start_burn_height IS NOT NULL AND
140+
lock_period IS NOT NULL AND
141+
lock_amount IS NOT NULL AND
142+
start_burn_height IS NOT NULL AND
143143
unlock_burn_height IS NOT NULL
144144
WHEN 'stack-increase' THEN
145-
increase_by IS NOT NULL AND
145+
increase_by IS NOT NULL AND
146146
total_locked IS NOT NULL
147147
WHEN 'stack-extend' THEN
148-
extend_count IS NOT NULL AND
148+
extend_count IS NOT NULL AND
149149
unlock_burn_height IS NOT NULL
150150
WHEN 'delegate-stx' THEN
151-
amount_ustx IS NOT NULL AND
151+
amount_ustx IS NOT NULL AND
152152
delegate_to IS NOT NULL
153153
WHEN 'delegate-stack-stx' THEN
154-
lock_period IS NOT NULL AND
155-
lock_amount IS NOT NULL AND
156-
start_burn_height IS NOT NULL AND
157-
unlock_burn_height IS NOT NULL AND
154+
lock_period IS NOT NULL AND
155+
lock_amount IS NOT NULL AND
156+
start_burn_height IS NOT NULL AND
157+
unlock_burn_height IS NOT NULL AND
158158
delegator IS NOT NULL
159159
WHEN 'delegate-stack-increase' THEN
160-
increase_by IS NOT NULL AND
160+
increase_by IS NOT NULL AND
161161
total_locked IS NOT NULL AND
162162
delegator IS NOT NULL
163163
WHEN 'delegate-stack-extend' THEN
164-
extend_count IS NOT NULL AND
165-
unlock_burn_height IS NOT NULL AND
164+
extend_count IS NOT NULL AND
165+
unlock_burn_height IS NOT NULL AND
166166
delegator IS NOT NULL
167167
WHEN 'stack-aggregation-commit' THEN
168-
reward_cycle IS NOT NULL AND
168+
reward_cycle IS NOT NULL AND
169169
amount_ustx IS NOT NULL
170170
WHEN 'stack-aggregation-commit-indexed' THEN
171-
reward_cycle IS NOT NULL AND
171+
reward_cycle IS NOT NULL AND
172172
amount_ustx IS NOT NULL
173173
WHEN 'stack-aggregation-increase' THEN
174-
reward_cycle IS NOT NULL AND
174+
reward_cycle IS NOT NULL AND
175175
amount_ustx IS NOT NULL
176176
ELSE false
177177
END

0 commit comments

Comments
 (0)