Skip to content
Merged
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
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ ifeq ($(BUILD_TYPE),debug)
endif

GO_TEST_PACKAGES ?= ./...
GO_TEST_FLAGS ?=

VERBOSE ?=
ifeq ($(VERBOSE),true)
GO_BUILD_PARAMS += -v
GO_TEST_FLAGS += -v
endif

TEST_PATTERN ?=
ifneq ($(TEST_PATTERN),)
GO_TEST_FLAGS += -run $(TEST_PATTERN)
endif

TEST_PACKAGES ?=
ifneq ($(TEST_PACKAGES),)
GO_TEST_PACKAGES := $(addprefix ./, $(addsuffix /..., $(subst :, ,$(TEST_PACKAGES))))
endif


ROLLUPS_CONTRACTS_ABI_BASEDIR:= rollups-contracts/
ROLLUPS_PRT_CONTRACTS_ABI_BASEDIR:= rollups-prt-contracts/
Expand Down Expand Up @@ -206,7 +224,7 @@ test: unit-test ## Execute all tests
unit-test: ## Execute go unit tests
@echo "Running go unit tests"
@go clean -testcache
@go test -p 1 $(GO_BUILD_PARAMS) $(GO_TEST_PACKAGES)
@go test -p 1 $(GO_BUILD_PARAMS) $(GO_TEST_FLAGS) $(GO_TEST_PACKAGES)

integration-test: ## Execute e2e tests
@echo "Running end-to-end tests"
Expand Down Expand Up @@ -245,6 +263,10 @@ deploy-exception-dapp: applications/exception-dapp ## Deploy exception-dapp test
@echo "Deploying exception-dapp test application"
@./cartesi-rollups-cli deploy application exception-dapp applications/exception-dapp/

deploy-prt-echo-dapp: applications/echo-dapp ## Deploy echo-dapp test application
@echo "Deploying echo-dapp test application"
@./cartesi-rollups-cli deploy application prt-echo-dapp applications/echo-dapp/ --prt

