Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzzzHui committed Feb 9, 2025
1 parent 11dfc84 commit 6456e3f
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 1,210 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
/rollups-espresso-reader
/rollups-node
/cartesi-rollups-*
.vscode
rollups-espresso-reader
docs
11 changes: 0 additions & 11 deletions .gitpod.yml

This file was deleted.

Empty file removed CHANGELOG.md
Empty file.
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,10 @@
#

env:
@echo export CGO_CFLAGS=\"$(CGO_CFLAGS)\"
@echo export CGO_LDFLAGS=\"$(CGO_LDFLAGS)\"
@echo export CARTESI_LOG_LEVEL="debug"
@echo export CARTESI_BLOCKCHAIN_HTTP_ENDPOINT=""
@echo export CARTESI_BLOCKCHAIN_WS_ENDPOINT=""
@echo export CARTESI_AUTH_MNEMONIC=\"test test test test test test test test test test test junk\"
@echo export CARTESI_POSTGRES_ENDPOINT="postgres://postgres:password@localhost:5432/rollupsdb?sslmode=disable"
@echo export CARTESI_TEST_POSTGRES_ENDPOINT="postgres://test_user:password@localhost:5432/test_rollupsdb?sslmode=disable"
@echo export CARTESI_TEST_MACHINE_IMAGES_PATH=\"$(CARTESI_TEST_MACHINE_IMAGES_PATH)\"
@echo export PATH=$(CURDIR):$$PATH
@echo export ESPRESSO_BASE_URL="https://query.decaf.testnet.espresso.network"
@echo export ESPRESSO_STARTING_BLOCK="1490657"
Expand Down
114 changes: 12 additions & 102 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,21 @@
// The sub-package generate specifies these environment variables.
package config

import (
"fmt"
"os"
)

// NodeConfig contains all the Node variables.
// See the corresponding environment variable for the variable documentation.
type NodeConfig struct {
LogLevel LogLevel
LogPrettyEnabled bool
BlockchainHttpEndpoint Redacted[string]
BlockchainWsEndpoint Redacted[string]
LegacyBlockchainEnabled bool
EvmReaderDefaultBlock DefaultBlock
BlockchainBlockTimeout int
SnapshotDir string
PostgresEndpoint Redacted[string]
HttpAddress string
HttpPort int
FeatureClaimSubmissionEnabled bool
FeatureMachineHashCheckEnabled bool
Auth Auth
AdvancerPollingInterval Duration
ValidatorPollingInterval Duration
ClaimerPollingInterval Duration
EspressoBaseUrl string
EspressoStartingBlock uint64
EspressoNamespace uint64
EspressoServiceEndpoint string
MaxRetries uint64
MaxDelay Duration
}

// Auth is used to sign transactions.
type Auth any

// AuthPrivateKey allows signing through private keys.
type AuthPrivateKey struct {
PrivateKey Redacted[string]
}

// AuthMnemonic allows signing through mnemonics.
type AuthMnemonic struct {
Mnemonic Redacted[string]
AccountIndex Redacted[int]
}

// AuthAWS allows signing through AWS services.
type AuthAWS struct {
KeyID Redacted[string]
Region Redacted[string]
LogLevel LogLevel
LogPrettyEnabled bool
BlockchainHttpEndpoint Redacted[string]
BlockchainWsEndpoint Redacted[string]
BlockchainBlockTimeout int
PostgresEndpoint Redacted[string]
EspressoBaseUrl string
EspressoStartingBlock uint64
EspressoNamespace uint64
EspressoServiceEndpoint string
MaxRetries uint64
MaxDelay Duration
}

