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

feat(advancer): add the repository and end-to-end tests to the advancer #528

Closed
wants to merge 4 commits into from
Closed
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
122 changes: 74 additions & 48 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,57 @@ permissions:
contents: write

jobs:
build-ci-base:
runs-on: ubuntu-22.04
outputs:
output: ${{ steps.export_tag.outputs.image_tag }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/cartesi/rollups-node-ci
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=ref,event=pr

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: depot/setup-action@v1
- name: Build and push docker image
id: docker_build
uses: depot/bake-action@v1
with:
files: |
./docker-bake.hcl
${{ steps.docker_meta.outputs.bake-file }}
./docker-bake.platforms.hcl
targets: rollups-node-ci
push: true
project: ${{ vars.DEPOT_PROJECT }}
workdir: build

- name: Export Image Tag
id : export_tag
run : echo "image_tag=${{steps.docker_meta.outputs.version}}" >> "$GITHUB_OUTPUT"

do-basic-checks:
runs-on: ubuntu-22.04
container:
image: ghcr.io/cartesi/rollups-node-ci:${{needs.build-ci-base.outputs.output}}
needs:
- build-ci-base
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -40,16 +89,38 @@ jobs:
path: ./
config: .github/license-check/config.json

- name: Check auto generated files
run: make check-generate

- name: Lint Markdown docs
uses: DavidAnson/markdownlint-cli2-action@v16
with:
globs: |
*.md
docs/*.md

check-generated-files:
runs-on: ubuntu-22.04
container:
image: ghcr.io/cartesi/rollups-node-ci:${{needs.build-ci-base.outputs.output}}
needs:
- build-ci-base
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
ref: ${{ github.event.pull_request.head.sha }}

- name: Fix VCS Issue
run : git config --global --add safe.directory /__w/rollups-node/rollups-node

- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'

- name: Check auto generated files
run: make check-generate


test-rust:
runs-on: ubuntu-22.04
env:
Expand Down Expand Up @@ -126,51 +197,6 @@ jobs:
- name: Run tests
run: cargo test

build-ci-base:
runs-on: ubuntu-22.04
outputs:
output: ${{ steps.export_tag.outputs.image_tag }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Docker meta
id: docker_meta
uses: docker/metadata-action@v5
with:
images: |
name=ghcr.io/cartesi/rollups-node-ci
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=ref,event=pr

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: depot/setup-action@v1
- name: Build and push docker image
id: docker_build
uses: depot/bake-action@v1
with:
files: |
./docker-bake.hcl
${{ steps.docker_meta.outputs.bake-file }}
./docker-bake.platforms.hcl
targets: rollups-node-ci
push: true
project: ${{ vars.DEPOT_PROJECT }}
workdir: build

- name: Export Image Tag
id : export_tag
run : echo "image_tag=${{steps.docker_meta.outputs.version}}" >> "$GITHUB_OUTPUT"

test-go:
runs-on: ubuntu-22.04
container:
Expand Down
36 changes: 36 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,42 @@ ARG GO_BUILD_PATH
ARG ROLLUPS_NODE_VERSION
WORKDIR ${GO_BUILD_PATH}

ARG MACHINE_EMULATOR_VERSION
ARG DEBIAN_FRONTEND=noninteractive

# Install ca-certificates and curl (setup).
RUN <<EOF
set -e
apt-get update
apt-get install -y --no-install-recommends ca-certificates curl
EOF

# Install the cartesi-machine (cartesi/machine-emulator).
RUN <<EOF
set -e
URL=https://github.com/cartesi/machine-emulator/releases/download
VERSION=v${MACHINE_EMULATOR_VERSION}
ARCH=$(dpkg --print-architecture)
ARTIFACT=cartesi-machine-${VERSION}_${ARCH}.deb
curl -fsSL ${URL}/${VERSION}/${ARTIFACT} -o ./cartesi-machine.deb
apt-get install -y ./cartesi-machine.deb
rm ./cartesi-machine.deb
EOF

# Configure cartesi user and cartesi group.
RUN <<EOF
set -e
addgroup --system --gid 102 cartesi
adduser --system --uid 102 \
--disabled-login \
--gecos "cartesi user" \
--home /nonexistent \
--ingroup cartesi \
--no-create-home \
--shell /bin/false \
cartesi
EOF

# Download external dependencies.
COPY go.mod .
COPY go.sum .
Expand Down
105 changes: 105 additions & 0 deletions cmd/cartesi-rollups-advancer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// (c) Cartesi and individual authors (see AUTHORS)
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)

package main

import (
"context"
"fmt"
"log/slog"
"os"
"os/signal"
"syscall"
"time"

"github.com/cartesi/rollups-node/internal/node/advancer"
"github.com/cartesi/rollups-node/internal/node/advancer/machines"
"github.com/cartesi/rollups-node/internal/node/config"
"github.com/cartesi/rollups-node/internal/node/startup"
"github.com/cartesi/rollups-node/internal/repository"
"github.com/spf13/cobra"
)

const CMD_NAME = "advancer"

var (
buildVersion = "devel"
Cmd = &cobra.Command{
Use: CMD_NAME,
Short: "Runs the Advancer",
Long: "Runs the Advancer in standalone mode",
Run: run,
}
)

func init() {
flags := Cmd.Flags()
flags.BytesHex("application-address", nil, "")
flags.String("server-address", "", "")
flags.String("snapshot", "", "")
flags.Int64("snapshot-input-index", -1, "")
flags.Uint64("machine-inc-cycles", 50_000_000, "")
flags.Uint64("machine-max-cycles", 5_000_000_000, "")
flags.Uint64("machine-advance-timeout", 60, "")
flags.Uint64("machine-inspect-timeout", 10, "")
}

func main() {
err := Cmd.Execute()
if err != nil {
os.Exit(1)
}
}

func getDatabase(ctx context.Context, c config.NodeConfig) (*repository.Database, error) {
err := startup.ValidateSchema(c)
if err != nil {
return nil, fmt.Errorf("invalid database schema: %w", err)
}

database, err := repository.Connect(ctx, c.PostgresEndpoint.Value)
if err != nil {
return nil, fmt.Errorf("failed to connect to the database: %w", err)
}

return database, nil
}

func run(cmd *cobra.Command, args []string) {
startTime := time.Now()

Check failure on line 69 in cmd/cartesi-rollups-advancer/main.go

View workflow job for this annotation

GitHub Actions / test-go

startTime declared and not used (typecheck)

ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

c := config.FromEnv()
startup.ConfigLogs(c)

slog.Info("Starting the Cartesi Rollups Node Advancer", "version", buildVersion, "config", c)

database, err := getDatabase(ctx, c)
if err != nil {
slog.Error(err.Error())
os.Exit(1)
}
defer database.Close()

repo := &repository.AdvancerRepository{Database: database}

machines, err := machines.Load(ctx, c, repo)
if err != nil {
slog.Error(err.Error())
os.Exit(1)
}
defer machines.Close()

advancer, err := advancer.New(machines, repo)

poller, err := advancer.Poller(5 * time.Second)

ready := make(chan struct{}, 1)

if err := poller.Start(ctx, ready); err != nil {
slog.Error("advancer exited with an error", "error", err)
os.Exit(1)
}
}
2 changes: 1 addition & 1 deletion cmd/cartesi-rollups-cli/root/app/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func run(cmd *cobra.Command, args []string) {
IConsensusAddress: common.HexToAddress(iConsensusAddress),
}

err := cmdcommom.Database.InsertApplication(ctx, &application)
_, err := cmdcommom.Database.InsertApplication(ctx, &application)
cobra.CheckErr(err)
fmt.Printf("Application %v successfully added\n", application.ContractAddress)
}
51 changes: 50 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ When enabled, will connect to postgres database via SSL.
* **Type:** `bool`
* **Default:** `"true"`

## `CARTESI_ADVANCER_POLLING_INTERVAL`

How many seconds the node will wait before querying the database for new inputs.

* **Type:** `Duration`
* **Default:** `"30"`

## `CARTESI_EPOCH_LENGTH`

Length of a rollups epoch in blocks.
Expand All @@ -234,7 +241,7 @@ At the end of each epoch, the node will send claims to the blockchain.

## `CARTESI_EVM_READER_RETRY_POLICY_MAX_DELAY`

How seconds the retry policy will wait between retries.
How many seconds the retry policy will wait between retries.

* **Type:** `Duration`
* **Default:** `"3"`
Expand All @@ -246,6 +253,13 @@ How many times some functions should be retried after an error.
* **Type:** `uint64`
* **Default:** `"3"`

## `CARTESI_MAX_CONCURRENT_INSPECTS`

Maximum number of inspect-state requests that can be concurrently active.

* **Type:** `uint8`
* **Default:** `"10"`

## `CARTESI_VALIDATOR_POLLING_INTERVAL`

How many seconds the node will wait before trying to finish epochs for all applications.
Expand All @@ -258,3 +272,38 @@ How many seconds the node will wait before trying to finish epochs for all appli
Path to the directory with the cartesi-machine snapshot that will be loaded by the node.

* **Type:** `string`

## `CARTESI_MACHINE_ADVANCE_TIMEOUT`

TODO.

* **Type:** `Duration`
* **Default:** `"60"`

## `CARTESI_MACHINE_INC_CYCLES`

TODO.

* **Type:** `uint64`
* **Default:** `"50000000"`

## `CARTESI_MACHINE_INSPECT_TIMEOUT`

TODO.

* **Type:** `Duration`
* **Default:** `"10"`

## `CARTESI_MACHINE_MAX_CYCLES`

TODO.

* **Type:** `uint64`
* **Default:** `"5000000000"`

## `CARTESI_MACHINE_SERVER_VERBOSITY`

TODO.

* **Type:** `string`
* **Default:** `"info"`
Loading
Loading