Skip to content

Commit e5c813f

Browse files
committed
feat(prt): add prt service boilerplate changes
1 parent 18dce93 commit e5c813f

10 files changed

Lines changed: 551 additions & 34 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ machine-snapshot/**
1414
/cartesi-rollups-validator
1515
/cartesi-rollups-claimer
1616
/cartesi-rollups-jsonrpc-api
17+
/cartesi-rollups-prt
1718
/rollups-contracts
1819
/rollups-prt-contracts
1920
/applications

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ 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 := $(addprefix cartesi-rollups-,node cli evm-reader advancer validator claimer jsonrpc-api prt)
5959

6060
# fixme(vfusco): path on all oses
6161
CGO_CFLAGS:= -I$(PREFIX)/include
@@ -97,7 +97,7 @@ env:
9797
@echo export CARTESI_CONTRACTS_AUTHORITY_FACTORY_ADDRESS="0xC7003566dD09Aa0fC0Ce201aC2769aFAe3BF0051"
9898
@echo export CARTESI_CONTRACTS_APPLICATION_FACTORY_ADDRESS="0xc7006f70875BaDe89032001262A846D3Ee160051"
9999
@echo export CARTESI_CONTRACTS_SELF_HOSTED_APPLICATION_FACTORY_ADDRESS="0xc700285Ab555eeB5201BC00CFD4b2CC8DED90051"
100-
@echo export CARTESI_CONTRACTS_PRT_FACTORY_ADDRESS="0x6e362c9458fE812D4aA796651C64D02C87AbD1cB"
100+
@echo export CARTESI_CONTRACTS_PRT_CONSENSUS_FACTORY_ADDRESS="0x6e362c9458fE812D4aA796651C64D02C87AbD1cB"
101101
@echo export CARTESI_AUTH_MNEMONIC=\"test test test test test test test test test test test junk\"
102102
@echo export CARTESI_DATABASE_CONNECTION="postgres://postgres:password@localhost:5432/rollupsdb?sslmode=disable"
103103
@echo export CARTESI_SNAPSHOTS_DIR="snapshots"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Supported Environment Variables:
5252
CARTESI_CONTRACTS_INPUT_BOX_ADDRESS Input Box contract address
5353
CARTESI_CONTRACTS_APPLICATION_FACTORY_ADDRESS Application Factory address
5454
CARTESI_CONTRACTS_SELF_HOSTED_APPLICATION_FACTORY_ADDRESS Self Hosted Application Factory address
55-
CARTESI_CONTRACTS_PRT_FACTORY_ADDRESS PRT Factory address`,
55+
CARTESI_CONTRACTS_PRT_CONSENSUS_FACTORY_ADDRESS PRT Factory address`,
5656
}
5757

5858
const applicationExamples = `
@@ -463,7 +463,7 @@ func buildPrtApplicationDeployment(
463463
var err error
464464
request := &ethutil.PRTApplicationDeployment{}
465465
if !cmd.Flags().Changed("prt-factory") {
466-
request.FactoryAddress, err = config.GetContractsPrtFactoryAddress()
466+
request.FactoryAddress, err = config.GetContractsPrtConsensusFactoryAddress()
467467
} else {
468468
request.FactoryAddress, err = parseHexAddress(factoryAddressParam)
469469
}

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: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
cfg *config.ValidatorConfig
29+
)
30+
31+
var Cmd = &cobra.Command{
32+
Use: "cartesi-rollups-" + serviceName,
33+
Short: "Runs cartesi-rollups-" + serviceName,
34+
Long: "Runs cartesi-rollups-" + serviceName + " in standalone mode",
35+
Run: run,
36+
Version: version.BuildVersion,
37+
}
38+
39+
func init() {
40+
Cmd.Flags().StringVar(&telemetryAddress, "telemetry-address", ":10003", "Health check and metrics address and port")
41+
cobra.CheckErr(viper.BindPFlag(config.TELEMETRY_ADDRESS, Cmd.Flags().Lookup("telemetry-address")))
42+
43+
Cmd.Flags().StringVar(&logLevel, "log-level", "info", "Log level: debug, info, warn or error")
44+
cobra.CheckErr(viper.BindPFlag(config.LOG_LEVEL, Cmd.Flags().Lookup("log-level")))
45+
46+
Cmd.Flags().BoolVar(&logColor, "log-color", true, "Tint the logs (colored output)")
47+
cobra.CheckErr(viper.BindPFlag(config.LOG_COLOR, Cmd.Flags().Lookup("log-color")))
48+
49+
Cmd.Flags().StringVar(&databaseConnection, "database-connection", "",
50+
"Database connection string in the URL format\n(eg.: 'postgres://user:password@hostname:port/database') ")
51+
cobra.CheckErr(viper.BindPFlag(config.DATABASE_CONNECTION, Cmd.Flags().Lookup("database-connection")))
52+
53+
Cmd.Flags().StringVar(&pollInterval, "poll-interval", "7", "Poll interval")
54+
cobra.CheckErr(viper.BindPFlag(config.VALIDATOR_POLLING_INTERVAL, Cmd.Flags().Lookup("poll-interval")))
55+
56+
Cmd.Flags().StringVar(&maxStartupTime, "max-startup-time", "15", "Maximum startup time in seconds")
57+
cobra.CheckErr(viper.BindPFlag(config.MAX_STARTUP_TIME, Cmd.Flags().Lookup("max-startup-time")))
58+
59+
// TODO: validate on preRunE
60+
Cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
61+
var err error
62+
cfg, err = config.LoadValidatorConfig()
63+
if err != nil {
64+
return err
65+
}
66+
return nil
67+
}
68+
}
69+
70+
func run(cmd *cobra.Command, args []string) {
71+
ctx, cancel := context.WithTimeout(context.Background(), cfg.MaxStartupTime)
72+
defer cancel()
73+
74+
createInfo := prt.CreateInfo{
75+
CreateInfo: service.CreateInfo{
76+
Name: serviceName,
77+
LogLevel: cfg.LogLevel,
78+
LogColor: cfg.LogColor,
79+
EnableSignalHandling: true,
80+
TelemetryCreate: true,
81+
TelemetryAddress: cfg.TelemetryAddress,
82+
PollInterval: cfg.ValidatorPollingInterval,
83+
},
84+
Config: *cfg,
85+
}
86+
var err error
87+
createInfo.Repository, err = factory.NewRepositoryFromConnectionString(ctx, cfg.DatabaseConnection.String())
88+
cobra.CheckErr(err)
89+
defer createInfo.Repository.Close()
90+
91+
validatorService, err := prt.Create(ctx, &createInfo)
92+
cobra.CheckErr(err)
93+
94+
cobra.CheckErr(validatorService.Serve())
95+
}

internal/config/generate/Config.toml

Lines changed: 30 additions & 23 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
@@ -33,7 +33,7 @@ default = "true"
3333
go-type = "bool"
3434
description = """
3535
If set to false, the node will not submit claims (reader mode)."""
36-
used-by = ["claimer", "node"]
36+
used-by = ["claimer", "node", "prt"]
3737

3838
[features.CARTESI_FEATURE_INSPECT_ENABLED]
3939
default = "true"
@@ -82,12 +82,19 @@ description = """
8282
How many seconds the node will wait before querying the database for new claims."""
8383
used-by = ["claimer", "node"]
8484

85+
[rollups.CARTESI_PRT_POLLING_INTERVAL]
86+
default = "3"
87+
go-type = "Duration"
88+
description = """
89+
How many seconds the node will wait before trying to finish epochs for all applications."""
90+
used-by = ["prt", "node"]
91+
8592
[rollups.CARTESI_MAX_STARTUP_TIME]
8693
default = "15"
8794
go-type = "Duration"
8895
description = """
8996
How many seconds the node expects services take initializing before aborting."""
90-
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node"]
97+
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node", "prt"]
9198

9299
#
93100
# Blockchain
@@ -97,13 +104,13 @@ used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node"]
97104
go-type = "uint64"
98105
description = """
99106
An unique identifier representing a blockchain network."""
100-
used-by = ["evmreader", "claimer", "node"]
107+
used-by = ["evmreader", "claimer", "node", "prt"]
101108

102109
[blockchain.CARTESI_BLOCKCHAIN_HTTP_ENDPOINT]
103110
go-type = "URL"
104111
description = """
105112
HTTP endpoint for the blockchain RPC provider."""
106-
used-by = ["evmreader", "claimer", "node"]
113+
used-by = ["evmreader", "claimer", "node", "prt"]
107114

108115
[blockchain.CARTESI_BLOCKCHAIN_WS_ENDPOINT]
109116
go-type = "URL"
@@ -117,15 +124,15 @@ go-type = "bool"
117124
description = """
118125
If set to true the node will send transactions using the legacy gas fee model
119126
(instead of EIP-1559)."""
120-
used-by = ["claimer", "node", "cli"]
127+
used-by = ["claimer", "node", "cli", "prt"]
121128

122129
[blockchain.CARTESI_BLOCKCHAIN_DEFAULT_BLOCK]
123130
default = "finalized"
124131
go-type = "DefaultBlock"
125132
description = """
126133
The default block to be used by EVM Reader and Claimer when requesting new blocks.
127134
One of 'latest', 'pending', 'safe', 'finalized'"""
128-
used-by = ["evmreader", "claimer", "node"]
135+
used-by = ["evmreader", "claimer", "node", "prt"]
129136

130137
[blockchain.CARTESI_BLOCKCHAIN_SUBSCRIPTION_TIMEOUT]
131138
default = "60"
@@ -139,28 +146,28 @@ default = "4"
139146
go-type = "uint64"
140147
description = """
141148
Maximum number of retry attempts for HTTP blockchain requests after encountering an error."""
142-
used-by = ["evmreader", "claimer", "node"]
149+
used-by = ["evmreader", "claimer", "node", "prt"]
143150

144151
[rollups.CARTESI_BLOCKCHAIN_HTTP_RETRY_MIN_WAIT]
145152
default = "1"
146153
go-type = "Duration"
147154
description = """
148155
Minimum wait time in seconds for the exponential backoff retry policy. This is the initial delay before the first retry for HTTP blockchain requests."""
149-
used-by = ["evmreader", "claimer", "node"]
156+
used-by = ["evmreader", "claimer", "node", "prt"]
150157

151158
[rollups.CARTESI_BLOCKCHAIN_HTTP_RETRY_MAX_WAIT]
152159
default = "60"
153160
go-type = "Duration"
154161
description = """
155162
Maximum wait time in seconds for the exponential backoff retry policy. The delay between retries for HTTP blockchain requests will never exceed this value, regardless of the backoff calculation."""
156-
used-by = ["evmreader", "claimer", "node"]
163+
used-by = ["evmreader", "claimer", "node", "prt"]
157164

158165
[rollups.CARTESI_BLOCKCHAIN_MAX_BLOCK_RANGE]
159166
default = "0"
160167
go-type = "uint64"
161168
description = """
162169
Maximum number of blocks in a single query to the provider. Queries with larger ranges will be broken into multiple smaller queries. Zero for unlimited."""
163-
used-by = ["evmreader", "claimer", "node"]
170+
used-by = ["evmreader", "claimer", "node", "prt"]
164171

165172
#
166173
# Contracts
@@ -210,7 +217,7 @@ default = "/var/lib/cartesi-rollups-node/snapshots"
210217
go-type = "string"
211218
description = """
212219
Path to the directory where the snapshots will be written."""
213-
used-by = ["advancer", "node"]
220+
used-by = ["advancer", "node", "prt"]
214221

215222
#
216223
# Auth
@@ -224,36 +231,36 @@ One of "private_key", "private_key_file", "mnemonic", "mnemonic_file", "aws".
224231
225232
The auth variable for the kind defined here is required. Eg.: CARTESI_AUTH_MNEMONIC"""
226233
omit = true
227-
used-by = ["claimer", "node", "cli"]
234+
used-by = ["claimer", "node", "cli", "prt"]
228235

229236
[auth.CARTESI_AUTH_PRIVATE_KEY]
230237
go-type = "RedactedString"
231238
description = """
232239
The node will use this private key to sign transactions."""
233240
omit = true
234-
used-by = ["claimer", "node", "cli"]
241+
used-by = ["claimer", "node", "cli", "prt"]
235242

236243
[auth.CARTESI_AUTH_PRIVATE_KEY_FILE]
237244
go-type = "string"
238245
description = """
239246
The node will use the private key contained in this file to sign transactions."""
240247
omit = true
241-
used-by = ["claimer", "node", "cli"]
248+
used-by = ["claimer", "node", "cli", "prt"]
242249

243250
[auth.CARTESI_AUTH_MNEMONIC]
244251
go-type = "RedactedString"
245252
description = """
246253
The node will use the private key generated from this mnemonic to sign transactions."""
247254
omit = true
248-
used-by = ["claimer", "node", "cli"]
255+
used-by = ["claimer", "node", "cli", "prt"]
249256

250257
[auth.CARTESI_AUTH_MNEMONIC_FILE]
251258
go-type = "string"
252259
description = """
253260
The node will use the private key generated from the mnemonic contained in this file
254261
to sign transactions."""
255262
omit = true
256-
used-by = ["claimer", "node", "cli"]
263+
used-by = ["claimer", "node", "cli", "prt"]
257264

258265
[auth.CARTESI_AUTH_MNEMONIC_ACCOUNT_INDEX]
259266
default = "0"
@@ -262,7 +269,7 @@ description = """
262269
When using mnemonics to sign transactions,
263270
the node will use this account index to generate the private key."""
264271
omit = true
265-
used-by = ["claimer", "node", "cli"]
272+
used-by = ["claimer", "node", "cli", "prt"]
266273

267274
[auth.CARTESI_AUTH_AWS_KMS_KEY_ID]
268275
go-type = "RedactedString"
@@ -271,7 +278,7 @@ If set, the node will use the AWS KMS service with this key ID to sign transacti
271278
272279
Must be set alongside `CARTESI_AUTH_AWS_KMS_REGION`."""
273280
omit = true
274-
used-by = ["claimer", "node", "cli"]
281+
used-by = ["claimer", "node", "cli", "prt"]
275282

276283
[auth.CARTESI_AUTH_AWS_KMS_REGION]
277284
go-type = "RedactedString"
@@ -280,7 +287,7 @@ An AWS KMS Region.
280287
281288
Must be set alongside `CARTESI_AUTH_AWS_KMS_KEY_ID`."""
282289
omit = true
283-
used-by = ["claimer", "node", "cli"]
290+
used-by = ["claimer", "node", "cli", "prt"]
284291

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

303310
#
304311
# Telemetry http address
@@ -308,7 +315,7 @@ used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node", "
308315
go-type = "string"
309316
description = """
310317
HTTP address for telemetry service."""
311-
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node", "cli"]
318+
used-by = ["advancer", "claimer", "evmreader", "validator", "jsonrpc", "node", "cli", "prt"]
312319

313320
#
314321
# HTTP

0 commit comments

Comments
 (0)