Skip to content

Commit

Permalink
refactor: removed snapshot storage
Browse files Browse the repository at this point in the history
  • Loading branch information
gligneul committed Jan 19, 2024
1 parent 350841e commit 12b0690
Show file tree
Hide file tree
Showing 27 changed files with 189 additions and 1,408 deletions.
26 changes: 14 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ jobs:
with:
submodules: recursive

- name: Build and dependency images
uses: depot/bake-action@v1
with:
files: |
./docker-bake.hcl
./docker-bake.override.hcl
./docker-bake.platforms.hcl
targets: |
rollups-node-devnet
rollups-node-snapshot
project: ${{ vars.DEPOT_PROJECT }}
workdir: build
load: true

- name: 📦 Install protoc
run: sudo apt update && sudo apt install -y protobuf-compiler libprotobuf-dev

Expand Down Expand Up @@ -85,18 +99,6 @@ jobs:

- uses: depot/setup-action@v1

- name: Build and load devnet image
uses: depot/bake-action@v1
with:
files: |
./docker-bake.hcl
./docker-bake.override.hcl
./docker-bake.platforms.hcl
targets: rollups-node-devnet
project: ${{ vars.DEPOT_PROJECT }}
workdir: build
load: true

- name: Run Go tests
working-directory: ${{ github.workspace }}
run: go test ./...
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
instead of /opt/cartesi/bin.
- Changed the base Docker image to debian-bookworm instead cartesi/server-manager.

### Removed

- Removed snapshot-saving feature. Now, the node will always start from the begining.

## [1.2.0]

### Added
Expand Down
31 changes: 16 additions & 15 deletions build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ ARG LINUX_KERNEL_VERSION
ARG ROM_VERSION

# Build directories.
ARG MACHINE_SNAPSHOT_BUILD_PATH=/build/machine-snapshot
ARG SNAPSHOT_BUILD_PATH=/build/snapshot
ARG DEVNET_BUILD_PATH=/build/devnet
ARG RUST_BUILD_PATH=/build/rollups-node/rust
ARG GO_BUILD_PATH=/build/rollups-node/go

# Runtime dir for the cartesi-machine snapshot.
ARG MACHINE_SNAPSHOT_RUNTIME_PATH=/usr/share/cartesi/snapshots
ARG SNAPSHOT_RUNTIME_PATH=/usr/share/cartesi/snapshots
ARG SNAPSHOT_FILENAME=test-application

####################################################################################################
# STAGE: emulator-base
Expand Down Expand Up @@ -87,12 +88,13 @@ ADD https://github.com/cartesi/image-kernel/releases/download/v${LINUX_VERSION}/
ADD https://github.com/cartesi/machine-emulator-rom/releases/download/v${ROM_VERSION}/rom-v${ROM_VERSION}.bin rom.bin

# Generate snapshot with echo and store it.
ARG MACHINE_SNAPSHOT_BUILD_PATH
WORKDIR ${MACHINE_SNAPSHOT_BUILD_PATH}
ARG SNAPSHOT_BUILD_PATH
ARG SNAPSHOT_FILENAME
WORKDIR ${SNAPSHOT_BUILD_PATH}
RUN cartesi-machine \
--ram-length=128Mi \
--rollup \
--store=$MACHINE_SNAPSHOT_BUILD_PATH/snapshot \
--store=$SNAPSHOT_BUILD_PATH/$SNAPSHOT_FILENAME \
-- "ioctl-echo-loop --vouchers=1 --notices=1 --reports=1 --verbose=1"

# STAGE: rollups-node-snapshot
Expand All @@ -103,14 +105,12 @@ RUN cartesi-machine \
FROM emulator-base as rollups-node-snapshot

# Copy image from the builder stage.
ARG MACHINE_SNAPSHOT_BUILD_PATH
ARG MACHINE_SNAPSHOT_RUNTIME_PATH
WORKDIR ${MACHINE_SNAPSHOT_RUNTIME_PATH}
COPY --from=snapshot-builder --chown=cartesi:cartesi ${MACHINE_SNAPSHOT_BUILD_PATH}/snapshot ./0_0
RUN <<EOF
ln -s ${MACHINE_SNAPSHOT_RUNTIME_PATH}/0_0 ${MACHINE_SNAPSHOT_RUNTIME_PATH}/latest
chown -R cartesi:cartesi ${MACHINE_SNAPSHOT_RUNTIME_PATH}
EOF
ARG SNAPSHOT_BUILD_PATH
ARG SNAPSHOT_RUNTIME_PATH
WORKDIR ${SNAPSHOT_RUNTIME_PATH}
COPY --from=snapshot-builder --chown=cartesi:cartesi \
${SNAPSHOT_BUILD_PATH}/${SNAPSHOT_FILENAME} \
${SNAPSHOT_RUNTIME_PATH}/${SNAPSHOT_FILENAME}

