Skip to content

Commit

Permalink
ir: Use default network settings for auto-deploy and drop configuration
Browse files Browse the repository at this point in the history
Network settings configuration did not justify itself because used only
when initializing the FS chain.

Use default network settings during the FS chain auto-deployment (same
ones used by the NeoFS ADM tool). Introduce `fschain_autodeploy` config
flag that replaces mode tuning previously based on `network_settings`
section presence.

Closes #2660.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Dec 2, 2023
1 parent d772cf9 commit ac357fb
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 401 deletions.
41 changes: 3 additions & 38 deletions config/example/ir.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,44 +76,9 @@ morph:
interval: 30s # Optional time period between pings. Defaults to 30s. Must not be negative
timeout: 90s # Optional time period to wait for pong. Defaults to 1m. Must not be negative

network_settings: # NeoFS network settings managed in the Netmap contract
epoch_duration: 240 # Time interval (approximate) between two adjacent NeoFS epochs measured in Sidechain blocks.
# Must be an integer in range [1, 18446744073709551615]
max_object_size: 67108864 # [bytes] Maximum size of physically stored NeoFS objects. Note that this applies
# only to objects located on storage nodes: user objects have no restrictions and, if necessary, are sliced.
# Must be an integer in range [1, 18446744073709551615]
require_homomorphic_hashing: true # Toggles the requirement for homomorphic hashing of object payloads.
# Must be 'true' or 'false'
allow_maintenance_mode: true # Toggles permission to transition storage nodes to maintenance state.
# Must be 'true' or 'false'
eigen_trust:
alpha: 0.1 # Alpha parameter of EigenTrust algorithm used in the Reputation system.
# Must be a floating point number in range [0, 1].
iterations_number: 4 # Number of EigenTrust algorithm iterations to pass in the Reputation system.
# Must be an integer in range [1, 18446744073709551615]
price: # Price settings. NEOFS means NeoFS Balance contract tokens (usually GASe-12).
storage: 100000000 # [NEOFS] Price for 1GB of data paid every epoch by data owner to storage nodes.
# Must be an integer in range [0, 18446744073709551615]
fee:
ir_candidate: 100 # [GASe-8] Contribution from the new candidate to the Inner Ring. Must be non-negative integer
# Must be an integer in range [0, 18446744073709551615]
withdraw: 100000000 # [GASe-8] Fee paid by the user account to;
# - NeoFS Processing contract (if Notary service is enabled in the NeoFS Mainchain)
# - each Alphabet member (otherwise)
# Must be an integer in range [0, 18446744073709551615]
audit: 10000 # [NEOFS] Fee for data audit paid by storage group owner to the auditor (Inner Ring member).
# Must be an integer in range [0, 18446744073709551615]
new_container: 1000 # [NEOFS] Fee for new container paid by creator to each Alphabet member.
# Must be an integer in range [0, 18446744073709551615]
container_domain: 500 # [NEOFS] Fee for container's NNS domain paid by container creator to each Alphabet member.
# Must be a non-negative integer
custom: # Optional list of custom key-value pairs to be set in the network configuration. Forbidden keys:
# [AuditFee, BasicIncomeRate, ContainerAliasFee, ContainerFee, EigenTrustAlpha, EigenTrustIterations, EpochDuration,
# HomomorphicHashingDisabled, InnerRingCandidateFee, MaintenanceModeAllowed, MaxObjectSize, WithdrawFee]
# Note that this list can be extended in the future, so, to avoid potential collision, it is recommended
# to use the most specific keys.
- my_custom_key1=val1
- my_custom_key2=val2
fschain_autodeploy: true # Optional flag to run auto-deployment procedure of the FS chain. By default,
# the chain is expected to be deployed/updated in the background (e.g. via NeoFS ADM tool).
# If set, must be 'true' or 'false'.

nns:
system_email: [email protected]
Expand Down
180 changes: 24 additions & 156 deletions pkg/innerring/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ import (
)

