Skip to content

Define migration process and perform the first migration for second to ms #207

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

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
44 changes: 43 additions & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,48 @@ on:
workflow_dispatch:

jobs:
format-and-commit:
runs-on: ubuntu-latest
# Grant permissions for the built-in GITHUB_TOKEN to create a commit and push.
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
# We need to fetch the history to allow pushing, and potentially check diffs.
# Setting persist-credentials to true isn't strictly necessary with actions/checkout@v4+
# when using the default GITHUB_TOKEN, but it doesn't hurt.
fetch-depth: 0 # Fetch all history for comparison and commit user info

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24' # <--- CHANGE THIS to your project's Go version

- name: Run gofmt
run: gofmt -w .

- name: Commit changes
run: |
# Configure Git using the GITHUB_ACTOR pattern or a generic bot name
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

# Check if there are any changes staged/unstaged
# git diff --quiet exits with 1 if there are changes, 0 if not.
if ! git diff --quiet; then
echo "Detected changes, committing..."
git add . # Stage all changes, including new files if any (though gofmt shouldn't create new files)
# Alternative: git add -u # Only stage modified/deleted tracked files
git commit -m "style: Automated gofmt" -m "Formatted Go code using gofmt."
echo "Pushing changes..."
git push
else
echo "No formatting changes detected."
fi
shell: bash # Explicitly use bash

publish-dev-build:
name: Publish dev build docker image to dockerhub
runs-on: 'ubuntu-latest'
Expand Down Expand Up @@ -55,4 +97,4 @@ jobs:
file: dockerfiles/operator.Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
labels: ${{ steps.meta.outputs.labels }}
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
- pkg/graphql
- pkg/byte4
- pkg/erc4337/preset
- core/backup
- core/migrator
- migrations

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ dev-build:
mkdir out || true
go build \
-o ./out/ap \
-ldflags "-X github.com/AvaProtocol/ap-avs/version.revision=$(shell git rev-parse HEAD)"
-ldflags "-X github.com/AvaProtocol/EigenLayer-AVS/version.revision=$(shell git rev-parse HEAD)"

## dev-agg: run aggregator locally with dev build
dev-agg:
Expand Down
41 changes: 30 additions & 11 deletions aggregator/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,27 @@ import (
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/ethereum/go-ethereum/ethclient"

"github.com/AvaProtocol/ap-avs/aggregator/types"
"github.com/AvaProtocol/ap-avs/core"
"github.com/AvaProtocol/ap-avs/core/apqueue"
"github.com/AvaProtocol/ap-avs/core/chainio"
"github.com/AvaProtocol/ap-avs/core/chainio/aa"
"github.com/AvaProtocol/ap-avs/core/config"
"github.com/AvaProtocol/ap-avs/core/taskengine"
"github.com/AvaProtocol/ap-avs/version"
sdkclients "github.com/Layr-Labs/eigensdk-go/chainio/clients"
blsagg "github.com/Layr-Labs/eigensdk-go/services/bls_aggregation"
sdktypes "github.com/Layr-Labs/eigensdk-go/types"
"github.com/allegro/bigcache/v3"

"github.com/AvaProtocol/ap-avs/storage"
cstaskmanager "github.com/AvaProtocol/EigenLayer-AVS/contracts/bindings/AutomationTaskManager"

cstaskmanager "github.com/AvaProtocol/ap-avs/contracts/bindings/AutomationTaskManager"
"github.com/AvaProtocol/EigenLayer-AVS/storage"

"github.com/AvaProtocol/EigenLayer-AVS/aggregator/types"
"github.com/AvaProtocol/EigenLayer-AVS/core"
"github.com/AvaProtocol/EigenLayer-AVS/core/apqueue"
"github.com/AvaProtocol/EigenLayer-AVS/core/chainio"
"github.com/AvaProtocol/EigenLayer-AVS/core/chainio/aa"
"github.com/AvaProtocol/EigenLayer-AVS/core/config"
"github.com/AvaProtocol/EigenLayer-AVS/core/taskengine"
"github.com/AvaProtocol/EigenLayer-AVS/version"

"github.com/AvaProtocol/EigenLayer-AVS/core/backup"
"github.com/AvaProtocol/EigenLayer-AVS/core/migrator"
"github.com/AvaProtocol/EigenLayer-AVS/migrations"
)

