Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation #1

Merged
merged 29 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1e4578f
Initial implementation
fernandofcampos Sep 19, 2024
4a5f219
Rename some types
fernandofcampos Sep 25, 2024
96948a5
Process multiple blocks in parallel
fernandofcampos Sep 26, 2024
abf0884
Set partition as block height % number of partitions
fernandofcampos Oct 1, 2024
62a2237
Unit tests
fernandofcampos Oct 2, 2024
bfe4314
Use snappy compression as this is the only compression type supported…
fernandofcampos Oct 2, 2024
0ca2457
Set key to block height to guarantee message order
fernandofcampos Oct 2, 2024
c70eb35
Unit tests
fernandofcampos Oct 3, 2024
96b5265
Optimize rpc client parameters
fernandofcampos Oct 4, 2024
0bd83b1
Action to upload image to ECR
fernandofcampos Oct 4, 2024
9d8ac8b
Action to upload image to ECR
fernandofcampos Oct 4, 2024
9624936
fix dockerfileand make sure actions work with tag
okedeji Oct 7, 2024
770b3be
add tag to docker image
okedeji Oct 7, 2024
2c19020
use root to access the /run/secrets
okedeji Oct 7, 2024
aaf0619
add jq for terminal formatting
okedeji Oct 7, 2024
064a63a
PROTO-2634: Implement support for untyped events and add validator re…
fernandofcampos Oct 9, 2024
2314549
PROTO-2539: Integration tests for PG repository module
fernandofcampos Oct 10, 2024
6140687
PROTO-2538: Integration tests for Codec module
fernandofcampos Oct 10, 2024
23d7984
PROTO-2537: Integration tests for Kafka client module
fernandofcampos Oct 10, 2024
26e6be4
PROTO-2540: Integration tests for Allora Client module
fernandofcampos Oct 10, 2024
0ff40c4
Add fund data topic and event
fernandofcampos Oct 17, 2024
929e8af
PROTO-2735: add the configurations for the new environments
fernandofcampos Oct 22, 2024
7cf5d21
Add support for allora-chain v0.6.0
fernandofcampos Oct 23, 2024
eb28635
add new topics required by studio
KjetilVaa Oct 30, 2024
a5b5d89
fix tests and add cancel-remove-delegate-stake topic and event
KjetilVaa Oct 31, 2024
df977e7
feat/new_topics_allora_studio (#2)
KjetilVaa Oct 31, 2024
ac677eb
add missing staking topics and make a topic per staking event
KjetilVaa Oct 31, 2024
b6c2ca0
fix linter
KjetilVaa Oct 31, 2024
e7bd7fd
fix-allora-studio-staking-topics (#3)
KjetilVaa Oct 31, 2024
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
34 changes: 34 additions & 0 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: build_test
on:
push:
branches:
- main
- dev
pull_request:

jobs:
build_test:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.22]
steps:
- uses: actions/checkout@v4

- name: Cache Go modules
uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: go build
run: make build

- name: go test
run: make test
50 changes: 50 additions & 0 deletions .github/workflows/ecr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: ECR
on:
push:
tags:
- 'v*'

jobs:
ecr:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, tag, and push docker image to Amazon ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: allora-producer
IMAGE_TAG: ${{ github.sha }}
run: |

GIT_TAG="$(echo $GITHUB_REF| sed 's#refs/tags/##')"

# Testnet
CHAIN_NAME="allora-testnet-1"
docker build -t $REGISTRY/$REPOSITORY:$GIT_TAG --build-arg CHAIN_NAME=${CHAIN_NAME} .
docker push $REGISTRY/$REPOSITORY:$GIT_TAG

docker build -t $REGISTRY/$REPOSITORY/${CHAIN_NAME}:$GIT_TAG --build-arg CHAIN_NAME=${CHAIN_NAME} .
docker push $REGISTRY/$REPOSITORY/${CHAIN_NAME}:$GIT_TAG

# Mainnet
CHAIN_NAME="allora-mainnet-1"
docker build -t $REGISTRY/$REPOSITORY/${CHAIN_NAME}:$GIT_TAG --build-arg CHAIN_NAME=${CHAIN_NAME} .
docker push $REGISTRY/$REPOSITORY/${CHAIN_NAME}:$GIT_TAG

# Devnet
CHAIN_NAME="allora-devnet-1"
docker build -t $REGISTRY/$REPOSITORY/${CHAIN_NAME}:$GIT_TAG --build-arg CHAIN_NAME=${CHAIN_NAME} .
docker push $REGISTRY/$REPOSITORY/${CHAIN_NAME}:$GIT_TAG
27 changes: 27 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: golangci-lint
on:
push:
branches:
- main
- dev
- release-*
pull_request:

permissions:
contents: read
# Optional: allow write access to checks to allow the action to annotate code in the PR.
checks: write

jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: stable
- name: golangci-lint
uses: golangci/[email protected]
with:
version: v1.61.0
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
bin/
*.out
config.yaml
*.env
*.log
*.html
*.tmp
coverage/
*.txt
54 changes: 54 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
run:
timeout: 5m

linters:
disable-all: true
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default-linters
enable:
- asciicheck
- bidichk
- durationcheck
- errcheck
- errname
- copyloopvar
- forcetypeassert
- goconst
- gofmt
- goimports
- goheader
- gomodguard
- goprintffuncname
- gosimple
- govet
- importas
- ineffassign
- makezero
- misspell
- nakedret
- nilnil
- promlinter
- staticcheck
- stylecheck
- tenv
- thelper
- tparallel
- typecheck
- thelper
- unconvert
- unused
- whitespace
- unparam
- revive
- gosec
- testifylint

issues:
max-issues-per-linter: 10000
max-same-issues: 10000

exclude-files:
- ".*\\.pb\\.go"
- ".*\\.pb\\.gw\\.go"
- ".*\\.pulsar\\.go"
- ".*_mocks\\.go"
3 changes: 3 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
with-expecter: True
keeptree: True
output: ./mocks
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM golang:1.22-alpine
RUN apk add git

# Default to localnet
ARG CHAIN_NAME=allora-localnet-1

ENV GO111MODULE=on \
CGO_ENABLED=0

RUN apk add --no-cache jq


WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . .

RUN go build -buildvcs -o allora-producer ./cmd/producer

COPY ./config/config.${CHAIN_NAME}.yaml ./config.yaml

CMD ["./allora-producer"]
60 changes: 60 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Makefile for building the Allora Producer project

# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
GOTEST=$(GOCMD) test
GOGET=$(GOCMD) get
GOGENERATE=$(GOCMD) generate
# Main package path
MAIN_PACKAGE=./cmd/producer
PWD=$(shell pwd)

# Binary name
BINARY_NAME=bin/allora-producer

# Build the project
build:
$(GOBUILD) -o $(BINARY_NAME) -v $(MAIN_PACKAGE)

# Clean build files
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)

