diff --git a/.dockerignore b/.dockerignore index 85eb02fb567b..14b8a9115711 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,11 +1,6 @@ -config.vars -.cargo/ -.vscode/ -.venv/ -dist/ -target/ -release/ -focal/ -jammy/ -noble/ -resolute/ +# The runtime Dockerfile needs only the entrypoint from the main context; +# release artifacts and bitcoin-cli arrive as named build contexts. There are +# no builder images in the tree any more -- the release is a Nix derivation -- +# so nothing else has to stay visible. +* +!tools/docker-entrypoint.sh diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml deleted file mode 100644 index fb9a51abfa33..000000000000 --- a/.github/workflows/docker-build.yml +++ /dev/null @@ -1,88 +0,0 @@ -name: Docker build - -on: - workflow_call: - inputs: - version: - type: string - required: true - dh-repository-owner: - type: string - required: true - platforms-to-build: - type: string - required: true - -jobs: - # Turn the comma-separated platforms-to-build input into a JSON matrix array, - # so we can fan out per-platform without hardcoding the list twice. - plan: - name: Plan platform matrix - runs-on: ubuntu-24.04 - outputs: - platforms: ${{ steps.plan.outputs.platforms }} - steps: - - id: plan - env: - PLATFORMS_TO_BUILD: ${{ inputs.platforms-to-build }} - run: | - IFS=',' read -ra ARR <<< "$PLATFORMS_TO_BUILD" - JSON=$(printf '%s\n' "${ARR[@]}" | jq -R . | jq -sc .) - echo "platforms=$JSON" >> "$GITHUB_OUTPUT" - - build: - name: Build ${{ matrix.target == 'lightningd-vls-signer' && 'vls' || 'normal' }} / ${{ matrix.platform }} - needs: plan - strategy: - fail-fast: false - matrix: - target: - - lightningd - - lightningd-vls-signer - platform: ${{ fromJson(needs.plan.outputs.platforms) }} - runs-on: ${{ matrix.platform == 'linux/arm64' && 'ubuntu-22.04-arm' || 'ubuntu-22.04' }} - steps: - - name: Checkout repository - uses: actions/checkout@v7 - with: - fetch-depth: 0 - - - name: Set up QEMU - if: matrix.platform == 'linux/arm/v7' - uses: docker/setup-qemu-action@v4 - - - name: Setup Docker Buildx - uses: docker/setup-buildx-action@v4 - - - name: Log in to Docker Hub - uses: docker/login-action@v4 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build single-platform image, push by digest - id: build - uses: docker/build-push-action@v7 - with: - context: . - file: ./Dockerfile - target: ${{ matrix.target }} - platforms: ${{ matrix.platform }} - build-args: | - VERSION=${{ inputs.version }} - outputs: type=image,name=${{ inputs.dh-repository-owner }}/lightningd,push-by-digest=true,name-canonical=true,push=true - cache-from: type=gha,scope=${{ matrix.target }}-${{ matrix.platform }} - cache-to: type=gha,mode=max,scope=${{ matrix.target }}-${{ matrix.platform }} - - - name: Save digest - run: | - mkdir -p /tmp/digests - echo "${{ steps.build.outputs.digest }}" > /tmp/digests/digest.txt - - - name: Upload digest - uses: actions/upload-artifact@v7 - with: - name: digest_${{ matrix.target }}_${{ strategy.job-index }} - path: /tmp/digests/digest.txt - if-no-files-found: error - retention-days: 1 diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml deleted file mode 100644 index 9aee3a2a186a..000000000000 --- a/.github/workflows/docker-publish.yml +++ /dev/null @@ -1,76 +0,0 @@ -name: Docker publish - -on: - workflow_call: - inputs: - version: - type: string - required: true - dh-repository-owner: - type: string - required: true - push-latest: - type: string - required: true - -jobs: - publish: - name: Tag and publish ${{ matrix.target }} - runs-on: ubuntu-22.04 - strategy: - fail-fast: false - matrix: - include: - - target: lightningd - tag_suffix: '' - - target: lightningd-vls-signer - tag_suffix: '-vls' - steps: - - name: Setup Docker Buildx - uses: docker/setup-buildx-action@v4 - - - name: Log in to Docker Hub - uses: docker/login-action@v4 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Download platform digests for this target - uses: actions/download-artifact@v8 - with: - pattern: digest_${{ matrix.target }}_* - path: /tmp/digests - merge-multiple: false - - - name: Set up values - env: - DH_REPOSITORY_OWNER: ${{ inputs.dh-repository-owner }} - PUSH_LATEST: ${{ inputs.push-latest }} - VERSION: ${{ inputs.version }} - REF_TYPE: ${{ github.ref_type }} - run: | - DIGEST_REFS="" - for f in /tmp/digests/*/digest.txt; do - D=$(cat "$f") - DIGEST_REFS="$DIGEST_REFS ${DH_REPOSITORY_OWNER}/lightningd@${D}" - done - echo "DIGEST_REFS=$DIGEST_REFS" >> $GITHUB_ENV - - if [[ "$PUSH_LATEST" == "true" ]] || - ([[ "$REF_TYPE" == "tag" ]] && [[ ! "$VERSION" =~ rc ]]); then - echo "PUSHLATEST=true" >> $GITHUB_ENV - else - echo "PUSHLATEST=false" >> $GITHUB_ENV - fi - - - name: Create and push real tag(s) - env: - DH_REPOSITORY_OWNER: ${{ inputs.dh-repository-owner }} - VERSION: ${{ inputs.version }} - TAG_SUFFIX: ${{ matrix.tag_suffix }} - run: | - TAG_ARGS=(-t "${DH_REPOSITORY_OWNER}/lightningd:${VERSION}${TAG_SUFFIX}") - if [[ "$PUSHLATEST" == "true" ]]; then - TAG_ARGS+=(-t "${DH_REPOSITORY_OWNER}/lightningd:latest${TAG_SUFFIX}") - fi - docker buildx imagetools create "${TAG_ARGS[@]}" $DIGEST_REFS diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml deleted file mode 100644 index 57102c5c3177..000000000000 --- a/.github/workflows/release-build.yml +++ /dev/null @@ -1,106 +0,0 @@ -name: Release binaries build - -on: - workflow_call: - inputs: - version: - type: string - required: true - skip_validation: - type: boolean - required: true - -jobs: - releases: - name: Releases - runs-on: ${{ matrix.runner }} - strategy: - fail-fast: false - matrix: - # dir is where build-release.sh puts the target's output; arch picks - # the merged artifact, since each architecture is checksummed and - # signed separately. - include: - - { target: 'bin-Fedora', runner: 'ubuntu-24.04', arch: 'amd64', dir: 'release' } - - { target: 'bin-Ubuntu-jammy', runner: 'ubuntu-24.04', arch: 'amd64', dir: 'release' } - - { target: 'bin-Ubuntu-noble', runner: 'ubuntu-24.04', arch: 'amd64', dir: 'release' } - - { target: 'bin-Ubuntu-resolute', runner: 'ubuntu-24.04', arch: 'amd64', dir: 'release' } - # arm64 builds natively on an arm64 runner. - - { target: 'bin-Ubuntu-jammy-arm64', runner: 'ubuntu-24.04-arm', arch: 'arm64', dir: 'release-arm64' } - - { target: 'bin-Ubuntu-noble-arm64', runner: 'ubuntu-24.04-arm', arch: 'arm64', dir: 'release-arm64' } - - { target: 'bin-Ubuntu-resolute-arm64', runner: 'ubuntu-24.04-arm', arch: 'arm64', dir: 'release-arm64' } - # armv7 cross-compiles in the amd64 builder image (see - # tools/repro-build.armv7.sh), with qemu for the few armv7 programs - # the build runs. - - { target: 'bin-Ubuntu-jammy-armv7', runner: 'ubuntu-24.04', arch: 'armv7', dir: 'release-armv7' } - - { target: 'bin-Ubuntu-noble-armv7', runner: 'ubuntu-24.04', arch: 'armv7', dir: 'release-armv7' } - - { target: 'bin-Ubuntu-resolute-armv7', runner: 'ubuntu-24.04', arch: 'armv7', dir: 'release-armv7' } - steps: - - name: Git checkout - uses: actions/checkout@v7 - with: - fetch-depth: 0 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v4 - with: - platforms: arm - if: endsWith(matrix.target, '-armv7') - - - name: Build environment setup - run: | - distribution=$(echo ${{ matrix.target }} | cut -d'-' -f3) - # Same naming as contrib/cl-repro.sh: arm64 images are suffixed. - suffix="" - [ "$(dpkg --print-architecture)" = arm64 ] && suffix="-arm64" - sudo docker run --rm -v $(pwd):/build ubuntu:${distribution} bash -c "\ - apt-get update && \ - apt-get install -y debootstrap && \ - debootstrap ${distribution} /build/${distribution}" - sudo tar -C ${distribution} -c . | docker import - ${distribution} - docker build -t cl-repro-${distribution}${suffix} - < contrib/reprobuild/Dockerfile.${distribution} - if: contains(matrix.target, 'Ubuntu') - - - name: Build release - env: - SKIP_VALIDATION: ${{ inputs.skip_validation }} - INPUT_VERSION: ${{ inputs.version }} - run: | - if [[ "$SKIP_VALIDATION" == "true" ]]; then - tools/build-release.sh ${{ matrix.target }} --force-version "$INPUT_VERSION" --force-unclean --force-mtime "$(date +%Y-%m-%d)" - else - tools/build-release.sh ${{ matrix.target }} - fi - - - name: Upload target artifacts - uses: actions/upload-artifact@v7 - with: - path: ${{ matrix.dir }}/ - name: ${{ matrix.arch }}-${{ matrix.target }} - if-no-files-found: error - - artifact: - name: Construct release artifact - needs: releases - runs-on: ubuntu-24.04 - steps: - - name: Merge amd64 artifacts - uses: actions/upload-artifact/merge@v7 - with: - name: c-lightning-${{ inputs.version }} - pattern: amd64-bin-* - delete-merged: true - - - name: Merge arm64 artifacts - uses: actions/upload-artifact/merge@v7 - with: - name: c-lightning-${{ inputs.version }}-arm64 - pattern: arm64-bin-* - delete-merged: true - - - name: Merge armv7 artifacts - uses: actions/upload-artifact/merge@v7 - with: - name: c-lightning-${{ inputs.version }}-armv7 - pattern: armv7-bin-* - delete-merged: true diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml deleted file mode 100644 index 1e8aa44d4fbd..000000000000 --- a/.github/workflows/release-publish.yml +++ /dev/null @@ -1,117 +0,0 @@ -name: Release publish - -on: - workflow_call: - inputs: - version: - type: string - required: true - create_release: - type: boolean - required: true - -jobs: - release: - name: Sign and prepare release draft - runs-on: ubuntu-24.04 - steps: - - name: Git checkout - uses: actions/checkout@v7 - with: - fetch-depth: 0 - - - name: Download artifact - uses: actions/download-artifact@v8 - with: - name: c-lightning-${{ inputs.version }} - path: release/ - - - name: Download arm64 artifact - uses: actions/download-artifact@v8 - with: - name: c-lightning-${{ inputs.version }}-arm64 - path: release-arm64/ - - - name: Download armv7 artifact - uses: actions/download-artifact@v8 - with: - name: c-lightning-${{ inputs.version }}-armv7 - path: release-armv7/ - - - name: Import GPG keys - id: gpg - uses: crazy-max/ghaction-import-gpg@v7 - with: - gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.GPG_PASSPHRASE }} - trust_level: 5 - - - name: Set default GPG key - env: - GPG_KEYID: ${{ steps.gpg.outputs.keyid }} - run: echo "default-key $GPG_KEYID" >> ~/.gnupg/gpg.conf - - - name: Sign release - env: - INPUT_VERSION: ${{ inputs.version }} - run: | - tools/build-release.sh --without-zip sign - for arch in arm64 armv7; do - tools/sign-release-arm.sh "$INPUT_VERSION" "$arch" - # Their manifests and signatures sit next to the amd64 ones. - mv release-"$arch"/SHA256SUMS-* release/ - done - - - name: Upload signed artifact - uses: actions/upload-artifact@v7 - with: - name: c-lightning-${{ inputs.version }} - overwrite: true - path: release/ - - - name: Upload arm64 artifact - uses: actions/upload-artifact@v7 - with: - name: c-lightning-${{ inputs.version }}-arm64 - overwrite: true - path: release-arm64/ - - - name: Upload armv7 artifact - uses: actions/upload-artifact@v7 - with: - name: c-lightning-${{ inputs.version }}-armv7 - overwrite: true - path: release-armv7/ - - - name: Determine release data - id: release_data - env: - INPUT_VERSION: ${{ inputs.version }} - run: | - VERSION="$INPUT_VERSION" - CHANGELOG_VERSION=${VERSION#v} - CHANGELOG_TITLE=$(grep "## \[${CHANGELOG_VERSION}\]" CHANGELOG.md) - RELEASE_TITLE=$(echo $CHANGELOG_TITLE | cut -d'"' -f2) - echo "release_title=$RELEASE_TITLE" >> "$GITHUB_OUTPUT" - - # Never replace what is already on the release: release captains add - # their signatures to the .asc files by hand, and a re-run must keep - # them. tools/publish-release-assets.sh uploads only missing files, - # refuses any that differ from the published copy, and appends our - # signature to an existing .asc instead of overwriting it. - - name: Prepare release draft - if: ${{ github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && inputs.create_release) }} - env: - GH_TOKEN: ${{ github.token }} - INPUT_VERSION: ${{ inputs.version }} - RELEASE_TITLE: ${{ steps.release_data.outputs.release_title }} - run: | - if ! gh release view "$INPUT_VERSION" >/dev/null 2>&1; then - PRERELEASE="" - case "$INPUT_VERSION" in *-rc*) PRERELEASE=--prerelease;; esac - # --target only matters for an untagged test run: gh then - # creates the tag, as the previous upload action did. - gh release create "$INPUT_VERSION" --draft --target "$GITHUB_SHA" $PRERELEASE \ - --title "$INPUT_VERSION $RELEASE_TITLE" --notes "" - fi - tools/publish-release-assets.sh "$INPUT_VERSION" release/* release-arm64/* release-armv7/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7bb09de679b8..8b7bfa7282a0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,5 +1,21 @@ --- # https://docs.corelightning.org/docs/release-checklist +# +# The release *binaries* are no longer built or signed here: they are produced +# and signed locally by `tools/reprobuild`, from one static build per +# architecture, and published from the release captain's machine. The jobs that +# built the old per-distribution tarballs, drafted the release and signed it +# with the project key are gone with the scripts they called. +# +# The Docker images are gone from here too. They are built locally by +# `tools/reprobuild docker` -- a Dockerfile over the digest-pinned +# debian:trixie-slim, consuming the static tarball that was just signed, so the +# image compiles nothing -- and pushed by `tools/reprobuild publish` with +# `skopeo copy --all --preserve-digests`, which is what makes the digests users +# pull the digests the release manifests signed. `latest` is a deliberate +# `--latest` flag, never applied automatically and never to an rc. +# +# What is left here is the tag check and PyPI. name: "Release 🚀" on: push: @@ -17,20 +33,6 @@ on: description: Skip release validation for untagged commit testing default: false type: boolean - create_release: - description: Create a draft release - default: false - type: boolean - dh-repository-owner: - description: 'Dockerhub repository owner' - default: 'elementsproject' - platforms-to-build: - description: 'List of platforms to build' - default: 'linux/amd64,linux/arm64,linux/arm/v7' - push-latest: - description: 'Push the latest Docker tag' - type: boolean - default: false dist-location: description: 'PyPI distribution location' type: choice @@ -48,16 +50,6 @@ jobs: skip_validation: ${{ github.event.inputs.skip_validation == 'true' }} - docker-build: - name: Docker build - needs: check-version - uses: ./.github/workflows/docker-build.yml - with: - version: ${{ needs.check-version.outputs.version }} - dh-repository-owner: ${{ github.event.inputs.dh-repository-owner || 'elementsproject' }} - platforms-to-build: ${{ github.event.inputs.platforms-to-build || 'linux/amd64,linux/arm64,linux/arm/v7' }} - secrets: inherit - pypi-build: name: PyPI build needs: check-version @@ -66,46 +58,12 @@ jobs: version: ${{ needs.check-version.outputs.version }} secrets: inherit - release-build: - name: Release binaries build - needs: check-version - uses: ./.github/workflows/release-build.yml - with: - version: ${{ needs.check-version.outputs.version }} - skip_validation: ${{ github.event.inputs.skip_validation == 'true' }} - secrets: inherit - - gate: - name: All builds succeeded - needs: [docker-build, pypi-build, release-build] - runs-on: ubuntu-24.04 - steps: - - run: echo "All three build paths succeeded — proceeding to publish." - - docker-publish: - name: Docker publish - needs: [check-version, gate] - uses: ./.github/workflows/docker-publish.yml - with: - version: ${{ needs.check-version.outputs.version }} - dh-repository-owner: ${{ github.event.inputs.dh-repository-owner || 'elementsproject' }} - push-latest: ${{ github.event.inputs.push-latest }} - secrets: inherit - pypi-publish: name: PyPI publish - needs: [check-version, gate] + needs: [check-version, pypi-build] uses: ./.github/workflows/pypi-publish.yml with: version: ${{ needs.check-version.outputs.version }} dist-location: ${{ github.event.inputs.dist-location }} secrets: inherit - release-publish: - name: Release sign + draft - needs: [check-version, gate] - uses: ./.github/workflows/release-publish.yml - with: - version: ${{ needs.check-version.outputs.version }} - create_release: ${{ github.event.inputs.create_release == 'true' }} - secrets: inherit diff --git a/.github/workflows/repro.yml b/.github/workflows/repro.yml deleted file mode 100644 index ee4913c293d3..000000000000 --- a/.github/workflows/repro.yml +++ /dev/null @@ -1,114 +0,0 @@ ---- -# https://docs.corelightning.org/docs/repro -name: Repro Build Nightly -on: - # 05:00 Berlin, 03:00 UTC, 23:00 New York, 20:00 Los Angeles - schedule: - - cron: "0 3 * * *" - workflow_dispatch: - -jobs: - ubuntu: - name: "Ubuntu repro build: ${{ matrix.version }}" - runs-on: ubuntu-22.04 - strategy: - fail-fast: false # Let each build finish. - matrix: - version: ['jammy', 'noble', 'resolute'] - steps: - - name: Git checkout - uses: actions/checkout@v7 - - - name: Build environment setup - ${{ matrix.version }} - run: | - echo "Building base image for ${{ matrix.version }}" - echo "STEP=Build environment setup" >> "$GITHUB_ENV" - sudo docker run --rm -v $(pwd):/build ubuntu:${{ matrix.version }} bash -c "\ - apt-get update && \ - apt-get install -y debootstrap && \ - debootstrap ${{ matrix.version }} /build/${{ matrix.version }}" - sudo tar -C ${{ matrix.version }} -c . | docker import - ${{ matrix.version }} - - - name: Builder image setup - ${{ matrix.version }} - run: | - echo "STEP=Builder image setup" >> "$GITHUB_ENV" - docker build -t cl-repro-${{ matrix.version }} - < contrib/reprobuild/Dockerfile.${{ matrix.version }} - - - name: Build reproducible image and store Git state - ${{ matrix.version }} - run: | - echo "STEP=Build reproducible image and store Git state" >> "$GITHUB_ENV" - - # Create release directory. - mkdir $GITHUB_WORKSPACE/release - - # Perform the repro build. - docker run --name cl-build -v $GITHUB_WORKSPACE:/repo -e FORCE_MTIME=$(date +%F) -t cl-repro-${{ matrix.version }} - - # Commit the image in order to inspect the build later. - docker commit cl-build cl-repro - - # Inspect the version. - docker run --rm -v $GITHUB_WORKSPACE:/repo -t cl-repro bash -c "make version > /repo/release/version.txt" - - # Inspect the Git tree state. - docker run --rm -v $GITHUB_WORKSPACE:/repo -t cl-repro bash -c "\ - git --no-pager status > /repo/release/git.log && \ - git --no-pager diff >> /repo/release/git.log" - - # Change permissions on the release files for access by the runner environment. - sudo chown -R runner $GITHUB_WORKSPACE/release - - - name: Assert clean version - ${{ matrix.version }} - run: | - echo "STEP=Assert clean version" >> "$GITHUB_ENV" - echo 'Version:' - cat release/version.txt - echo -e - - releasefile=$(ls release/clightning-*) - echo 'Release file:' - ls -al release/clightning-* - echo -e - if [ -n "$(cat release/version.txt | sed -n '/-modded/p')" ] || \ - [ -n "$(echo $releasefile | sed -n '/-modded/p')" ]; then - echo "Git Status and Diff:" - cat release/git.log - echo -e - echo 'Error: release modded / dirty tree.' - exit 1 - else - echo 'Success! Clean release.' - fi - - - name: Upload release artifact - ${{ matrix.version }} - uses: actions/upload-artifact@v7 - with: - name: release-${{ matrix.version }} - path: release - retention-days: 3 # Automatically delete after 3 days - - - name: Send email on failure - if: ${{ failure() }} - uses: dawidd6/action-send-mail@v23 - with: - server_address: smtp.gmail.com - server_port: 465 - secure: true - username: ${{ secrets.EMAIL_USERNAME }} - password: ${{ secrets.EMAIL_PASSWORD }} - from: ${{ secrets.EMAIL_USERNAME }} - to: ${{ vars.DISTRIBUTION_LIST }} - subject: "CI Failure: Step ${{ env.STEP }} failed for distro ${{ matrix.version }}" - convert_markdown: true - html_body: | - - -