const (
Expand Down Expand Up @@ -93,6 +98,9 @@ type Aggregator struct {
status AggregatorStatus

cache *bigcache.BigCache

backup *backup.Service
migrator *migrator.Migrator
}

// NewAggregator creates a new Aggregator with the provided config.
Expand Down Expand Up @@ -229,16 +237,26 @@ func (agg *Aggregator) init() {
aa.SetEntrypointAddress(agg.config.SmartWallet.EntrypointAddress)
}

func (agg *Aggregator) migrate() {
agg.backup = backup.NewService(agg.logger, agg.db, agg.config.BackupDir)
agg.migrator = migrator.NewMigrator(agg.db, agg.backup, migrations.Migrations)
if err := agg.migrator.Run(); err != nil {
agg.logger.Fatalf("failed to run migrations", "error", err)
}
}

func (agg *Aggregator) Start(ctx context.Context) error {
agg.logger.Infof("Starting aggregator %s", version.Get())

agg.init()

agg.logger.Infof("Initialize Storagre")
agg.logger.Infof("Initialize Storage")
if err := agg.initDB(ctx); err != nil {
agg.logger.Fatalf("failed to initialize storage", "error", err)
}

agg.migrate()

agg.logger.Infof("Starting Task engine")
agg.startTaskEngine(ctx)

Expand Down Expand Up @@ -268,6 +286,7 @@ func (agg *Aggregator) Start(ctx context.Context) error {
agg.status = shutdownStatus
agg.stopRepl()
agg.stopTaskEngine()

agg.db.Close()

return nil
Expand Down
6 changes: 3 additions & 3 deletions aggregator/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"strings"

"github.com/AvaProtocol/ap-avs/core/auth"
"github.com/AvaProtocol/ap-avs/model"
avsproto "github.com/AvaProtocol/ap-avs/protobuf"
"github.com/AvaProtocol/EigenLayer-AVS/core/auth"
"github.com/AvaProtocol/EigenLayer-AVS/model"
avsproto "github.com/AvaProtocol/EigenLayer-AVS/protobuf"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down
8 changes: 4 additions & 4 deletions aggregator/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"testing"
"time"

"github.com/AvaProtocol/ap-avs/core/auth"
"github.com/AvaProtocol/ap-avs/core/config"
"github.com/AvaProtocol/EigenLayer-AVS/core/auth"
"github.com/AvaProtocol/EigenLayer-AVS/core/config"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
"github.com/golang-jwt/jwt/v5"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"

"github.com/AvaProtocol/ap-avs/core/chainio/signer"
avsproto "github.com/AvaProtocol/ap-avs/protobuf"
"github.com/AvaProtocol/EigenLayer-AVS/core/chainio/signer"
avsproto "github.com/AvaProtocol/EigenLayer-AVS/protobuf"
sdklogging "github.com/Layr-Labs/eigensdk-go/logging"
)

Expand Down
2 changes: 1 addition & 1 deletion aggregator/http_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
"net/http"

"github.com/AvaProtocol/ap-avs/version"
"github.com/AvaProtocol/EigenLayer-AVS/version"
"github.com/labstack/echo/v4"
)

Expand Down
4 changes: 2 additions & 2 deletions aggregator/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"time"

"github.com/AvaProtocol/ap-avs/core/auth"
"github.com/AvaProtocol/ap-avs/core/config"
"github.com/AvaProtocol/EigenLayer-AVS/core/auth"
"github.com/AvaProtocol/EigenLayer-AVS/core/config"
"github.com/golang-jwt/jwt/v5"
)

Expand Down
6 changes: 3 additions & 3 deletions aggregator/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (

timestamppb "google.golang.org/protobuf/types/known/timestamppb"

"github.com/AvaProtocol/ap-avs/core/config"
avsproto "github.com/AvaProtocol/ap-avs/protobuf"
"github.com/AvaProtocol/ap-avs/storage"
"github.com/AvaProtocol/EigenLayer-AVS/core/config"
avsproto "github.com/AvaProtocol/EigenLayer-AVS/protobuf"
"github.com/AvaProtocol/EigenLayer-AVS/storage"
)

