-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
1e4578f
Initial implementation
fernandofcampos 4a5f219
Rename some types
fernandofcampos 96948a5
Process multiple blocks in parallel
fernandofcampos abf0884
Set partition as block height % number of partitions
fernandofcampos 62a2237
Unit tests
fernandofcampos bfe4314
Use snappy compression as this is the only compression type supported…
fernandofcampos 0ca2457
Set key to block height to guarantee message order
fernandofcampos c70eb35
Unit tests
fernandofcampos 96b5265
Optimize rpc client parameters
fernandofcampos 0bd83b1
Action to upload image to ECR
fernandofcampos 9d8ac8b
Action to upload image to ECR
fernandofcampos 9624936
fix dockerfileand make sure actions work with tag
okedeji 770b3be
add tag to docker image
okedeji 2c19020
use root to access the /run/secrets
okedeji aaf0619
add jq for terminal formatting
okedeji 064a63a
PROTO-2634: Implement support for untyped events and add validator re…
fernandofcampos 2314549
PROTO-2539: Integration tests for PG repository module
fernandofcampos 6140687
PROTO-2538: Integration tests for Codec module
fernandofcampos 23d7984
PROTO-2537: Integration tests for Kafka client module
fernandofcampos 26e6be4
PROTO-2540: Integration tests for Allora Client module
fernandofcampos 0ff40c4
Add fund data topic and event
fernandofcampos 929e8af
PROTO-2735: add the configurations for the new environments
fernandofcampos 7cf5d21
Add support for allora-chain v0.6.0
fernandofcampos eb28635
add new topics required by studio
KjetilVaa a5b5d89
fix tests and add cancel-remove-delegate-stake topic and event
KjetilVaa df977e7
feat/new_topics_allora_studio (#2)
KjetilVaa ac677eb
add missing staking topics and make a topic per staking event
KjetilVaa b6c2ca0
fix linter
KjetilVaa e7bd7fd
fix-allora-studio-staking-topics (#3)
KjetilVaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
bin/ | ||
*.out | ||
config.yaml | ||
*.env | ||
*.log | ||
*.html | ||
*.tmp | ||
coverage/ | ||
*.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
with-expecter: True | ||
keeptree: True | ||
output: ./mocks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
||
### 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 | ||
``` | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.