GitHub Workflow ${{ github.workflow }} Failed! For more details, click on the action below.

- Failure Details:
- Event: ${{ github.event_name }}
- Job: ${{ github.job }}
- Distro: ${{ matrix.version }}
- Step: ${{ env.STEP }}
- Action: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
- - diff --git a/Dockerfile b/Dockerfile index b6285d8bc6a2..3d4b19b9b560 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,287 +1,82 @@ -# syntax=docker/dockerfile:1.7-labs - -FROM --platform=${BUILDPLATFORM} debian:bookworm-slim AS base-host - -SHELL ["/bin/bash", "-euo", "pipefail", "-c"] - -FROM --platform=${TARGETPLATFORM} debian:bookworm-slim AS base-target - -SHELL ["/bin/bash", "-euo", "pipefail", "-c"] - -FROM base-host AS downloader-linux-amd64 - -ARG target_arch=x86_64-linux-gnu - -FROM base-host AS downloader-linux-arm64 - -ARG target_arch=aarch64-linux-gnu - -FROM base-host AS downloader-linux-arm - -ARG target_arch=arm-linux-gnueabihf - -FROM downloader-${TARGETOS}-${TARGETARCH} AS downloader - -RUN apt-get update && \ - apt-get install -qq -y --no-install-recommends \ - gnupg - -ARG BITCOIN_VERSION=27.1 -ARG BITCOIN_URL=https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION} -ARG BITCOIN_TARBALL=bitcoin-${BITCOIN_VERSION}-${target_arch}.tar.gz - -WORKDIR /opt/bitcoin - -ADD ${BITCOIN_URL}/${BITCOIN_TARBALL} . -ADD ${BITCOIN_URL}/SHA256SUMS . -ADD ${BITCOIN_URL}/SHA256SUMS.asc . -COPY contrib/keys/bitcoin/ gpg/ - -RUN gpg --quiet --import gpg/* && \ - gpg --verify SHA256SUMS.asc SHA256SUMS && \ - sha256sum -c SHA256SUMS --ignore-missing - -RUN tar xzf ${BITCOIN_TARBALL} --strip-components=1 - -FROM base-host AS base-builder - -RUN apt-get update && \ - apt-get install -qq -y --no-install-recommends \ - build-essential \ - ca-certificates \ - wget \ - git \ - autoconf \ - automake \ - bison \ - flex \ - jq \ - libtool \ - gettext - -WORKDIR /opt - -ADD --chmod=750 https://astral.sh/uv/install.sh install-uv.sh -ADD --chmod=750 https://sh.rustup.rs install-rust.sh - -WORKDIR /opt/lightningd - -COPY --exclude=.git/ . . - -FROM base-builder AS base-builder-linux-amd64 - -ARG target_arch=x86_64-linux-gnu -ARG target_arch_gcc=x86-64-linux-gnu -ARG target_arch_dpkg=amd64 -ARG target_arch_rust=x86_64-unknown-linux-gnu -ARG COPTFLAGS="-O2 -march=x86-64" - -FROM base-builder AS base-builder-linux-arm64 - -ARG target_arch=aarch64-linux-gnu -ARG target_arch_gcc=aarch64-linux-gnu -ARG target_arch_dpkg=arm64 -ARG target_arch_rust=aarch64-unknown-linux-gnu -ARG COPTFLAGS="-O2 -march=armv8-a" - -FROM base-builder AS base-builder-linux-arm - -ARG target_arch=arm-linux-gnueabihf -ARG target_arch_gcc=arm-linux-gnueabihf -ARG target_arch_dpkg=armhf -ARG target_arch_rust=armv7-unknown-linux-gnueabihf -ARG COPTFLAGS="-O2 -march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard" - -FROM base-builder-${TARGETOS}-${TARGETARCH} AS builder - -ENV LIGHTNINGD_VERSION=master - -RUN dpkg --add-architecture ${target_arch_dpkg} - -# Install architecture-independent libraries -RUN apt-get update && \ - apt-get install -qq -y --no-install-recommends \ - python3-dev \ - lowdown - -# Install target-arch libraries -RUN apt-get install -qq -y --no-install-recommends \ - pkg-config:${target_arch_dpkg} \ - libffi-dev:${target_arch_dpkg} \ - libicu-dev:${target_arch_dpkg} \ - zlib1g-dev:${target_arch_dpkg} \ - libsqlite3-dev:${target_arch_dpkg} \ - libpq-dev:${target_arch_dpkg} \ - libsodium-dev:${target_arch_dpkg} \ - crossbuild-essential-${target_arch_dpkg} - -ARG AR=${target_arch}-ar -ARG AS=${target_arch}-as -ARG CC=${target_arch}-gcc -ARG CXX=${target_arch}-g++ -ARG LD=${target_arch}-ld -ARG STRIP=${target_arch}-strip -ARG TARGET=${target_arch_rust} -ARG RUST_PROFILE=release -ARG VERSION -ENV VERSION=${VERSION} - -#TODO: set all the following cargo config options via env variables (https://doc.rust-lang.org/cargo/reference/environment-variables.html) -RUN mkdir -p .cargo && tee .cargo/config.toml </bin/bitcoin-cli, pre-verified by `tools/reprobuild fetch` +# vls remote_hsmd_socket-${VLS_VERSION}-{amd64,arm64,armhf} +# +# and the build args VERSION, VLS_VERSION, SOURCE_DATE_EPOCH, CREATED, REVISION. +# The main context only supplies tools/docker-entrypoint.sh (see .dockerignore). + +# Base pinned by index digest; bumped deliberately, like a package pin. +FROM debian:trixie-slim@sha256:d7e12182ce18b85b93007c1dedf31f2d29e01ccf3182cc4017c709b6259bc132 AS base + +# --- arch selector: Docker's TARGETARCH -> the matrix's arch token and the +# Bitcoin Core release triplet. ARGs propagate to the derived stages. +FROM base AS arch-linux-amd64 +ARG cl_arch=amd64 +ARG bitcoin_triplet=x86_64-linux-gnu + +FROM base AS arch-linux-arm64 +ARG cl_arch=arm64 +ARG bitcoin_triplet=aarch64-linux-gnu + +FROM base AS arch-linux-arm +ARG cl_arch=armhf +ARG bitcoin_triplet=arm-linux-gnueabihf + +# --- lightningd: the published image +FROM arch-${TARGETOS}-${TARGETARCH} AS lightningd ARG VERSION -ARG VLS_VERSION=v0.14.0 - -# Install cross-compilation toolchain (same as builder stage) -RUN dpkg --add-architecture ${target_arch_dpkg} +ARG CREATED +ARG REVISION +# The one unpinned, network-touching input: the entrypoint's +# runtime deps plus xz-utils (trixie-slim has no xz, the tarball needs it). +# Everything apt leaves behind that is not package content is +# removed so the layer depends on the package set only. RUN apt-get update && \ - apt-get install -qq -y --no-install-recommends \ - protobuf-compiler \ - pkg-config:${target_arch_dpkg} \ - crossbuild-essential-${target_arch_dpkg} && \ + apt-get install -y --no-install-recommends bash inotify-tools socat jq xz-utils && \ apt-get clean && \ - rm -rf /var/lib/apt/lists/* - -ENV PATH="/root/.cargo/bin:/root/.local/bin:${PATH}" -ENV PKG_CONFIG_PATH=/usr/lib/${target_arch}/pkgconfig -ENV PKG_CONFIG_LIBDIR=/usr/lib/${target_arch}/pkgconfig - -WORKDIR /opt - -RUN ./install-uv.sh -q -RUN ./install-rust.sh -y -q --profile minimal --component rustfmt --target ${target_arch_rust} - -RUN git clone --depth 1 --branch ${VLS_VERSION} https://gitlab.com/lightning-signer/validating-lightning-signer.git -WORKDIR /opt/validating-lightning-signer - -RUN mkdir -p .cargo && tee .cargo/config.toml < $TMPCFILE + # Needs a main(). Without one the link fails -- "undefined reference to + # `main'" -- on every platform, not just a fully static one against musl's + # crt1.o, so the probe answered "no" however capable the toolchain was. + echo "int foo(void); int foo(void) { return 0; } int main(void) { return foo(); }" > $TMPCFILE # We *want* this to fail if we get a warning, hence use -Werror. $1 $2 -Werror -ffunction-sections -Wl,--gc-sections $TMPCFILE -o $TMPOBJFILE } @@ -258,7 +276,10 @@ usage() echo " Note: On macOS, -g is used instead of -g3 for libbacktrace compatibility" fi usage_with_default "CONFIGURATOR_CC" "${CONFIGURATOR_CC:-$CC}" - echo " To override compile line for configurator itself" + echo " To override compile line for configurator itself (it runs on" + echo " the build machine, so set it to a native compiler when cross-compiling)" + usage_with_default "CONFIGURATOR_WRAPPER" "$CONFIGURATOR_WRAPPER" + echo " Command prefix to run configurator's test programs, e.g. qemu-aarch64-static -L /" usage_with_default "PYTEST" "$PYTEST" usage_with_default "VALGRIND" "$VALGRIND" usage_with_default "SED" "$SED" @@ -324,6 +345,7 @@ for opt in "$@"; do ;; CC=*) CC="${opt#CC=}";; CONFIGURATOR_CC=*) CONFIGURATOR_CC="${opt#CONFIGURATOR_CC=}";; + CONFIGURATOR_WRAPPER=*) CONFIGURATOR_WRAPPER="${opt#CONFIGURATOR_WRAPPER=}";; CWARNFLAGS=*) CWARNFLAGS="${opt#CWARNFLAGS=}";; CDEBUGFLAGS=*) CDEBUGFLAGS="${opt#CDEBUGFLAGS=}";; COPTFLAGS=*) COPTFLAGS="${opt#COPTFLAGS=}";; @@ -400,8 +422,11 @@ else fi # We assume warning flags don't affect congfigurator that much! +# The configurator itself runs here, on the build machine, so it is compiled +# with CONFIGURATOR_CC (defaults to CC; a native compiler when cross-compiling). +# Its test programs are compiled with CC and run via CONFIGURATOR_WRAPPER. echo -n "Compiling $CONFIGURATOR..." -$CC ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $LDFLAGS -o $CONFIGURATOR $CONFIGURATOR.c +$CONFIGURATOR_CC ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $LDFLAGS -o $CONFIGURATOR $CONFIGURATOR.c echo "done" if [ "$CLANG_COVERAGE" = "1" ]; then @@ -441,11 +466,20 @@ if command -v "${PKG_CONFIG}" >/dev/null; then SODIUM_LDLIBS="$("${PKG_CONFIG}" --silence-errors --libs libsodium || :)" fi -POSTGRES_INCLUDE="" -POSTGRES_LDLIBS="" +# Anything that did not come from the environment is re-probed, exactly as a +# first run would: see POSTGRES_*_FROM_ENV above. +[ -n "$POSTGRES_LDLIBS_FROM_ENV" ] || unset POSTGRES_LDLIBS +[ -n "$POSTGRES_INCLUDE_FROM_ENV" ] || unset POSTGRES_INCLUDE if command -v "${PG_CONFIG}" >/dev/null; then - POSTGRES_INCLUDE="-I$("${PG_CONFIG}" --includedir)" - POSTGRES_LDLIBS="-L$("${PG_CONFIG}" --libdir) -lpq" + : ${POSTGRES_INCLUDE="-I$("${PG_CONFIG}" --includedir)"} + : ${POSTGRES_LDLIBS="-L$("${PG_CONFIG}" --libdir) -lpq"} +else + # No pg_config, but the environment may still say how to reach libpq -- + # which is how a static or cross build states it (the comment above). + # Assigning here unconditionally would throw that answer away and + # silently drop PostgreSQL support, so default rather than assign. + : ${POSTGRES_INCLUDE=} + : ${POSTGRES_LDLIBS=} fi # Clean up on exit. @@ -455,7 +489,7 @@ CONFIGURATOR_PATH_FLAGS= [ -z "$CPATH" ] || CONFIGURATOR_PATH_FLAGS="$CONFIGURATOR_PATH_FLAGS -I$CPATH" [ -z "$LIBRARY_PATH" ] || CONFIGURATOR_PATH_FLAGS="$CONFIGURATOR_PATH_FLAGS -L$LIBRARY_PATH" -$CONFIGURATOR --extra-tests --autotools-style --var-file=$CONFIG_VAR_FILE.$$ --header-file=$CONFIG_HEADER.$$ --configurator-cc="$CONFIGURATOR_CC" --wrapper="$CONFIGURATOR_WRAPPER" "$CC" ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $CSANFLAGS $CONFIGURATOR_PATH_FLAGS $SQLITE3_CFLAGS $SODIUM_CFLAGS $POSTGRES_INCLUDE <-arm64 targets resolve. amd64 keeps its bare name. - SUFFIX="" - [ "$(dpkg --print-architecture)" = arm64 ] && SUFFIX="-arm64" - # shellcheck disable=SC2024 - sudo docker build --no-cache -t cl-repro-$v$SUFFIX - < "$LIGHTNING_DIR"/contrib/reprobuild/Dockerfile.$v -done diff --git a/contrib/docker/Dockerfile.builder.fedora b/contrib/docker/Dockerfile.builder.fedora deleted file mode 100644 index 3a51e0f33e29..000000000000 --- a/contrib/docker/Dockerfile.builder.fedora +++ /dev/null @@ -1,63 +0,0 @@ -FROM fedora:40 - -ENV UV_PYTHON=3.12 -ENV BITCOIN_VERSION=27.1 -ENV SOURCE_DATE_EPOCH=1672531200 -ENV RUSTFLAGS="-C link-arg=-Wl,--build-id=none" - -WORKDIR /tmp - -RUN dnf update -y && \ - dnf groupinstall -y \ - 'C Development Tools and Libraries' \ - 'Development Tools' && \ - dnf install -y \ - clang \ - libsq3-devel \ - redhat-lsb \ - net-tools \ - valgrind \ - wget \ - git \ - jq \ - xz \ - zlib-devel \ - libsodium-devel \ - which \ - sed \ - gettext-devel \ - gmp-devel \ - python3-devel \ - python3-pip \ - python3-poetry \ - postgresql-devel && \ - dnf clean all - -# Install Rust via rustup (for lockfile v4 support) -RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.92.0 -ENV PATH="/root/.cargo/bin:${PATH}" - -# Install lowdown -RUN wget https://github.com/kristapsdz/lowdown/archive/refs/tags/VERSION_1_0_2.tar.gz && \ - tar -xzf VERSION_1_0_2.tar.gz && \ - cd lowdown-VERSION_1_0_2 && \ - ./configure && \ - make && \ - make install && \ - ldconfig && \ - cd /tmp && \ - rm -rf VERSION_1_0_2.tar.gz lowdown-VERSION_1_0_2 - -# Install Bitcoin Core -RUN wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-x86_64-linux-gnu.tar.gz \ - -O bitcoin.tar.gz && \ - tar -xvzf bitcoin.tar.gz && \ - mv bitcoin-$BITCOIN_VERSION/bin/bitcoin* /usr/local/bin/ && \ - mv bitcoin-$BITCOIN_VERSION/lib/* /usr/local/lib/ && \ - mv bitcoin-$BITCOIN_VERSION/include/* /usr/local/include/ && \ - mv bitcoin-$BITCOIN_VERSION/share/man/man1/* /usr/share/man/man1 && \ - rm -rf bitcoin.tar.gz bitcoin-$BITCOIN_VERSION - -# Install uv -ENV PATH="${PATH}:/root/.local/bin" -RUN wget -qO- https://astral.sh/uv/install.sh | sh diff --git a/contrib/reprobuild/Dockerfile.jammy b/contrib/reprobuild/Dockerfile.jammy deleted file mode 100644 index e8c1c8a6356e..000000000000 --- a/contrib/reprobuild/Dockerfile.jammy +++ /dev/null @@ -1,87 +0,0 @@ -FROM jammy - -ENV TZ=UTC -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -ENV SOURCE_DATE_EPOCH=1672531200 -ENV RUST_PROFILE=release -ENV PATH=/root/.pyenv/shims:/root/.pyenv/bin:/root/.cargo/bin:/root/.local/bin:$PATH - -RUN sed -i '/updates/d' /etc/apt/sources.list && \ - sed -i '/security/d' /etc/apt/sources.list - -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - autoconf \ - automake \ - build-essential \ - ca-certificates \ - file \ - gettext \ - git \ - libsqlite3-dev \ - libpq-dev \ - libsodium23 \ - libsodium-dev \ - libtool \ - m4 \ - sudo \ - unzip \ - wget \ - jq \ - zip \ - && cd /tmp \ - && wget https://github.com/kristapsdz/lowdown/archive/refs/tags/VERSION_1_0_2.tar.gz \ - && tar -xzf VERSION_1_0_2.tar.gz \ - && cd lowdown-VERSION_1_0_2 \ - && ./configure \ - && make \ - && make install \ - && ldconfig \ - && cd / \ - && rm -rf /tmp/VERSION_1_0_2.tar.gz /tmp/lowdown-VERSION_1_0_2 - -# Ensure correct ownership -RUN chown root:root /etc/sudoers -RUN chown root:root /etc/sudo.conf -RUN chown root:root /usr/libexec/sudo/sudoers.so - -# Install Python3.10 (more reproducible than relying on python3-setuptools) -RUN git clone https://github.com/pyenv/pyenv.git /root/.pyenv && \ - apt-get install -y --no-install-recommends \ - libbz2-dev \ - libffi-dev \ - libreadline-dev \ - libsqlite3-dev \ - libssl-dev \ - zlib1g-dev && \ - pyenv install 3.10.0 && \ - pyenv global 3.10.0 - -RUN wget -qO- https://astral.sh/uv/install.sh | sh - -RUN wget https://sh.rustup.rs -O rustup-install.sh && \ - bash rustup-install.sh --default-toolchain none --quiet -y && \ - rm rustup-install.sh && \ - /root/.cargo/bin/rustup install 1.85 - -RUN mkdir /build -WORKDIR /build - -# We mount the repo into `/repo` and then we take a snapshot of it -# first by cloning it. This ensures we're not including any -# uncommitted changes in the working directory on the host. Notice -# that we no longer take the zipfile. -CMD git clone /repo . \ - && uv sync --all-extras --all-groups \ - && if [ "$REPRO_ARCH" = armv7 ]; then \ - uv run tools/repro-build.armv7.sh \ - && mkdir -p /repo/release-armv7 \ - && cp *.xz /repo/release-armv7/; \ - elif [ "$(dpkg --print-architecture)" = arm64 ]; then \ - uv run tools/repro-build.arm64.sh \ - && mkdir -p /repo/release-arm64 \ - && cp *.xz /repo/release-arm64/; \ - else \ - uv run tools/repro-build.sh \ - && cp *.xz /repo/release/; \ - fi diff --git a/contrib/reprobuild/Dockerfile.noble b/contrib/reprobuild/Dockerfile.noble deleted file mode 100644 index f7a1d3a4b55f..000000000000 --- a/contrib/reprobuild/Dockerfile.noble +++ /dev/null @@ -1,77 +0,0 @@ -FROM noble - -ENV TZ=UTC -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -ENV SOURCE_DATE_EPOCH=1672531200 -ENV RUST_PROFILE=release -ENV PATH=/root/.pyenv/shims:/root/.pyenv/bin:/root/.cargo/bin:/root/.local/bin:$PATH - -RUN sed -i '/updates/d' /etc/apt/sources.list && \ - sed -i '/security/d' /etc/apt/sources.list && \ - sed -i 's/^deb \(.*\) noble main$/deb \1 noble main universe/' /etc/apt/sources.list - -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - autoconf \ - automake \ - build-essential \ - ca-certificates \ - file \ - gettext \ - git \ - curl \ - libsqlite3-dev \ - libpq-dev \ - libsodium23 \ - libsodium-dev \ - lowdown \ - libtool \ - m4 \ - sudo \ - unzip \ - wget \ - jq \ - zip - -# Configure /repo/.git as 'safe.directory' -RUN git config --global --add safe.directory /repo/.git - -# Install Python3.10 (more reproducible than relying on python3-setuptools) -RUN git clone https://github.com/pyenv/pyenv.git /root/.pyenv && \ - apt-get install -y --no-install-recommends \ - libbz2-dev \ - libffi-dev \ - libreadline-dev \ - libssl-dev \ - zlib1g-dev && \ - pyenv install 3.10.0 && \ - pyenv global 3.10.0 - -RUN wget -qO- https://astral.sh/uv/install.sh | sh - -RUN wget https://sh.rustup.rs -O rustup-install.sh && \ - bash rustup-install.sh --default-toolchain none --quiet -y && \ - rm rustup-install.sh && \ - /root/.cargo/bin/rustup install 1.85 - -RUN mkdir /build -WORKDIR /build - -# We mount the repo into `/repo` and then we take a snapshot of it -# first by cloning it. This ensures we're not including any -# uncommitted changes in the working directory on the host. Notice -# that we no longer take the zipfile. -CMD git clone /repo . \ - && uv sync --all-extras --all-groups \ - && if [ "$REPRO_ARCH" = armv7 ]; then \ - uv run tools/repro-build.armv7.sh \ - && mkdir -p /repo/release-armv7 \ - && cp *.xz /repo/release-armv7/; \ - elif [ "$(dpkg --print-architecture)" = arm64 ]; then \ - uv run tools/repro-build.arm64.sh \ - && mkdir -p /repo/release-arm64 \ - && cp *.xz /repo/release-arm64/; \ - else \ - uv run tools/repro-build.sh \ - && cp *.xz /repo/release/; \ - fi diff --git a/contrib/reprobuild/Dockerfile.resolute b/contrib/reprobuild/Dockerfile.resolute deleted file mode 100644 index 5b783dd7fa57..000000000000 --- a/contrib/reprobuild/Dockerfile.resolute +++ /dev/null @@ -1,77 +0,0 @@ -FROM resolute - -ENV TZ=UTC -RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone -ENV SOURCE_DATE_EPOCH=1672531200 -ENV RUST_PROFILE=release -ENV PATH=/root/.pyenv/shims:/root/.pyenv/bin:/root/.cargo/bin:/root/.local/bin:$PATH - -RUN sed -i '/updates/d' /etc/apt/sources.list && \ - sed -i '/security/d' /etc/apt/sources.list && \ - sed -i 's/^deb \(.*\) resolute main$/deb \1 resolute main universe/' /etc/apt/sources.list - -RUN apt-get update \ - && apt-get install -y --no-install-recommends \ - autoconf \ - automake \ - build-essential \ - ca-certificates \ - file \ - gettext \ - git \ - curl \ - libsqlite3-dev \ - libpq-dev \ - libsodium23 \ - libsodium-dev \ - lowdown \ - libtool \ - m4 \ - sudo \ - unzip \ - wget \ - jq \ - zip - -# Configure /repo/.git as 'safe.directory' -RUN git config --global --add safe.directory /repo/.git - -# Install Python3.10 (more reproducible than relying on python3-setuptools) -RUN git clone https://github.com/pyenv/pyenv.git /root/.pyenv && \ - apt-get install -y --no-install-recommends \ - libbz2-dev \ - libffi-dev \ - libreadline-dev \ - libssl-dev \ - zlib1g-dev && \ - pyenv install 3.10.0 && \ - pyenv global 3.10.0 - -RUN wget -qO- https://astral.sh/uv/install.sh | sh - -RUN wget https://sh.rustup.rs -O rustup-install.sh && \ - bash rustup-install.sh --default-toolchain none --quiet -y && \ - rm rustup-install.sh && \ - /root/.cargo/bin/rustup install 1.85 - -RUN mkdir /build -WORKDIR /build - -# We mount the repo into `/repo` and then we take a snapshot of it -# first by cloning it. This ensures we're not including any -# uncommitted changes in the working directory on the host. Notice -# that we no longer take the zipfile. -CMD git clone /repo . \ - && uv sync --all-extras --all-groups \ - && if [ "$REPRO_ARCH" = armv7 ]; then \ - uv run tools/repro-build.armv7.sh \ - && mkdir -p /repo/release-armv7 \ - && cp *.xz /repo/release-armv7/; \ - elif [ "$(dpkg --print-architecture)" = arm64 ]; then \ - uv run tools/repro-build.arm64.sh \ - && mkdir -p /repo/release-arm64 \ - && cp *.xz /repo/release-arm64/; \ - else \ - uv run tools/repro-build.sh \ - && cp *.xz /repo/release/; \ - fi diff --git a/contrib/reprobuild/check.sh b/contrib/reprobuild/check.sh new file mode 100755 index 000000000000..6a6a42b6d32d --- /dev/null +++ b/contrib/reprobuild/check.sh @@ -0,0 +1,148 @@ +#!/bin/sh +# What the driver's `check` runs on a finished tarball. +# +# contrib/reprobuild/check.sh release/clightning-...tar.xz +# +# These are properties a release must have and the build could lose silently, +# so they are asserted on the shipped bytes rather than trusted, and `sign` +# refuses a tarball that fails: +# +# * stripped -- no .symtab or .debug_* in any shipped ELF; +# * static-pie -- pkgsStatic's stdenv appends `-static`, which quietly +# yields a non-PIE static binary and loses ASLR; +# * a build-id -- nixpkgs' toolchain emits none by default, and without one +# a crash report from a stripped binary cannot be resolved at all. +set -eu + +tarball=${1:?usage: check.sh } +tmp=$(mktemp -d) +# chmod first: a tarball built straight out of a Nix store path carries +# read-only directories, which makes the cleanup fail. +trap 'chmod -R u+w "$tmp" 2>/dev/null; rm -rf "$tmp"' EXIT +tar -xf "$tarball" -C "$tmp" + +# The documented install is `-C /usr/local --strip-components=2`, which only +# works when every member is usr/local/..., as in the official tarballs. +if tar -tf "$tarball" | grep -qvE '^usr/(local/.*)?$'; then + echo "check: $tarball has members outside usr/local/:" >&2 + tar -tf "$tarball" | grep -vE '^usr/(local/.*)?$' | head -5 >&2 + exit 1 +fi + +# Located rather than spelled out: which prefix the tarball installs under is +# the release derivation's business, not a second fact this script has to keep +# in step with it. +lightningd=$(find "$tmp" -type f -name lightningd | head -1) +[ -n "$lightningd" ] || { echo "check: no lightningd in $tarball" >&2; exit 1; } + +elfs=0 bad=0 nonpie=0 nobuildid=0 stripped_bad=0 +# shellcheck disable=SC2044 +for fp in $(find "$tmp" -type f); do + [ "$(head -c 4 "$fp" | od -An -tx1 | tr -d ' \n')" = "7f454c46" ] || continue + elfs=$((elfs + 1)) + rel=${fp#"$tmp"} + + sections=$(readelf -SW "$fp" 2>/dev/null || true) + hdr=$(readelf -hW "$fp" 2>/dev/null || true) + notes=$(readelf -nW "$fp" 2>/dev/null || true) + + if printf '%s' "$sections" | grep -qE '\.symtab|\.debug_'; then + echo "FAIL $rel: carries .symtab/.debug_*" + stripped_bad=$((stripped_bad + 1)); bad=$((bad + 1)) + fi + if ! printf '%s' "$hdr" | grep -q 'Type:[[:space:]]*DYN'; then + echo "FAIL $rel: not position-independent" + nonpie=$((nonpie + 1)); bad=$((bad + 1)) + fi + if ! printf '%s' "$notes" | grep -q 'Build ID'; then + echo "FAIL $rel: no build-id" + nobuildid=$((nobuildid + 1)); bad=$((bad + 1)) + fi + # A truly static binary has no INTERP and no NEEDED entries. + if readelf -lW "$fp" 2>/dev/null | grep -q 'INTERP'; then + echo "FAIL $rel: has a PT_INTERP (dynamically linked)" + bad=$((bad + 1)) + fi +done + +# The arm tarballs are for the Raspberry Pi (nix/release-rows): armhf must +# run on a Pi 2 (Cortex-A7: ARMv7, VFPv4, NEON), arm64 on a Pi 3 +# (Cortex-A53: ARMv8.0). Neither shows in the checks above. +machine=$(readelf -hW "$lightningd" | sed -n 's/^ *Machine: *//p') +case "$machine" in +*AArch64*) qemu=qemu-aarch64 cpu=cortex-a53 ;; +*ARM*) qemu=qemu-arm cpu=cortex-a7 ;; +*) qemu='' cpu='' ;; +esac + +# armhf: what each binary was compiled for. A tag above the Pi 2, or a +# soft-float ABI, fails. +armattr_bad=0 +if [ "$qemu" = qemu-arm ]; then + # shellcheck disable=SC2044 + for fp in $(find "$tmp" -type f); do + [ "$(head -c 4 "$fp" | od -An -tx1 | tr -d ' \n')" = "7f454c46" ] || continue + rel=${fp#"$tmp"} + attrs=$(readelf -A "$fp" 2>/dev/null || true) + tag() { printf '%s\n' "$attrs" | sed -n "s/^ *$1: //p"; } + why= + [ "$(tag Tag_CPU_arch)" = v7 ] || why="$why CPU_arch=$(tag Tag_CPU_arch)" + case "$(tag Tag_FP_arch)" in + VFPv3 | VFPv3-D16 | VFPv4 | VFPv4-D16) ;; + *) why="$why FP_arch=$(tag Tag_FP_arch)" ;; + esac + case "$(tag Tag_Advanced_SIMD_arch)" in + "" | NEONv1 | "NEONv1 with Fused-MAC") ;; + *) why="$why Advanced_SIMD=$(tag Tag_Advanced_SIMD_arch)" ;; + esac + [ "$(tag Tag_ABI_VFP_args)" = "VFP registers" ] || why="$why not hard-float" + if [ -n "$why" ]; then + echo "FAIL $rel: not for a Raspberry Pi 2:$why" + armattr_bad=$((armattr_bad + 1)); bad=$((bad + 1)) + fi + done +fi + +# Both arm rows: run every binary on the oldest Pi's CPU. This catches +# code the attributes do not declare (rustc's armv7 target used D16-D31 +# under a VFPv3 tag). The plugins exit with no lightningd on stdin, which +# is fine; a signal is not. qemu is the pinned one, not the host's. +cpu_bad=0 +if [ -n "$qemu" ]; then + top=$(cd "$(dirname "$0")/../.." && pwd) + qemudir=$(nix --extra-experimental-features 'nix-command flakes' build --impure \ + --no-link --print-out-paths --expr \ + "(import (builtins.getFlake \"git+file://$top?submodules=1\").inputs.nixpkgs { system = \"x86_64-linux\"; }).qemu-user" | + head -1) + [ -x "$qemudir/bin/$qemu" ] || { echo "CHECK FAILED: no $qemu in $qemudir" >&2; exit 1; } + echo "--- running every ELF on $cpu" + # shellcheck disable=SC2044 + for fp in $(find "$tmp" -type f); do + [ "$(head -c 4 "$fp" | od -An -tx1 | tr -d ' \n')" = "7f454c46" ] || continue + rc=0 + timeout 120 "$qemudir/bin/$qemu" -cpu "$cpu" "$fp" --version /dev/null 2>&1 || rc=$? + if [ "$rc" -ge 124 ]; then + echo "FAIL ${fp#"$tmp"}: died on $cpu (exit $rc)" + cpu_bad=$((cpu_bad + 1)); bad=$((bad + 1)) + fi + done +fi + +echo "---" +echo "ELFs checked: $elfs" +echo "unstripped: $stripped_bad" +echo "non-PIE: $nonpie" +echo "missing build-id: $nobuildid" +if [ -n "$qemu" ]; then + [ "$qemu" = qemu-arm ] && echo "above Pi 2 ABI: $armattr_bad" + echo "crashed on $cpu: $cpu_bad" +fi +if [ "$elfs" = 0 ]; then + echo "CHECK FAILED: no ELF files found in $tarball" >&2 + exit 1 +fi +if [ "$bad" != 0 ]; then + echo "CHECK FAILED: $bad problem(s)" >&2 + exit 1 +fi +echo "check: OK ($elfs ELFs, all static-pie, stripped, with build-id)" diff --git a/contrib/reprobuild/fetch-bitcoin.sh b/contrib/reprobuild/fetch-bitcoin.sh new file mode 100755 index 000000000000..9ce37290fd39 --- /dev/null +++ b/contrib/reprobuild/fetch-bitcoin.sh @@ -0,0 +1,68 @@ +#!/bin/sh +# What `tools/reprobuild fetch` runs: download Bitcoin Core's release tarballs for every arch in the matrix plus +# SHA256SUMS(.asc), verify on the host (gpg against contrib/keys/bitcoin/, +# then sha256sum), and extract bin/bitcoin-cli per triplet into the cache +# that `docker` hands the Dockerfile as the `bitcoin` build context. +# +# contrib/reprobuild/fetch-bitcoin.sh [--cache=DIR] +# +# Downloads land in release/cache/dl (never a build context). +# Result: $CACHE//bin/bitcoin-cli for x86_64-linux-gnu, +# aarch64-linux-gnu, arm-linux-gnueabihf. Idempotent: existing downloads are +# kept, verification always re-runs. +set -eu + +top=$(cd "$(dirname "$0")/../.." && pwd) +pins=$top/contrib/reprobuild/pins +BITCOIN_VERSION=$(sed -n 's/^BITCOIN_VERSION=//p' "$pins") +BITCOIN_URL=$(sed -n 's/^BITCOIN_URL=//p' "$pins") +MIN_SIGS=$(sed -n 's/^BITCOIN_MIN_SIGS=//p' "$pins") +CACHE=$top/release/cache/bitcoin-$BITCOIN_VERSION +for arg; do + case "$arg" in + --cache=*) CACHE=${arg#*=} ;; + *) echo "unknown arg $arg" >&2; exit 1 ;; + esac +done +# arch -> Bitcoin Core release triplet (the matrix's three arches) +TRIPLETS="x86_64-linux-gnu aarch64-linux-gnu arm-linux-gnueabihf" + +DL=$(dirname "$CACHE")/dl +mkdir -p "$DL" "$CACHE" +cd "$DL" +# shellcheck disable=SC2086 +for f in SHA256SUMS SHA256SUMS.asc $(for t in $TRIPLETS; do echo "bitcoin-$BITCOIN_VERSION-$t.tar.gz"; done); do + [ -s "$f" ] && { echo "fetch: have $f"; continue; } + echo "fetch: $BITCOIN_URL/$f" + curl -fsSL -o "$f.part" "$BITCOIN_URL/$f" && mv "$f.part" "$f" +done + +# gpg: throwaway keyring holding only the vendored keys; count good sigs +# rather than trusting gpg's exit status (SHA256SUMS.asc carries many +# signatures, most from keys we do not vendor). +GNUPGHOME=$(mktemp -d) +export GNUPGHOME +trap 'rm -rf "$GNUPGHOME"' EXIT +gpg --batch --quiet --import "$top"/contrib/keys/bitcoin/* 2>/dev/null +status=$(gpg --batch --status-fd 1 --verify SHA256SUMS.asc SHA256SUMS 2>/dev/null || true) +# Distinct *keys*, not signature lines: the point of a minimum is that several +# independent maintainers vouched for these bytes, and two signatures from one +# key -- or one key imported twice -- would otherwise count as two vouches. +good=$(printf '%s\n' "$status" | sed -n 's/^\[GNUPG:\] VALIDSIG \([0-9A-F]*\) .*/\1/p' | sort -u | grep -c . || true) +bad=$(printf '%s\n' "$status" | grep -c '^\[GNUPG:\] BADSIG ' || true) +printf '%s\n' "$status" | sed -n 's/^\[GNUPG:\] GOODSIG [0-9A-F]* /fetch: good signature: /p' +echo "fetch: $good distinct key(s) with a good signature, $bad bad (minimum $MIN_SIGS)" +[ "$bad" -eq 0 ] || { echo "fetch: BAD signature on SHA256SUMS.asc" >&2; exit 1; } +[ "$good" -ge "$MIN_SIGS" ] || { echo "fetch: too few good signatures" >&2; exit 1; } + +# sha256: only our three tarballs are present; make sure all three were checked +checked=$(sha256sum -c --ignore-missing SHA256SUMS | tee /dev/stderr | grep -c ': OK$') +[ "$checked" -eq 3 ] || { echo "fetch: expected 3 verified tarballs, got $checked" >&2; exit 1; } + +for t in $TRIPLETS; do + rm -rf "${CACHE:?}/$t" + mkdir -p "$CACHE/$t/bin" + tar -xzf "bitcoin-$BITCOIN_VERSION-$t.tar.gz" -C "$CACHE/$t/bin" --strip-components=2 \ + "bitcoin-$BITCOIN_VERSION/bin/bitcoin-cli" + echo "fetch: $CACHE/$t/bin/bitcoin-cli ($(file -b "$CACHE/$t/bin/bitcoin-cli" | cut -d, -f1-3))" +done diff --git a/contrib/reprobuild/pins b/contrib/reprobuild/pins new file mode 100644 index 000000000000..b0c299e0d6b4 --- /dev/null +++ b/contrib/reprobuild/pins @@ -0,0 +1,48 @@ +# Data pins for the release driver (tools/reprobuild). Bumped deliberately, +# reviewed as a diff, exactly like every other pin on this route. +# +# The builder is the upstream `nixos/nix` container, pinned by *index* digest +# so it resolves the same on every architecture. The release build runs inside +# it, so the host needs docker, coreutils and python3 but no Nix -- and no host +# nix.conf, whose sandbox, substituters and filter-syscalls settings would +# otherwise be unrecorded inputs to a signed artifact. `--host-nix` is the +# opt-in for whoever has Nix and wants the faster loop; both are expected to +# produce the same bytes, which has been measured on two machines. +NIX_IMAGE=nixos/nix@sha256:7a007c766426c1877758ddc5cb87a965ac131fc78c582ce0083d922d51ae945c +NIX_IMAGE_TAG=2.35.2 + +# The skopeo the `docker` verb uses for OCI layouts and pushes. +# Ubuntu 22.04's skopeo 1.4.1 lacks --preserve-digests, so the pinned +# container is the normative path (a new enough host skopeo is used if found, +# so this is the floor and not a ceiling). +# +# 1.22.3 is the newest skopeo *image*, which is not the newest skopeo: there are +# v1.23.0, v1.24.0 and v1.24.1 source releases, but no 1.23.x or 1.24.x +# container on quay.io/skopeo/stable (all 77 tags checked), on +# quay.io/containers/skopeo, on ghcr.io or on Docker Hub. skopeo maintains +# several stable branches at once and backports to them -- v1.22.3 shipped the +# same day as v1.24.1 -- and the image track follows one of those branches. So +# do not "fix" this to 1.24.x without first checking that an image exists. +# +# By *index* digest, like NIX_IMAGE above -- but of the `-immutable` tag, which +# matters more than it sounds. quay's version tags float: `v1.22.3` was +# re-pushed on 2026-10-02 and again on 2026-10-07. Worse, quay garbage-collects +# a manifest once no tag points at it, so a digest taken from the floating tag +# *stops resolving*: the digest below's predecessor, 249b92db, was verified +# working on 2026-09-30 and was `manifest unknown` by 2026-10-07, which broke the +# docker verb. Upstream publishes `-immutable` for exactly this, and it has not +# moved since 2026-09-21. Pin that digest, so a tag keeps the manifest alive. +SKOPEO_IMAGE=quay.io/skopeo/stable@sha256:c0ee1f4edca5c01cb8d5611124f92f3cc47196ecab68aee5d0f90834e00574d5 +SKOPEO_IMAGE_TAG=v1.22.3-immutable + +# The runtime image's base digest lives in the Dockerfile itself +# (FROM debian:trixie-slim@sha256:...), bumped deliberately like a pin. +# +# Bitcoin Core: `tools/reprobuild fetch` downloads the release tarballs for +# every arch of the matrix from BITCOIN_URL, verifies SHA256SUMS.asc against +# contrib/keys/bitcoin/ on the host, and extracts bin/bitcoin-cli into the +# cache the Dockerfile COPYs from. Bumped at release time. +BITCOIN_VERSION=31.1 +BITCOIN_URL=https://bitcoincore.org/bin/bitcoin-core-31.1 +# Minimum number of good signatures on SHA256SUMS.asc from the vendored keys. +BITCOIN_MIN_SIGS=3 diff --git a/contrib/reprobuild/portability.sh b/contrib/reprobuild/portability.sh new file mode 100755 index 000000000000..6b7f6dd36946 --- /dev/null +++ b/contrib/reprobuild/portability.sh @@ -0,0 +1,95 @@ +#!/bin/sh +# The portability matrix, run against a release tarball. +# +# contrib/reprobuild/portability.sh release/clightning-...tar.xz +# +# One tarball per architecture replaced one per distribution, and the whole +# bet is that a static binary runs anywhere. That is a claim about other +# people's systems, so it is measured every time rather than assumed -- and +# measured again whenever the toolchain moves, because a result obtained with +# a different libc does not transfer. +# +# The arch is read off the tarball name, and picks both the set of distro +# images and the `--platform` the foreign rows run under. +# +# Each row unpacks the tarball over / in a bare distro container and runs +# smoke.sh: --version, a regtest start, and a getmanifest +# handshake with every plugin -- the pass mark is every plugin the tarball +# actually ships, counted at run time. +set -eu + +tarball=${1:?usage: portability.sh [--images="ubuntu:26.04 ..."]} +shift +IMAGES_OVERRIDE= +for arg; do + case "$arg" in + --images=*) IMAGES_OVERRIDE=${arg#*=} ;; + *) echo "unknown arg $arg" >&2; exit 1 ;; + esac +done +top=$(cd "$(dirname "$0")/../.." && pwd) +smoke=$top/contrib/reprobuild/smoke.sh +tarball=$(cd "$(dirname "$tarball")" && pwd)/$(basename "$tarball") + +# The matrix rows, which are the runtime promise. Fedora has no +# armhf row (no such image); everything else is the full three-Ubuntu set. +case "$tarball" in +*-amd64*) ARCH=amd64; PLATFORM=linux/amd64; IMAGES="ubuntu:22.04 ubuntu:24.04 ubuntu:26.04 fedora:43" ;; +*-arm64*) ARCH=arm64; PLATFORM=linux/arm64; IMAGES="ubuntu:22.04 ubuntu:24.04 ubuntu:26.04 fedora:43" ;; +*-armhf*) ARCH=armhf; PLATFORM=linux/arm/v7; IMAGES="ubuntu:22.04 ubuntu:24.04 ubuntu:26.04" ;; +*) echo "cannot tell the arch from $tarball" >&2; exit 1 ;; +esac +# A release run checks the newest distro only -- enough to catch "the tarball +# does not run" -- and the full matrix is kept for the acceptance suite. +[ -n "$IMAGES_OVERRIDE" ] && IMAGES=$IMAGES_OVERRIDE +echo "portability: $ARCH ($PLATFORM) <- $(basename "$tarball")" +echo "portability: images: $IMAGES" + +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +mkdir -p "$tmp/tree" +tar -xf "$tarball" -C "$tmp/tree" + +# How many plugins must answer getmanifest: counted from the tarball, not +# written down. A hardcoded number stops meaning anything the moment a plugin +# is added or removed -- it would either keep passing against a stale floor or +# fail a release for a deliberate removal. The path is globbed rather than +# spelled out so the install prefix is not baked in here too. +plugins=$(find "$tmp/tree" -path '*/libexec/c-lightning/plugins/*' -type f | grep -c . || true) +[ "$plugins" -gt 0 ] || { echo "portability: no plugins found in the tarball" >&2; exit 1; } +echo "portability: $plugins plugins in the tarball; every one must answer getmanifest" + +# Every image at once (each container only reads the shared tree), reported +# afterwards in the order listed. The tag goes into the file name, so ':' is +# replaced. +for img in $IMAGES; do + docker run --rm --platform "$PLATFORM" \ + -v "$tmp/tree:/cln:ro" -v "$smoke:/smoke.sh:ro" \ + "$img" sh /smoke.sh > "$tmp/out.$(echo "$img" | tr ':/' '__')" 2>&1 & +done +wait + +pass=0 fail=0 +for img in $IMAGES; do + out=$tmp/out.$(echo "$img" | tr ':/' '__') + echo "################ $img ($PLATFORM)" + ok=$(grep -c '^ok ' "$out" || true) + bad=$(grep -c '^FAIL ' "$out" || true) + ver=$(grep -m1 -A1 '=== --version' "$out" | tail -1 || true) + echo " version line: $ver" + echo " plugins: $ok ok, $bad FAIL (of $plugins in the tarball)" + if [ "$bad" = 0 ] && [ "$ok" -eq "$plugins" ]; then + echo " => PASS" + pass=$((pass + 1)) + else + echo " => FAIL" + # The failing plugins first: in an image run they come last, and the + # 40-line head of the log would cut them off. + grep '^FAIL ' "$out" || true + sed -n '1,40p' "$out" + fail=$((fail + 1)) + fi +done + +echo "================ portability $ARCH: $pass pass, $fail fail" +[ "$fail" = 0 ] diff --git a/contrib/reprobuild/publish.vars b/contrib/reprobuild/publish.vars new file mode 100644 index 000000000000..7d1011640c6b --- /dev/null +++ b/contrib/reprobuild/publish.vars @@ -0,0 +1,38 @@ +# Where a release is published. Data, not secrets: the bucket is public-read, +# and the credentials that write it never appear here (see below). +# +# The bucket is configured for public read of exact keys with *listing +# refused*, and object versioning is off on purpose -- see the key layout +# below for what that means for the driver. + +# The public base URL a downloader resolves an artifact at, and what the +# release notes and manifest links print. No custom domain fronts the bucket; +# moving to one later would leave earlier releases' links on this host. +PUBLISH_BASE_URL=https://storage.googleapis.com/cln-releases + +# The S3-compatible endpoint and bucket that `publish` uploads to. GCS speaks +# S3 through its interoperability API, so one client (rclone, s3 backend, +# provider=GCS) covers it. +REPRO_S3_ENDPOINT=https://storage.googleapis.com +REPRO_S3_BUCKET=cln-releases +REPRO_S3_PROVIDER=GCS + +# Key layout. Release artifacts go to `/`, one-to-one with the +# staging dir `release/publish//`; `publish` refuses to overwrite an +# existing `/` prefix, because with versioning off immutability has to be +# a driver rule. +# +# The source archive gets its own prefix: `certify` `nix copy`s the +# fixed-output source paths there and it is served as a plain Nix binary cache +# (`nix-cache-info` at its root), listed ahead of cache.nixos.org in the +# substituter list the driver passes. Co-signers read it **anonymously** -- +# content-addressed paths are verified by hash, so it needs no signing key and +# no credentials. +PUBLISH_PREFIX_ARCHIVE=nix-cache + +# Credentials: the HMAC key of one shared publisher account, kept in the team's +# password manager and shared with every captain. Sourced into the environment +# as REPRO_S3_ACCESS_KEY_ID / REPRO_S3_SECRET_ACCESS_KEY for the length of the +# command and never written to disk. That account cannot write under `debug/`, +# so the unstripped binaries and symbol files cannot be published even by a +# driver bug: the bucket refuses them, not just the staging rule. diff --git a/contrib/reprobuild/smoke.sh b/contrib/reprobuild/smoke.sh new file mode 100644 index 000000000000..5ac977ea0ba5 --- /dev/null +++ b/contrib/reprobuild/smoke.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# Runtime smoke test of a static tarball on a foreign distro (16, 22), run by +# portability.sh: +# docker run --rm -v :/cln:ro \ +# -v $PWD/contrib/reprobuild/smoke.sh:/smoke.sh:ro debian:bookworm-slim sh /smoke.sh +# Runs inside a bare debian:bookworm-slim with the extracted tree at /cln. +set -u +cp -a /cln/. / || exit 1 +# Found on PATH, not at a fixed path: the install prefix is the release's +# business, and this script should not be a second place that has to know it. +lightningd_bin=$(command -v lightningd) || { echo "lightningd not on PATH after unpacking" >&2; exit 1; } +echo "=== ldd (expect: not a dynamic executable / static-pie)" +ldd "$lightningd_bin" 2>&1 | head -2 +echo "=== --version" +lightningd --version +lightning-cli --version +echo "=== regtest start without bitcoind (expect: bcli fails to reach bitcoin-cli, lightningd exits)" +mkdir -p /tmp/ln +# Through a file, not a pipe: `cmd | tail` would make $? tail's status, so +# the exit code reported here would always be tail's 0 and this check would +# pass however lightningd died. POSIX sh has no PIPESTATUS. +timeout 60 lightningd --network=regtest --lightning-dir=/tmp/ln --log-level=info --disable-plugin=clnrest > /tmp/ln/start.log 2>&1 +rc=$? +tail -25 /tmp/ln/start.log +echo "lightningd exit=$rc" +echo "=== plugin manifest handshake: every plugin must answer getmanifest (static Rust included)" +plugin_dir=$(dirname "$(dirname "$lightningd_bin")")/libexec/c-lightning/plugins +req='{"jsonrpc":"2.0","id":"cln:getmanifest#0","method":"getmanifest","params":{"allow-deprecated-apis":false}}' +# All plugins at once. stdin stays open until the reply is in (a plugin that +# sees EOF right after the request exits 0 without answering), and closes as +# soon as it is: under qemu every plugin answers in about a second, so a fixed +# wait per plugin was nearly all of this test's run time. +handshake() { + out=/tmp/manifest.$(basename "$1") + : > "$out" + # The feeder polls the file the plugin writes, on purpose. + # shellcheck disable=SC2094 + { + printf '%s\n\n' "$req" + i=0 + while [ $i -lt 200 ] && ! grep -q '"result"' "$out"; do + sleep 0.1 + i=$((i + 1)) + done + } | timeout 25 "$1" > "$out" 2>/dev/null +} +for p in "$plugin_dir"/*; do handshake "$p" & done +wait +for p in "$plugin_dir"/*; do + out=/tmp/manifest.$(basename "$p") + if grep -q '"result"' "$out"; then + echo "ok $(basename "$p")" + else + got=$(head -c 200 "$out" | tr -d '\n') + echo "FAIL $(basename "$p"): ${got:-no output}" + fi +done diff --git a/contrib/reprobuild/two-tree-probe.sh b/contrib/reprobuild/two-tree-probe.sh new file mode 100755 index 000000000000..ec2c05af154b --- /dev/null +++ b/contrib/reprobuild/two-tree-probe.sh @@ -0,0 +1,104 @@ +#! /bin/sh +# The two-tree probe, for one row. +# +# contrib/reprobuild/two-tree-probe.sh [--arch=amd64] [--jobs=N] [--host-nix] +# +# Build the same row from two trees that differ **only** by one tracked file +# that is never compiled and never shipped, and require identical bytes. +# +# Why this and not a string check: the first proposal was "zero /nix/store +# references" as the invariant, and 40 retired it as both unreachable +# (lightningd keeps 8 OpenSSL store-path strings deliberately) and insufficient +# -- a variant whose bytes tracked the tree carried no offending string at all, +# because the path reached the bytes through gcc's `-frandom-seed` and +# `DW_AT_producer`, which `--strip-all` then deletes while keeping the +# consequence. Only rebuilding from a second tree can see that. +# +# This runs on **every** row rather than one: an amd64-only probe +# was amd64-only, and the armhf Rust binaries were separately carrying a +# DT_RUNPATH naming their output path -- invisible on the row that was checked. +# +# It costs two builds of one row, so it belongs in `certify`'s acceptance suite +# rather than in every release. The probe commits are made on a throwaway +# branch and removed afterwards; the tree is left as it was found. +set -eu + +top=$(cd "$(dirname "$0")/../.." && pwd) +ARCH=amd64 +JOBS=$(nproc 2>/dev/null || echo 4) +HOST_NIX= +for arg; do + case "$arg" in + --arch=*) ARCH=${arg#*=} ;; + --jobs=*) JOBS=${arg#*=} ;; + --host-nix) HOST_NIX=--host-nix ;; + *) echo "unknown arg $arg" >&2; exit 1 ;; + esac +done + +[ -z "$(git -C "$top" status --porcelain --untracked-files=no)" ] || + { echo "two-tree-probe: commit first; this makes commits of its own" >&2; exit 1; } + +start_branch=$(git -C "$top" rev-parse --abbrev-ref HEAD) +start_rev=$(git -C "$top" rev-parse HEAD) +probe=probe/two-tree-$$ +out=${TMPDIR:-/tmp}/two-tree-probe.$$ +mkdir -p "$out" + +# Invoked by the trap below, which shellcheck does not count as a use (SC2329 +# in 0.11, SC2317 in 0.9/0.10). +# shellcheck disable=SC2329,SC2317 +cleanup() { + git -C "$top" checkout -q "$start_branch" 2>/dev/null || + git -C "$top" checkout -q "$start_rev" 2>/dev/null + git -C "$top" branch -qD "$probe" 2>/dev/null + rm -f "$top/TWO-TREE-PROBE.md" + rm -rf "$out" +} +trap cleanup EXIT INT TERM + +echo "two-tree-probe: $ARCH, from $start_rev on a throwaway branch" +git -C "$top" checkout -q -b "$probe" + +build() { + label=$1 + "$top/tools/reprobuild" $HOST_NIX --jobs="$JOBS" \ + --version=probe --mtime=2020-01-01 --out="$out/$label" build "$ARCH" \ + > "$out/$label.log" 2>&1 || { + echo "two-tree-probe: build $label FAILED" >&2 + tail -n 20 "$out/$label.log" >&2 + exit 1 + } + sha256sum "$out/$label/clightning-probe-static-$ARCH.tar.xz" | cut -d' ' -f1 +} + +# Tree A: the commit under test, plus the probe file with one value. Both +# builds carry the file, so what differs between them is only its *contents* -- +# a file that no compiler reads and no artifact contains. +printf 'probe A\n' > "$top/TWO-TREE-PROBE.md" +git -C "$top" add TWO-TREE-PROBE.md +git -C "$top" -c user.name=probe -c user.email=probe@localhost \ + commit -q -m "probe A" +a=$(build A) +echo "two-tree-probe: A $a" + +printf 'probe B -- one tracked, unshipped, uncompiled file, different bytes\n' \ + > "$top/TWO-TREE-PROBE.md" +git -C "$top" add TWO-TREE-PROBE.md +git -C "$top" -c user.name=probe -c user.email=probe@localhost \ + commit -q -m "probe B" +b=$(build B) +echo "two-tree-probe: B $b" + +echo "---" +if [ "$a" = "$b" ]; then + echo "two-tree-probe: OK ($ARCH) -- the release bytes do not track the tree" + exit 0 +fi +echo "two-tree-probe: FAILED ($ARCH) -- the bytes track the tree" >&2 +echo " A $a" >&2 +echo " B $b" >&2 +echo " Something in the build reads a path that moves with the source: check" >&2 +echo " build-ids first (nixpkgs seeds -frandom-seed from \$out), then rpaths," >&2 +echo " then panic-location strings in the Rust artifacts (40, 47)." >&2 +exit 1 diff --git a/contrib/reprobuild/vls-check.sh b/contrib/reprobuild/vls-check.sh new file mode 100755 index 000000000000..611856f8c319 --- /dev/null +++ b/contrib/reprobuild/vls-check.sh @@ -0,0 +1,105 @@ +#!/bin/sh +# check.sh's assertions for the VLS signer binary. VLS is deferred from the +# release, so this runs only when the `vls` verb is used directly, and it +# is part of the gate for bringing VLS back. +# +# contrib/reprobuild/vls-check.sh release/remote_hsmd_socket-v0.14.0- +# +# Same three assertions as the tarball check -- the strip, static-pie and +# the build-id -- plus the two +# things that are specific to this artifact: +# +# * it is *run*, under the closure's own qemu on a cross row, so the claim +# is "this binary works on that arch" and not "it links". The smoke +# test lives outside the derivation so it can be run here. +# smoke test outside the derivation precisely so it could be run here. +# * `--git-desc` has to name the pinned commit. vls-util/build.rs bakes +# `git describe` into the binary, and a fixed-output source fetch has no +# `.git`; without the shim in nix/pkgs/vls.nix every VLS we ship would +# report the literal `git-desc-failed`. This is the assertion that the +# shim is still doing its job. +set -eu + +bin=${1:?usage: vls-check.sh } +top=$(cd "$(dirname "$0")/../.." && pwd) + +[ "$(head -c 4 "$bin" | od -An -tx1 | tr -d ' \n')" = "7f454c46" ] || + { echo "CHECK FAILED: $bin is not an ELF" >&2; exit 1; } + +bad=0 +sections=$(readelf -SW "$bin") +hdr=$(readelf -hW "$bin") +notes=$(readelf -nW "$bin") + +if printf '%s' "$sections" | grep -qE '\.symtab|\.debug_'; then + echo "FAIL carries .symtab/.debug_*"; bad=$((bad + 1)) +fi +if ! printf '%s' "$hdr" | grep -q 'Type:[[:space:]]*DYN'; then + echo "FAIL not position-independent"; bad=$((bad + 1)) +fi +if ! printf '%s' "$notes" | grep -q 'Build ID'; then + echo "FAIL no build-id"; bad=$((bad + 1)) +fi +if readelf -lW "$bin" | grep -q 'INTERP'; then + echo "FAIL has a PT_INTERP (dynamically linked)"; bad=$((bad + 1)) +fi + +machine=$(printf '%s' "$hdr" | sed -n 's/^ *Machine: *//p') +case "$machine" in +*X86-64*) emu=; qemu= ;; +# The oldest Raspberry Pi each arm row must run on (nix/release-rows). +*AArch64*) qemu="qemu-aarch64" cpu=cortex-a53 ;; +*ARM*) + qemu="qemu-arm" cpu=cortex-a7 + echo "--- ARM build attributes" + readelf -A "$bin" | + grep -E 'Tag_CPU_arch|Tag_FP_arch|Tag_ABI_VFP_args|Tag_Advanced_SIMD|Tag_CPU_name' || true + ;; +*) echo "FAIL unexpected machine: $machine"; bad=$((bad + 1)); qemu= ;; +esac + +if [ -n "${qemu:-}" ]; then + # The emulator comes from the *pinned* nixpkgs, not the host: + # made the same choice inside the derivation, because a build (or a + # check) must not depend on how the captain's kernel registered binfmt. + qemudir=$(nix --extra-experimental-features 'nix-command flakes' build --impure \ + --no-link --print-out-paths --expr \ + "(import (builtins.getFlake \"git+file://$top?submodules=1\").inputs.nixpkgs { system = \"x86_64-linux\"; }).qemu" | + head -1) + emu="$qemudir/bin/$qemu -cpu $cpu" + [ -x "$qemudir/bin/$qemu" ] || { echo "CHECK FAILED: no $qemu in $qemudir" >&2; exit 1; } +fi + +echo "--- run" +desc=$($emu "$bin" --git-desc 2>&1) || { + echo "FAIL could not run $bin${emu:+ under $emu}: $desc" + bad=$((bad + 1)) + desc= +} +echo " $desc" +case "$desc" in +*git-desc-failed* | *git-desc-error* | *git-desc-badstr*) + echo "FAIL GIT_DESC is the build.rs fallback -- the git shim is not working" + bad=$((bad + 1)) + ;; +"remote_hsmd_socket git_desc=v"*) + rev=$(sed -n 's/^ *rev = "\([0-9a-f]*\)";.*/\1/p' "$top/nix/pkgs/vls.nix") + short=$(printf '%s' "$rev" | cut -c1-12) + case "$desc" in + *"-g$short") ;; + *) echo "FAIL GIT_DESC does not name the pinned rev $short"; bad=$((bad + 1)) ;; + esac + ;; +"") ;; +*) echo "FAIL unexpected --git-desc output"; bad=$((bad + 1)) ;; +esac + +echo "---" +echo "size: $(stat -c %s "$bin") bytes" +echo "sha256: $(sha256sum "$bin" | cut -c1-64)" +echo "build-id: $(printf '%s' "$notes" | sed -n 's/.*Build ID: //p')" +if [ "$bad" != 0 ]; then + echo "CHECK FAILED: $bad problem(s)" >&2 + exit 1 +fi +echo "check: OK (static-pie, stripped, build-id, runs, names the pinned rev)" diff --git a/contrib/reprobuild/vls-regtest.sh b/contrib/reprobuild/vls-regtest.sh new file mode 100755 index 000000000000..735936be9dd8 --- /dev/null +++ b/contrib/reprobuild/vls-regtest.sh @@ -0,0 +1,212 @@ +#! /bin/sh +# The CLN-VLS pair, on regtest (research 14; runs it every +# release). This is the one test that exercises the *pair* rather than either +# binary alone, and it is why the driver builds a test-only `vlsd`: +# `remote_hsmd_socket` is CLN's hsmd replacement and does nothing by itself but +# listen on port 7701 for a signer to connect. +# +# contrib/reprobuild/vls-regtest.sh --tarball= \ +# --signer= --vlsd=/bin/vlsd \ +# --bitcoin=/bin +# +# It is deliberately outside the derivation: it needs bitcoind, a +# writable directory and several minutes, none of which belong in a build. +# `tools/reprobuild` supplies the paths -- vlsd and bitcoind from the certified +# nixpkgs, so the test does not depend on what the host happens to have +# installed. +# +# Native row only. The released lightningd for a cross row runs under the +# host's binfmt in the portability harness; asking a qemu-emulated node and +# signer to complete a channel open would be testing the emulator. +# +# What it asserts, in order of what it would catch: +# * lightningd comes up *at all* with the signer as hsmd -- the version +# handshake (`VLS_CLN_VERSION`) is checked by VLS itself, and research 14 +# recorded v0.14.0 against CLN 25.12+/26.x as untested upstream; +# * `getinfo` returns a node id: the node key came from the signer; +# * `newaddr` and `signmessage` succeed: two more signer round trips; +# * the signer logged no policy failure. +set -eu + +TARBALL= +SIGNER= +VLSD= +BITCOIN_BIN= +KEEP=0 +TIMEOUT=300 +for arg; do + case "$arg" in + --tarball=*) TARBALL=${arg#*=} ;; + --signer=*) SIGNER=${arg#*=} ;; + --vlsd=*) VLSD=${arg#*=} ;; + --bitcoin=*) BITCOIN_BIN=${arg#*=} ;; + --keep) KEEP=1 ;; + --timeout=*) TIMEOUT=${arg#*=} ;; + *) echo "unknown arg $arg" >&2; exit 1 ;; + esac +done +for v in TARBALL SIGNER VLSD BITCOIN_BIN; do + eval "val=\$$v" + [ -n "$val" ] || { echo "vls-regtest: --$(echo "$v" | tr 'A-Z_' 'a-z-') is required" >&2; exit 1; } +done +[ -f "$TARBALL" ] || { echo "vls-regtest: no $TARBALL" >&2; exit 1; } +[ -x "$SIGNER" ] || { echo "vls-regtest: no $SIGNER" >&2; exit 1; } +[ -x "$VLSD" ] || { echo "vls-regtest: no $VLSD" >&2; exit 1; } + +tmp=$(mktemp -d) +# Ports are derived from the pid rather than fixed: bitcoind is started +# detached, so a run that dies before its cleanup (the first one here did, +# on a vlsd panic) leaves a daemon holding the port and every later run +# fails at startup with nothing but "Error during initialization". +RPCPORT=$((18000 + $$ % 1000)) +LNPORT=$((19000 + $$ % 1000)) +VLS_PORT=$((7700 + $$ % 100)) +# The signer panics unless BITCOIND_RPC_URL, VLS_NETWORK and VLS_CLN_VERSION +# are all set (vls-proxy/src/util/env_var.rs), and lightningd -- which only +# sees an hsmd that never answers -- then hangs with no error of its own. The +# released -vls image was missing two of the three. +VLS_NETWORK=regtest +export VLS_PORT VLS_NETWORK +# Set once the RPC port is known, below. +BITCOIND_RPC_URL= +export BITCOIND_RPC_URL + +cleanup() { + [ -n "${LN_PID:-}" ] && kill "$LN_PID" 2>/dev/null + [ -n "${VLSD_PID:-}" ] && kill "$VLSD_PID" 2>/dev/null + # bitcoind is detached, so ask it to stop rather than killing a pid that + # is not ours; fall back to the pid if the RPC is already gone. + "$BITCOIN_BIN/bitcoin-cli" -datadir="$tmp/btc" stop >/dev/null 2>&1 || + { [ -n "${BTC_PID:-}" ] && kill "$BTC_PID" 2>/dev/null; } + sleep 2 + if [ "$KEEP" = 1 ]; then + echo "vls-regtest: kept $tmp" + return + fi + chmod -R u+w "$tmp" 2>/dev/null + rm -rf "$tmp" +} +trap cleanup EXIT INT TERM + +echo "vls-regtest: $(basename "$TARBALL") + $(basename "$SIGNER")" +# `--integration-test` makes vlsd keep its own hsm_secret (in VLS deployments +# the signer holds the key, and CLN's hsmd only proxies), at +# /..//hsm_secret -- a sibling of the datadir that it does +# not create itself. +mkdir -p "$tmp/tree" "$tmp/ln" "$tmp/vls" "$tmp/btc" "$tmp/regtest" +tar -xf "$TARBALL" -C "$tmp/tree" +# Located, not spelled out: the install prefix belongs to the release +# derivation, not to this harness. +LIGHTNINGD=$(find "$tmp/tree" -type f -name lightningd | head -1) +CLI=$(find "$tmp/tree" -type f -name lightning-cli | head -1) +if [ -z "$LIGHTNINGD" ] || [ -z "$CLI" ]; then + echo "vls-regtest: no lightningd/lightning-cli in the tarball" >&2 + exit 1 +fi +[ -x "$LIGHTNINGD" ] || { echo "vls-regtest: the tarball has no usr/bin/lightningd" >&2; exit 1; } + +# --- bitcoind --------------------------------------------------------------- +cat > "$tmp/btc/bitcoin.conf" </dev/null +BTC_PID=$(pgrep -n -f "bitcoind -datadir=$tmp/btc" || true) +BITCOIND_RPC_URL="http://repro:repro@127.0.0.1:$RPCPORT" +echo "vls-regtest: bitcoind rpc $RPCPORT, signer port $VLS_PORT" +btccli() { "$BITCOIN_BIN/bitcoin-cli" -datadir="$tmp/btc" -rpcwait "$@"; } +btccli createwallet repro >/dev/null 2>&1 || btccli loadwallet repro >/dev/null 2>&1 || true +addr=$(btccli getnewaddress) +btccli generatetoaddress 101 "$addr" >/dev/null +echo "vls-regtest: bitcoind at height $(btccli getblockcount)" + +# --- the signer ------------------------------------------------------------- +# +# VLS refuses to sign for a node whose version it was not told about, so +# VLS_CLN_VERSION must equal exactly what this lightningd reports (research +# 14; the -vls image bakes the same value). Reading it off the binary under +# test is the point: a stale constant would pass while the pair was wrong. +CLN_VERSION=$("$LIGHTNINGD" --version) +echo "vls-regtest: lightningd $CLN_VERSION, signer $("$SIGNER" --git-desc)" + +( cd "$tmp/vls" && VLS_CLN_VERSION="$CLN_VERSION" "$VLSD" \ + --connect "http://127.0.0.1:$VLS_PORT" --network regtest \ + --integration-test --datadir "$tmp/vls" --log-level info \ + > "$tmp/vlsd.log" 2>&1 ) & +VLSD_PID=$! + +# --- lightningd, with the signer as hsmd ------------------------------------ +VLS_CLN_VERSION="$CLN_VERSION" "$LIGHTNINGD" \ + --network=regtest --lightning-dir="$tmp/ln" \ + --bitcoin-rpcuser=repro --bitcoin-rpcpassword=repro \ + --bitcoin-rpcconnect=127.0.0.1 --bitcoin-rpcport="$RPCPORT" \ + --subdaemon=hsmd:"$SIGNER" \ + --log-level=debug --log-file="$tmp/ln/log" \ + --addr=127.0.0.1:"$LNPORT" & +LN_PID=$! + +ok=0 +waited=0 +while [ "$waited" -lt "$TIMEOUT" ]; do + waited=$((waited + 2)) + if "$CLI" --lightning-dir="$tmp/ln" --network=regtest getinfo > "$tmp/getinfo" 2>/dev/null; then + ok=1 + break + fi + kill -0 "$LN_PID" 2>/dev/null || break + sleep 2 +done + +fail=0 +if [ "$ok" != 1 ]; then + echo "FAIL lightningd never answered getinfo with the VLS signer as hsmd" + echo "--- lightningd log (tail)"; tail -n 40 "$tmp/ln/log" 2>/dev/null + echo "--- vlsd log (tail)"; tail -n 40 "$tmp/vlsd.log" 2>/dev/null + exit 1 +fi + +nodeid=$(sed -n 's/.*"id"[ ]*:[ ]*"\([0-9a-f]\{66\}\)".*/\1/p' "$tmp/getinfo" | head -1) +if [ -n "$nodeid" ]; then + echo "ok node id from the signer: $nodeid" +else + echo "FAIL getinfo returned no node id"; fail=1 +fi + +if "$CLI" --lightning-dir="$tmp/ln" --network=regtest newaddr >/dev/null 2>&1; then + echo "ok newaddr (signer derived a key)" +else + echo "FAIL newaddr"; fail=1 +fi + +if "$CLI" --lightning-dir="$tmp/ln" --network=regtest \ + signmessage "reprobuild" > "$tmp/signmessage" 2>/dev/null; then + echo "ok signmessage (signer signed): $(sed -n 's/.*"zbase"[ ]*:[ ]*"\([^"]*\)".*/\1/p' "$tmp/signmessage" | cut -c1-24)..." +else + echo "FAIL signmessage"; fail=1 +fi + +# A policy violation is how VLS refuses; it is not an lightningd error and +# would otherwise pass unnoticed. +if grep -qiE "policy failure|VLS_.*mismatch|refus" "$tmp/vlsd.log"; then + echo "FAIL the signer logged a refusal:" + grep -iE "policy failure|VLS_.*mismatch|refus" "$tmp/vlsd.log" | head -5 | sed 's/^/ /' + fail=1 +fi + +echo "---" +if [ "$fail" != 0 ]; then + echo "vls-regtest: FAILED ($fail problem(s))" >&2 + exit 1 +fi +echo "vls-regtest: OK (the released signer signed for the released node)" diff --git a/doc/Makefile b/doc/Makefile index 2775eb1c9c49..a7c2a1dbc5ed 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -205,7 +205,7 @@ OLD_MARKDOWNPAGES_WITH_EXT := $(PREFIXED_MANPAGES:=.md) # - Generate the tables schema via plugins/sql # - Merge both and generate final schemas/sql.json doc/schemas/sql.json: doc/schemas/sql-template.json plugins/sql - @plugins/sql --print-docs | jq --arg sqldata "$$(awk '{printf "%s\n", $$0}')" '.tables += [$$sqldata]' $< > "$@.tmp" && mv "$@.tmp" "$@"; + @$(CONFIGURATOR_WRAPPER) plugins/sql --print-docs | jq --arg sqldata "$$(awk '{printf "%s\n", $$0}')" '.tables += [$$sqldata]' $< > "$@.tmp" && mv "$@.tmp" "$@"; doc-all: $(MANPAGES) doc/index.rst diff --git a/doc/contribute-to-core-lightning/docker-images.md b/doc/contribute-to-core-lightning/docker-images.md index 99e1bf1211a1..4fd219cff53d 100644 --- a/doc/contribute-to-core-lightning/docker-images.md +++ b/doc/contribute-to-core-lightning/docker-images.md @@ -75,11 +75,35 @@ Platforms: linux/amd64, linux/amd64/v2, linux/amd64/v3, linux/amd64/v4, linux/38 ``` # Building/publishing images on Dockerhub -1. Ensure that your multiarch setup is working -2. Run script `tools/build-release.sh --push docker` to build `amd64`, `arm64v8`, `latest` and `multiarch` images and publish them on Dockerhub. +Release images are built and published by the release driver, from the same +static tarballs the release signs — the image compiles nothing: -3. If you do not want to push the images directly on Dockerhub then run `tools/build-release.sh docker`. It will only create images locally but not push them to Dockerhub. +1. Ensure that your multiarch setup is working (the driver smoke-tests every + platform of the image under `binfmt` before it is published). + +2. `tools/reprobuild docker` builds one multi-arch image into a local OCI layout + under `release/docker/` and logs its per-architecture digests. Nothing is + pushed, and the digests are not signed — see below. + +3. `tools/reprobuild publish` pushes it, with `skopeo copy --all + --preserve-digests`, so what users pull is what was built and smoke-tested + rather than a recompressed copy. Before pushing it checks the layout's own + OCI labels, so a layout left over from another release or another commit is + refused. Add `--latest` to also move the `latest` tag; it is never implied and + never applied to an rc. + +The image digests are deliberately **not** part of the signed manifests. The +image has one unpinned, network-touching input — the `apt-get install` of the +entrypoint's runtime dependencies — so a third party cannot rebuild it later and +arrive at the same digest, and a signature over a hash nobody can re-derive +would claim more than it can support. What is attested is stronger and sits one +level down: the release tarballs are built from source under Nix, reproduce +byte-for-byte, and carry three signatures, and the image is built from those +signed bytes. + +See the [release checklist](https://docs.corelightning.org/docs/release-checklist) +for where those steps sit in a release. # Miscellaneous @@ -96,26 +120,20 @@ The Core Lightning (CLN) Docker image (platforms: `linux/amd64`, `linux/arm64`, docker run -it --rm --platform=linux/amd64 --network=host -v '/root/.lightning:/root/.lightning' -v '/root/.bitcoin:/root/.bitcoin' elementsproject/lightningd:latest --network=regtest ``` -## Test repro Dockerfiles and repro-build.sh: -1. Once the `cl-repro-` builder image is created, you can run it with: - -```shell -docker run -it -v $(pwd):/repo cl-repro-noble /bin/bash -``` - -2. Get the Docker container ID of the above container using: - -```shell -docker container ps -``` +## Testing the reproducible build -3. Start a shell in the container with: +There are no `cl-repro-` builder images any more: the release is built +by a Nix derivation inside a digest-pinned `nixos/nix` container, and +`tools/reprobuild` is the only entry point. To poke at the build environment: ```shell -docker exec -it bash +tools/reprobuild build amd64 # one row +tools/reprobuild build amd64 --rebuild # and have Nix prove it reproduces ``` -4. You can now run `. tools/repro-build.sh` with `--force-version` and `--force-mtime` arguments as needed. +`--host-nix` uses your own Nix instead of the container, which is faster if you +have one. See the [reproducible builds +page](https://docs.corelightning.org/docs/repro) for the full flow. ## Execute other scripts for testing: @@ -162,7 +180,15 @@ export RUST_BACKTRACE=1 4. Finally, run the Core Lightning node: -4.1 Either by utilizing our docker image flavor `elementsproject/lightningd:v25.12-vls` which comes with pre-built `remote_hsmd_socket` binaries. +> 🚧 The `-vls` image flavour is not published at the moment +> +> Core Lightning offers channel splicing by default and refuses to start with a +> signer that cannot sign splice transactions, which no released VLS does yet. +> The `-vls` image and the released `remote_hsmd_socket` binaries are therefore +> suspended — 4.1 below describes how they work and will work again, but for now +> use 4.2 with a signer you built yourself. + +4.1 Either by utilizing our docker image flavor `elementsproject/lightningd:v25.12-vls` which comes with pre-built `remote_hsmd_socket` binaries. The image sets `VLS_ENABLED`, `VLS_CLN_VERSION` and the network for you; you still have to pass `BITCOIND_RPC_URL`, because the signer validates against the chain itself and its bitcoind need not be the node's. ```shell docker run -it --rm -d \ diff --git a/doc/contribute-to-core-lightning/release-checklist.md b/doc/contribute-to-core-lightning/release-checklist.md index b669bc67851f..caf63fe233bf 100644 --- a/doc/contribute-to-core-lightning/release-checklist.md +++ b/doc/contribute-to-core-lightning/release-checklist.md @@ -22,7 +22,7 @@ Here's a checklist for the release process. 2. Use `devtools/changelog.py` to collect the changelog entries from pull request commit messages and merge them into the manually maintained `CHANGELOG.md`. This does API queries to GitHub, which are severely ratelimited unless you use an API token: set the `GH_TOKEN` environment variable to a Personal Access Token from https://github.com/settings/tokens 3. Check that `CHANGELOG.md` is well formatted, ordered in areas, covers all significant changes, and sub-ordered approximately by user impact & coolness. 4. Manually remove any entries which were mentioned for in the previous point releases (they will be duplicates!) -5. Create a new CHANGELOG.md heading to `vrc1`, and create a link at the bottom. Note that you should exactly copy the date and name format from a previous release, as the `build-release.sh` script relies on this. +5. Create a new CHANGELOG.md heading to `vrc1`, and create a link at the bottom. Note that you should exactly copy the date and name format from a previous release, as the release tooling parses the date from it. 6. Update the package versions: `uv run make update-versions NEW_VERSION=vrc1` 7. Create a PR with the above. @@ -31,16 +31,32 @@ Here's a checklist for the release process. 1. Merge the above PR. 2. Tag it `git pull && git tag -s vrc1`. Note that you should get a prompt to give this tag a 'message'. Make sure you fill this in. 3. Confirm that the tag will show up for builds with `git describe`. We don't push it to GitHub yet, just in case the following steps fail, and more fixes are required! -4. Run `contrib/cl-repro.sh` to generate the required `cl-repro-` builder images for the reproducible build environment. -5. Execute `tools/build-release.sh bin-Fedora bin-Ubuntu sign` to locally reproduce the release, generating a matching `SHA256SUMS-v` file and signing it with your GPG key. -6. Push the tag to trigger the "Release 🚀" CI action, which drafts a new `vrc1` pre-release on GitHub and uploads reproducible builds alongside the `SHA256SUMS-v` file and its signature from the `cln@blockstream.com` key. The arm64 and armv7 tarballs each come with their own manifest, `SHA256SUMS-v-arm64` and `SHA256SUMS-v-armv7`, and its `.asc`. The CI never replaces a file already on the release: re-running it only adds missing files, and appends its signature to an `.asc` that already has yours. -7. Verify your local `SHA256SUMS-v` file matches the one in the draft release, then append your local signatures to the release's `SHA256SUMS-v.asc` file to attest to the build's integrity. +4. Build and sign the release locally: `tools/reprobuild all`. This is the whole + build — three static tarballs, the source zip, the multi-arch image and both + signed manifests — and it needs only docker, coreutils and python3. Every rc is a + rehearsal of the release flow, so do not skip it. The signing key has to answer + before the build starts, so that an hour of building cannot end on a key nobody + can reach. If you would rather not sit next to the machine for that hour, add + `--wait-for-key`: the build then runs unattended and waits (30 minutes by + default, `--wait-for-key=SECONDS` to change it) once it has something to sign, + so you only need to plug in and unlock the smartcard at the end. It polls the + key rather than waiting for a keypress, so this works for a detached run whose + log you are tailing. +5. Publish the rc: `tools/reprobuild publish`. That is the whole publication — + tarballs, manifests, signatures and the source zip to the download host, the + multi-arch image to Docker Hub, the tag to GitHub, and the GitHub release. + `latest` is never applied to an rc. **The "Release 🚀" workflow must be + disabled** (`gh workflow disable "Release 🚀"`): pushing a tag would publish + the pyln modules on its own schedule, and `publish` refuses while it is + enabled. Re-enable it afterwards. 8. Announce rc1 release on core-lightning's release-chat channel on Discord & Telegram. 9. Use `devtools/credit --markdown v` to generate a single contributor list for the release notes. Use `devtools/credit --verbose v` for namer selection and detailed annotations. 10. Prepare release notes draft including the contributor list from above, and share with the team for editing. 11. Upgrade your personal nodes to the rc1, to help testing. 12. Github action `Publish Python 🐍 distributions 📦 to PyPI and TestPyPI` uploads the pyln modules on test PyPI server. Make sure that the action has been triggered with RC tag and that the modules have been published on `https://test.pypi.org/project/pyln-*/#history`. -13. Docker image publishing is handled by the GitHub action `Build and push multi-platform docker images`. Ensure that this action is triggered and that the RC image has been successfully uploaded to Docker Hub after the action completes. Alternatively, you can publish Docker images by running the `tools/build-release.sh docker` script. The GitHub action takes approximately 3-4 hours, while the script takes about 6-7 hours. It is highly recommended to test your Docker setup if you haven't done so before. Prior to building docker images by `tools/build-release.sh` script, ensure that `multiarch/qemu-user-static` setup is working on your system as described [here](https://docs.corelightning.org/docs/docker-images#setting-up-multiarchqemu-user-static). +13. The rc's Docker images were published in step 5 by `tools/reprobuild + publish`, which pushes one multi-arch image built from the same tarballs + that were signed. There is nothing to trigger in CI. ## Releasing -rc2, ..., -rcN @@ -48,13 +64,14 @@ Here's a checklist for the release process. 2. Update the package versions: `uv run make update-versions NEW_VERSION=vrcN` 3. Add a PR with the rcN, and merge it. 4. Tag it `git pull && git tag -s vrcN && git push origin vrcN`. -5. Pushing the tag automatically starts the "Release 🚀" CI job, creating a draft pre-release and uploading reproducible builds with their `SHA256SUMS` files signed by the project key. -6. Set up the reproducible build environment by running the script `contrib/cl-repro.sh` to generate the necessary builder images. -7. Use the command `tools/build-release.sh bin-Fedora bin-Ubuntu sign` to locally rebuild the release and generate a personal signature file for the checksums. -8. After confirming the local and pre-release `SHA256SUMS-v` files match, append your signatures to the pre-release's `SHA256SUMS-v.asc` file to formally attest to the build's validity. +5. Build, sign and publish as for rc1: `tools/reprobuild all`, then + `tools/reprobuild publish`. +6. Co-signers rebuild with `tools/reprobuild verify SHA256SUMS-vrcN` and + send you their signatures; append them to the manifest's `.asc`. 9. Announce tagged rc release on core-lightning's release-chat channel on Discord & Telegram. 10. Upgrade your personal nodes to the rcN. -11. Confirm that Github actions for PyPI and Docker publishing are working as expected. +11. Confirm the PyPI action worked as expected. Docker images are published by + `tools/reprobuild publish`, not by CI. ## Tagging the Release @@ -66,34 +83,52 @@ Here's a checklist for the release process. - Set the current release version in your shell (e.g., if the current release is `v26.04`): `VERSION=26.04` - Create a signed, annotated tag: `git tag -a -s v$VERSION -m "v$VERSION"` - Push the tag: `git push origin v$VERSION` -5. Pushing the tag will trigger the CI pipeline, which will draft the pre-release and upload the build artifacts with project-signed checksums. -6. Prepare the build environments by executing the `contrib/cl-repro.sh` script. -7. Run `tools/build-release.sh bin-Fedora bin-Ubuntu sign` (with `--sudo` if you need root to run Docker) to: - - Create reproducible zipfile - - Build reproducible Fedora image - - Build reproducible Ubuntu-v22.04, Ubuntu-v24.04 and Ubuntu-v26.04 images. Follow [link](https://docs.corelightning.org/docs/repro#building-using-the-builder-image) for manually Building Ubuntu Images. - - Build Docker images for amd64 and arm64v8. Follow [link](https://docs.corelightning.org/docs/docker-images) for more details on Docker publishing. - - Create and sign checksums. Follow [link](https://docs.corelightning.org/docs/repro#co-signing-the-release-manifest) for manually signing the release. -8. If you used `--sudo`, the tarballs may be owned by root, so revert ownership if necessary: `sudo chown ${USER}:${USER} *${VERSION}*` -9. Verify the checksums match the pre-release `SHA256SUMS-v`, then append your signatures to the official signature `SHA256SUMS-v.asc` file to confirm the build's integrity. -10. Send `SHA256SUMS-v` & `SHA256SUMS-v.asc` files to the rest of the team to check and sign the release. -11. Team members can verify the release with the help of `build-release.sh`: - - Copy the release captain's `SHA256SUMS-v` and `SHA256SUMS-v.asc` into the root folder (`lightning`). - - Run `tools/build-release.sh --verify`. It will create reproducible images, verify checksums and sign. - - Send your signatures from `release/SHA256SUMS-v.asc` to release captain. - - Or follow [link](https://docs.corelightning.org/docs/repro#verifying-a-reproducible-build) for manual verification instructions. -12. Append signatures shared by the team into the `SHA256SUMS-v.asc` file, verify with `gpg --verify SHA256SUMS-v.asc SHA256SUMS-v` (always pass the manifest as the second argument, otherwise `gpg` may verify a payload embedded in the `.asc` and exit successfully without ever reading the checksums) and include the file in the draft release. +5. Do **not** push the tag by hand: `tools/reprobuild publish` pushes it, last, + once everything else has gone out and been verified. Confirm the + "Release 🚀" workflow is disabled. +6. Build and sign everything: `tools/reprobuild all`. It ends with + `SHA256SUMS-v`, signed with your key. The build takes 1–2 hours for + all three rows. +7. Send the manifest and your signature to the co-signers. They run + `tools/reprobuild verify SHA256SUMS-v` — which rebuilds from the + commit and timestamp the manifest names — and send back + `SHA256SUMS-v.asc.`. +8. Append their signatures to `SHA256SUMS-v.asc` and check the result + with `gpg --verify SHA256SUMS-v.asc SHA256SUMS-v` — always + pass the manifest as the second argument, or `gpg` may verify a payload + embedded in the `.asc` and exit successfully without reading the checksums. **Three good + signatures** — yours plus two co-signers', distinct keys from + `contrib/keys/` — are required before publishing; `publish` checks. The + `armhf` manifest may carry only your signature, which does not hold up the + release (see the caveat in the [reproducible builds + page](https://docs.corelightning.org/docs/repro)). +9. Publish: `tools/reprobuild publish`, or `tools/reprobuild publish --latest` + if this release should also become `latest` on Docker Hub. This uploads the + artifacts and the source zip, reads them back and checks them against the + signed manifest, pushes the images, pushes the tag and creates the GitHub + release — in that order, so the irreversible step comes last. +10. Run the acceptance suite if you have not since certifying: + `tools/reprobuild accept`. It runs the portability matrix and the two-tree + probe; `tools/reprobuild certify` is the fuller version that rebuilds + everything from source without the binary cache. 13. The GitHub action `Publish Python 🐍 distributions 📦 to PyPI and TestPyPI` should upload the pyln modules to pypi.org. However, this can also be done manually by running `uv run make pyln-release`. This process requires keys for each of the `pyln-client`, `pyln-proto`, and `pyln-testing` modules to be accessible to uv. You can set the key as an environment variable and build and publish each pyln release independently: - `export UV_PUBLISH_TOKEN=` - `uv run make pyln-release-client` - ... repeat for each pyln package with the appropriate token. -14. Publish multi-arch Docker images (`elementsproject/lightningd:v${VERSION}` and `elementsproject/lightningd:latest`) to Docker Hub either using the GitHub action `Build and push multi-platform docker images` or by running the `tools/build-release.sh docker` script. Prior to building docker images by `tools/build-release.sh` script, ensure that `multiarch/qemu-user-static` setup is working on your system as described [here](https://docs.corelightning.org/docs/docker-images#setting-up-multiarchqemu-user-static). +14. Docker images were published by `tools/reprobuild publish` in step 9; there + is nothing to trigger in CI, and the CI image workflow stays disabled. + Re-enable the "Release 🚀" workflow if the project wants it back on + (`gh workflow enable "Release 🚀"`). ## Performing the Release -1. Edit the GitHub draft and include the `SHA256SUMS-v.asc` file. -2. Publish the release as not a draft. -3. Announce the final release on core-lightning's release-chat channel on Discord & Telegram. +1. `tools/reprobuild publish` in the previous section already pushed the tag and + created the GitHub release **as a draft** — the artifacts and the tag are + public at that point, but the release page is not. Check that it reads the way + you want, publish it, and re-enable the "Release 🚀" workflow + (`gh workflow enable "Release 🚀"`) if the project wants it back on. +2. Announce the final release on core-lightning's release-chat channel on Discord & Telegram. +3. Send a mail to c-lightning mailing list (`c-lightning@lists.ozlabs.org`), using the same wording as the Release Notes in GitHub. 4. Write release blog, post it on [Blockstream](https://blog.blockstream.com/) and announce the release on Twitter. ## Post-release @@ -118,13 +153,24 @@ Here's a checklist for the release process. 5. Create a new commit that includes the updates from `update-versions` and `CHANGELOG.md`. 6. Tag the release with `git pull && git tag -s v.`. You will be prompted to enter a tag message, ensure this is filled out. 7. Confirm that the tag is properly set up for builds by running `git describe`. -8. Trigger the pre-release by pushing the version tag with `git push origin v.`; the CI will handle drafting the release and uploading the initial signed checksums, for amd64 (`SHA256SUMS-v`), arm64 (`SHA256SUMS-v-arm64`) and armv7 (`SHA256SUMS-v-armv7`). -9. Generate the required builder images by running `contrib/cl-repro.sh`. -10. Sign the release locally by running `tools/build-release.sh bin-Fedora bin-Ubuntu sign` which will sign the release contents and create `SHA256SUMS-v` and `SHA256SUMS-v.asc` in the release folder. -11. Validate that your local checksums `SHA256SUMS-v` match the Draft release's, then add your signatures to the draft release's signature `SHA256SUMS-v.asc` file. -12. Share the `SHA256SUMS-v` and `SHA256SUMS-v.asc` files with the team for verification and signing. -13. Append the signatures received from the team to the `SHA256SUMS-v.asc` file. Verify the file using `gpg --verify SHA256SUMS-v.asc SHA256SUMS-v`; the manifest must be passed as the second argument, otherwise `gpg` may verify a payload embedded in the `.asc` and exit successfully without ever reading the checksums. Then re-upload the file. +8. Do not push the tag by hand; `tools/reprobuild publish` does it. Confirm the + "Release 🚀" workflow is disabled. +9. Build and sign: `tools/reprobuild all`. +10. Send both manifests and their signatures to the co-signers, who run + `tools/reprobuild verify SHA256SUMS-v.` and send + back their detached signatures. +11. Append their signatures; three good ones from distinct committed keys are + required before publishing. Check the result with `gpg --verify + SHA256SUMS-v..asc + SHA256SUMS-v.` — the manifest must be the second + argument, or `gpg` may verify a payload embedded in the `.asc` instead. +12. `tools/reprobuild publish`. Add `--latest` only if this point release should + become `latest` on Docker Hub. It publishes the artifacts, pushes the tag and + creates the GitHub release. 14. Finalize and publish the release (change it from draft to public). -15. Ensure that the GitHub Actions for `Publish Python 🐍 distributions 📦 to PyPI and TestPyPI` and `Build and push multi-platform docker images` are functioning correctly. Check that the `PyPI` modules published on `https://pypi.org/project/pyln-*` and that the Docker image has been uploaded to Docker Hub. +15. Check that the `Publish Python 🐍 distributions 📦 to PyPI and TestPyPI` + action published the pyln modules on `https://pypi.org/project/pyln-*`, or + publish them manually with `uv run make pyln-release`. Docker images were + already pushed in step 12. 16. Create a PR to merge updates from `update-versions` and `CHANGELOG.md` into `master` to keep it up-to-date for the next release. 17. Announce the hotfix release in the core-lightning release-chat channel on Discord and on Telegram. diff --git a/doc/getting-started/advanced-setup/repro.md b/doc/getting-started/advanced-setup/repro.md index ac0579b31ef4..d7f4224ee6d4 100644 --- a/doc/getting-started/advanced-setup/repro.md +++ b/doc/getting-started/advanced-setup/repro.md @@ -6,7 +6,16 @@ privacy: --- [Reproducible builds](https://reproducible-builds.org/) close the final gap in the lifecycle of open-source projects by allowing anyone to verify that a given binary was produced by compiling publicly available source code. -Core Lightning has provided a manifest of the binaries included in a release, along with signatures from the maintainers since version 0.6.2. +Core Lightning has provided a manifest of the binaries included in a release, along with signatures from the maintainers, since version 0.6.2. + +> 🚧 Status +> +> This page documents the Nix-based build introduced on the +> `prototype/nix-static` branch, driven by `tools/reprobuild`. All three +> architectures build, reproduce under `nix build --rebuild` and pass the +> release checks, and a co-signer's `verify` has reproduced every file in +> both manifests. What has not yet run against a real key is the signing +> itself. The steps involved in creating reproducible builds are: @@ -16,105 +25,140 @@ The steps involved in creating reproducible builds are: - Creation of a manifest (`SHA256SUMS` file containing the cryptographic hashes of the binaries and packages) - Signing of the manifest by maintainers and volunteers that have reproduced the files in the manifest starting from the source. -The bulk of these operations are handled by the [`repro-build.sh`](https://github.com/ElementsProject/lightning/blob/master/tools/repro-build.sh) script, but some manual operations are required to setup the build environment. Since a binary is built against platform specific libraries we also need to replicate the steps once for each OS distribution and architecture, so the majority of this guide will describe how to set up those starting from a minimal trusted base. This minimal trusted base in most cases is the official installation medium from the OS provider. - -Note: Since your signature certifies the integrity of the resulting binaries, please familiarize yourself with both the [`repro-build.sh`](https://github.com/ElementsProject/lightning/blob/master/tools/repro-build.sh) script, as well as with the setup instructions for the build environments before signing anything. - -# Build Environment Setup - -The build environments are a set of docker images that are created directly from the installation mediums and repositories from the OS provider. The following sections describe how to create those images. Don't worry, you only have to create each image once and can then reuse the images for future builds. - -## Script cl-repro - -The script `contrib/cl-repro.sh` covers below `Base image creation` and `Builder image setup` steps. You can skip these steps by simply running the `contrib/cl-repro.sh` script. - -## Base image creation - -Depending on the distribution that we want to build for the instructions to create a base image can vary. In the following sections we discuss the specific instructions for each distribution, whereas the instructions are identical again once we have the base image. - -### Debian / Ubuntu and derivative OSs - -For operating systems derived from Debian we can use the `debootstrap` tool to build a minimal OS image, that can then be transformed into a docker image. The packages for the minimal OS image are directly downloaded from the installation repositories operated by the OS provider. - -We cannot really use the `debian` and `ubuntu` images from the docker hub, mainly because it'd be yet another trusted third party, but it is also complicated by the fact that the images have some of the packages updated. The latter means that if we disable the `updates` and `security` repositories for `apt` we find ourselves in a situation where we can't install any additional packages (wrongly updated packages depending on the versions not available in -the non-updated repos). - -The following table lists the codenames of distributions that we currently support: - -- Ubuntu 22.04: - - Distribution Version: 22.04 - - Codename: jammy -- Ubuntu 24.04: - - Distribution Version: 24.04 - - Codename: noble -- Ubuntu 26.04: - - Distribution Version: 26.04 - - Codename: resolute - -Depending on your host OS release you might not have `debootstrap` manifests for versions newer than your host OS. Due to this we run the `debootstrap` commands in a container of the latest version itself: +Note: Since your signature certifies the integrity of the resulting binaries, please familiarize yourself with the build setup before signing anything. + +# The available binaries + +Every release ships **one build per architecture**, not one per distribution. The binaries are statically linked against [musl libc](https://musl.libc.org/), so they carry no runtime dependency on the libc, OpenSSL, sqlite or libpq of the machine they run on, and the same tarball works on any Linux distribution for that architecture. + +| Artifact | Architecture | Runs on | Notes | +|---|---|---|---| +| `clightning--static-amd64.tar.xz` | x86-64 | any Linux, x86-64 | baseline x86-64; uses hardware CRC32 where the CPU reports it | +| `clightning--static-arm64.tar.xz` | AArch64 (`arm64`) | any Linux, ARMv8-A and newer | Raspberry Pi 3, 4, 5, Zero 2 W; most ARM servers | +| `clightning--static-armhf.tar.xz` | 32-bit ARM (`armhf`) | any Linux, **ARMv7-A** hard-float and newer | Raspberry Pi 2 and newer. **Not** Pi 1 / Zero / Zero W, which are ARMv6 | +| `lightningd` Docker image | amd64, arm64, arm/v7 | Docker | built *from* the tarballs above, one multi-arch manifest | +| `clightning-.zip` | — | — | source archive | + +What this means in practice: + +- **There is no distribution dimension any more.** Earlier releases shipped + `clightning--Ubuntu-22.04.tar.xz` and friends, one per distribution and + version, because the binaries were dynamically linked against that distribution's + libraries. Pick the tarball for your architecture instead. +- **32-bit ARM requires ARMv7-A with hardware floating point.** Raspberry Pi 1, + Pi Zero and Pi Zero W are ARMv6 and are not supported; build from source there. + On a Pi 3, 4 or 5 prefer the `arm64` tarball, even if you run a 32-bit userland — + the hardware is ARMv8. +- **PostgreSQL and sqlite are both built in.** `--wallet=postgres://…` works out of + the box; libpq is linked statically like everything else. +- **The binaries are stripped**, and each one keeps its GNU build-id so a crash + report can still be resolved against the release. Debug symbols are not published. +- Every executable is a **static PIE** (`static-pie`), so ASLR still applies. +- **There is no Validating Lightning Signer binary and no `-vls` image in this + release.** Core Lightning offers channel splicing by default and refuses to + run with a signer that cannot sign splice transactions; no released VLS + implements that yet, so the signer binary and the image built around it + could only have been published unable to start. Both return, with the + manifest lines that go with them, once upstream VLS signs splices. The build + recipe stays in the tree (`tools/reprobuild vls`) for anyone who wants to + build one anyway. + +## Installing a tarball + +The tarballs install into `/usr/local`, where they always have: ```shell -for v in jammy noble resolute; do - echo "Building base image for $v" - docker run --rm -v $(pwd):/build ubuntu:$v \ - bash -c "apt-get update && apt-get install -y debootstrap && debootstrap $v /build/$v" - tar -C $v -c . | docker import - $v -done +sudo tar -xvf clightning--static-.tar.xz -C /usr/local --strip-components=2 ``` -Verify that the image corresponds to our expectation and is runnable: +Inspect one first with `tar -tvf` if you would rather see what it contains before +unpacking it, or unpack it somewhere harmless and copy what you need. + +# Build environment setup + +The build environment is a **pinned nixpkgs revision**, recorded in `flake.lock` in +the repository. There are no builder images to construct from installation media, +no package pin lists to refresh and no per-distribution setup: the compiler, every +library and every build tool are content-addressed store paths, fixed by that one +revision, and Nix builds them in a sandbox with no network access. + +The one exception is Rust: the release uses the Rust project's own release +binaries (`rustc`, `cargo`, and the standard library for each target), pinned by +sha256 in `nix/pkgs/rust-bin.nix`. nixpkgs has no prebuilt Rust compiler for the +static cross rows, so otherwise every arm build would compile rustc from source +first. nixpkgs' own rustc is bootstrapped from these same binaries, so this adds +no new trust. + +All you need is Nix with flakes enabled (`nix-command` and `flakes` in +`experimental-features`). The builds above are produced with Nix 2.31.3; if your +Nix cannot evaluate the flake, the driver can also run the whole build inside a +digest-pinned `nixos/nix` container instead of using your own Nix. + +The release artifacts are built from **the same derivation as `packages.default`**, +evaluated as a static (and, for the arm rows, cross) variant — the flake's +`cln-release-static-amd64`, `cln-release-static-arm64` and +`cln-release-static-armhf` attributes, which are generated from the plain table +in `nix/release-rows`. The thing that gets tested hardest every release is +therefore the same thing Nix users install. + +Two guards keep that sharing honest. `nix/release-rows` also records the nixpkgs +revision the release is *certified* against: if `flake.lock` moves, the release +attributes refuse to evaluate and `nix flake check` fails, in the commit that +moved it. And each row commits a short file under `nix/release-manifests/` +listing what that row is made of — its direct inputs with versions, the +toolchain versions, the build flags and the environment — so a change that +reaches the release shows up as a diff you can read without knowing Nix. + +# Building + +Check out the tag you are building and run the driver. It needs **docker, +coreutils and python3 (3.10 or newer)**, and nothing else: the driver is a +single standard-library script, and every Nix command runs inside a +digest-pinned `nixos/nix` container, with a store under +`~/.cache/cln-reprobuild`. If you have Nix yourself and want the faster loop, +add `--host-nix`. ```shell -docker run ubuntu:noble cat /etc/lsb-release +tools/reprobuild build # all three rows +tools/reprobuild build amd64 # or one ``` -Which should result in the following output for `noble`: - -```shell -DISTRIB_ID=Ubuntu -DISTRIB_RELEASE=24.04 -DISTRIB_CODENAME=noble -DISTRIB_DESCRIPTION="Ubuntu 24.04 LTS" -``` +The driver refuses to build a release from a tree with uncommitted changes: Nix +caches the working tree it fetched, so the artifacts could otherwise be labelled +with a commit they were not built from. -## Builder image setup +The arm rows are cross-compiled from x86-64; no emulation is involved except for +the handful of build steps that run their own output, which use a QEMU taken from +the pinned closure rather than from the host's `binfmt` registration. That matters +for reproducibility: a build that relied on the host's `binfmt` would give a +different answer on a machine configured differently. -Once we have the clean base image we need to customize it to be able to build Core Lightning. This includes disabling the update repositories, downloading the build dependencies and specifying the steps required to perform the build. - -For this purpose we have a number of Dockerfiles in the [`contrib/reprobuild`](https://github.com/ElementsProject/lightning/tree/master/contrib/reprobuild) directory that have the specific instructions for each base image. - -We can then build the builder image by calling `docker build` and passing it the `Dockerfile`: +Each row prints the hash of the artifact it wrote, and then checks it — every +shipped executable must be stripped, position-independent, free of any embedded +library search path, and still carry its build-id: ```shell -docker build -t cl-repro-jammy - < contrib/reprobuild/Dockerfile.jammy -docker build -t cl-repro-noble - < contrib/reprobuild/Dockerfile.noble -docker build -t cl-repro-resolute - < contrib/reprobuild/Dockerfile.resolute +reprobuild: wrote release/clightning-v25.12-static-amd64.tar.xz +57666565916779e12046cf8277e31554e1ce65ea08f3cd459694fb7101f85346 release/clightning-v25.12-static-amd64.tar.xz +check: OK (40 ELFs, all static-pie, stripped, with build-id) ``` -Since we pass the `Dockerfile` through `stdin` the build command will not create a context, i.e., the current directory is not passed to `docker` and it'll be independent of the currently checked out version. This also means that you will be able to reuse the docker image for future builds, and don't have to repeat this dance every time. Verifying the `Dockerfile` therefore is -sufficient to ensure that the resulting `cl-repro-` image is reproducible. - -The dockerfiles assume that the base image has the codename as its image name. - -# Building using the builder image - -Finally, after finishing the environment setup we can perform the actual build. At this point we have a container image that has been prepared to build reproducibly. As you can see from the `Dockerfile` above we assume the source git repository gets mounted as `/repo` in the docker container. The container will clone the repository to an internal path, in order to keep the repository clean, build the artifacts there, and then copy them back to `/repo/release`. -We'll need the release directory available for this, so create it now if it doesn't exist:`mkdir release`, then we can simply execute the following command inside the git repository (remember to checkout the tag you are trying to build): - -```bash -docker run --rm -v $(pwd):/repo -ti cl-repro-jammy -docker run --rm -v $(pwd):/repo -ti cl-repro-noble -docker run --rm -v $(pwd):/repo -ti cl-repro-resolute -``` - -The last few lines of output also contain the `sha256sum` hashes of all artifacts, so if you're just verifying the build those are the lines that are of interest to you: +The tarball is itself a Nix output, so `--rebuild` has Nix build it a second +time and compare against the store. That is a stronger statement than running +the driver twice, which is only a store hit, and it covers the exact bytes that +get signed rather than a `tar` run afterwards: ```shell -ee83cf4948228ab1f644dbd9d28541fd8ef7c453a3fec90462b08371a8686df8 /repo/release/clightning-v0.9.0rc1-Ubuntu-18.04.tar.xz -94bd77f400c332ac7571532c9f85b141a266941057e8fe1bfa04f054918d8c33 /repo/release/clightning-v0.9.0rc1.zip +tools/reprobuild build amd64 --rebuild ``` -Repeat this step for each distribution and each architecture you wish to sign. Once all the binaries are in the `release/` subdirectory we can sign the hashes. +A row takes about 5 minutes on a 24-thread machine once its toolchain is in the +store. The first `armhf` run also builds that architecture's C toolchain (gcc, +binutils, musl and the static libraries), which adds about 10 minutes. + +The source archive is a Nix output too, built from the same tree rather than +assembled on your machine, so `tools/reprobuild zip` gives the same bytes +everywhere. ## ARM builds (arm64 and armv7) @@ -134,62 +178,92 @@ Once the tarballs are built, `tools/sign-release-arm.sh v arm64` (or `a # Signing the release manifest -The release captain is in charge of creating the manifest, whereas contributors and interested bystanders may contribute their signatures to further increase trust in the binaries. +The release captain is in charge of creating the manifest, whereas contributors and +interested bystanders may contribute their signatures to further increase trust in +the binaries. -## Script build-release -1: Pull latest code from master +There is **one** manifest, `SHA256SUMS-` — every release file, all +three architectures. Every co-signer is expected to reproduce and sign it. -2: Run the `tools/build-release.sh bin-Fedora bin-Ubuntu sign` script. This will create a release directory, build binaries for Fedora, and build binaries for Ubuntu (Jammy, Noble, and Resolute). Finally, it will sign the ZIP, Fedora, and Ubuntu builds. - -## Manual -The release captain creates the manifest as follows: +The release captain writes and signs it with one command: ```shell -cd release/ -sha256sum *v0.9.0* > SHA256SUMS -gpg -sb --armor SHA256SUMS +tools/reprobuild sign ``` -# Co-signing the release manifest - -## Script build-release -1: Pull latest code from master. - -2: Rename checksum files, shared by the release captain, to `SHA256SUMS-v($VERSION)` and `SHA256SUMS-v($VERSION).asc`. +Each manifest begins with a comment block recording what the build consumed — +the commit, the flake's `narHash`, whether submodules were included, the +timestamp baked into the artifacts, and the certified nixpkgs revision. +`sha256sum` ignores those lines; they are there so that a hash is never +reported without the tree it came from. The driver refuses to write a manifest +whose files were not all built from the same tree. -2: Copy above files in the lightning directory. +# Co-signing the release manifest -3: Run `tools/build-release.sh --verify` script. It will build binaries for Ubuntu (Jammy, Noble & Resolute), verify zip & Ubuntu builds while copying Fedora checksums from the release captain's file. +Co-maintainers and contributors wishing to add their own signature rebuild the +release and compare it against the captain's manifest. Hand the manifest to the +driver and it does the rest: -4. Then send the resulting `release/SHA256SUMS.asc` file to the release captain so it can be merged with the other signatures into `SHASUMS.asc`. +```shell +tools/reprobuild verify SHA256SUMS- +``` -## Manual -Co-maintainers and contributors wishing to add their own signature verify that the `SHA256SUMS` and `SHA256SUMS.asc` files created by the release captain matches their binaries before also signing the manifest. +It takes the commit and the timestamp **from the manifest**, not from whatever +you have checked out — so you need that commit in your clone, but not on your +current branch — rebuilds every file the manifest lists, compares them, and +writes `SHA256SUMS-.asc.` only if all of them matched. Send +that signature to the release captain, who merges it with the others. -Always pass **both** files to `gpg --verify`: the signature first, then the file it is supposed to cover. See [Verifying a reproducible build](doc:repro#verifying-a-reproducible-build) below for why the single-argument form is not sufficient. +If the driver tells you that commit is not in your clone, fetch the tag first. +The tag is on GitHub: ```shell -cd release/ -gpg --verify SHA256SUMS.asc SHA256SUMS -sha256sum -c SHA256SUMS -cat SHA256SUMS | gpg -sb --armor > SHA256SUMS.new +git fetch origin tag v ``` -Then send the resulting `SHA256SUMS.new` file to the release captain so it can be merged with the other signatures into `SHASUMS.asc`. +You do not need to check the tag out: `verify` builds the commit the manifest +names, wherever your working tree happens to be. + +Lines for image digests are reported but never block: building the images is +optional for a co-signer. + +If a file differs, the driver prints both hashes and withholds the signature. +That is the whole protocol: tell the captain what you got, and the two of you +work out the cause before anything is published. + +For the second manifest, run the same command against it. If it does not match, +do not sign it — report the hashes you got and move on. That is a +known-possible outcome today, and withholding the signature is the correct +response, not a reason to hold up the release. + +Because one tarball now covers every distribution for its architecture, a co-signer +with an x86-64 machine can reproduce **all three** rows: the arm rows are +cross-compiled, so no ARM hardware is needed. + +> **History: the `armhf` row used to diverge across machines.** +> +> Until the 2026 toolchain move, the 32-bit ARM Rust binaries differed +> stably between build machines — a reordered string table in the ARM +> exception-unwinding objects Rust links in — and those artifacts lived in +> a separate `SHA256SUMS--armhf` manifest, which a co-signer +> signed only if they had reproduced it. That divergence is gone: all +> three rows now come out byte-identical across machines (different CPU +> vendors, host Nix and pinned container alike, confirmed by independent +> co-signers), so `armhf` co-signs like every other row. Releases from +> the split era keep their `-armhf` manifest, and `tools/reprobuild +> verify` still reproduces and signs those. # Verifying a reproducible build You can verify the reproducible build in two ways: - Repeating the entire reproducible build, making sure from scratch that the binaries match. Just follow the instructions above for this. -- Verifying that the downloaded binaries match the hashes in `SHA256SUMS` and that the signatures in `SHA256SUMS.asc` are valid. +- Verifying that the downloaded binaries match the hashes in `SHA256SUMS-` and that the signatures in `SHA256SUMS-.asc` are valid. -Each release has one manifest per architecture: `SHA256SUMS-` covers the amd64 binaries and the source zip, and `SHA256SUMS--arm64` and `SHA256SUMS--armv7` cover the ARM binaries. Each manifest's signatures are in a matching `.asc` file. Assuming you have downloaded the binaries, the manifests and the signatures into the same directory, you can verify the signatures with the following (using v26.06.9 as the example): +Assuming you have downloaded the binaries, the manifest and the signatures into the same directory, you can verify the signatures with the following: ```shell -gpg --verify SHA256SUMS-v26.06.9.asc SHA256SUMS-v26.06.9 -gpg --verify SHA256SUMS-v26.06.9-arm64.asc SHA256SUMS-v26.06.9-arm64 -gpg --verify SHA256SUMS-v26.06.9-armv7.asc SHA256SUMS-v26.06.9-armv7 +gpg --verify SHA256SUMS-.asc SHA256SUMS- ``` Pass both filenames explicitly. With a single argument `gpg` picks its verification mode from the packet structure of the `.asc` file: for a genuine detached signature it guesses the sibling `SHA256SUMS`, but for an inline (clear-signed or embedded) message it verifies only the payload carried inside the `.asc` itself. It never reads `SHA256SUMS` in that case, and although it prints `WARNING: not a detached signature; file 'SHA256SUMS' was NOT verified!`, it still exits with status 0 — so the warning is easy to miss by eye and invisible to any script that only checks the exit code. Naming the manifest as the second argument forces `gpg` to check the signatures against that exact file, and to fail outright if the `.asc` is not a detached signature over it. @@ -214,61 +288,27 @@ gpg: Good signature from "Lagrang3 " [full] gpg: Signature made Wed Oct 7 13:49:21 2026 UTC gpg: using RSA key 616C52F99D0612B2A151B1074129A994AA7E9852 gpg: Good signature from "Core Lightning (CLN) " [full] -gpg: Signature made Tue Oct 6 19:43:33 2026 UTC -gpg: using EDDSA key 4E4A142F8BD3C38A56B362ED578CAC08472545C5 -gpg: Good signature from "nGoline " [full] -gpg: aka "Níckolas Goline " [full] -gpg: Signature made Tue Oct 6 21:51:11 2026 UTC -gpg: using EDDSA key 13054F60BEEB87D2B9C7D77DFAFE0D6665547AD6 -gpg: issuer "jaonoctus@protonmail.com" -gpg: Good signature from "jaonoctus " [full] -gpg: Signature made Wed Oct 7 01:31:17 2026 UTC -gpg: using RSA key 1A371C2C30645FAA91AA6B7DB643E61284221961 -gpg: Good signature from "Sangbida Chaudhuri " [full] -gpg: Signature made Wed Oct 7 13:49:22 2026 UTC -gpg: using RSA key 616C52F99D0612B2A151B1074129A994AA7E9852 -gpg: Good signature from "Core Lightning (CLN) " [full] -gpg: Signature made Tue Oct 6 21:26:43 2026 UTC -gpg: using EDDSA key 4E4A142F8BD3C38A56B362ED578CAC08472545C5 -gpg: Good signature from "nGoline " [full] -gpg: aka "Níckolas Goline " [full] -gpg: Signature made Tue Oct 6 20:52:35 2026 UTC -gpg: using EDDSA key 13054F60BEEB87D2B9C7D77DFAFE0D6665547AD6 -gpg: issuer "jaonoctus@protonmail.com" -gpg: Good signature from "jaonoctus " [full] -gpg: Signature made Tue Oct 6 20:38:44 2026 UTC -gpg: using EDDSA key 8A079421A871D0B1083511937AB4802ED5A639F3 -gpg: Good signature from "daywalker90 " [full] -gpg: Signature made Wed Oct 7 13:49:23 2026 UTC -gpg: using RSA key 616C52F99D0612B2A151B1074129A994AA7E9852 -gpg: Good signature from "Core Lightning (CLN) " [full] ``` -If there are any issues `gpg` will print `Bad signature`, it might be because the signatures in `SHA256SUMS.asc` do not match the `SHA256SUMS` file, and could be the result of a filename change. Do not continue using the binaries, and contact the maintainers, if this is not the case, a failure here means that the verification failed. +If there are any issues `gpg` will print `Bad signature`, it might be because the signatures do not match the manifest, and could be the result of a filename change. Do not continue using the binaries, and contact the maintainers, if this is not the case, a failure here means that the verification failed. Next we verify that the binaries match the ones in the manifest: ```shell -sha256sum -c SHA256SUMS-v26.06.9 SHA256SUMS-v26.06.9-arm64 SHA256SUMS-v26.06.9-armv7 +sha256sum -c --ignore-missing SHA256SUMS- ``` Producing output similar to the following: ```shell -clightning-v26.06.9-Fedora-40-amd64.tar.gz: OK -clightning-v26.06.9-Ubuntu-22.04-amd64.tar.xz: OK -clightning-v26.06.9-Ubuntu-24.04-amd64.tar.xz: OK -clightning-v26.06.9-Ubuntu-26.04-amd64.tar.xz: OK -clightning-v26.06.9.zip: OK -clightning-v26.06.9-Ubuntu-22.04-arm64.tar.xz: OK -clightning-v26.06.9-Ubuntu-24.04-arm64.tar.xz: OK -clightning-v26.06.9-Ubuntu-26.04-arm64.tar.xz: OK -clightning-v26.06.9-Ubuntu-22.04-armv7.tar.xz: OK -clightning-v26.06.9-Ubuntu-24.04-armv7.tar.xz: OK -clightning-v26.06.9-Ubuntu-26.04-armv7.tar.xz: OK +clightning-v25.12-static-amd64.tar.xz: OK +clightning-v25.12-static-arm64.tar.xz: OK +clightning-v25.12.zip: OK ``` -Each file should be marked as `OK`. If you only downloaded some of the files, add `--ignore-missing` to skip the ones you don't have. A failure to verify the hash would give a warning like the following: +`--ignore-missing` is there because the manifest lists every file in the +release and you have probably downloaded only the ones you need. Without it, +`sha256sum` reports the files you do not have as failures. A failure to verify the hash would give a warning like the following: ```shell sha256sum: WARNING: 1 computed checksum did NOT match diff --git a/doc/getting-started/getting-started/installation.md b/doc/getting-started/getting-started/installation.md index 129a23ddc734..a13cfca2e01e 100644 --- a/doc/getting-started/getting-started/installation.md +++ b/doc/getting-started/getting-started/installation.md @@ -17,13 +17,25 @@ sudo snap refresh --hold bitcoin-core # To prevent automated update of bitcoin-c sudo ln -s /snap/bitcoin-core/current/bin/bitcoin{d,-cli} /usr/local/bin/ ``` -Then you can fetch a pre-compiled binary from the [releases](https://github.com/ElementsProject/lightning/releases) page on GitHub. Core Lightning provides binaries for both Ubuntu and Fedora distributions. Normally these binaries are extracted into /usr/local: +Then you can fetch a pre-compiled binary from the [releases](https://github.com/ElementsProject/lightning/releases) page on GitHub. There is **one binary tarball per architecture**, not one per distribution: the binaries are statically linked, so the same tarball works on any Linux distribution. + +| Tarball | Architecture | Requires | +|---|---|---| +| `clightning--static-amd64.tar.xz` | x86-64 | any Linux | +| `clightning--static-arm64.tar.xz` | AArch64 (`arm64`) | any Linux, ARMv8-A or newer — Raspberry Pi 3, 4, 5 | +| `clightning--static-armhf.tar.xz` | 32-bit ARM (`armhf`) | any Linux, ARMv7-A hard-float or newer — Raspberry Pi 2 and newer, **not** Pi 1 / Zero / Zero W | + +Unsure which one you want? `dpkg --print-architecture`, or `uname -m` (`x86_64` → amd64, `aarch64` → arm64, `armv7l` → armhf). On a Raspberry Pi 3, 4 or 5 prefer `arm64` even if your userland is 32-bit, since the hardware is ARMv8. + +Normally these binaries are extracted into `/usr/local`: ```shell sudo rm -R /usr/local/libexec/c-lightning/plugins # If you are upgrading run this first to avoid plugin conflicts -sudo tar -xvf .tar.xz -C /usr/local --strip-components=2 +sudo tar -xvf clightning--static-.tar.xz -C /usr/local --strip-components=2 ``` -If you're on a different distribution or OS, you can compile the source by following the instructions from [Installing from Source](doc:installation#installing-from-source). +Both sqlite and PostgreSQL support are built in, and the binaries need no libraries from your distribution — not even a libc. + +If you're on an OS other than Linux, or on 32-bit ARM older than ARMv7, you can compile the source by following the instructions from [Installing from Source](doc:installation#installing-from-source). # Docker diff --git a/external/Makefile b/external/Makefile index 4ff220539eb5..03d5e3791ae5 100644 --- a/external/Makefile +++ b/external/Makefile @@ -23,6 +23,24 @@ JSMN_HEADERS := external/jsmn/jsmn.h GHEAP_HEADERS := external/gheap/gheap.h LIBBACKTRACE_HEADERS := external/libbacktrace/backtrace.h +# backtrace-supported.h is generated by libbacktrace's configure into the build +# dir; objects that include it must wait for that build, otherwise they race it +# (and, where the compiler ships its own copy of the header, silently pick that +# one up instead -- as gcc's libgcc-dev does). +# +# Deliberately *not* in EXTERNAL_HEADERS, and an order-only prerequisite of the +# objects. EXTERNAL_HEADERS depends on the phony submodcheck, which is always +# newer, so every member of it is permanently out of date -- harmless for +# checked-out headers that have no recipe, but a header we *generate* would then +# re-run libbacktrace's configure on every single make. Order-only says what we +# actually mean: it has to exist before anything compiles, and its timestamp is +# not a reason to recompile. +# +# Like $(EXTERNAL_LIBS), and for the same reason, it also has to be named in +# TESTPACK_EXTRAS: the testpack prunes external/, so otherwise it does not reach +# the phase that only checks. +EXTERNAL_GEN_HEADERS := $(TARGET_DIR)/libbacktrace-build/backtrace-supported.h + EXTERNAL_HEADERS := $(LIBWALLY_HEADERS) $(LIBSECP_HEADERS) $(JSMN_HEADERS) $(GHEAP_HEADERS) $(LIBBACKTRACE_HEADERS) EXTERNAL_LIBS := ${TARGET_DIR}/libwallycore.a ${TARGET_DIR}/libsecp256k1.a ${TARGET_DIR}/libjsmn.a ${TARGET_DIR}/libbacktrace.a @@ -92,7 +110,10 @@ $(TARGET_DIR)/libjsmn.a: $(TARGET_DIR)/jsmn-build/jsmn.o .INTERMEDIATE: $(TARGET_DIR)/jsmn-build/jsmn.o # Need separate build dir: changes inside submodule make git think it's dirty. -$(TARGET_DIR)/libbacktrace.a: external/libbacktrace/backtrace.h +# One recipe produces the archive and the generated header, so say so with a +# grouped target: a plain recipe-less rule would let make treat the missing +# header as freshly made, and silently rebuild every object instead. +$(TARGET_DIR)/libbacktrace.a $(EXTERNAL_GEN_HEADERS) &: external/libbacktrace/backtrace.h mkdir -p $(TARGET_DIR)/libbacktrace-build cd $(TARGET_DIR)/libbacktrace-build && $(TOP)/libbacktrace/configure CC="$(CC)" --enable-static=yes $(CROSSCOMPILE_OPTS) --enable-shared=no --prefix=/ --libdir=/ && $(MAKE) $(MAKE) -C $(TARGET_DIR)/libbacktrace-build DESTDIR=$$(pwd)/$(TARGET_DIR) install-exec diff --git a/flake.lock b/flake.lock index 5474f69f3930..f6092165a695 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "advisory-db": { "flake": false, "locked": { - "lastModified": 1750151065, - "narHash": "sha256-il+CAqChFIB82xP6bO43dWlUVs+NlG7a4g8liIP5HcI=", + "lastModified": 1790752539, + "narHash": "sha256-SemOq7VmtTtujPa5IvPSIdoRn6JtlYYkXDkO9vGtlxI=", "owner": "rustsec", "repo": "advisory-db", - "rev": "7573f55ba337263f61167dbb0ea926cdc7c8eb5d", + "rev": "9b3a3b73a7f42606494c943e95f8196e9994df46", "type": "github" }, "original": { @@ -18,11 +18,11 @@ }, "crane": { "locked": { - "lastModified": 1750266157, - "narHash": "sha256-tL42YoNg9y30u7zAqtoGDNdTyXTi8EALDeCB13FtbQA=", + "lastModified": 1789760033, + "narHash": "sha256-jtT4yxZpR8seYnlCMMWSSPlFN92zO6ICuZ8pJrmi86k=", "owner": "ipetkov", "repo": "crane", - "rev": "e37c943371b73ed87faf33f7583860f81f1d5a48", + "rev": "73b980519cefc727a5f6cc8e5c0947a2f9be6edd", "type": "github" }, "original": { @@ -36,11 +36,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1749398372, - "narHash": "sha256-tYBdgS56eXYaWVW3fsnPQ/nFlgWi/Z2Ymhyu21zVM98=", + "lastModified": 1788450739, + "narHash": "sha256-glZLQlzIn1fXH6PazR2iUmTo7kzzyYSshrWhLS9TqCU=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "9305fe4e5c2a6fcf5ba6a3ff155720fbe4076569", + "rev": "31729ca8cbdb4fa927b34e5f4353e6a83f39e993", "type": "github" }, "original": { @@ -51,11 +51,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1761373498, - "narHash": "sha256-Q/uhWNvd7V7k1H1ZPMy/vkx3F8C13ZcdrKjO7Jv7v0c=", + "lastModified": 1790689126, + "narHash": "sha256-ilerN1WLSvF+HMjziC/Wv99J5y02maDH+6hZPwsORKg=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "6a08e6bb4e46ff7fcbb53d409b253f6bad8a28ce", + "rev": "b4fd65b198c599cbe814fcb9f42d25d021595ec9", "type": "github" }, "original": { @@ -67,11 +67,11 @@ }, "nixpkgs-lib": { "locked": { - "lastModified": 1748740939, - "narHash": "sha256-rQaysilft1aVMwF14xIdGS3sj1yHlI6oKQNBRTF40cc=", + "lastModified": 1788057806, + "narHash": "sha256-DTQSMxzDWmT0zhguthvegnVkn7CFqGCv4IHCzk5ZUpM=", "owner": "nix-community", "repo": "nixpkgs.lib", - "rev": "656a64127e9d791a334452c6b6606d17539476e2", + "rev": "596e2e3940e09b2abbeb03f75fa1828c57fcd72c", "type": "github" }, "original": { @@ -96,11 +96,11 @@ ] }, "locked": { - "lastModified": 1761311587, - "narHash": "sha256-Msq86cR5SjozQGCnC6H8C+0cD4rnx91BPltZ9KK613Y=", + "lastModified": 1786901030, + "narHash": "sha256-WSFCsDSE5ffgD2MqzkM2CYjeFiKhRF/dJUN8uedb6YE=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "2eddae033e4e74bf581c2d1dfa101f9033dbd2dc", + "rev": "27b3b12a8e6375f28ebe122f07d230ca5459bbfa", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 9cd4aad229b5..797dc373e306 100644 --- a/flake.nix +++ b/flake.nix @@ -49,7 +49,9 @@ { _module.args.pkgs = import inputs.nixpkgs { inherit system; - overlays = [ (final: prev: { craneLib = (inputs.crane.mkLib pkgs); }) ]; + overlays = [ + (final: prev: { craneLib = (inputs.crane.mkLib pkgs); }) + ]; }; }; }; diff --git a/mkdocs.yml b/mkdocs.yml index 7112dac569f2..47593d08576a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -54,7 +54,7 @@ nav: - "Fuzzing": FUZZING.md - Maintainers: - "Making Releases": MAKING-RELEASES.md - - "Reproducible Builds": REPRODUCIBLE.md + - "Reproducible Builds": getting-started/advanced-setup/repro.md - Reference: - reference/index.md diff --git a/nix/pkgs/default.nix b/nix/pkgs/default.nix index 8820741b9432..36f2a3219fe0 100644 --- a/nix/pkgs/default.nix +++ b/nix/pkgs/default.nix @@ -4,59 +4,228 @@ pkgs, config, postgresSupport ? false, + # Release mode. + # + # The release artifacts are built from *this* derivation, as a static and/or + # cross variant of it, rather than from a second release-only derivation that + # could drift from what `nix build .#cln` produces. `release = true` switches + # on everything the release needs and nothing an ordinary build wants: + # + # * version/mtime come from the driver (REPRO_VERSION / REPRO_MTIME), + # not from `.version` and `self.lastModifiedDate` -- bit-identity + # across two runs of different checkouts depends on it; + # * one `make install` builds the Rust plugins itself, + # so the crane side-build and NO_PYTHON=1 are off and cargo is fed + # an offline vendor dir instead of the network; + # * -static-pie on the compiler driver, with PIE_LDFLAGS overridden + # (the Makefile's trailing -pie turns -static-pie into + # a *dynamic* link); + # * strip --strip-all on every shipped ELF. + release ? false, + releaseVersion ? null, + releaseMtime ? null, + # The row's arch token from nix/release-rows (amd64, arm64, + # armhf). It only names the artifact; which package set the + # row builds under is decided by the caller. + releaseArch ? null, }: with pkgs; let - version = builtins.readFile ../../.version; - py3 = python3.withPackages (p: [ + version = if release then releaseVersion else builtins.readFile ../../.version; + mtime = if release then releaseMtime else self.lastModifiedDate; + # Build-machine tools. `with pkgs;` bypasses callPackage's splicing, so + # under pkgsStatic a bare `cargo`/`python3` is the *static* build of that + # tool (cargo's is even marked broken) rather than the native one that + # targets musl. For a native package set buildPackages == pkgs, so this + # is a no-op off the release path. + bp = pkgs.buildPackages; + py3 = bp.python3.withPackages (p: [ p.grpcio-tools p.mako ]); -in -stdenv.mkDerivation { - name = "cln"; - src = ../../.; - inherit version; - makeFlags = [ - "VERSION=${version}" - "MTIME=${self.lastModifiedDate}" - "NO_PYTHON=1" - ]; + # Offline cargo vendor dir. A Nix sandbox has no network, so "fetches are + # allowed as long as the lockfile pins them" becomes a vendor derivation keyed + # on Cargo.lock: the same inputs, pinned the same way, fetched earlier. + cargoVendor = buildPackages.rustPlatform.importCargoLock { + lockFile = ../../Cargo.lock; + }; + rustTarget = stdenv.hostPlatform.rust.rustcTarget; + rustTargetEnv = lib.toUpper (builtins.replaceStrings [ "-" ] [ "_" ] rustTarget); + # The cross rows. + # + # `canExecute` is nixpkgs' name for a fact this build had to discover the + # hard way: the build machine cannot run what a cross row produces, and + # CLN's build *does* run its own output in five places (the configurator's + # test programs, tools/headerversions, `plugins/sql --print-docs`, ...). + # On the host those had been running silently under the kernel's binfmt + # registration -- which is `F`-flagged here, so it reaches inside the Nix + # sandbox too. A release build must not depend on how the captain's + # kernel happens to be configured, so the emulator comes from *this + # closure*: `hostPlatform.emulator buildPackages` is the qemu-user binary + # nixpkgs would use, pinned by the same revision as everything else. + crossRow = !(stdenv.buildPlatform.canExecute stdenv.hostPlatform); + emulator = stdenv.hostPlatform.emulator bp; + # How a release binary is linked lives in static-pie.nix, imported here and + # by vls.nix so the signer links exactly as Core Lightning does. That file + # carries the reasoning for each wrapper; these are just the names it exports. + inherit (import ./static-pie.nix { inherit pkgs lib; }) + arm32 + extraObjsManifest + staticPieFlags + staticPieCc + releaseCc + rustStaticPieCc + rustTargetFlags + noRpathEnv + ; + rustBin = import ./rust-bin.nix { inherit pkgs lib; }; + # The row's libpq, bound once. + # + # This used to carry `hardeningDisable = [ "pie" ]` on the 32-bit ARM row, + # because postgres could not even *configure* there: its "whether the C + # compiler works" test links an executable, and nixpkgs' `pie` hardening plus + # pkgsStatic's `-static` made gcc pick the non-PIE crtbeginT.o for a PIE link + # ("relocation R_ARM_MOVW_ABS_NC against a local symbol can not be used when + # making a shared object"). `pie` is no longer one of nixpkgs' hardening + # flags, so naming it now aborts evaluation outright, and there is nothing + # left to disable under that name. Dropped rather than translated: the flag + # it would translate to is not obviously the same flag, and the 32-bit ARM + # row is what decides whether the problem is back. + # + # Still bound to a name rather than written inline in buildInputs, because + # `POSTGRES_LDLIBS` below has to refer to the *same* derivation -- naming + # `libpq` twice pulled two of them into the closure. + libpqRow = libpq; # when building on darwin we need cctools to provide the correct libtool # as libwally-core detects the host as darwin and tries to add the -static # option to libtool, also we have to add the modified gsed package. - nativeBuildInputs = [ - autoconf - autogen - automake - gettext - gitMinimal - libtool - # lowdown calls sandbox_init(3) on darwin, which fails inside a nix build. - lowdown-unsandboxed - pkgconf - py3 - unzip - which - ] - ++ lib.optionals postgresSupport [ - libpq - libpq.pg_config - ] - ++ lib.optionals stdenv.isDarwin [ - cctools - darwin.autoSignDarwinBinariesHook - ]; + nativeInputs = + with bp; + [ + autoconf + # No GNU autogen: libwally's tools/autogen.sh is a shell script that runs + # autoreconf, and nothing in this build invokes the autogen program. It + # was pulling guile 2.2.7 and its boehm-gc into the closure, which is + # broken under pkgsStatic in current nixpkgs. + automake + gettext + gitMinimal + libtool + # lowdown calls sandbox_init(3) on darwin, which fails inside a nix build. + lowdown-unsandboxed + pkgconf + py3 + unzip + which + ] + ++ lib.optionals (postgresSupport && !release) [ + pkgs.libpq + pkgs.libpq.pg_config + ] + ++ lib.optionals release [ + rustBin + protobuf + file + # configure needs a jq it can *run* ("*** We need jq!"); the one in + # buildInputs is the musl-static target build. The Alpine builder + # same requirement for the Alpine builder. + jq + # A build-platform C compiler reachable as plain `cc`. cargo compiles + # build scripts and proc macros *for the build machine* and asks rustc + # for its default linker, which is `cc`; the cross stdenv only puts + # `x86_64-unknown-linux-musl-gcc` on PATH, so every build script fails + # with "linker `cc` not found". Same class as CC_FOR_BUILD below. + stdenv.cc + ] + ++ lib.optionals stdenv.isDarwin [ + cctools + darwin.autoSignDarwinBinariesHook + ]; - buildInputs = [ + hostInputs = [ gmp jq libsodium sqlite zlib + ] + ++ lib.optionals (postgresSupport && release) [ + libpqRow + # libpq.a is linked, not loaded, so *its* dependencies become ours: + # nixpkgs records them in libpq's own `LIBS` as + # `-lpgcommon -lpgport -lssl -lcrypto -lz -lm`. zlib is already here; + # OpenSSL is not, and libpq propagates only its `-dev` output (whose + # `lib/` holds nothing but pkgconfig), so without this the link path + # has no `libssl.a`/`libcrypto.a` at all. + openssl + ]; + + # Everything make is told on the release path except version and mtime, + # which are per-release labels; both are listed in the input manifest. + releaseMakeFlags = + lib.optionals release [ + "RUST_PROFILE=release" + "PIE_LDFLAGS=-static-pie" + "TARGET=${rustTarget}" + # $(AR) has no assignment in the Makefile, so it would fall back to + # make's built-in `ar` -- the *build* machine's, which cannot index a + # foreign archive. Stated rather than left to the stdenv's exported AR. + "AR=${stdenv.cc.targetPrefix}ar" + ] + ++ lib.optionals (release && crossRow) [ + # external/Makefile switches to --host/--build only when BUILD is set; + # without it libwally/libbacktrace configure as if native and their own + # run-tests decide wrong. CC_FOR_BUILD is there because + # cdump-enumstr is a build-machine program (it is *run* to generate + # source), so it must not be cross-compiled. + "BUILD=${stdenv.buildPlatform.config}" + "MAKE_HOST=${stdenv.hostPlatform.config}" + "CC_FOR_BUILD=cc" + ]; + + # -O2 on the release path. CLN's configure defaults COPTFLAGS to -Og, which + # is "optimise without getting in the debugger's way" -- roughly -O1, and not + # what a shipped binary wants. Measured on this tree: three interleaved pairs + # of runs, +17% on listpays and grpc getinfo, +8% and +7% on grpc listpeers + # and listinvoices, with identical RSS. Only the C half was affected; Rust + # already builds with RUST_PROFILE=release. + configureFlags = + [ "--disable-valgrind" ] + ++ lib.optionals release [ + "--prefix=/usr/local" + "COPTFLAGS=-O2" ]; + # Environment the release build needs set; also listed in the input + # manifest, since each of these moves release bytes. + releaseEnv = { + NIX_OUTPATH_USED_AS_RANDOM_SEED = "cln-release"; + } + // noRpathEnv; + # Stated once so the input manifest can list it: these reach every Rust + # artifact's bytes, and a reviewer who does not read Nix should see a diff + # when they change. The vendor path itself is deliberately *not* + # in the manifest line -- remapping is what stops it mattering -- but its + # presence is. + vendorRemap = "--remap-path-prefix=${cargoVendor}=/home/clightning/vendor"; + rustflagsShape = "--remap-path-prefix=$NIX_BUILD_TOP=/home/clightning --remap-path-prefix==/home/clightning/vendor -C link-arg=-Wl,--build-id=sha1${rustTargetFlags}"; + +in +stdenv.mkDerivation { + name = "cln"; + src = ../../.; + inherit version; + makeFlags = [ + "VERSION=${version}" + "MTIME=${mtime}" + ] + ++ lib.optionals (!release) [ "NO_PYTHON=1" ] + ++ releaseMakeFlags; + + nativeBuildInputs = nativeInputs; + buildInputs = hostInputs; + # this causes some python trouble on a darwin host so we skip this step. # also we have to tell libwally-core to use sed instead of gsed. postPatch = @@ -76,22 +245,303 @@ stdenv.mkDerivation { substituteInPlace external/libwally-core/configure.ac --replace gsed sed ''; - configureFlags = [ "--disable-valgrind" ]; + # The unpacked source directory is named after the *source + # store path* (`-source`), so its name changes with any tree + # change, shipped or not. It reaches the shipped bytes through rustc panic + # locations, DWARF `comp_dir` and -- once a -ffile-prefix-map names it -- + # `CCAN_CFLAGS` in the generated `ccan/config.h`; the latter two move the + # link-time `--build-id=sha1` and are then stripped away, so a build-id is + # all that is left to see. A constant name removes all of them, and the + # $NIX_BUILD_TOP map below then yields a constant `/home/clightning/source`. + ${if release then "postUnpack" else null} = '' + mv -- "$sourceRoot" source + export sourceRoot=source + ''; + + inherit configureFlags; + + # CLN's ./configure is hand-rolled, not autotools: it rejects the flags + # nixpkgs' configurePhase adds for a static cross build + # (`--enable-static --disable-shared`, `--build=`, `--host=`) with + # "Unknown option". Suppress them and hand it the one prefix it wants; + # `prefix` (not a configureFlags entry) so nixpkgs emits it exactly once. + # The tarball must unpack over `/`, so the release installs to a DESTDIR + # with --prefix=/usr/local -- where CLN has always documented its binaries, + # and where a hand-built `make install` puts them. A release tarball is not + # the place to move a project's install directory. + # `prefix` is not the knob to use here: nixpkgs feeds it to configure + # *and* runs `mkdir -p "$prefix"` in installPhase, so an absolute prefix + # fails with "mkdir: cannot create directory: Permission denied". + # Suppress nixpkgs' own --prefix and pass ours in configureFlags; $out + # stays the prefix nixpkgs creates, and DESTDIR + --prefix=/usr/local gives + # a tarball that unpacks over `/`. + dontAddPrefix = release; + dontAddStaticConfigureFlags = release; + configurePlatforms = [ ]; + + preConfigure = + lib.optionalString release '' + export PYTEST= + export SOURCE_DATE_EPOCH LANG=C LC_ALL=C TZ=UTC + + # cargo, offline, against the vendored crates. + export CARGO_HOME=$NIX_BUILD_TOP/cargo-home + mkdir -p $CARGO_HOME + cat > $CARGO_HOME/config.toml <