// Redacted is a wrapper that redacts a given field from the logs.
Expand All @@ -74,21 +38,7 @@ func FromEnv() NodeConfig {
config.LogPrettyEnabled = GetLogPrettyEnabled()
config.BlockchainHttpEndpoint = Redacted[string]{GetBlockchainHttpEndpoint()}
config.BlockchainWsEndpoint = Redacted[string]{GetBlockchainWsEndpoint()}
config.LegacyBlockchainEnabled = GetLegacyBlockchainEnabled()
config.EvmReaderDefaultBlock = GetEvmReaderDefaultBlock()
config.BlockchainBlockTimeout = GetBlockchainBlockTimeout()
config.SnapshotDir = GetSnapshotDir()
config.PostgresEndpoint = Redacted[string]{GetPostgresEndpoint()}
config.HttpAddress = GetHttpAddress()
config.HttpPort = GetHttpPort()
config.FeatureClaimSubmissionEnabled = GetFeatureClaimSubmissionEnabled()
config.FeatureMachineHashCheckEnabled = GetFeatureMachineHashCheckEnabled()
if config.FeatureClaimSubmissionEnabled {
config.Auth = AuthFromEnv()
}
config.AdvancerPollingInterval = GetAdvancerPollingInterval()
config.ValidatorPollingInterval = GetValidatorPollingInterval()
config.ClaimerPollingInterval = GetClaimerPollingInterval()
config.EspressoBaseUrl = GetBaseUrl() + "/v0"
config.EspressoStartingBlock = GetStartingBlock()
config.EspressoNamespace = GetNamespace()
Expand All @@ -97,43 +47,3 @@ func FromEnv() NodeConfig {
config.MaxDelay = GetPolicyMaxDelay()
return config
}

func AuthFromEnv() Auth {
switch GetAuthKind() {
case AuthKindPrivateKeyVar:
return AuthPrivateKey{
PrivateKey: Redacted[string]{GetAuthPrivateKey()},
}
case AuthKindPrivateKeyFile:
path := GetAuthPrivateKeyFile()
privateKey, err := os.ReadFile(path)
if err != nil {
panic(fmt.Sprintf("failed to read private-key file: %v", err))
}
return AuthPrivateKey{
PrivateKey: Redacted[string]{string(privateKey)},
}
case AuthKindMnemonicVar:
return AuthMnemonic{
Mnemonic: Redacted[string]{GetAuthMnemonic()},
AccountIndex: Redacted[int]{GetAuthMnemonicAccountIndex()},
}
case AuthKindMnemonicFile:
path := GetAuthMnemonicFile()
mnemonic, err := os.ReadFile(path)
if err != nil {
panic(fmt.Sprintf("failed to read mnemonic file: %v", err))
}
return AuthMnemonic{
Mnemonic: Redacted[string]{string(mnemonic)},
AccountIndex: Redacted[int]{GetAuthMnemonicAccountIndex()},
}
case AuthKindAWS:
return AuthAWS{
KeyID: Redacted[string]{GetAuthAwsKmsKeyId()},
Region: Redacted[string]{GetAuthAwsKmsRegion()},
}
default:
panic("invalid auth kind")
}
}
147 changes: 0 additions & 147 deletions internal/config/generate/Config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,6 @@ go-type = "bool"
description = """
If set to true, the node will add colors to its log output."""

#
# Features
#

[features.CARTESI_FEATURE_CLAIM_SUBMISSION_ENABLED]
default = "true"
go-type = "bool"
description = """
If set to false, the node will not submit claims (reader mode)."""

[features.CARTESI_FEATURE_MACHINE_HASH_CHECK_ENABLED]
default = "true"
go-type = "bool"
description = """
If set to false, the node will *not* check whether the Cartesi machine hash from
the snapshot matches the hash in the Application contract."""

#
# Rollups
#

[rollups.CARTESI_ADVANCER_POLLING_INTERVAL]
default = "7"
go-type = "Duration"
description = """
How many seconds the node will wait before querying the database for new inputs."""

[rollups.CARTESI_VALIDATOR_POLLING_INTERVAL]
default = "7"
go-type = "Duration"
description = """
How many seconds the node will wait before trying to finish epochs for all applications."""

[rollups.CARTESI_CLAIMER_POLLING_INTERVAL]
default = "7"
go-type = "Duration"
description = """
How many seconds the node will wait before querying the database for new claims."""

#
# Blockchain
#
Expand All @@ -68,88 +29,6 @@ go-type = "string"
description = """
WebSocket endpoint for the blockchain RPC provider."""

[blockchain.CARTESI_LEGACY_BLOCKCHAIN_ENABLED]
default = "false"
go-type = "bool"
description = """
If set to true the node will send transactions using the legacy gas fee model
(instead of EIP-1559)."""

[blockchain.CARTESI_EVM_READER_DEFAULT_BLOCK]
default = "finalized"
go-type = "DefaultBlock"
description = """
The default block to be used by EVM Reader when requesting new blocks.
One of 'latest', 'pending', 'safe', 'finalized'"""

[blockchain.CARTESI_BLOCKCHAIN_BLOCK_TIMEOUT]
default = "60"
go-type = "int"
description = """
Block subscription timeout in seconds."""

#
# Snapshot
#

[snapshot.CARTESI_SNAPSHOT_DIR]
default = "/var/lib/cartesi-rollups-node/snapshots"
go-type = "string"
description = """
Path to the directory with the cartesi-machine snapshot that will be loaded by the node."""

#
# Auth
#

[auth.CARTESI_AUTH_KIND]
default = "mnemonic"
go-type = "AuthKind"
description = """
One of "private_key", "private_key_file", "mnemonic", "mnemonic_file", "aws"."""

[auth.CARTESI_AUTH_PRIVATE_KEY]
go-type = "string"
description = """
The node will use this private key to sign transactions."""

[auth.CARTESI_AUTH_PRIVATE_KEY_FILE]
go-type = "string"
description = """
The node will use the private key contained in this file to sign transactions."""

[auth.CARTESI_AUTH_MNEMONIC]
go-type = "string"
description = """
The node will use the private key generated from this mnemonic to sign transactions."""

[auth.CARTESI_AUTH_MNEMONIC_FILE]
go-type = "string"
description = """
The node will use the private key generated from the mnemonic contained in this file
to sign transactions."""

[auth.CARTESI_AUTH_MNEMONIC_ACCOUNT_INDEX]
default = "0"
go-type = "int"
description = """
When using mnemonics to sign transactions,
the node will use this account index to generate the private key."""

[auth.CARTESI_AUTH_AWS_KMS_KEY_ID]
go-type = "string"
description = """
If set, the node will use the AWS KMS service with this key ID to sign transactions.
Must be set alongside `CARTESI_AUTH_AWS_KMS_REGION`."""

[auth.CARTESI_AUTH_AWS_KMS_REGION]
go-type = "string"
description = """
An AWS KMS Region.
Must be set alongside `CARTESI_AUTH_AWS_KMS_KEY_ID`."""

#
# Postgres
#
Expand All @@ -167,23 +46,6 @@ It is also possible to set the endpoint without a password and load it from Post
See [this](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNECT-PASSFILE)
for more information."""

#
# HTTP
#

[http.CARTESI_HTTP_ADDRESS]
default = "127.0.0.1"
go-type = "string"
description = """
HTTP address for the node."""

[http.CARTESI_HTTP_PORT]
default = "10000"
go-type = "int"
description = """
HTTP port for the node.
The node will also use the 20 ports after this one for internal services."""

#
# Espresso
#
Expand Down Expand Up @@ -224,12 +86,3 @@ go-type = "Duration"
description = """
How many seconds the retry policy will wait between retries."""

#
# Temporary
#

[temp.CARTESI_MACHINE_SERVER_VERBOSITY]
default = "info"
go-type = "string"
description = """
TODO."""
Loading

0 comments on commit 6456e3f

Please sign in to comment.