Skip to content
Open
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
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Builds the `indexer` bin from the `services` crate via docker/Dockerfile (BIN_MODE),
# renamed to `vectorx-indexer`, and pushes to registry.digitalocean.com/availj.
name: Release vectorx-indexer

on:
push:
tags:
- 'v*.*.*'
- 'v*.*.*-*'
workflow_dispatch:
inputs:
tag:
description: 'Image tag to publish (e.g. v0.7.0)'
required: true

jobs:
docker_build_push:
runs-on: ubuntu-22.04
strategy:
fail-fast: true
matrix:
# The services crate currently exposes only the `indexer` bin.
# Add more here (e.g. operator) once they exist as [[bin]] targets.
binary: [indexer]
steps:
- name: Checkout
uses: actions/checkout@v4

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

- name: Resolve image tag + registry
id: meta
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "tag_name=${{ inputs.tag }}" >> "$GITHUB_OUTPUT"
else
echo "tag_name=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT"
fi
echo "do_registry=registry.digitalocean.com" >> "$GITHUB_OUTPUT"

- name: Login to DigitalOcean Container Registry
uses: docker/login-action@v3
with:
registry: ${{ steps.meta.outputs.do_registry }}
username: ${{ secrets.DO_USER_EMAIL }}
password: ${{ secrets.DO_USER_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./docker/Dockerfile
platforms: linux/amd64
push: true
tags: |
${{ steps.meta.outputs.do_registry }}/availj/vectorx-${{ matrix.binary }}:${{ steps.meta.outputs.tag_name }}
build-args: |
BUILD_PROFILE=release
BIN_MODE=${{ matrix.binary }}
cache-from: type=gha,scope=vectorx-${{ matrix.binary }}
cache-to: type=gha,scope=vectorx-${{ matrix.binary }},mode=max
1 change: 0 additions & 1 deletion script/bin/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! `cargo build --release --bin genesis`
//!
use avail_subxt::config::Header;
use clap::Parser;
use services::input::RpcDataFetcher;
use sp1_sdk::{HashableKey, Prover, ProverClient};
Expand Down
2 changes: 1 addition & 1 deletion services/bin/indexer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use avail_subxt::primitives::Header;
use avail_subxt::RpcParams;
use codec::Decode;
use serde::de::Error;
use serde::Deserialize;
use services::avail::Header;
use services::input::RpcDataFetcher;
use services::postgres::PostgresClient;
use services::types::{Commit, GrandpaJustification};
Expand Down
94 changes: 94 additions & 0 deletions services/src/avail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use avail_subxt::config::substrate::Digest;
use codec::{Decode, Encode};
use serde::{de::Visitor, Deserialize, Deserializer, Serialize};
use sp_core::H256;
use std::fmt;

#[derive(Clone, Debug, Decode, Encode, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FriBlobCommitment {
pub blob_hash: H256,
pub size_bytes: u64,
pub commitment: Vec<u8>,
}

#[derive(Clone, Debug, Default, Decode, Encode, PartialEq, Serialize, Deserialize)]
pub enum FriParamsVersion {
#[default]
V0,
}

#[derive(Clone, Debug, Default, Decode, Encode, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct FriHeaderExtension {
pub blobs: Vec<FriBlobCommitment>,
pub params_version: FriParamsVersion,
pub data_root: H256,
}

#[derive(Clone, Debug, Decode, Encode, PartialEq, Serialize, Deserialize)]
pub enum HeaderExtension {
#[codec(index = 0)]
V1(FriHeaderExtension),
}

impl HeaderExtension {
pub fn data_root(&self) -> H256 {
match self {
HeaderExtension::V1(extension) => extension.data_root,
}
}
}

#[derive(Clone, Debug, Decode, Encode, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Header {
pub parent_hash: H256,
#[codec(compact)]
#[serde(deserialize_with = "deserialize_block_number")]
pub number: u32,
pub state_root: H256,
pub extrinsics_root: H256,
pub digest: Digest,
pub extension: HeaderExtension,
}

fn deserialize_block_number<'de, D>(deserializer: D) -> Result<u32, D::Error>
where
D: Deserializer<'de>,
{
struct BlockNumberVisitor;

impl<'de> Visitor<'de> for BlockNumberVisitor {
type Value = u32;

fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a u32 block number or hex-encoded block number")
}

fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
value
.try_into()
.map_err(|_| E::custom("block number exceeds u32"))
}

fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: serde::de::Error,
{
let value = value.strip_prefix("0x").unwrap_or(value);
u32::from_str_radix(value, 16).map_err(E::custom)
}
}

