Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/evm reader no websocket #596

Open
wants to merge 4 commits into
base: next/2.0
Choose a base branch
from
Open
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
26 changes: 13 additions & 13 deletions cmd/cartesi-rollups-evm-reader/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ var (
defaultBlock string
postgresEndpoint string
blockchainHttpEndpoint string
blockchainWsEndpoint string
inputBoxAddress string
inputBoxDeploymentBlockNumber uint64
verbose bool
Expand All @@ -67,12 +66,6 @@ func init() {
"",
"Blockchain HTTP Endpoint")

Cmd.Flags().StringVarP(&blockchainWsEndpoint,
"blockchain-ws-endpoint",
"w",
"",
"Blockchain WS Endpoint")

Cmd.Flags().StringVarP(&inputBoxAddress,
"inputbox-address",
"i",
Expand Down Expand Up @@ -105,7 +98,7 @@ func run(cmd *cobra.Command, args []string) {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

c := config.FromEnv()
c := config.EvmReaderConfigFromEnv()

// Override configs
if verbose {
Expand All @@ -117,14 +110,14 @@ func run(cmd *cobra.Command, args []string) {
if blockchainHttpEndpoint != "" {
c.BlockchainHttpEndpoint = config.Redacted[string]{Value: blockchainHttpEndpoint}
}
if blockchainWsEndpoint != "" {
c.BlockchainWsEndpoint = config.Redacted[string]{Value: blockchainWsEndpoint}
}
if defaultBlock != "" {
evmReaderDefaultBlock, err := config.ToDefaultBlockFromString(defaultBlock)
cobra.CheckErr(err)
c.EvmReaderDefaultBlock = evmReaderDefaultBlock
}
if inputBoxAddress != "" {
c.ContractsInputBoxAddress = inputBoxAddress
}

// setup log
startup.ConfigLogs(c.LogLevel, c.LogPrettyEnabled)
Expand All @@ -145,7 +138,14 @@ func run(cmd *cobra.Command, args []string) {
}
defer database.Close()

_, err = startup.SetupNodePersistentConfig(ctx, database, c)
_, err = startup.SetupNodePersistentConfig(
ctx,
database,
c.EvmReaderDefaultBlock,
c.ContractsInputBoxAddress,
c.ContractsInputBoxDeploymentBlockNumber,
c.BlockchainID,
)
if err != nil {
slog.Error("EVM Reader couldn't connect to the database", "error", err)
os.Exit(1)
Expand All @@ -154,10 +154,10 @@ func run(cmd *cobra.Command, args []string) {
// create EVM Reader Service
service := service.NewEvmReaderService(
c.BlockchainHttpEndpoint.Value,
c.BlockchainWsEndpoint.Value,
database,
c.EvmReaderRetryPolicyMaxRetries,
c.EvmReaderRetryPolicyMaxDelay,
c.EvmReaderPollingInterval,
)

// logs startup time
Expand Down
16 changes: 9 additions & 7 deletions cmd/cartesi-rollups-node/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,35 @@ func main() {
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

config := config.FromEnv()
c := config.FromEnv()

// setup log
startup.ConfigLogs(config.LogLevel, config.LogPrettyEnabled)
slog.Info("Starting the Cartesi Rollups Node", "version", buildVersion, "config", config)
startup.ConfigLogs(c.LogLevel, c.LogPrettyEnabled)
slog.Info("Starting the Cartesi Rollups Node", "version", buildVersion, "config", c)

err := startup.ValidateSchema(config.PostgresEndpoint.Value, config.PostgresSslDisabled)
err := startup.ValidateSchema(c.PostgresEndpoint.Value, c.PostgresSslDisabled)
if err != nil {
slog.Error("Node exited with an error", "error", err)
os.Exit(1)
}

database, err := repository.Connect(ctx, config.PostgresEndpoint.Value)
database, err := repository.Connect(ctx, c.PostgresEndpoint.Value)
if err != nil {
slog.Error("Node couldn't connect to the database", "error", err)
os.Exit(1)
}
defer database.Close()

_, err = startup.SetupNodePersistentConfig(ctx, database, config)
_, err = startup.SetupNodePersistentConfig(ctx, database, c.EvmReaderDefaultBlock,
c.ContractsInputBoxAddress, uint64(c.ContractsInputBoxDeploymentBlockNumber),
c.BlockchainID)
if err != nil {
slog.Error("Node exited with an error", "error", err)
os.Exit(1)
}

// create the node supervisor
supervisor, err := node.Setup(ctx, config, "", database)
supervisor, err := node.Setup(ctx, c, "", database)
if err != nil {
slog.Error("Node exited with an error", "error", err)
os.Exit(1)
Expand Down
20 changes: 12 additions & 8 deletions cmd/cartesi-rollups-validator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,31 @@ var (
Long: "Runs Validator in standalone mode",
Run: run,
}
inputBoxDeploymentBlockNumber int64
pollingInterval int64
inputBoxDeploymentBlockNumber uint64
pollingInterval uint64
postgresEndpoint string
verbose bool
)

func init() {
Cmd.Flags().Int64VarP(&inputBoxDeploymentBlockNumber,
Cmd.Flags().Uint64VarP(&inputBoxDeploymentBlockNumber,
"inputbox-block-number",
"n",
-1,
0,
"Input Box deployment block number",
)
Cmd.Flags().Int64VarP(
Cmd.Flags().Uint64VarP(
&pollingInterval,
"polling-interval",
"",
-1,
0,
"the amount of seconds to wait before trying to finish epochs for all applications",
)
Cmd.Flags().StringVarP(&postgresEndpoint, "postgres-endpoint", "p", "", "Postgres endpoint")
Cmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "enable verbose logging")

err := Cmd.MarkFlagRequired("input-box-block-number")
cobra.CheckErr(err)
}

func main() {
Expand All @@ -68,7 +71,7 @@ func run(cmd *cobra.Command, args []string) {
c := config.FromEnv()

// Override configs
if inputBoxDeploymentBlockNumber >= 0 {
if inputBoxDeploymentBlockNumber > 0 {
c.ContractsInputBoxDeploymentBlockNumber = inputBoxDeploymentBlockNumber
}
if pollingInterval > 0 {
Expand Down Expand Up @@ -99,7 +102,8 @@ func run(cmd *cobra.Command, args []string) {
}
defer database.Close()

_, err = startup.SetupNodePersistentConfig(ctx, database, c)
_, err = startup.SetupNodePersistentConfig(ctx, database, c.EvmReaderDefaultBlock,
c.ContractsInputBoxAddress, c.ContractsInputBoxDeploymentBlockNumber, c.BlockchainID)
if err != nil {
slog.Error("configuration error", "error", err)
os.Exit(1)
Expand Down
9 changes: 8 additions & 1 deletion docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Address of the InputBox contract.
The deployment block for the input box contract.
The node will begin to read blockchain events from this block.

* **Type:** `int64`
* **Type:** `uint64`

## `CARTESI_EXPERIMENTAL_SERVER_MANAGER_LOG_BYPASS_ENABLED`

Expand Down Expand Up @@ -239,6 +239,13 @@ At the end of each epoch, the node will send claims to the blockchain.
* **Type:** `uint64`
* **Default:** `"7200"`

## `CARTESI_EVMREADER_POLLING_INTERVAL`

How many seconds the node will wait before fetching new blocks.

* **Type:** `Duration`
* **Default:** `"1"`

## `CARTESI_EVM_READER_RETRY_POLICY_MAX_DELAY`

How many seconds the retry policy will wait between retries.
Expand Down
Loading
Loading