# Run tests
test:
$(GOTEST) -v ./...

# Get dependencies
deps:
$(GOGET) -v -t -d ./...

generate:
$(GOGENERATE) ./...

# Build and run
run: build
./$(BINARY_NAME)

lint:
@echo "--> Running linter"
docker run -t --rm -v $(PWD):/app -v ~/.cache/golangci-lint/v1.61.0:/root/.cache -w /app golangci/golangci-lint:v1.61.0 golangci-lint run -v

# golangci-lint must be installed locally. It's the fastest way to run the linter.
lint-local:
@echo "--> Running linter"
golangci-lint run --timeout=10m


cover:
mkdir -p coverage
rm -rf coverage/*
$(GOTEST) -coverprofile=./coverage/coverage.out.tmp ./...
grep -v mock ./coverage/coverage.out.tmp | grep -v allora-chain > ./coverage/coverage.out
$(GOCMD) tool cover -html=./coverage/coverage.out -o ./coverage/coverage.html
$(GOCMD) tool cover -func=./coverage/coverage.out

# Default target
.DEFAULT_GOAL := build
125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Allora Chain Producer

This repository implements a service to monitor Allora Chain blocks, parse specific transactions and events, and send them to Kafka server topics.

## Features

- Monitors Allora Chain blocks in real-time
- Parses configurable transactions and events
- Sends parsed data to specified Kafka topics
- Offers flexible configuration for data processing and topic associations
- Optimized for efficient processing and near real-time data handling

## Architecture Diagram

![Architecture Diagram](images/architecture.png)

## Configuration

Transactions, events, and their associations with Kafka topics are configurable.

The configuration is managed via the `config.yaml` file, which supports overriding through environment variables. We use [Viper](https://github.com/spf13/viper) to help loading the configurations.

### Configuring Transactions and Events

Events and transactions can be configured at the `filter_event` and `filter_transaction` sections of the configuration file. Example:

```yaml
filter_event:
types:
- "emissions.v4.EventNetworkLossSet"
- "emissions.v4.EventRewardsSettled"

filter_transaction:
types:
- "emissions.v4.RemoveStakeRequest"
- "emissions.v4.InsertReputerPayloadRequest"
```

You must use the fully qualified name of the protobuf type.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we publish new versions, would it be good to be able to specify regexes here?
Eg to use any v of a particular type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regex is a great idea, but I think we should implement that in a new iteration.


### Configuring association with Kafka topics

Events and Transactions can be associated with Kafta topics at the kafka_topic_router section:

```yaml
kafka_topic_router:
- name: "domain-event.input.allora.staking"
types:
- "emissions.v4.AddStakeRequest"
- "emissions.v4.RemoveStakeRequest"
- name: "domain-event.input.allora.delegation"
types:
- "emissions.v3.DelegateStakeRemovalInfo"
```

`name` refers to the topic name and `types` is a list of fully qualified names of the types.

### Other configurations

Postgres, Kafka and Allora RPC configurations can also be performed at the config file:

```yaml
database:
url: "postgres://devuser:devpass@localhost:5432/dev-indexer?sslmode=disable"

kafka:
seeds:
- "localhost:9092"
user: "user"
password: "pass"

allora:
rpc: "https://allora-rpc.testnet.allora.network"
timeout: 10

```

### Overriding configurations using environment variables

To override configurations using environment variables, you:
1. Join the different levels of the yaml config using underscore (`_`).
2. Change it to uppercase
3. Add this prefix: `ALLORA_`

Example:

```yaml
database:
url: "postgres://devuser:devpass@localhost:5432/dev-indexer?sslmode=disable"
```

Becomes:

```yaml
ALLORA_DATABASE_URL: "postgres://devuser:devpass@localhost:5432/dev-indexer?sslmode=disable"
```

## Setup and Usage

[Add instructions on how to set up and run the service]

## Project Structure

- `cmd/`: Contains the main entry point for the application (producer).
- `app/`: Implements the business logic, including the use cases for monitoring transactions and events.
- `app/domain/`: Defines core abstractions such as interfaces for repositories and services.
- `infra/`: Handles interactions with external infrastructure like Kafka, PostgreSQL, and the Allora blockchain.
- `util/`: Contains utility functions like logging execution time.
- `config/`: Manages configuration loading and validation using Viper.

## Technologies

- Go 1.22+
- Kafka (Franz-Go)
- Postgres (pgx)
- Cosmos SDK Go client
- Mockery

## Testing

1. Unit tests:
```bash
make test
```

Loading
Loading