Skip to content

Commit dfc9b3e

Browse files
committed
PRT tool WIP
1 parent 18dce93 commit dfc9b3e

16 files changed

Lines changed: 608 additions & 21 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ machine-snapshot/**
1919
/applications
2020
/test/downloads
2121
/snapshots
22+
compose.override.yml

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ DOCKER_PLATFORM=--platform $(BUILD_PLATFORM)
5555
endif
5656

5757
# Go artifacts
58-
GO_ARTIFACTS := cartesi-rollups-node cartesi-rollups-cli cartesi-rollups-evm-reader cartesi-rollups-advancer cartesi-rollups-validator cartesi-rollups-claimer cartesi-rollups-jsonrpc-api
58+
GO_ARTIFACTS := cartesi-rollups-node cartesi-rollups-cli cartesi-rollups-evm-reader cartesi-rollups-advancer cartesi-rollups-validator cartesi-rollups-prt cartesi-rollups-claimer cartesi-rollups-jsonrpc-api
5959

6060
# fixme(vfusco): path on all oses
61-
CGO_CFLAGS:= -I$(PREFIX)/include
62-
CGO_LDFLAGS:= -L$(PREFIX)/lib
61+
# /Users/mpernambuco/ctsi2/cartesi-install-dir
62+
CGO_CFLAGS:= -I/Users/mpernambuco/ctsi2/cartesi-install-dir/usr/include
63+
CGO_LDFLAGS:= -L/Users/mpernambuco/ctsi2/cartesi-install-dir/usr/lib
64+
# CGO_CFLAGS:= -I$(PREFIX)/include
65+
# CGO_LDFLAGS:= -L$(PREFIX)/lib
6366
export CGO_CFLAGS
6467
export CGO_LDFLAGS
6568

cmd/cartesi-rollups-cli/root/deploy/application.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,12 @@ func runDeployApplication(cmd *cobra.Command, args []string) {
150150
}
151151
}
152152

153+
application := model.Application{}
154+
application.ConsensusType = model.ConsensusType_Authority
155+
153156
var deployment ethutil.IApplicationDeployment
154157
if deploymentTypePRT {
158+
application.ConsensusType = model.ConsensusType_Prt
155159
deployment, err = buildPrtApplicationDeployment(cmd, args, client, txOpts)
156160
} else if deploySelfhosted := !cmd.Flags().Changed("consensus"); deploySelfhosted {
157161
deployment, err = buildSelfhostedApplicationDeployment(cmd, args, client, txOpts)
@@ -193,8 +197,6 @@ func runDeployApplication(cmd *cobra.Command, args []string) {
193197
fmt.Fprint(os.Stderr, result)
194198
}
195199

196-
application := model.Application{}
197-
198200
application.Name = applicationName
199201
application.TemplateURI = templateURI
200202
application.State = model.ApplicationState_Disabled
@@ -249,7 +251,6 @@ func runDeployApplication(cmd *cobra.Command, args []string) {
249251
cobra.CheckErr(fmt.Errorf("failed to register application: %w", err))
250252
}
251253
defer repo.Close()
252-
253254
_, err = repo.CreateApplication(ctx, &application)
254255
if err != nil {
255256
cobra.CheckErr(fmt.Errorf("failed to register application: %w", err))

cmd/cartesi-rollups-node/root/root.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var (
3232
advancerPollInterval string
3333
validatorPollInterval string
3434
claimerPollInterval string
35+
prtPollInterval string
3536
maxStartupTime string
3637
enableInputReader bool
3738
enableInspect bool

cmd/cartesi-rollups-prt/main.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// (c) Cartesi and individual authors (see AUTHORS)
2+
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)
3+
4+
package main
5+
6+
import (
7+
"os"
8+
9+
"github.com/cartesi/rollups-node/cmd/cartesi-rollups-prt/root"
10+
)
11+
12+
func main() {
13+
err := root.Cmd.Execute()
14+
if err != nil {
15+
os.Exit(1)
16+
}
17+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// (c) Cartesi and individual authors (see AUTHORS)
2+
// SPDX-License-Identifier: Apache-2.0 (see LICENSE)
3+
4+
package root
5+
6+
import (
7+
"context"
8+
9+
"github.com/cartesi/rollups-node/internal/config"
10+
"github.com/cartesi/rollups-node/internal/prt"
11+
"github.com/cartesi/rollups-node/internal/repository/factory"
12+
"github.com/cartesi/rollups-node/internal/version"
13+
"github.com/cartesi/rollups-node/pkg/service"
14+
15+
"github.com/spf13/cobra"
16+
"github.com/spf13/viper"
17+
)
18+
19+
const serviceName = "prt"
20+
21+
var (
22+
logLevel string
23+
logColor bool
24+
databaseConnection string
25+
pollInterval string
26+
maxStartupTime string
27+
telemetryAddress string
28+
inspectAddress string
29+
machinelogLevel string
30+
enableMachineHashCheck bool
31+
enableInspect bool
32+
// PRT-specific flags
33+
cfg *config.PrtConfig
34+
)
35+
36+
var Cmd = &cobra.Command{
37+
Use: "cartesi-rollups-" + serviceName,
38+
Short: "Runs cartesi-rollups-" + serviceName,
39+
Long: "Runs cartesi-rollups-" + serviceName + " - Permissionless Refereed Tournaments dispute resolution",
40+
Run: run,
41+
Version: version.BuildVersion,
42+
}
43+
44+
func init() {
45+
// Standard service flags (inherited from advancer)
46+
Cmd.Flags().StringVar(&inspectAddress, "inspect-address", ":10013", "Inspect service address and port")
47+
cobra.CheckErr(viper.BindPFlag(config.INSPECT_ADDRESS, Cmd.Flags().Lookup("inspect-address")))
48+
49+
Cmd.Flags().StringVar(&telemetryAddress, "telemetry-address", ":10003", "Health check and metrics address and port")
50+
cobra.CheckErr(viper.BindPFlag(config.TELEMETRY_ADDRESS, Cmd.Flags().Lookup("telemetry-address")))
51+
52+
Cmd.Flags().StringVar(&logLevel, "log-level", "info", "Log level: debug, info, warn or error")
53+
cobra.CheckErr(viper.BindPFlag(config.LOG_LEVEL, Cmd.Flags().Lookup("log-level")))
54+
55+
Cmd.Flags().BoolVar(&logColor, "log-color", true, "Tint the logs (colored output)")
56+
cobra.CheckErr(viper.BindPFlag(config.LOG_COLOR, Cmd.Flags().Lookup("log-color")))
57+
58+
Cmd.Flags().StringVar(&databaseConnection, "database-connection", "",
59+
"Database connection string in the URL format\n(eg.: 'postgres://user:password@hostname:port/database') ")
60+
cobra.CheckErr(viper.BindPFlag(config.DATABASE_CONNECTION, Cmd.Flags().Lookup("database-connection")))
61+
62+
Cmd.Flags().StringVar(&pollInterval, "poll-interval", "7", "Poll interval")
63+
cobra.CheckErr(viper.BindPFlag(config.PRT_POLLING_INTERVAL, Cmd.Flags().Lookup("poll-interval")))
64+
65+
Cmd.Flags().StringVar(&maxStartupTime, "max-startup-time", "15", "Maximum startup time in seconds")
66+
cobra.CheckErr(viper.BindPFlag(config.MAX_STARTUP_TIME, Cmd.Flags().Lookup("max-startup-time")))
67+
68+
Cmd.Flags().BoolVar(&enableInspect, "inspect-enabled", true, "Enable or disable the inspect service")
69+
cobra.CheckErr(viper.BindPFlag(config.FEATURE_INSPECT_ENABLED, Cmd.Flags().Lookup("inspect-enabled")))
70+
71+
Cmd.Flags().BoolVar(&enableMachineHashCheck, "machine-hash-check", true,
72+
"Enable or disable machine hash check (DO NOT USE IN PRODUCTION)")
73+
cobra.CheckErr(viper.BindPFlag(config.FEATURE_MACHINE_HASH_CHECK_ENABLED, Cmd.Flags().Lookup("machine-hash-check")))
74+
75+
Cmd.Flags().StringVar(&machinelogLevel, "machine-log-level", "info",
76+
"Remote Machine log level: trace, debug, info, warning, error, fatal")
77+
cobra.CheckErr(viper.BindPFlag(config.REMOTE_MACHINE_LOG_LEVEL, Cmd.Flags().Lookup("machine-log-level")))
78+
79+
// PRT-specific flags
80+
81+
// TODO: validate on preRunE
82+
Cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
83+
var err error
84+
cfg, err = config.LoadPrtConfig()
85+
if err != nil {
86+
return err
87+
}
88+
return nil
89+
}
90+
}
91+
92+
func run(cmd *cobra.Command, args []string) {
93+
ctx, cancel := context.WithTimeout(context.Background(), cfg.MaxStartupTime)
94+
defer cancel()
95+
96+
createInfo := prt.CreateInfo{
97+
CreateInfo: service.CreateInfo{
98+
Name: serviceName,
99+
LogLevel: cfg.LogLevel,
100+
LogColor: cfg.LogColor,
101+
EnableSignalHandling: true,
102+
TelemetryCreate: true,
103+
TelemetryAddress: cfg.TelemetryAddress,
104+
PollInterval: cfg.PrtPollingInterval,
105+
},
106+
Config: *cfg,
107+
}
108+
var err error
109+
createInfo.Repository, err = factory.NewRepositoryFromConnectionString(ctx, cfg.DatabaseConnection.String())
110+
cobra.CheckErr(err)
111+
defer createInfo.Repository.Close()
112+
113+
prtService, err := prt.Create(ctx, &createInfo)
114+
cobra.CheckErr(err)
115+
116+
cobra.CheckErr(prtService.Serve())
117+
}

internal/config/generate/Config.toml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ default = "info"
88
go-type = "LogLevel"
99
description = """
1010
One of "debug", "info", "warn", "error"."""
11-
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node"]
11+
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node", "prt"]
1212

1313
[logging.CARTESI_LOG_COLOR]
1414
default = "true"
1515
go-type = "bool"
1616
description = """
1717
If set to true, the node will add colors to its log output."""
18-
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node"]
18+
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node", "prt"]
1919

2020
#
2121
# Features
@@ -40,7 +40,7 @@ default = "true"
4040
go-type = "bool"
4141
description = """
4242
If set to false, the node will not start the inspect service."""
43-
used-by = ["advancer", "node"]
43+
used-by = ["advancer", "node", "prt"]
4444

4545
[features.CARTESI_FEATURE_JSONRPC_API_ENABLED]
4646
default = "true"
@@ -55,7 +55,7 @@ go-type = "bool"
5555
description = """
5656
If set to false, the node will *not* check whether the Cartesi machine hash from
5757
the snapshot matches the hash in the Application contract."""
58-
used-by = ["advancer", "node", "cli"]
58+
used-by = ["advancer", "node", "cli", "prt"]
5959

6060
#
6161
# Rollups
@@ -87,7 +87,17 @@ default = "15"
8787
go-type = "Duration"
8888
description = """
8989
How many seconds the node expects services take initializing before aborting."""
90-
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node"]
90+
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node", "prt"]
91+
92+
#
93+
# PRT (Permissionless Refereed Tournaments)
94+
95+
[rollups.CARTESI_PRT_POLLING_INTERVAL]
96+
default = "7"
97+
go-type = "Duration"
98+
description = """
99+
How many seconds the PRT service will wait before checking for new tournaments or tournament state changes."""
100+
used-by = ["prt", "node"]
91101

92102
#
93103
# Blockchain
@@ -194,7 +204,7 @@ Address of the SelfHostedApplicationFactory contract. Not required, used only by
194204
omit = true
195205
used-by = ["cli"]
196206

197-
[contracts.CARTESI_CONTRACTS_PRT_CONSENSUS_FACTORY_ADDRESS]
207+
[contracts.CARTESI_CONTRACTS_PRT_FACTORY_ADDRESS]
198208
go-type = "Address"
199209
description = """
200210
Address of the PRT consensus contract. Not required, used only by the CLI and tests"""
@@ -210,7 +220,7 @@ default = "/var/lib/cartesi-rollups-node/snapshots"
210220
go-type = "string"
211221
description = """
212222
Path to the directory where the snapshots will be written."""
213-
used-by = ["advancer", "node"]
223+
used-by = ["advancer", "node", "prt"]
214224

215225
#
216226
# Auth
@@ -298,7 +308,7 @@ See [this](https://www.postgresql.org/docs/current/libpq-envars.html) for more i
298308
It is also possible to set the endpoint without a password and load it from Postgres' passfile.
299309
See [this](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-PASSFILE)
300310
for more information."""
301-
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node", "cli"]
311+
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node", "cli", "prt"]
302312

303313
#
304314
# Telemetry http address
@@ -308,7 +318,7 @@ used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node", "
308318
go-type = "string"
309319
description = """
310320
HTTP address for telemetry service."""
311-
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node", "cli"]
321+
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node", "cli", "prt"]
312322

313323
#
314324
# HTTP
@@ -326,7 +336,7 @@ default = ":10012"
326336
go-type = "string"
327337
description = """
328338
HTTP address for inspect."""
329-
used-by = ["advancer", "node", "cli"]
339+
used-by = ["advancer", "node", "cli", "prt"]
330340

331341
#
332342
# Remote Cartesi Machine
@@ -338,4 +348,4 @@ go-type = "MachineLogLevel"
338348
description = """
339349
Remote Cartesi Machine server log level.
340350
One of "trace", "debug", "info", "warning", "error", "fatal"."""
341-
used-by = ["advancer", "node"]
351+
used-by = ["advancer", "node", "prt"]

0 commit comments

Comments
 (0)