Skip to content

Commit

Permalink
Allow empty filter if multiple filters specified (#397)
Browse files Browse the repository at this point in the history
### Summary

In some cases, it makes sense to allow an empty filter. This PR stops
the DNA server from erroring in that case.
  • Loading branch information
fracek authored Dec 2, 2024
2 parents 3a7c5f7 + ae8fed2 commit 086f6c8
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 119 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ jobs:
echo "USER=runner" >> "$GITHUB_ENV"
fi
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
- uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-23.11
- uses: cachix/cachix-action@v14
nix_path: nixpkgs=channel:nixos-24.11
- uses: cachix/cachix-action@v15
with:
name: apibara-public
authToken: "${{ secrets.cachix-token }}"
Expand Down
18 changes: 9 additions & 9 deletions .github/workflows/cd-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ jobs:
name: "Linux x86_64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-x64-4x
os: ubuntu-latest-x64-4x
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

build-linux-aarch64:
name: "Linux aarch64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-arm64-8x
os: ubuntu-latest-arm64-8x
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

build-macos-aarch64:
name: "MacOS aarch64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-macos-latest-arm64-6x
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
# build-macos-aarch64:
# name: "MacOS aarch64: Build"
# uses: ./.github/workflows/build.yml
# with:
# os: warp-macos-latest-arm64-6x
# secrets:
# cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
7 changes: 4 additions & 3 deletions .github/workflows/cd-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ jobs:
echo "USER=runner" >> "$GITHUB_ENV"
fi
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
- run: mkdir -p $HOME
- uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-23.11
- uses: cachix/cachix-action@v14
nix_path: nixpkgs=channel:nixos-24.11
- uses: cachix/cachix-action@v15
with:
name: apibara-public
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
Expand Down
122 changes: 61 additions & 61 deletions .github/workflows/cd-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
name: "Linux x86_64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-x64-4x
os: ubuntu-latest-x64-4x
target: ${{ inputs.target }}
secrets:
cachix-token: "${{ secrets.cachix-token }}"
Expand All @@ -42,19 +42,19 @@ jobs:
name: "Linux aarch64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-arm64-8x
os: ubuntu-latest-arm64-8x
target: ${{ inputs.target }}
secrets:
cachix-token: "${{ secrets.cachix-token }}"

build-macos-aarch64:
name: "MacOS aarch64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-macos-latest-arm64-6x
target: ${{ inputs.target }}
secrets:
cachix-token: "${{ secrets.cachix-token }}"
# build-macos-aarch64:
# name: "MacOS aarch64: Build"
# uses: ./.github/workflows/build.yml
# with:
# os: warp-macos-latest-arm64-6x
# target: ${{ inputs.target }}
# secrets:
# cachix-token: "${{ secrets.cachix-token }}"

# Step 2a: create release archive for all platforms

Expand All @@ -63,7 +63,7 @@ jobs:
needs: build-linux-x86_64
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-x64-4x
os: ubuntu-latest-x64-4x
target: ${{ inputs.target }}-archive
artifact_name: "${{ inputs.target }}-x86_64-linux"
secrets:
Expand All @@ -74,22 +74,22 @@ jobs:
needs: build-linux-aarch64
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-arm64-8x
os: ubuntu-latest-arm64-8x
target: ${{ inputs.target }}-archive
artifact_name: "${{ inputs.target }}-aarch64-linux"
secrets:
cachix-token: "${{ secrets.cachix-token }}"

build-macos-aarch64-archive:
name: "MacOS aarch64: Build archive"
needs: build-macos-aarch64
uses: ./.github/workflows/build.yml
with:
os: warp-macos-latest-arm64-6x
target: ${{ inputs.target }}-archive
artifact_name: "${{ inputs.target }}-aarch64-macos"
secrets:
cachix-token: "${{ secrets.cachix-token }}"
# build-macos-aarch64-archive:
# name: "MacOS aarch64: Build archive"
# needs: build-macos-aarch64
# uses: ./.github/workflows/build.yml
# with:
# os: warp-macos-latest-arm64-6x
# target: ${{ inputs.target }}-archive
# artifact_name: "${{ inputs.target }}-aarch64-macos"
# secrets:
# cachix-token: "${{ secrets.cachix-token }}"

# Step 2b: create Docker image for all (Linux) platforms.

Expand All @@ -98,7 +98,7 @@ jobs:
needs: build-linux-x86_64
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-x64-4x
os: ubuntu-latest-x64-4x
target: ${{ inputs.target }}-image
artifact_name: "${{ inputs.target }}-x86_64-image"
secrets:
Expand All @@ -109,7 +109,7 @@ jobs:
needs: build-linux-aarch64
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-arm64-8x
os: ubuntu-latest-arm64-8x
target: ${{ inputs.target }}-image
artifact_name: "${{ inputs.target }}-aarch64-image"
secrets:
Expand All @@ -128,10 +128,10 @@ jobs:
echo "USER=runner" >> "$GITHUB_ENV"
fi
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
- uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-23.11
- uses: cachix/cachix-action@v14
nix_path: nixpkgs=channel:nixos-24.11
- uses: cachix/cachix-action@v15
with:
name: apibara-public
authToken: "${{ secrets.cachix-token }}"
Expand Down Expand Up @@ -160,37 +160,37 @@ jobs:

# Step 3b: publish binaries

publish-binaries:
name: "Publish binaries"
needs:
- build-linux-x86_64-archive
- build-linux-aarch64-archive
- build-macos-aarch64-archive
runs-on: ubuntu-latest
steps:
- name: Download binary for Linux x86_64
uses: actions/download-artifact@v4
with:
name: ${{ inputs.target }}-x86_64-linux
path: /tmp/bin/x86_64-linux
- name: Download binary for Linux aarch64
uses: actions/download-artifact@v4
with:
name: ${{ inputs.target }}-aarch64-linux
path: /tmp/bin/aarch64-linux
- name: Download binary for MacOS aarch64
uses: actions/download-artifact@v4
with:
name: ${{ inputs.target }}-aarch64-macos
path: /tmp/bin/aarch64-macos
- name: Rename binaries
run: |
mkdir /tmp/artifacts
cp /tmp/bin/x86_64-linux/${{ inputs.target }}.gz /tmp/artifacts/${{ inputs.target }}-x86_64-linux.gz
cp /tmp/bin/aarch64-linux/${{ inputs.target }}.gz /tmp/artifacts/${{ inputs.target }}-aarch64-linux.gz
cp /tmp/bin/aarch64-macos/${{ inputs.target }}.gz /tmp/artifacts/${{ inputs.target }}-aarch64-macos.gz
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
with:
file: /tmp/artifacts/*
file_glob: true
# publish-binaries:
# name: "Publish binaries"
# needs:
# - build-linux-x86_64-archive
# - build-linux-aarch64-archive
# - build-macos-aarch64-archive
# runs-on: ubuntu-latest
# steps:
# - name: Download binary for Linux x86_64
# uses: actions/download-artifact@v4
# with:
# name: ${{ inputs.target }}-x86_64-linux
# path: /tmp/bin/x86_64-linux
# - name: Download binary for Linux aarch64
# uses: actions/download-artifact@v4
# with:
# name: ${{ inputs.target }}-aarch64-linux
# path: /tmp/bin/aarch64-linux
# - name: Download binary for MacOS aarch64
# uses: actions/download-artifact@v4
# with:
# name: ${{ inputs.target }}-aarch64-macos
# path: /tmp/bin/aarch64-macos
# - name: Rename binaries
# run: |
# mkdir /tmp/artifacts
# cp /tmp/bin/x86_64-linux/${{ inputs.target }}.gz /tmp/artifacts/${{ inputs.target }}-x86_64-linux.gz
# cp /tmp/bin/aarch64-linux/${{ inputs.target }}.gz /tmp/artifacts/${{ inputs.target }}-aarch64-linux.gz
# cp /tmp/bin/aarch64-macos/${{ inputs.target }}.gz /tmp/artifacts/${{ inputs.target }}-aarch64-macos.gz
# - name: Upload binaries to release
# uses: svenstaro/upload-release-action@v2
# with:
# file: /tmp/artifacts/*
# file_glob: true
18 changes: 9 additions & 9 deletions .github/workflows/ci-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
runs-on: "${{ inputs.os }}"
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
- uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-23.11
- uses: cachix/cachix-action@v14
nix_path: nixpkgs=channel:nixos-24.11
- uses: cachix/cachix-action@v15
with:
name: apibara-public
authToken: "${{ secrets.cachix-token }}"
Expand All @@ -31,10 +31,10 @@ jobs:
needs: lint
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
- uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-23.11
- uses: cachix/cachix-action@v14
nix_path: nixpkgs=channel:nixos-24.11
- uses: cachix/cachix-action@v15
with:
name: apibara-public
authToken: "${{ secrets.cachix-token }}"
Expand All @@ -48,10 +48,10 @@ jobs:
- unit-test
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
- uses: cachix/install-nix-action@v30
with:
nix_path: nixpkgs=channel:nixos-23.11
- uses: cachix/cachix-action@v14
nix_path: nixpkgs=channel:nixos-24.11
- uses: cachix/cachix-action@v15
with:
name: apibara-public
authToken: "${{ secrets.cachix-token }}"
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/ci-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
name: "Checks"
uses: ./.github/workflows/ci-check.yml
with:
os: warp-ubuntu-latest-x64-4x
os: ubuntu-latest-x64-4x
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

Expand All @@ -28,15 +28,15 @@ jobs:
name: "Linux x86_64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-ubuntu-latest-x64-4x
os: ubuntu-latest-x64-4x
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"

build-macos-aarch64:
needs: check
name: "MacOS aarch64: Build"
uses: ./.github/workflows/build.yml
with:
os: warp-macos-latest-arm64-6x
secrets:
cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
# build-macos-aarch64:
# needs: check
# name: "MacOS aarch64: Build"
# uses: ./.github/workflows/build.yml
# with:
# os: warp-macos-latest-arm64-6x
# secrets:
# cachix-token: "${{ secrets.CACHIX_AUTH_TOKEN }}"
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion beaconchain/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "apibara-dna-beaconchain"
version = "2.0.0-beta.7"
version = "2.0.0-beta.8"
edition.workspace = true
authors.workspace = true
repository.workspace = true
Expand Down
16 changes: 10 additions & 6 deletions beaconchain/src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ impl BlockFilterFactory for BeaconChainFilterFactory {
)));
}

proto_filters
let filters = proto_filters
.iter()
.map(BlockFilterExt::compile_to_block_filter)
.collect()
.collect::<tonic::Result<Vec<_>>>()?;

if filters.iter().any(|f| f.can_produce_data()) {
Ok(filters)
} else {
Err(tonic::Status::invalid_argument(
"at least one filter must be non-empty",
))
}
}
}

Expand Down Expand Up @@ -74,10 +82,6 @@ impl BlockFilterExt for beaconchain::Filter {
block_filter.add_filter(filter);
}

if !block_filter.always_include_header() && block_filter.is_empty() {
return Err(tonic::Status::invalid_argument("no filters provided"));
}

Ok(block_filter)
}
}
4 changes: 4 additions & 0 deletions common/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ pub struct BlockFilter {
}

impl BlockFilter {
pub fn can_produce_data(&self) -> bool {
self.always_include_header() || !self.is_empty()
}

pub fn always_include_header(&self) -> bool {
matches!(self.header_filter, HeaderFilter::Always)
}
Expand Down
Loading

0 comments on commit 086f6c8

Please sign in to comment.