type OperatorNode struct {
Expand Down
46 changes: 46 additions & 0 deletions aggregator/repl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package aggregator

import (
"bufio"
"context"
"fmt"
"log"
"net"
"os"
"path/filepath"
"strings"
"time"
)

var (
Expand Down Expand Up @@ -97,6 +100,15 @@ func handleConnection(agg *Aggregator, conn net.Conn) {
} else {
fmt.Fprintln(conn, "Usage: list <prefix>* or list *")
}
case "rm":
if keys, err := agg.db.ListKeys(parts[1]); err == nil {
for _, k := range keys {
fmt.Fprintln(conn, k)
if err := agg.db.Delete([]byte(k)); err == nil {
fmt.Fprintln(conn, "deleted "+k)
}
}
}
case "get":
if len(parts) == 2 {
if key, err := agg.db.GetKey([]byte(parts[1])); err == nil {
Expand Down Expand Up @@ -141,6 +153,40 @@ func handleConnection(agg *Aggregator, conn net.Conn) {
fmt.Fprintln(conn, "about to trigger on server")
//agg.engine.TriggerWith

case "backup":
if len(parts) == 2 {
backupDir := parts[1]
fmt.Fprintf(conn, "Starting backup to directory: %s\n", backupDir)

timestamp := fmt.Sprintf("%s", time.Now().Format("06-01-02-15-04"))
backupPath := filepath.Join(backupDir, timestamp)

if err := os.MkdirAll(backupPath, 0755); err != nil {
fmt.Fprintf(conn, "Failed to create backup directory: %v\n", err)
break
}

backupFile := filepath.Join(backupPath, "badger.backup")
f, err := os.Create(backupFile)
if err != nil {
fmt.Fprintf(conn, "Failed to create backup file: %v\n", err)
break
}

fmt.Fprintf(conn, "Running backup to %s\n", backupFile)
since := uint64(0) // Full backup
_, err = agg.db.Backup(context.Background(), f, since)
f.Close()

if err != nil {
fmt.Fprintf(conn, "Backup failed: %v\n", err)
} else {
fmt.Fprintf(conn, "Backup completed successfully to %s\n", backupFile)
}
} else {
fmt.Fprintln(conn, "Usage: backup <directory>")
}

default:
fmt.Fprintln(conn, "Unknown command:", command)
}
Expand Down
12 changes: 6 additions & 6 deletions aggregator/rpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import (
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
wrapperspb "google.golang.org/protobuf/types/known/wrapperspb"

"github.com/AvaProtocol/ap-avs/core/auth"
"github.com/AvaProtocol/ap-avs/core/chainio/aa"
"github.com/AvaProtocol/ap-avs/core/config"
"github.com/AvaProtocol/ap-avs/core/taskengine"
avsproto "github.com/AvaProtocol/ap-avs/protobuf"
"github.com/AvaProtocol/ap-avs/storage"
"github.com/AvaProtocol/EigenLayer-AVS/core/auth"
"github.com/AvaProtocol/EigenLayer-AVS/core/chainio/aa"
"github.com/AvaProtocol/EigenLayer-AVS/core/config"
"github.com/AvaProtocol/EigenLayer-AVS/core/taskengine"
avsproto "github.com/AvaProtocol/EigenLayer-AVS/protobuf"
"github.com/AvaProtocol/EigenLayer-AVS/storage"
)

// RpcServer is our grpc sever struct hold the entry point of request handler
Expand Down
6 changes: 3 additions & 3 deletions aggregator/task_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package aggregator
import (
"context"

"github.com/AvaProtocol/ap-avs/core/apqueue"
"github.com/AvaProtocol/ap-avs/core/taskengine"
"github.com/AvaProtocol/ap-avs/core/taskengine/macros"
"github.com/AvaProtocol/EigenLayer-AVS/core/apqueue"
"github.com/AvaProtocol/EigenLayer-AVS/core/taskengine"
"github.com/AvaProtocol/EigenLayer-AVS/core/taskengine/macros"
)

func (agg *Aggregator) stopTaskEngine() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/createAdminKey.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"github.com/AvaProtocol/ap-avs/aggregator"
"github.com/AvaProtocol/EigenLayer-AVS/aggregator"

"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/createAliasKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package cmd
import (
"github.com/spf13/cobra"

"github.com/AvaProtocol/ap-avs/operator"
"github.com/AvaProtocol/EigenLayer-AVS/operator"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/declareAlias.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package cmd
import (
"github.com/spf13/cobra"

"github.com/AvaProtocol/ap-avs/operator"
"github.com/AvaProtocol/EigenLayer-AVS/operator"
)

// declareAliasCmd represents the declareAlias command
Expand Down
2 changes: 1 addition & 1 deletion cmd/deregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package cmd
import (
"github.com/spf13/cobra"

"github.com/AvaProtocol/ap-avs/operator"
"github.com/AvaProtocol/EigenLayer-AVS/operator"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cmd
import (
"github.com/spf13/cobra"

"github.com/AvaProtocol/ap-avs/operator"
"github.com/AvaProtocol/EigenLayer-AVS/operator"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/removeAlias.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package cmd
import (
"github.com/spf13/cobra"

"github.com/AvaProtocol/ap-avs/operator"
"github.com/AvaProtocol/EigenLayer-AVS/operator"
)

// removeAliasCmd represents the removeAlias command
Expand Down
2 changes: 1 addition & 1 deletion cmd/runAggregator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cmd

import (
"github.com/AvaProtocol/ap-avs/aggregator"
"github.com/AvaProtocol/EigenLayer-AVS/aggregator"

"github.com/spf13/cobra"
)
Expand Down
Loading