Skip to content

Commit

Permalink
document validator node settings
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyPansier committed Apr 26, 2024
1 parent f1efedd commit 7bc59b2
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 43 deletions.
4 changes: 2 additions & 2 deletions accessnode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func main() {
logLevel := flag.String("log-level", environment.NewVariable("LOG_LEVEL").GetStringValue("info"), "The log level (possible values: 'debug', 'info', 'warn', 'error', 'fatal')")

flag.Parse()
logger := console.NewLogger(console.ParseLevel(*logLevel))
validatorNeighbor, err := p2p.NewNeighbor(*validatorIp, strconv.Itoa(*validatorPort), time.Minute, console.NewLogger(console.Fatal))
logger := console.NewLogger(*logLevel)
validatorNeighbor, err := p2p.NewNeighbor(*validatorIp, strconv.Itoa(*validatorPort), time.Minute, console.NewFatalLogger())
if err != nil {
logger.Fatal(fmt.Errorf("unable to find blockchain client: %w", err).Error())
}
Expand Down
144 changes: 135 additions & 9 deletions validatornode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,148 @@ At root level (ruthenium folder), run the validator node using the command `go r
go run validatornode/main.go -private-key=0x48913790c2bebc48417491f96a7e07ec94c76ccd0fe1562dc1749479d9715afd
```

## Program arguments:
## Program Arguments
```
-mnemonic: The mnemonic (required if the private key is not provided)
-derivation-path: The derivation path (unused if the mnemonic is omitted, default: "m/44'/60'/0'/0/0")
-password: The mnemonic password (unused if the mnemonic is omitted)
-private-key: The private key (required if the mnemonic is not provided, unused if the mnemonic is provided)
-infura-key: The infura key (required to check the proof of humanity)
-ip: The validator node IP or DNS address (detected if not provided)
-port: The TCP port number of the validator node (accepted values: "10600" for mainnet, "10601" to "10699" for testnet, default: "10600")
-settings-path: The settings file path (default: "config/settings.json")
-settings-path: The settings file path (default: "validatornode/settings.json")
-seeds-path: The seeds file path (default: "config/seeds.json")
-log-level: The log level (accepted values: "debug", "info", "warn", "error", "fatal", default: "info")
```


## Application Settings
<table>
<th>
Schema
</th>
<th>
Description
</th>
<th>
Example
</th>
<tr>
<td>

```
{
"host": {
"ip": string
"port": int
},
"network": {
"maxOutboundsCount": int
"seeds": []string
"synchronizationIntervalInSeconds": int
"connectionTimeoutInSeconds": int
},
"protocol": {
"blocksCountLimit": uint64
"coinDigitsCount": uint8
"genesisAmount": uint64
"halfLifeInDays": 373.float6
"incomeBase": uint64
"incomeLimit": uint64
"minimalTransactionFee": uint64
"validationIntervalInSeconds": int64
"validationTimeoutInSeconds": int64
"verificationsCountPerValidation": int64
},
"registry": {
"synchronizationIntervalInSeconds": int
},
"validator": {
"address": string
"infuraKey": string
},
"log": {
"logLevel": string
}
}
```
</td>
<td>

```
The validator node IP or DNS address (detected if not provided)
The TCP port number of the validator node (accepted values: "10600" for mainnet, "10601" to "10699" for testnet)
The maximum validator node outbounds count
The initial validator node neighbors
The neighbors blockchain synchronization interval in seconds
The neighbors connection timeout in seconds
The maximum returned blocks for a blocks request
The coin digits count
The genesis transaction reward amount
The coin half-life
The income amount after a period of one half-life for an empty initial balance
The balance limit to receive the income
The minimal transaction fee
The validation interval in seconds
The validation timeout in seconds
The verifications count per validation
The synchronization interval in seconds
The validator wallet address
The infura key (required to check the proof of humanity)
The log level (accepted values: "debug", "info", "warn", "error", "fatal")
```
</td>
<td>

```
{
"host": {
"ip": "",
"port": 10600
},
"network": {
"maxOutboundsCount": 8,
"seeds": ["seed-styx.ruthenium.my-cloud.me:10600"],
"synchronizationIntervalInSeconds": 6,
"connectionTimeoutInSeconds": 3
},
"protocol": {
"blocksCountLimit": 1440,
"coinDigitsCount": 8,
"genesisAmount": 5000000000000,
"halfLifeInDays": 373.59,
"incomeBase": 100000000000,
"incomeLimit": 5000000000000,
"minimalTransactionFee": 1000,
"validationIntervalInSeconds": 3,
"validationTimeoutInSeconds": 3,
"verificationsCountPerValidation": 6
},
"registry": {
"synchronizationIntervalInSeconds": 3600
},
"validator": {
"address": "",
"infuraKey": ""
},
"log": {
"logLevel": "info"
}
}
```
</td>
</tr>
</table>

## API
Base URL: `<validator node IP>:<validator node port>` (example: seed-styx.ruthenium.my-cloud.me:10600)

Expand Down Expand Up @@ -467,5 +595,3 @@ The value at the transaction timestamp
</td>
</tr>
</table>

[1]: https://go.dev/blog/gob "Gobs official documentation"
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
)

type networkSettingsDto struct {
ConnectionTimeoutInSeconds int
MaxOutboundsCount int
Seeds []string
SynchronizationIntervalInSeconds int
}

