-
Notifications
You must be signed in to change notification settings - Fork 586
Improving scripts used to regenerate the archive data #17520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: compatible
Are you sure you want to change the base?
Conversation
f193da9
to
9b0861e
Compare
e37480d
to
405b134
Compare
!ci-build-me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances portability and configurability of the archive-regeneration process by parameterizing PostgreSQL connection settings, tightening shell options, and updating documentation.
- Add strict shell flags (
set -euo pipefail
) and parameterize PG connection in all scripts - Replace hard-coded
psql
/dropdb
/createdb
calls withPGPASSWORD
-backed calls and unified env vars - Introduce
PG_*
variables and new Makefile targets for PostgreSQL setup, login, and cleanup; update README formatting
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
scripts/regenerate-archive.sh | Parameterize PG creds, tighten shell flags, improve quoting |
scripts/mina-local-network/split_precomputed_log.sh | Add strict shell flags, parameterize PG vars, psql refactor |
scripts/mina-local-network/mina-local-network.sh | Tighten shell flags, parameterize PG creds, refactor echo/printf |
scripts/mina-local-network/README.md | Wrap long list items for consistent Markdown rendering |
Makefile | Define PG_* variables, add postgres-setup , postgres-clean , regenerate-archive targets |
Comments suppressed due to low confidence (2)
scripts/mina-local-network/split_precomputed_log.sh:11
- [nitpick] The environment variable for password is split across
PG_PW
andPG_PASSWD
, which can be confusing. Consider using a single name (PG_PW
orPG_PASSWORD
) consistently.
PG_PASSWD=${PG_PW:-""}
scripts/regenerate-archive.sh:42
- The
-pd
flag is passed tomina-local-network.sh
to set the database, but there’s no evidence the script parses-pd
. Ensure the CLI parsing supports this option or correct it.
-pd "${PG_DB}" \
@sudo -u postgres createuser -d -r -s $(PG_USER) 2>/dev/null || true | ||
@sudo -u postgres psql -c "ALTER USER $(PG_USER) PASSWORD '$(PG_PW)'" 2>/dev/null || true | ||
@sudo -u postgres createdb -O $(PG_USER) $(PG_DB) 2>/dev/null || true | ||
@sudo -u postgres createdb -O $(PG_USER) $(PG_USER) 2>/dev/null || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This target creates a database named after the user twice ($(PG_USER)
as both DB name and owner). It seems unintended; remove or clarify the second createdb
invocation.
@sudo -u postgres createdb -O $(PG_USER) $(PG_USER) 2>/dev/null || true |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is expected. We must ensure that there is the default database created for the user, which uses, by convention, the username as the database name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we extract this feature into archive node, given people running archive node may want this feature?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, it doesn't seemed to set up a schema in the DB here.
a84ae41
to
c05aef3
Compare
!ci-nightly-me |
0606eee
to
1b57088
Compare
!ci-nightly-me |
95a751d
to
26f1537
Compare
!ci-nightly-me |
Using postgresql everywhere, even though both are accepted.
26f1537
to
def82e8
Compare
!ci-build-me |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor quality improvement request
@sudo -u postgres createuser -d -r -s $(PG_USER) 2>/dev/null || true | ||
@sudo -u postgres psql -c "ALTER USER $(PG_USER) PASSWORD '$(PG_PW)'" 2>/dev/null || true | ||
@sudo -u postgres createdb -O $(PG_USER) $(PG_DB) 2>/dev/null || true | ||
@sudo -u postgres createdb -O $(PG_USER) $(PG_USER) 2>/dev/null || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we extract this feature into archive node, given people running archive node may want this feature?
@sudo -u postgres createuser -d -r -s $(PG_USER) 2>/dev/null || true | ||
@sudo -u postgres psql -c "ALTER USER $(PG_USER) PASSWORD '$(PG_PW)'" 2>/dev/null || true | ||
@sudo -u postgres createdb -O $(PG_USER) $(PG_DB) 2>/dev/null || true | ||
@sudo -u postgres createdb -O $(PG_USER) $(PG_USER) 2>/dev/null || true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And, it doesn't seemed to set up a schema in the DB here.
REST_PORT=$((BASE_PORT + 1)) | ||
EXTERNAL_PORT=$((BASE_PORT + 2)) | ||
DAEMON_METRICS_PORT=$((BASE_PORT + 3)) | ||
LIBP2P_METRICS_PORT=$((BASE_PORT + 4)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll port clash if some port is occupied by another program. I'd use a random port that's unused if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or at least this is a good place to fail gracefully by checking if any ports are occupied
|
||
ARCHIVE_ADDRESS_CLI_ARG="-archive-address ${ARCHIVE_SERVER_PORT}" | ||
fi | ||
|
||
# ================================================ | ||
# Configure the Seed Peer ID | ||
|
||
SEED_PEER_ID="/ip4/127.0.0.1/tcp/$((${SEED_START_PORT} + 2))/p2p/12D3KooWAFFq2yEQFFzhU5dt64AWqawRuomG9hL8rSmm5vxhAsgr" | ||
SEED_PEER_ID="/ip4/127.0.0.1/tcp/$((SEED_START_PORT + 2))/p2p/12D3KooWAFFq2yEQFFzhU5dt64AWqawRuomG9hL8rSmm5vxhAsgr" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this port calculation and this magic address?
mkdir -p "${FOLDER}" | ||
spawn-node "${FOLDER}" $((${WHALE_START_PORT} + (${i} * 5))) -peer ${SEED_PEER_ID} -block-producer-key ${KEY_FILE} \ | ||
-libp2p-keypair "${LEDGER_FOLDER}"/libp2p_keys/whale_${i} "${ARCHIVE_ADDRESS_CLI_ARG}" | ||
spawn-node "${FOLDER}" $((WHALE_START_PORT + (i * 5))) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea why we're calculating ports like this here
I do not disagree with the requested changes, but I would prefer to achieve this in a follow-up PR. It's out of the context of this patch, which was revamping the script and making it more customizable (different db name, user, password). In addition to that, it fixes the ignored shellcheck warnings. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to do follow-up PRs, then
still exists with an error, but it seems to come from the replayer script. I'll investigate later.
The reviewer can check commit by commit.
The Makefile target can be used to use any user, database name or PostgreSQL instance.