Skip to content

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

Open
wants to merge 42 commits into
base: compatible
Choose a base branch
from

Conversation

dannywillems
Copy link
Member

@dannywillems dannywillems commented Jul 11, 2025

PG_DB=archive_test make postgres-setup
PG_DB=archive_test TOTAL_BLOCKS=2 make regenerate-archive

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.

@dannywillems dannywillems requested review from a team as code owners July 11, 2025 13:42
@dannywillems dannywillems marked this pull request as draft July 11, 2025 13:42
@dannywillems dannywillems force-pushed the dw/misc-mina-local-network-script branch 8 times, most recently from f193da9 to 9b0861e Compare July 11, 2025 17:59
@dannywillems dannywillems changed the title WIP - suggestion Improving scripts used to regenerate the archive data Jul 11, 2025
@dannywillems dannywillems marked this pull request as ready for review July 11, 2025 18:02
Base automatically changed from dkijania/regenerate_archive_data to compatible July 14, 2025 08:38
@dannywillems dannywillems force-pushed the dw/misc-mina-local-network-script branch 5 times, most recently from e37480d to 405b134 Compare July 14, 2025 09:33
@dannywillems
Copy link
Member Author

!ci-build-me

Copy link
Contributor

@Copilot Copilot AI left a 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 with PGPASSWORD-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 and PG_PASSWD, which can be confusing. Consider using a single name (PG_PW or PG_PASSWORD) consistently.
PG_PASSWD=${PG_PW:-""}

scripts/regenerate-archive.sh:42

  • The -pd flag is passed to mina-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
Copy link
Preview

Copilot AI Jul 14, 2025

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.

Suggested change
@sudo -u postgres createdb -O $(PG_USER) $(PG_USER) 2>/dev/null || true

Copilot uses AI. Check for mistakes.

Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member

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.

@dannywillems dannywillems force-pushed the dw/misc-mina-local-network-script branch from a84ae41 to c05aef3 Compare July 14, 2025 13:33
@dannywillems
Copy link
Member Author

!ci-nightly-me

@dannywillems dannywillems force-pushed the dw/misc-mina-local-network-script branch from 0606eee to 1b57088 Compare July 14, 2025 13:39
@dannywillems
Copy link
Member Author

!ci-nightly-me

@dannywillems dannywillems force-pushed the dw/misc-mina-local-network-script branch from 95a751d to 26f1537 Compare July 14, 2025 16:12
@dannywillems
Copy link
Member Author

!ci-nightly-me

@dannywillems
Copy link
Member Author

Using postgresql everywhere, even though both are accepted.
@dannywillems dannywillems force-pushed the dw/misc-mina-local-network-script branch from 26f1537 to def82e8 Compare July 17, 2025 18:51
@dannywillems
Copy link
Member Author

!ci-build-me

Copy link
Member

@glyh glyh left a 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
Copy link
Member

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
Copy link
Member

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))
Copy link
Member

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.

Copy link
Member

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"
Copy link
Member

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))) \
Copy link
Member

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

@dannywillems
Copy link
Member Author

Minor quality improvement request

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.

Copy link
Member

@glyh glyh left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants