Skip to content

Commit

Permalink
refactor: postgres schema and repository API (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
vfusco committed Feb 5, 2025
1 parent 79d0b67 commit 31150b3
Show file tree
Hide file tree
Showing 110 changed files with 7,631 additions and 6,769 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ machine-snapshot/**
/cartesi-rollups-validator
/cartesi-rollups-claimer
/rollups-contracts
/applications
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ linters:
- misspell
linters-settings:
lll:
line-length: 120
line-length: 140
tab-width: 4
mnd:
ignored-functions:
Expand Down
34 changes: 12 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ env:
@echo export CGO_CFLAGS=\"$(CGO_CFLAGS)\"
@echo export CGO_LDFLAGS=\"$(CGO_LDFLAGS)\"
@echo export CARTESI_LOG_LEVEL="info"
@echo export CARTESI_EVM_READER_DEFAULT_BLOCK="latest"
@echo export CARTESI_BLOCKCHAIN_HTTP_ENDPOINT="http://localhost:8545"
@echo export CARTESI_BLOCKCHAIN_WS_ENDPOINT="ws://localhost:8545"
@echo export CARTESI_BLOCKCHAIN_ID="31337"
Expand All @@ -79,7 +80,7 @@ env:
@echo export CARTESI_TEST_POSTGRES_ENDPOINT="postgres://test_user:password@localhost:5432/test_rollupsdb?sslmode=disable"
@echo export CARTESI_TEST_MACHINE_IMAGES_PATH=\"$(CARTESI_TEST_MACHINE_IMAGES_PATH)\"
@echo export CARTESI_FEATURE_CLAIMER_SUBMISSION_ENABLED=true
@echo export PATH=$(CURDIR):$$PATH
@echo export PATH=\"$(CURDIR):$$PATH\"

# =============================================================================
# Artifacts
Expand Down Expand Up @@ -119,6 +120,12 @@ migrate: ## Run migration on development database
@echo "Running PostgreSQL migration"
@go run $(GO_BUILD_PARAMS) dev/migrate/main.go

generate-db: ## Generate repository/db with Jet
@echo "Generating internal/repository/postgres/db with jet"
@rm -rf internal/repository/postgres/db
@go run github.com/go-jet/jet/v2/cmd/jet -dsn=$$CARTESI_POSTGRES_ENDPOINT -schema=public -path=./internal/repository/postgres/db
@rm -rf internal/repository/postgres/db/rollupsdb/public/model

# =============================================================================
# Clean
# =============================================================================
Expand Down Expand Up @@ -169,7 +176,7 @@ applications/echo-dapp: ## Create echo-dapp test application

deploy-echo-dapp: applications/echo-dapp ## Deploy echo-dapp test application
@echo "Deploying echo-dapp test application"
@./cartesi-rollups-cli app deploy -t applications/echo-dapp/ -v
@./cartesi-rollups-cli app deploy -n echo-dapp -t applications/echo-dapp/ -v

# =============================================================================
# Static Analysis
Expand Down Expand Up @@ -210,7 +217,7 @@ image: ## Build the docker images using bake
run-with-compose: ## Run the node with the anvil devnet
@docker compose up

run-devnet: ## Run the anvil devnet docker container
start-devnet: ## Run the anvil devnet docker container
@echo "Starting devnet"
@docker run --rm --name devnet -p 8545:8545 -d cartesi/rollups-node-devnet:$(IMAGE_TAG)
@$(MAKE) copy-devnet-files
Expand All @@ -220,28 +227,11 @@ copy-devnet-files deployment.json: ## Copy the devnet files to the host
@docker cp devnet:/usr/share/devnet/deployment.json deployment.json
@docker cp devnet:/usr/share/devnet/anvil_state.json anvil_state.json

run-postgres: ## Run the PostgreSQL 16 docker container
start-postgres: ## Run the PostgreSQL 16 docker container
@echo "Starting portgres"
@docker run --rm --name postgres -p 5432:5432 -d -e POSTGRES_PASSWORD=password -e POSTGRES_DB=rollupsdb -v $(CURDIR)/test/postgres/init-test-db.sh:/docker-entrypoint-initdb.d/init-test-db.sh postgres:16-alpine

run-postgraphile: ## Run the GraphQL server docker container
@docker run --rm --name postgraphile -p 10004:10004 -d --init \
graphile/postgraphile:4.14.0 \
--retry-on-init-fail \
--dynamic-json \
--no-setof-functions-contain-nulls \
--no-ignore-rbac \
--enable-query-batching \
--enhance-graphiql \
--extended-errors errcode \
--legacy-relations omit \
--connection "postgres://postgres:[email protected]:5432/rollupsdb?sslmode=disable" \
--schema graphql \
--host "0.0.0.0" \
--port 10004
# --append-plugins @graphile-contrib/pg-simplify-inflector \
start: run-postgres run-devnet ## Start the anvil devnet and PostgreSQL 16 docker containers
start: start-postgres start-devnet ## Start the anvil devnet and PostgreSQL 16 docker containers
@$(MAKE) migrate

stop-devnet: ## Stop the anvil devnet docker container
Expand Down
57 changes: 8 additions & 49 deletions api/openapi/inspect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ openapi: 3.0.0

info:
title: Inspect-state HTTP API for Cartesi Rollups
version: 0.6.0
version: 0.7.0
license:
name: Apache-2.0
url: https://www.apache.org/licenses/LICENSE-2.0.html
Expand All @@ -11,68 +11,27 @@ info:
API that allows the DApp frontend to make inspect-state requests to the DApp backend.
paths:
inspect/{dapp}/{payload}:
get:
operationId: inspect
summary: Inspect DApp state via GET
description: |
This method sends an inspect-state request to the DApp backend, passing the payload string in the URL.
The payload string should be URL-encoded; the inspect server will decode the string to UTF-8.
If the DApp frontend needs to pass a binary string to the backend then it is advised to use the POST method.
The response contains a status string and the reports generated by the DApp backend.
The status string can be either 'accept', 'reject', or 'exception'.
In case of exception, the field exception_payload will contain the exception payload;
Otherwise, this field will be null.
When running on machine mode, the whole Cartesi machine is rolled back after processing the inspect-state request.
On host mode, it is advised against changing the DApp backend state when processing an inspect-state request.
Notice that this method is synchronous, so it is not advised to be used for performing resource-intensive operations.
parameters:
- in: path
name: dapp
required: true
schema:
type: string
- in: path
name: payload
required: true
schema:
type: string

responses:
"200":
description: Inspect state response.
content:
application/json:
schema:
$ref: "#/components/schemas/InspectResult"

default:
description: Error response.
content:
text/plain:
schema:
$ref: "#/components/schemas/Error"

inspect/{dapp}:
post:
operationId: inspect_post
summary: Inspect DApp state via POST
description: |
Differently from the GET method, the POST method sends an inspect-state request to the DApp backend by passing its payload in the request body.
The payload should be a binary.
Other than that, it behaves the same way as described in the GET method.
This POST method sends an inspect-state request to the DApp backend, using the body contents as a binary payload for the inspect method.
The response includes a status string and reports generated by the DApp backend. If an exception occurs, the `exception_payload` field will contain the exception details; otherwise, this field will be null.
The inspect operation is executed on a temporary fork of the machine created upon request arrival, which is discarded afterward. Note that this method is synchronous and not recommended for resource-intensive operations.
parameters:
- in: path
name: dapp
description: dapp name or address
required: true
schema:
type: string

requestBody:
description: Binary payload
content:
application/octet-stream:
schema:
Expand Down
6 changes: 3 additions & 3 deletions cmd/cartesi-rollups-cli/root/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ import (
)

var Cmd = &cobra.Command{
Use: "app",
Short: "Application management related commands",
PersistentPreRun: common.Setup,
Use: "app",
Short: "Application management related commands",
PersistentPreRunE: common.PersistentPreRun,
}

func init() {
Expand Down
Loading

0 comments on commit 31150b3

Please sign in to comment.