// checks whether Inner Ring app is configured to initialize underlying NeoFS
// Sidechain or await for a background deployment.
func isAutoDeploymentMode(cfg *viper.Viper) bool {
return cfg.IsSet("network_settings")
// Sidechain or await for a background deployment. Returns an error if
// the configuration format is violated.
func isAutoDeploymentMode(cfg *viper.Viper) (bool, error) {
res, err := parseConfigBool(cfg, "fschain_autodeploy", "flag to auto-deploy the FS chain")
if err != nil && !errors.Is(err, errMissingConfig) {
return false, err
}

return res, nil
}

// checks if Inner Ring app is configured to be launched in local consensus
Expand Down Expand Up @@ -209,139 +215,21 @@ func parseBlockchainConfig(v *viper.Viper, _logger *zap.Logger) (c blockchain.Co
return c, nil
}

const networkSettingsConfigSection = "network_settings"

func parseNetworkSettingsConfig(v *viper.Viper) (c netmap.NetworkConfiguration, err error) {
if !v.IsSet(networkSettingsConfigSection) {
return c, fmt.Errorf("missing root section '%s'", networkSettingsConfigSection)
}

c.EpochDuration, err = parseConfigUint64Range(v, networkSettingsConfigSection+".epoch_duration", "epoch duration", 1, math.MaxUint32)
if err != nil {
return
}

c.MaxObjectSize, err = parseConfigUint64Range(v, networkSettingsConfigSection+".max_object_size", "max object size", 1, math.MaxUint64)
if err != nil {
return
}

requireHomoHash, err := parseConfigBool(v, networkSettingsConfigSection+".require_homomorphic_hashing", "is homomorphic hashing required")
if err != nil {
return
}

c.HomomorphicHashingDisabled = !requireHomoHash

c.MaintenanceModeAllowed, err = parseConfigBool(v, networkSettingsConfigSection+".allow_maintenance_mode", "is maintenance mode allowed")
if err != nil {
return
}

const eigenTrustSection = networkSettingsConfigSection + ".eigen_trust"
if !v.IsSet(eigenTrustSection) {
return c, fmt.Errorf("missing EigenTrust section '%s'", eigenTrustSection)
}

c.EigenTrustAlpha, err = parseConfigFloatRange(v, eigenTrustSection+".alpha", "EigenTrust alpha parameter", 0, 1)
if err != nil {
return
}

c.EigenTrustIterations, err = parseConfigUint64Range(v, eigenTrustSection+".iterations_number", "number of EigenTrust iterations", 1, math.MaxUint64)
if err != nil {
return
}

const priceSection = networkSettingsConfigSection + ".price"
if !v.IsSet(priceSection) {
return c, fmt.Errorf("missing price section '%s'", priceSection)
}

c.StoragePrice, err = parseConfigUint64Max(v, priceSection+".storage", "storage price", math.MaxUint64)
if err != nil {
return
}

const feeSection = priceSection + ".fee"
if !v.IsSet(feeSection) {
return c, fmt.Errorf("missing fee section '%s'", feeSection)
}

c.IRCandidateFee, err = parseConfigUint64Max(v, feeSection+".ir_candidate", "Inner Ring candidate fee", math.MaxUint64)
if err != nil {
return
}

c.WithdrawalFee, err = parseConfigUint64Max(v, feeSection+".withdraw", "withdrawal fee", math.MaxUint64)
if err != nil {
return
}

c.AuditFee, err = parseConfigUint64Max(v, feeSection+".audit", "data audit fee", math.MaxUint64)
if err != nil {
return
}

c.ContainerFee, err = parseConfigUint64Max(v, feeSection+".new_container", "container creation fee", math.MaxUint64)
if err != nil {
return
}

c.ContainerAliasFee, err = parseConfigUint64Max(v, feeSection+".container_domain", "container domain fee", math.MaxUint64)
if err != nil {
return
}

customSettingsKey := networkSettingsConfigSection + ".custom"
if v.IsSet(customSettingsKey) {
var sss []string
sss, err = parseConfigStrings(v, customSettingsKey, "custom settings")
if err != nil {
return
}

if len(sss) == 0 {
return c, fmt.Errorf("missing custom settings '%s'", customSettingsKey)
}

c.Raw = make([]netmap.RawNetworkParameter, len(sss))

for i := range sss {
const sep = "="
ss := strings.Split(sss[i], sep)
if len(ss) != 2 {
return c, fmt.Errorf("invalid %s '%s' (%s-separated key-value): failed to parse element #%d", customSettingsKey, ss[i], sep, i)
}

switch ss[0] {
default:
for j := 0; j < i; j++ {
if ss[0] == c.Raw[j].Name {
return c, fmt.Errorf("duplicated custom network setting '%s' in '%s'", ss[0], customSettingsKey)
}
}
case "AuditFee",
"BasicIncomeRate",
"ContainerAliasFee",
"ContainerFee",
"EigenTrustAlpha",
"EigenTrustIterations",
"EpochDuration",
"HomomorphicHashingDisabled",
"InnerRingCandidateFee",
"MaintenanceModeAllowed",
"MaxObjectSize",
"WithdrawFee":
return c, fmt.Errorf("invalid %s '%s' (%s-separated key-value): key to element #%d is forbidden", customSettingsKey, ss[i], sep, i)
}

c.Raw[i].Name = ss[0]
c.Raw[i].Value = []byte(ss[1])
}
}

return
// sets NeoFS network settings to be used for the NeoFS Sidechain
// auto-deployment.
func setNetworkSettingsDefaults(netCfg *netmap.NetworkConfiguration) {
netCfg.MaxObjectSize = 64 << 20 // 64MB of object payload
netCfg.EpochDuration = 240 // in NeoFS Sidechain blocks (e.g. ~1h for 15s block interval)
netCfg.StoragePrice = 0 // in GAS per 1GB (NeoFS Balance contract's decimals)
netCfg.AuditFee = 0 // in GAS per audit (NeoFS Balance contract's decimals)
netCfg.ContainerFee = 1000 // in GAS per container (NeoFS Balance contract's decimals)
netCfg.ContainerAliasFee = 500 // in GAS per container (NeoFS Balance contract's decimals)
netCfg.IRCandidateFee = 0 // in GAS per candidate (Fixed8)
netCfg.WithdrawalFee = 0 // in GAS per withdrawal (Fixed8)
netCfg.EigenTrustIterations = 4
netCfg.EigenTrustAlpha = 0.1
netCfg.HomomorphicHashingDisabled = false
netCfg.MaintenanceModeAllowed = false

Check warning on line 232 in pkg/innerring/config.go

View check run for this annotation

Codecov / codecov/patch

pkg/innerring/config.go#L220-L232

Added lines #L220 - L232 were not covered by tests
}

type nnsConfig struct {
Expand Down Expand Up @@ -530,26 +418,6 @@ func parseConfigBool(v *viper.Viper, key, desc string) (bool, error) {
return res, nil
}

func parseConfigFloatRange(v *viper.Viper, key, desc string, min, max float64) (float64, error) {
var res float64
var err error
if !v.IsSet(key) {
err = errMissingConfig
}
if err == nil {
res, err = cast.ToFloat64E(v.Get(key))
if err == nil {
if res < min || res > max {
err = fmt.Errorf("out of allowable range [%.2f:%.2f]", min, max)
}
}
}
if err != nil {
return res, fmt.Errorf("invalid %s '%s' (boolean): %w", desc, key, err)
}
return res, nil
}

func parseConfigString(v *viper.Viper, key, desc string) (string, error) {
var res string
var err error
Expand Down
Loading

0 comments on commit ac357fb

Please sign in to comment.