Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 124 additions & 44 deletions .github/workflows/build-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,46 @@ on:

env:
REGISTRY: ghcr.io
PROVER_IMAGE_NAME: ${{ github.repository }}
STREAMR_IMAGE_NAME: ${{ github.repository }}/streamr-client

permissions:
contents: read
packages: write
attestations: write
id-token: write

jobs:
build-and-push-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
build-platform:
strategy:
matrix:
include:
- platform: linux/amd64
runner: ubuntu-latest
arch: amd64
- platform: linux/arm64
runner: ubuntu-24.04-arm
arch: arm64

runs-on: ${{ matrix.runner }}

steps:
- name: Checkout repository
uses: actions/checkout@v5

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Normalize image names
run: |
echo "PROVER_IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
echo "STREAMR_IMAGE_NAME=${GITHUB_REPOSITORY,,}/streamr-client" >> $GITHUB_ENV

- name: Free disk space
uses: jlumbroso/free-disk-space@main
with:
platforms: arm64
tool-cache: true
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Expand All @@ -40,50 +60,110 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Build and push Prover image (energy-tracker)
- name: Extract metadata for Prover image
id: meta-prover
uses: docker/metadata-action@v5
# Prover image - push by digest with repository name
- name: Build Prover image (single platform)
id: build-prover
uses: docker/build-push-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }}
context: .
platforms: ${{ matrix.platform }}
push: ${{ github.event_name != 'pull_request' }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }},push-by-digest=true
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }}:buildcache-${{ matrix.arch }}
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }}:buildcache-${{ matrix.arch }},mode=max

- name: Build and push Prover image
# Streamr client image - push by digest with repository name
- name: Build Streamr client image (single platform)
id: build-streamr
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
context: ./streamr-client
platforms: ${{ matrix.platform }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-prover.outputs.tags }}
labels: ${{ steps.meta-prover.outputs.labels }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }},push-by-digest=true
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }}:buildcache-${{ matrix.arch }}
cache-to: type=registry,ref=${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }}:buildcache-${{ matrix.arch }},mode=max

- name: Save digests to files
if: github.event_name != 'pull_request'
run: |
echo ${{ steps.build-prover.outputs.digest }} > digests-${{ matrix.arch }}-prover-digest.txt
echo ${{ steps.build-streamr.outputs.digest }} > digests-${{ matrix.arch }}-streamr-digest.txt

- name: Generate attestation for Prover image
- name: Upload digests artifact
if: github.event_name != 'pull_request'
uses: actions/attest-build-provenance@v3
uses: actions/upload-artifact@v4
with:
subject-name: ${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }}
subject-digest: ${{ steps.build-and-push-prover.outputs.digest }}
push-to-registry: true
name: digests-${{ matrix.arch }}
path: |
digests-${{ matrix.arch }}-prover-digest.txt
digests-${{ matrix.arch }}-streamr-digest.txt

create-manifests:
needs: build-platform
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest

steps:
- name: Normalize image names
run: |
echo "PROVER_IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
echo "STREAMR_IMAGE_NAME=${GITHUB_REPOSITORY,,}/streamr-client" >> $GITHUB_ENV

- name: Download all digests
uses: actions/download-artifact@v4
with:
pattern: digests-*
merge-multiple: true

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Extract metadata for Prover image
id: meta-prover
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }}

- name: Create multi-arch manifest for Prover
run: |
AMD64_DIGEST=$(cat digests-amd64-prover-digest.txt)
ARM64_DIGEST=$(cat digests-arm64-prover-digest.txt)
echo AMD64_DIGEST=$AMD64_DIGEST
echo ARM64_DIGEST=$ARM64_DIGEST
TAGS=(${{ steps.meta-prover.outputs.tags }})
TAG_ARGS=""
for tag in "${TAGS[@]}"; do
TAG_ARGS="$TAG_ARGS --tag $tag"
done
docker buildx imagetools create $TAG_ARGS \
${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }}@$AMD64_DIGEST \
${{ env.REGISTRY }}/${{ env.PROVER_IMAGE_NAME }}@$ARM64_DIGEST

# Build and push Streamr client image
- name: Extract metadata for Streamr client image
id: meta-streamr
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }}

- name: Build and push Streamr client image
uses: docker/build-push-action@v6
with:
context: ./streamr-client
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta-streamr.outputs.tags }}
labels: ${{ steps.meta-streamr.outputs.labels }}

- name: Generate attestation for Streamr client image
if: github.event_name != 'pull_request'
uses: actions/attest-build-provenance@v3
with:
subject-name: ${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }}
subject-digest: ${{ steps.build-and-push-streamr.outputs.digest }}
push-to-registry: true
- name: Create multi-arch manifest for Streamr client
run: |
AMD64_DIGEST=$(cat digests-amd64-streamr-digest.txt)
ARM64_DIGEST=$(cat digests-arm64-streamr-digest.txt)
echo AMD64_DIGEST=$AMD64_DIGEST
echo ARM64_DIGEST=$ARM64_DIGEST
TAGS=(${{ steps.meta-streamr.outputs.tags }})
TAG_ARGS=""
for tag in "${TAGS[@]}"; do
TAG_ARGS="$TAG_ARGS --tag $tag"
done
docker buildx imagetools create $TAG_ARGS \
${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }}@$AMD64_DIGEST \
${{ env.REGISTRY }}/${{ env.STREAMR_IMAGE_NAME }}@$ARM64_DIGEST
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,10 @@
"editor.formatOnSave": true,
"editor.hover.enabled": "on"
},
"cSpell.words": [
"buildcache",
"Buildx",
"imagetools",
"jlumbroso"
],
}
17 changes: 8 additions & 9 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,21 @@ pub fn track_energy(
let mut energy_sum = 0u64;
for payload in m3ter_payloads {
println!("nonce {}, payload nonce {}", nonce, payload.nonce);
if !m3ter.validate_payload(payload, verifying_key) {
println!("Invalid payload: {:?}", payload);
break;
};
if nonce >= payload.nonce {
continue;
}
if nonce + 1 != payload.nonce {
println!(
"Invalid nonce: {} not consercutive to {} for m3ter_id {}",
&nonce, &payload.nonce, &m3ter.m3ter_id
);
nonce = if nonce < payload.nonce {
nonce
} else {
payload.nonce
};
break;
}
if !m3ter.validate_payload(payload, verifying_key) {
println!("Invalid payload: {:?}", payload);
break;
};

nonce = payload.nonce;
energy_sum += payload.energy;
println!(
Expand Down
Loading