type NetworkSettings struct {
connectionTimeout time.Duration
maxOutboundsCount int
seeds []string
synchronizationTimer time.Duration
Expand All @@ -23,12 +25,17 @@ func (settings *NetworkSettings) UnmarshalJSON(data []byte) error {
if err != nil {
return err
}
settings.connectionTimeout = time.Duration(dto.ConnectionTimeoutInSeconds) * time.Second
settings.maxOutboundsCount = dto.MaxOutboundsCount
settings.seeds = dto.Seeds
settings.synchronizationTimer = time.Duration(dto.SynchronizationIntervalInSeconds) * time.Second
return nil
}

func (settings *NetworkSettings) ConnectionTimeout() time.Duration {
return settings.connectionTimeout
}

func (settings *NetworkSettings) MaxOutboundsCount() int {
return settings.maxOutboundsCount
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package configuration

import (
"encoding/json"
"math"
"time"
)

type protocolSettingsDto struct {
BlocksCountLimit uint64
CoinDigitsCount uint8
GenesisAmount uint64
HalfLifeInDays float64
IncomeBase uint64
IncomeLimit uint64
MinimalTransactionFee uint64
SmallestUnitsPerCoin uint64
ValidationIntervalInSeconds int64
ValidationTimeoutInSeconds int64
VerificationsCountPerValidation int64
Expand Down Expand Up @@ -47,7 +48,7 @@ func (settings *ProtocolSettings) UnmarshalJSON(data []byte) error {
settings.incomeBase = dto.IncomeBase
settings.incomeLimit = dto.IncomeLimit
settings.minimalTransactionFee = dto.MinimalTransactionFee
settings.smallestUnitsPerCoin = dto.SmallestUnitsPerCoin
settings.smallestUnitsPerCoin = uint64(math.Pow10(int(dto.CoinDigitsCount)))
settings.validationTimeout = time.Duration(dto.ValidationTimeoutInSeconds) * time.Second
settings.validationTimer = time.Duration(dto.ValidationIntervalInSeconds) * time.Second
settings.validationTimestamp = dto.ValidationIntervalInSeconds * time.Second.Nanoseconds()
Expand Down

This file was deleted.

42 changes: 23 additions & 19 deletions validatornode/infrastructure/log/console/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,67 @@ import (
type Level uint32

const (
Debug Level = iota
Info
Warn
Error
Fatal
debug Level = iota
info
warn
err
fatal
)

func ParseLevel(level string) Level {
func parseLevel(level string) Level {
switch strings.ToLower(level) {
case "debug":
return Debug
return debug
case "info":
return Info
return info
case "warn":
return Warn
return warn
case "error":
return Error
return err
case "fatal":
return Fatal
return fatal
}
return Info
return info
}

type Logger struct {
level Level
}

func NewLogger(level Level) *Logger {
return &Logger{level}
func NewLogger(level string) *Logger {
return &Logger{parseLevel(level)}
}

func NewFatalLogger() *Logger {
return &Logger{fatal}
}

func (logger *Logger) Debug(msg string) {
if logger.level <= Debug {
if logger.level <= debug {
log.Println("DEBUG:", msg)
}
}

func (logger *Logger) Info(msg string) {
if logger.level <= Info {
if logger.level <= info {
log.Println("INFO:", msg)
}
}

func (logger *Logger) Warn(msg string) {
if logger.level <= Warn {
if logger.level <= warn {
log.Println("WARN:", msg)
}
}

func (logger *Logger) Error(msg string) {
if logger.level <= Error {
if logger.level <= err {
log.Println("ERROR:", msg)
}
}

func (logger *Logger) Fatal(msg string) {
if logger.level <= Fatal {
if logger.level <= fatal {
log.Panicln("FATAL:", msg)
}
}
4 changes: 2 additions & 2 deletions validatornode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func main() {
if err != nil {
panic(err.Error())
}
logger := console.NewLogger(console.ParseLevel(settings.Log().LogLevel()))
logger := console.NewLogger(settings.Log().LogLevel())
node, err := createHostNode(settings, logger)
if err != nil {
logger.Fatal(err.Error())
Expand Down Expand Up @@ -67,7 +67,7 @@ func createNeighborhood(settings *configuration.Settings, watch *clock.Watch, lo
scoresBySeedTargetValue[seedStringTargetValue] = 0
}
ipFinder := net.NewIpFinderImplementation(logger)
neighborFactory := p2p.NewNeighborFactory(ipFinder, settings.Protocol().ValidationTimeout(), console.NewLogger(console.Fatal))
neighborFactory := p2p.NewNeighborFactory(ipFinder, settings.Network().ConnectionTimeout(), console.NewFatalLogger())
hostIp, err := findHostPublicIp(settings.Host().Ip(), logger)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion validatornode/presentation/api/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewHost(blocksManager application.BlocksManager,
if err != nil {
return nil, fmt.Errorf("failed to instantiate host on port %s: %w", port, err)
}
server.SetLogger(console.NewLogger(console.Fatal))
server.SetLogger(console.NewFatalLogger())
serverSettings := gp2p.NewServerSettings()
serverSettings.SetConnTimeout(validationTimeout)
server.SetSettings(serverSettings)
Expand Down
2 changes: 1 addition & 1 deletion validatornode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
},
"protocol": {
"blocksCountLimit": 1440,
"coinDigitsCount": 8,
"genesisAmount": 5000000000000,
"halfLifeInDays": 373.59,
"incomeBase": 100000000000,
"incomeLimit": 5000000000000,
"minimalTransactionFee": 1000,
"smallestUnitsPerCoin": 100000000,
"validationIntervalInSeconds": 3,
"validationTimeoutInSeconds": 3,
"verificationsCountPerValidation": 6
Expand Down

0 comments on commit 7bc59b2

Please sign in to comment.