Skip to content
Draft
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
35 changes: 35 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,41 @@ start-postgres: ## Run the PostgreSQL 16 docker container
@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:17-alpine
@$(MAKE) migrate

################################################################################
# Protorype PRT (WIP)
DAVE_ROOT=$(PWD)/dave
APP_NAME?=honeypot
DEPLOYMENTS_DIR := "$(DAVE_ROOT)/cartesi-rollups/contracts/deployments/31337"
ANVIL_KEY_0=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
ANVIL_KEY_7=0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356

# retrive application variables from the database based on APP_NAME
APP_ADDRESS=$(shell psql $${CARTESI_DATABASE_CONNECTION} -qtc "select iapplication_address from application WHERE name = '$(APP_NAME)';" | lua5.4 -e 'print((io.read("*a"):gsub("\\x", "0x"):gsub("%s+", "")))')
APP_URI=$(shell psql $${CARTESI_DATABASE_CONNECTION} -qtc "select template_uri from application WHERE name = '$(APP_NAME)';" | lua5.4 -e 'print((io.read("*a"):gsub("%s+", "")))')
APP_STATE=$(APP_URI)/_state/

APP_KEY=$(ANVIL_KEY_7)

# prototype node expected environment variables
export WEB3_PRIVATE_KEY=$(ANVIL_KEY_0)
export DAVE_APP_FACTORY=$(shell jq -j ".DaveAppFactory" deployment.json)
export INPUT_BOX=$(shell jq -j .InputBox deployment.json)
export ERC20_PORTAL=$(shell jq -j .ERC20Portal deployment.json)
export ERC20_TOKEN=$(shell jq -j .TestFungibleToken deployment.json)
start-prt: deployment.json ## Run the prototype PRT node
rm -rf $(APP_STATE) && mkdir -p $(APP_STATE)
docker container create --name cp cartesi/rollups-node-devnet:devel
docker cp cp:/opt/cartesi/rollups-contracts/deployments/31337/ \
$(DAVE_ROOT)/cartesi-rollups/contracts/deployments/;
docker container rm cp
env \
MACHINE_PATH=$(APP_URI) \
APP_ADDRESS=$(APP_ADDRESS) \
STATE_DIR=$(APP_STATE) \
RUST_BACKTRACE=full \
$(DAVE_ROOT)/target/debug/cartesi-rollups-prt-node --sleep-duration-seconds 1 pk --web3-private-key $(APP_KEY)
################################################################################

start: start-postgres start-devnet ## Start the anvil devnet and PostgreSQL 16 docker containers

stop-devnet: ## Stop the anvil devnet docker container
Expand Down
28 changes: 15 additions & 13 deletions cmd/cartesi-rollups-cli/root/app/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,21 @@ func run(cmd *cobra.Command, args []string) {
}

application := model.Application{
Name: validName,
IApplicationAddress: address,
IConsensusAddress: consensus,
IInputBoxAddress: *inputBoxAddress,
TemplateURI: templatePath,
TemplateHash: parsedTemplateHash,
EpochLength: epochLength,
DataAvailability: encodedDA,
ConsensusType: consensusType,
State: applicationState,
IInputBoxBlock: inputBoxBlockNumber,
LastInputCheckBlock: 0,
LastOutputCheckBlock: 0,
Name: validName,
IApplicationAddress: address,
IConsensusAddress: consensus,
IInputBoxAddress: *inputBoxAddress,
TemplateURI: templatePath,
TemplateHash: parsedTemplateHash,
EpochLength: epochLength,
DataAvailability: encodedDA,
ConsensusType: consensusType,
State: applicationState,
IInputBoxBlock: inputBoxBlockNumber,
LastEpochCheckBlock: 0,
LastInputCheckBlock: 0,
LastOutputCheckBlock: 0,
LastTournamentCheckBlock: 0,
}

// load execution parameters from a file?
Expand Down
4 changes: 4 additions & 0 deletions cmd/cartesi-rollups-node/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ func run(cmd *cobra.Command, args []string) {
createInfo.ClaimerClient, err = createEthClient(ctx, cfg.BlockchainHttpEndpoint.String(), logger)
cobra.CheckErr(err)

logger = service.NewLogger(cfg.LogLevel, cfg.LogColor).With("service", "prt")
createInfo.PrtClient, err = createEthClient(ctx, cfg.BlockchainHttpEndpoint.String(), logger)
cobra.CheckErr(err)

createInfo.Repository, err = factory.NewRepositoryFromConnectionString(ctx, cfg.DatabaseConnection.String())
cobra.CheckErr(err)
defer createInfo.Repository.Close()
Expand Down
40 changes: 37 additions & 3 deletions cmd/cartesi-rollups-prt/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ package root

import (
"context"
"log/slog"

"github.com/cartesi/rollups-node/internal/config"
"github.com/cartesi/rollups-node/internal/prt"
"github.com/cartesi/rollups-node/internal/repository/factory"
"github.com/cartesi/rollups-node/internal/version"
"github.com/cartesi/rollups-node/pkg/service"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
"github.com/hashicorp/go-retryablehttp"

"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand All @@ -25,7 +29,7 @@ var (
pollInterval string
maxStartupTime string
telemetryAddress string
cfg *config.ValidatorConfig
cfg *config.PrtConfig
)

var Cmd = &cobra.Command{
Expand Down Expand Up @@ -59,14 +63,39 @@ func init() {
// TODO: validate on preRunE
Cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
var err error
cfg, err = config.LoadValidatorConfig()
cfg, err = config.LoadPrtConfig()
if err != nil {
return err
}
return nil
}
}

func createEthClient(ctx context.Context, endpoint string, logger *slog.Logger) (*ethclient.Client, error) {
rclient := retryablehttp.NewClient()
rclient.Logger = logger
rclient.RetryMax = int(cfg.BlockchainHttpMaxRetries)
rclient.RetryWaitMin = cfg.BlockchainHttpRetryMinWait
rclient.RetryWaitMax = cfg.BlockchainHttpRetryMaxWait

clientOptions := []rpc.ClientOption{
rpc.WithHTTPClient(rclient.StandardClient()),
}

authOpt, err := config.HTTPAuthorizationOption()
cobra.CheckErr(err)
if authOpt != nil {
clientOptions = append(clientOptions, authOpt)
}

rpcClient, err := rpc.DialOptions(ctx, endpoint, clientOptions...)
if err != nil {
return nil, err
}

return ethclient.NewClient(rpcClient), nil
}

func run(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(context.Background(), cfg.MaxStartupTime)
defer cancel()
Expand All @@ -79,11 +108,16 @@ func run(cmd *cobra.Command, args []string) {
EnableSignalHandling: true,
TelemetryCreate: true,
TelemetryAddress: cfg.TelemetryAddress,
PollInterval: cfg.ValidatorPollingInterval,
PollInterval: cfg.PrtPollingInterval,
},
Config: *cfg,
}

var err error
logger := service.NewLogger(cfg.LogLevel, cfg.LogColor).With("service", serviceName)
createInfo.EthClient, err = createEthClient(ctx, cfg.BlockchainHttpEndpoint.String(), logger)
cobra.CheckErr(err)

createInfo.Repository, err = factory.NewRepositoryFromConnectionString(ctx, cfg.DatabaseConnection.String())
cobra.CheckErr(err)
defer createInfo.Repository.Close()
Expand Down
Loading
Loading