deserializer.deserialize_any(BlockNumberVisitor)
}

impl Header {
pub fn hash(&self) -> H256 {
H256::from(sp_core::blake2_256(&self.encode()))
}
}
39 changes: 17 additions & 22 deletions services/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use std::cmp::Ordering;
use std::env;
use subxt::backend::rpc::RpcSubscription;

use crate::avail::Header;
use crate::types::{EncodedFinalityProof, FinalityProof, GrandpaJustification};
use alloy::primitives::{B256, B512};
use avail_subxt::avail_client::AvailClient;
use avail_subxt::config::substrate::DigestItem;
use avail_subxt::primitives::Header;
use avail_subxt::{api, RpcParams};
use codec::{Compact, Decode, Encode};
use futures::future::join_all;
Expand Down Expand Up @@ -236,12 +236,7 @@ impl RpcDataFetcher {

pub async fn get_header(&self, block_number: u32) -> Header {
let block_hash = self.get_block_hash(block_number).await;
let header_result = self
.client
.legacy_rpc()
.chain_get_header(Some(H256::from(block_hash.0)))
.await;
header_result.unwrap().unwrap()
self.get_header_by_hash(H256::from(block_hash.0)).await
}

pub async fn get_head(&self) -> Header {
Expand All @@ -251,12 +246,18 @@ impl RpcDataFetcher {
.chain_get_finalized_head()
.await
.unwrap();
let header = self
.client
.legacy_rpc()
.chain_get_header(Some(head_block_hash))
.await;
header.unwrap().unwrap()
self.get_header_by_hash(head_block_hash).await
}

pub async fn get_header_by_hash(&self, block_hash: H256) -> Header {
let mut params = RpcParams::new();
params.push(block_hash).unwrap();
self.client
.rpc()
.request::<Option<Header>>("chain_getHeader", params)
.await
.unwrap()
.unwrap()
}

pub async fn get_authority_set_id(&self, block_number: u32) -> u64 {
Expand Down Expand Up @@ -376,12 +377,8 @@ impl RpcDataFetcher {
if let Some(Ok(justification)) = sub.next().await {
// Get the header corresponding to the new justification.
let header = self
.client
.legacy_rpc()
.chain_get_header(Some(justification.commit.target_hash))
.await
.unwrap()
.unwrap();
.get_header_by_hash(justification.commit.target_hash)
.await;
let block_number = header.number;
return (
self.compute_data_from_justification(justification, block_number)
Expand Down Expand Up @@ -587,8 +584,6 @@ fn get_merkle_tree_size(num_headers: u32) -> usize {
#[cfg(test)]
mod tests {
use crate::types::{Commit, Precommit, SignerMessage};
use avail_subxt::config::Header;
use avail_subxt::primitives::Header as DaHeader;
use ed25519::Public;
use serde::{Deserialize, Serialize};
use sp1_vector_primitives::{
Expand Down Expand Up @@ -683,7 +678,7 @@ mod tests {
pub struct JsonGrandpaJustification {
pub round: u64,
pub commit: Commit,
pub votes_ancestries: Vec<DaHeader>,
pub votes_ancestries: Vec<Header>,
}

impl From<GrandpaJustification> for JsonGrandpaJustification {
Expand Down
1 change: 1 addition & 0 deletions services/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod avail;
pub mod input;
pub mod postgres;
pub mod types;
Expand Down
3 changes: 1 addition & 2 deletions services/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ impl PostgresClient {
mod tests {
use super::*;
use crate::types::{Commit, GrandpaJustification, Precommit, SignedPrecommit};
use avail_subxt::primitives::Header;
use sp_core::ed25519::{Public, Signature};
use sp_core::H256;

Expand Down Expand Up @@ -149,7 +148,7 @@ mod tests {
target_number: 12345,
},
signature: Signature::from_slice(&[1u8; 64]).unwrap(),
id: Public::from_slice(&[1u8; 32]).unwrap(),
id: Public::from_raw([1u8; 32]),
}],
},
votes_ancestries: vec![],
Expand Down
3 changes: 2 additions & 1 deletion services/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use avail_subxt::primitives::Header;
use codec::{Decode, Encode};
use serde::{Deserialize, Serialize};
use sp_core::ed25519::{Public as EdPublic, Signature};
use sp_core::Bytes;
use sp_core::H256;

use crate::avail::Header;

#[derive(Clone, Debug, Decode, Encode, Serialize, Deserialize)]
pub struct Precommit {
pub target_hash: H256,
Expand Down
Loading