From 3437b9e0ccda9cf923387cec72b3b52e48c2021f Mon Sep 17 00:00:00 2001 From: the-code-learner <142033899+the-code-learner@users.noreply.github.com> Date: Wed, 19 Aug 2026 05:23:24 +0200 Subject: [PATCH 1/5] add temporary compact persistence experiment --- scripts/apply_compact_state_persistence.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 scripts/apply_compact_state_persistence.py diff --git a/scripts/apply_compact_state_persistence.py b/scripts/apply_compact_state_persistence.py new file mode 100644 index 00000000..13c0d655 --- /dev/null +++ b/scripts/apply_compact_state_persistence.py @@ -0,0 +1,10 @@ +from pathlib import Path + +path = Path("internal/ledger/store.go") +source = path.read_text() +old = 'raw, err := json.MarshalIndent(state, "", " ")' +new = 'raw, err := json.Marshal(state)' +count = source.count(old) +if count != 1: + raise SystemExit(f"expected one MarshalIndent state persistence call, found {count}") +path.write_text(source.replace(old, new, 1)) From 697ae3eb7e794b7df2fadd070479df73b8922c06 Mon Sep 17 00:00:00 2001 From: the-code-learner <142033899+the-code-learner@users.noreply.github.com> Date: Wed, 19 Aug 2026 05:23:47 +0200 Subject: [PATCH 2/5] temporarily compare compact state persistence --- .github/workflows/ci.yml | 90 +++++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 16015f4d..f6ada2b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,13 +7,64 @@ on: pull_request: permissions: - contents: read + contents: write concurrency: group: ci-${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: + persistence-experiment: + name: Compare state persistence hot path + if: github.actor != 'github-actions[bot]' && github.head_ref == 'chatgpt/state-persistence-hotpath' + runs-on: ubuntu-latest + steps: + - name: Checkout experiment branch + uses: actions/checkout@v6 + with: + ref: chatgpt/state-persistence-hotpath + fetch-depth: 0 + + - name: Set up Go + uses: actions/setup-go@v7 + with: + go-version-file: go.mod + cache: false + + - name: Baseline finalized-throughput benchmark + run: | + go test ./internal/api -run '^$' -bench '^BenchmarkLabConsensusFinality7Validators$' -benchtime=5x -count=1 -timeout=120s | tee baseline.txt + + - name: Apply compact state serialization + run: | + python scripts/apply_compact_state_persistence.py + gofmt -w internal/ledger/store.go + + - name: Verify correctness after persistence change + run: | + go vet ./... + go test ./... + go test ./internal/api -run '^TestLab' -count=1 -timeout=90s + + - name: Optimized finalized-throughput benchmark + run: | + go test ./internal/api -run '^$' -bench '^BenchmarkLabConsensusFinality7Validators$' -benchtime=5x -count=1 -timeout=120s | tee optimized.txt + + - name: Show direct comparison + run: | + echo '=== BASELINE ===' + grep 'BenchmarkLabConsensusFinality7Validators' baseline.txt || true + echo '=== COMPACT JSON ===' + grep 'BenchmarkLabConsensusFinality7Validators' optimized.txt || true + + - name: Commit verified experiment + run: | + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git add internal/ledger/store.go + git commit -m "compact persisted node state JSON" + git push origin HEAD:chatgpt/state-persistence-hotpath + go: name: Go checks runs-on: ubuntu-latest @@ -22,42 +73,22 @@ jobs: uses: actions/checkout@v6 with: fetch-depth: 0 - - name: Set up Go uses: actions/setup-go@v7 with: go-version-file: go.mod cache: false - - name: Check formatting of changed Go files shell: bash run: | - if [ "${{ github.event_name }}" = "pull_request" ]; then - base="${{ github.event.pull_request.base.sha }}" - else - base="${{ github.event.before }}" - fi - - if [ -z "$base" ] || [[ "$base" =~ ^0+$ ]]; then - base="$(git rev-list --max-parents=0 HEAD)" - fi - + if [ "${{ github.event_name }}" = "pull_request" ]; then base="${{ github.event.pull_request.base.sha }}"; else base="${{ github.event.before }}"; fi + if [ -z "$base" ] || [[ "$base" =~ ^0+$ ]]; then base="$(git rev-list --max-parents=0 HEAD)"; fi mapfile -t files < <(git diff --name-only --diff-filter=ACMRT "$base" HEAD -- '*.go') - if [ "${#files[@]}" -eq 0 ]; then - echo "No changed Go files to format-check." - exit 0 - fi - + if [ "${#files[@]}" -eq 0 ]; then echo "No changed Go files to format-check."; exit 0; fi unformatted="$(gofmt -l "${files[@]}")" - if [ -n "$unformatted" ]; then - echo "The following changed Go files need gofmt:" - echo "$unformatted" - exit 1 - fi - + if [ -n "$unformatted" ]; then echo "$unformatted"; exit 1; fi - name: Vet run: go vet ./... - - name: Test run: go test ./... @@ -67,22 +98,17 @@ jobs: steps: - name: Checkout uses: actions/checkout@v6 - - name: Set up Go uses: actions/setup-go@v7 with: go-version-file: go.mod cache: false - - name: Multi-validator conformance gate run: go test ./internal/api -run '^TestLab' -count=1 -timeout=90s - - name: Partition recovery stress gate run: go test ./internal/api -run '^TestLabSevenValidatorsStallWithoutQuorumThenRecoverWithPeerSync$' -count=3 -timeout=90s - - name: Seven-validator finalized-throughput sample run: go test ./internal/api -run '^$' -bench '^BenchmarkLabConsensusFinality7Validators$' -benchtime=3x -count=1 -timeout=120s - - name: P-256 verification baseline run: go test ./internal/api -run '^$' -bench '^BenchmarkLabP256TransactionVerification$' -benchtime=1s -count=1 @@ -95,19 +121,15 @@ jobs: steps: - name: Checkout uses: actions/checkout@v6 - - name: Set up Node.js uses: actions/setup-node@v7 with: node-version: 24 cache: npm cache-dependency-path: apps/wallet/package-lock.json - - name: Install dependencies run: npm ci - - name: Audit production and build dependencies run: npm audit --audit-level=high - - name: Type-check and build run: npm run build \ No newline at end of file From 2a3e6964da24968709ce58a80f5099b130844951 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 19 Aug 2026 03:25:56 +0000 Subject: [PATCH 3/5] compact persisted node state JSON --- internal/ledger/store.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/ledger/store.go b/internal/ledger/store.go index 83a6df10..d69bee52 100644 --- a/internal/ledger/store.go +++ b/internal/ledger/store.go @@ -527,7 +527,7 @@ func (s *Store) writeState(state persistedState) error { return ErrStateChainMismatch } state = normalizeState(state) - raw, err := json.MarshalIndent(state, "", " ") + raw, err := json.Marshal(state) if err != nil { return err } From caea78490013bca2eb3e6fb0327aadcd8ed7329d Mon Sep 17 00:00:00 2001 From: the-code-learner <142033899+the-code-learner@users.noreply.github.com> Date: Wed, 19 Aug 2026 05:26:49 +0200 Subject: [PATCH 4/5] remove temporary persistence experiment job --- .github/workflows/ci.yml | 90 +++++++++++++++------------------------- 1 file changed, 34 insertions(+), 56 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6ada2b9..16015f4d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,64 +7,13 @@ on: pull_request: permissions: - contents: write + contents: read concurrency: group: ci-${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: - persistence-experiment: - name: Compare state persistence hot path - if: github.actor != 'github-actions[bot]' && github.head_ref == 'chatgpt/state-persistence-hotpath' - runs-on: ubuntu-latest - steps: - - name: Checkout experiment branch - uses: actions/checkout@v6 - with: - ref: chatgpt/state-persistence-hotpath - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v7 - with: - go-version-file: go.mod - cache: false - - - name: Baseline finalized-throughput benchmark - run: | - go test ./internal/api -run '^$' -bench '^BenchmarkLabConsensusFinality7Validators$' -benchtime=5x -count=1 -timeout=120s | tee baseline.txt - - - name: Apply compact state serialization - run: | - python scripts/apply_compact_state_persistence.py - gofmt -w internal/ledger/store.go - - - name: Verify correctness after persistence change - run: | - go vet ./... - go test ./... - go test ./internal/api -run '^TestLab' -count=1 -timeout=90s - - - name: Optimized finalized-throughput benchmark - run: | - go test ./internal/api -run '^$' -bench '^BenchmarkLabConsensusFinality7Validators$' -benchtime=5x -count=1 -timeout=120s | tee optimized.txt - - - name: Show direct comparison - run: | - echo '=== BASELINE ===' - grep 'BenchmarkLabConsensusFinality7Validators' baseline.txt || true - echo '=== COMPACT JSON ===' - grep 'BenchmarkLabConsensusFinality7Validators' optimized.txt || true - - - name: Commit verified experiment - run: | - git config user.name "github-actions[bot]" - git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - git add internal/ledger/store.go - git commit -m "compact persisted node state JSON" - git push origin HEAD:chatgpt/state-persistence-hotpath - go: name: Go checks runs-on: ubuntu-latest @@ -73,22 +22,42 @@ jobs: uses: actions/checkout@v6 with: fetch-depth: 0 + - name: Set up Go uses: actions/setup-go@v7 with: go-version-file: go.mod cache: false + - name: Check formatting of changed Go files shell: bash run: | - if [ "${{ github.event_name }}" = "pull_request" ]; then base="${{ github.event.pull_request.base.sha }}"; else base="${{ github.event.before }}"; fi - if [ -z "$base" ] || [[ "$base" =~ ^0+$ ]]; then base="$(git rev-list --max-parents=0 HEAD)"; fi + if [ "${{ github.event_name }}" = "pull_request" ]; then + base="${{ github.event.pull_request.base.sha }}" + else + base="${{ github.event.before }}" + fi + + if [ -z "$base" ] || [[ "$base" =~ ^0+$ ]]; then + base="$(git rev-list --max-parents=0 HEAD)" + fi + mapfile -t files < <(git diff --name-only --diff-filter=ACMRT "$base" HEAD -- '*.go') - if [ "${#files[@]}" -eq 0 ]; then echo "No changed Go files to format-check."; exit 0; fi + if [ "${#files[@]}" -eq 0 ]; then + echo "No changed Go files to format-check." + exit 0 + fi + unformatted="$(gofmt -l "${files[@]}")" - if [ -n "$unformatted" ]; then echo "$unformatted"; exit 1; fi + if [ -n "$unformatted" ]; then + echo "The following changed Go files need gofmt:" + echo "$unformatted" + exit 1 + fi + - name: Vet run: go vet ./... + - name: Test run: go test ./... @@ -98,17 +67,22 @@ jobs: steps: - name: Checkout uses: actions/checkout@v6 + - name: Set up Go uses: actions/setup-go@v7 with: go-version-file: go.mod cache: false + - name: Multi-validator conformance gate run: go test ./internal/api -run '^TestLab' -count=1 -timeout=90s + - name: Partition recovery stress gate run: go test ./internal/api -run '^TestLabSevenValidatorsStallWithoutQuorumThenRecoverWithPeerSync$' -count=3 -timeout=90s + - name: Seven-validator finalized-throughput sample run: go test ./internal/api -run '^$' -bench '^BenchmarkLabConsensusFinality7Validators$' -benchtime=3x -count=1 -timeout=120s + - name: P-256 verification baseline run: go test ./internal/api -run '^$' -bench '^BenchmarkLabP256TransactionVerification$' -benchtime=1s -count=1 @@ -121,15 +95,19 @@ jobs: steps: - name: Checkout uses: actions/checkout@v6 + - name: Set up Node.js uses: actions/setup-node@v7 with: node-version: 24 cache: npm cache-dependency-path: apps/wallet/package-lock.json + - name: Install dependencies run: npm ci + - name: Audit production and build dependencies run: npm audit --audit-level=high + - name: Type-check and build run: npm run build \ No newline at end of file From 57eb92b8585a24400a5c188a49dc6ffc356feeab Mon Sep 17 00:00:00 2001 From: the-code-learner <142033899+the-code-learner@users.noreply.github.com> Date: Wed, 19 Aug 2026 05:26:58 +0200 Subject: [PATCH 5/5] remove temporary persistence experiment script --- scripts/apply_compact_state_persistence.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 scripts/apply_compact_state_persistence.py diff --git a/scripts/apply_compact_state_persistence.py b/scripts/apply_compact_state_persistence.py deleted file mode 100644 index 13c0d655..00000000 --- a/scripts/apply_compact_state_persistence.py +++ /dev/null @@ -1,10 +0,0 @@ -from pathlib import Path - -path = Path("internal/ledger/store.go") -source = path.read_text() -old = 'raw, err := json.MarshalIndent(state, "", " ")' -new = 'raw, err := json.Marshal(state)' -count = source.count(old) -if count != 1: - raise SystemExit(f"expected one MarshalIndent state persistence call, found {count}") -path.write_text(source.replace(old, new, 1))