Skip to content

Commit

Permalink
feat(advancer): add the advancer's repository
Browse files Browse the repository at this point in the history
  • Loading branch information
renan061 committed Aug 28, 2024
1 parent 5cdb0a8 commit d79023c
Show file tree
Hide file tree
Showing 10 changed files with 789 additions and 113 deletions.
94 changes: 49 additions & 45 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 Down Expand Up @@ -126,51 +175,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
16 changes: 10 additions & 6 deletions internal/node/advancer/advancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ func (advancer *Advancer) Step(ctx context.Context) error {
}
}

// Updates the status of the epochs.
for _, app := range apps {
err := advancer.repository.UpdateEpochs(ctx, app)
if err != nil {
return err
}
}

return nil
}

Expand Down Expand Up @@ -99,11 +107,7 @@ func (advancer *Advancer) process(ctx context.Context, app Address, inputs []*In
}
}

// Updates the status of the epochs based on the last processed input.
lastInput := inputs[len(inputs)-1]
err := advancer.repository.UpdateEpochs(ctx, app, lastInput)

return err
return nil
}

// ------------------------------------------------------------------------------------------------
Expand All @@ -114,7 +118,7 @@ type Repository interface {

StoreAdvanceResult(context.Context, *Input, *nodemachine.AdvanceResult) error

UpdateEpochs(_ context.Context, app Address, lastInput *Input) error
UpdateEpochs(_ context.Context, app Address) error
}

// A map of application addresses to machines.
Expand Down
43 changes: 10 additions & 33 deletions internal/node/advancer/advancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (s *AdvancerSuite) TestRun() {
res3 := randomAdvanceResult()

repository := &MockRepository{
GetInputsReturn: map[Address][]*Input{
GetUnprocessedInputsReturn: map[Address][]*Input{
app1: {
{Id: 1, RawData: marshal(res1)},
{Id: 2, RawData: marshal(res2)},
Expand All @@ -94,7 +94,9 @@ func (s *AdvancerSuite) TestRun() {
require.Len(repository.StoredResults, 3)
})

// NOTE: missing more test cases
s.Run("Error/UpdateEpochs", func() {
s.T().Skip("TODO")
})
}

func (s *AdvancerSuite) TestProcess() {
Expand Down Expand Up @@ -124,7 +126,6 @@ func (s *AdvancerSuite) TestProcess() {
err := advancer.process(context.Background(), app, inputs)
require.Nil(err)
require.Len(repository.StoredResults, 7)
require.Equal(*inputs[6], repository.LastInput)
})

s.Run("Panic", func() {
Expand Down Expand Up @@ -183,25 +184,7 @@ func (s *AdvancerSuite) TestProcess() {
require.Errorf(err, "store-advance error")
require.Len(repository.StoredResults, 1)
})

s.Run("UpdateEpochs", func() {
require := s.Require()

_, repository, advancer, app := setup()
inputs := []*Input{
{Id: 1, RawData: marshal(randomAdvanceResult())},
{Id: 2, RawData: marshal(randomAdvanceResult())},
{Id: 3, RawData: marshal(randomAdvanceResult())},
{Id: 4, RawData: marshal(randomAdvanceResult())},
}
repository.UpdateEpochsError = errors.New("update-epochs error")

err := advancer.process(context.Background(), app, inputs)
require.Errorf(err, "update-epochs error")
require.Len(repository.StoredResults, 4)
})
})

}

func (s *AdvancerSuite) TestKeysFrom() {
Expand All @@ -228,20 +211,19 @@ func (mock *MockMachine) Advance(
// ------------------------------------------------------------------------------------------------

type MockRepository struct {
GetInputsReturn map[Address][]*Input
GetInputsError error
StoreAdvanceError error
UpdateEpochsError error
GetUnprocessedInputsReturn map[Address][]*Input
GetUnprocessedInputsError error
StoreAdvanceError error
UpdateEpochsError error

StoredResults []*nodemachine.AdvanceResult
LastInput Input
}

func (mock *MockRepository) GetUnprocessedInputs(
_ context.Context,
appAddresses []Address,
) (map[Address][]*Input, error) {
return mock.GetInputsReturn, mock.GetInputsError
return mock.GetUnprocessedInputsReturn, mock.GetUnprocessedInputsError
}

func (mock *MockRepository) StoreAdvanceResult(
Expand All @@ -253,12 +235,7 @@ func (mock *MockRepository) StoreAdvanceResult(
return mock.StoreAdvanceError
}

func (mock *MockRepository) UpdateEpochs(
_ context.Context,
_ Address,
lastInput *Input,
) error {
mock.LastInput = *lastInput
func (mock *MockRepository) UpdateEpochs(_ context.Context, _ Address) error {
return mock.UpdateEpochsError
}

Expand Down
Loading

0 comments on commit d79023c

Please sign in to comment.