# Temporary test dependencies target while we are not using distribution packages
DOWNLOADS_DIR = test/downloads
CARTESI_TEST_MACHINE_IMAGES = $(DOWNLOADS_DIR)/linux.bin
Expand Down
39 changes: 25 additions & 14 deletions cmd/cartesi-rollups-cli/root/app/register/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var (
inputBoxAddressFromEnv bool
dataAvailability string
enableMachineHashCheck bool
applicationTypePRT bool
disabled bool
printAsJSON bool
executionParametersFileParam string
Expand All @@ -75,7 +76,7 @@ func init() {
"Application template hash. (DO NOT USE IN PRODUCTION)\nThis value is retrieved from the application contract",
)

Cmd.Flags().Uint64VarP(&epochLength, "epoch-length", "e", 10, // nolint: mnd
Cmd.Flags().Uint64VarP(&epochLength, "epoch-length", "e", 0, // nolint: mnd
"Consensus Epoch length. (DO NOT USE IN PRODUCTION)\nThis value is retrieved from the consensus contract",
)

Expand All @@ -97,6 +98,8 @@ func init() {
"Enable or disable machine hash check (DO NOT DISABLE IN PRODUCTION)")
cobra.CheckErr(viper.BindPFlag(config.FEATURE_MACHINE_HASH_CHECK_ENABLED, Cmd.Flags().Lookup("machine-hash-check")))

Cmd.Flags().BoolVarP(&applicationTypePRT, "prt", "", false, "Register as PRT application.")

origHelpFunc := Cmd.HelpFunc()
Cmd.SetHelpFunc(func(command *cobra.Command, strings []string) {
command.Flags().Lookup("verbose").Hidden = false
Expand Down Expand Up @@ -165,7 +168,7 @@ func run(cmd *cobra.Command, args []string) {
}
}

if !cmd.Flags().Changed("epoch-length") {
if !cmd.Flags().Changed("epoch-length") && !applicationTypePRT {
epochLength, err = getEpochLength(ctx, consensus)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to get epoch length from consensus: %v\n", err)
Expand Down Expand Up @@ -201,19 +204,27 @@ func run(cmd *cobra.Command, args []string) {
os.Exit(1)
}

consensusType := model.Consensus_Authority
if applicationTypePRT {
consensusType = model.Consensus_PRT
}

application := model.Application{
Name: validName,
IApplicationAddress: address,
IConsensusAddress: consensus,
IInputBoxAddress: *inputBoxAddress,
TemplateURI: templatePath,
TemplateHash: parsedTemplateHash,
EpochLength: epochLength,
DataAvailability: encodedDA,
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
2 changes: 2 additions & 0 deletions cmd/cartesi-rollups-cli/root/deploy/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func runDeployApplication(cmd *cobra.Command, args []string) {
application.Name = applicationName
application.TemplateURI = templateURI
application.State = model.ApplicationState_Disabled
application.ConsensusType = model.Consensus_Authority
if applicationEnableParam {
application.State = model.ApplicationState_Enabled
}
Expand Down Expand Up @@ -256,6 +257,7 @@ func runDeployApplication(cmd *cobra.Command, args []string) {
application.EpochLength = res.Deployment.EpochLength
application.DataAvailability = res.DataAvailability
application.IInputBoxBlock = res.IInputBoxBlock
application.ConsensusType = model.Consensus_PRT
default:
panic("unimplemented deployment type\n")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cartesi-rollups-cli/root/read/epochs/epochs.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func run(cmd *cobra.Command, args []string) {
if err := status.Scan(statusFilter); err != nil {
cobra.CheckErr(fmt.Errorf("invalid status filter: %w", err))
}
filter.Status = &status
filter.Status = []model.EpochStatus{status}
}

// Limit is validated in PreRunE
Expand Down
8 changes: 8 additions & 0 deletions cmd/cartesi-rollups-node/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var (
advancerPollInterval string
validatorPollInterval string
claimerPollInterval string
prtPollInterval string
maxStartupTime string
enableInputReader bool
enableInspect bool
Expand Down Expand Up @@ -93,6 +94,9 @@ func init() {
Cmd.Flags().StringVar(&claimerPollInterval, "claimer-poll-interval", "3", "Claimer poll interval")
cobra.CheckErr(viper.BindPFlag(config.CLAIMER_POLLING_INTERVAL, Cmd.Flags().Lookup("claimer-poll-interval")))

Cmd.Flags().StringVar(&prtPollInterval, "prt-poll-interval", "3", "Claimer poll interval")
cobra.CheckErr(viper.BindPFlag(config.PRT_POLLING_INTERVAL, Cmd.Flags().Lookup("prt-poll-interval")))

Cmd.Flags().StringVar(&maxStartupTime, "max-startup-time", "15", "Maximum startup time in seconds")
cobra.CheckErr(viper.BindPFlag(config.MAX_STARTUP_TIME, Cmd.Flags().Lookup("max-startup-time")))

Expand Down Expand Up @@ -184,6 +188,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
44 changes: 39 additions & 5 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 All @@ -50,23 +54,48 @@ func init() {
"Database connection string in the URL format\n(eg.: 'postgres://user:password@hostname:port/database') ")
cobra.CheckErr(viper.BindPFlag(config.DATABASE_CONNECTION, Cmd.Flags().Lookup("database-connection")))

Cmd.Flags().StringVar(&pollInterval, "poll-interval", "7", "Poll interval")
cobra.CheckErr(viper.BindPFlag(config.VALIDATOR_POLLING_INTERVAL, Cmd.Flags().Lookup("poll-interval")))
Cmd.Flags().StringVar(&pollInterval, "poll-interval", "3", "Poll interval")
cobra.CheckErr(viper.BindPFlag(config.PRT_POLLING_INTERVAL, Cmd.Flags().Lookup("poll-interval")))

Cmd.Flags().StringVar(&maxStartupTime, "max-startup-time", "15", "Maximum startup time in seconds")
cobra.CheckErr(viper.BindPFlag(config.MAX_STARTUP_TIME, Cmd.Flags().Lookup("max-startup-time")))

// 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