# Set dummy command.
CMD /bin/bash
Expand Down Expand Up @@ -156,8 +156,9 @@ ARG DEVNET_BUILD_PATH
WORKDIR ${DEVNET_BUILD_PATH}

# Copy machine snapshot hash.
ARG MACHINE_SNAPSHOT_BUILD_PATH
COPY --from=snapshot-builder ${MACHINE_SNAPSHOT_BUILD_PATH}/snapshot/hash hash.bin
ARG SNAPSHOT_BUILD_PATH
ARG SNAPSHOT_FILENAME
COPY --from=snapshot-builder ${SNAPSHOT_BUILD_PATH}/${SNAPSHOT_FILENAME}/hash hash.bin

# Generate Anvil state.
COPY scripts scripts
Expand Down
2 changes: 1 addition & 1 deletion build/compose-snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ services:
machine_snapshot_setup:
condition: service_completed_successfully
environment:
CARTESI_SNAPSHOT_DIR: "/usr/share/cartesi/snapshots"
CARTESI_SNAPSHOT_DIR: "/usr/share/cartesi/snapshots/test-application"
volumes:
- machine:/usr/share/cartesi/snapshots

Expand Down
8 changes: 2 additions & 6 deletions cmd/cartesi-rollups-node/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,9 @@ func newAdvanceRunner() services.CommandService {
if config.GetCartesiFeatureHostMode() || config.GetCartesiFeatureDisableMachineHashCheck() {
s.Env = append(s.Env, "SNAPSHOT_VALIDATION_ENABLED=false")
}
if config.GetCartesiFeatureHostMode() {
s.Env = append(s.Env, "SNAPSHOT_ENABLED=false")
} else {
s.Env = append(s.Env,
fmt.Sprintf("SNAPSHOT_DIR=%v", config.GetCartesiSnapshotDir()))
if !config.GetCartesiFeatureHostMode() {
s.Env = append(s.Env,
fmt.Sprintf("SNAPSHOT_LATEST=%v/latest", config.GetCartesiSnapshotDir()))
fmt.Sprintf("MACHINE_SNAPSHOT_PATH=%v", config.GetCartesiSnapshotDir()))
}
s.Env = append(s.Env, os.Environ()...)
return s
Expand Down
2 changes: 1 addition & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ At the end of each epoch, the node will send claims to the blockchain.

## `CARTESI_SNAPSHOT_DIR`

Path to the directory of the cartesi-machine snapshots.
Path to the directory with the cartesi-machine snapshot that will be loaded by the node.

* **Type:** `string`

2 changes: 1 addition & 1 deletion internal/config/generate/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ The node will begin to read blockchain events from this block."""
[snapshot.CARTESI_SNAPSHOT_DIR]
go-type = "string"
description = """
Path to the directory of the cartesi-machine snapshots."""
Path to the directory with the cartesi-machine snapshot that will be loaded by the node."""

#
# Auth
Expand Down
4 changes: 0 additions & 4 deletions offchain/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions offchain/advance-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,19 @@ name = "cartesi-rollups-advance-runner"
path = "src/main.rs"

[dependencies]
contracts = { path = "../contracts" }
grpc-interfaces = { path = "../grpc-interfaces" }
http-health-check = { path = "../http-health-check" }
log = { path = "../log" }
rollups-events = { path = "../rollups-events" }

async-trait.workspace = true
backoff = { workspace = true, features = ["tokio"] }
clap = { workspace = true, features = ["derive", "env"] }
ethers.workspace = true
hex.workspace = true
sha3 = { workspace = true, features = ["std"] }
snafu.workspace = true
tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread"] }
tonic.workspace = true
tracing.workspace = true
url.workspace = true
uuid = { workspace = true, features = ["v4"] }

[dev-dependencies]
Expand Down
Loading

0 comments on commit 12b0690

Please sign in to comment.