[#738] neofs-adm: Set more network configuration values

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
remotes/fyrchik/meta-pebble
Alex Vanin 2021-08-03 15:04:38 +03:00 committed by Alex Vanin
parent 3a34e4a48e
commit 37cc702271
3 changed files with 41 additions and 25 deletions

View File

@ -15,11 +15,16 @@ import (
)
type configTemplate struct {
Endpoint string
AlphabetDir string
MaxObjectSize int
EpochDuration int
Glagolitics []string
Endpoint string
AlphabetDir string
MaxObjectSize int
EpochDuration int
BasicIncomeRate int
AuditFee int
CandidateFee int
ContainerFee int
WithdrawFee int
Glagolitics []string
}
const configTxtTemplate = `rpc-endpoint: {{ .Endpoint}}
@ -27,6 +32,12 @@ alphabet-wallets: {{ .AlphabetDir}}
network:
max_object_size: {{ .MaxObjectSize}}
epoch_duration: {{ .EpochDuration}}
basic_income_rate: {{ .BasicIncomeRate}}
fee:
audit: {{ .AuditFee}}
candidate: {{ .CandidateFee}}
container: {{ .ContainerFee}}
withdraw: {{ .WithdrawFee}}
# if credentials section is omitted, then neofs-adm will require manual password input
credentials:{{ range.Glagolitics}}
{{.}}: password{{end}}
@ -92,22 +103,27 @@ func defaultConfigPath() (string, error) {
// want to order records in specific order in file and, probably, provide
// some comments as well.
func generateConfigExample(appDir string, credSize int) (string, error) {
input := configTemplate{
Endpoint: "https://neo.rpc.node:30333",
MaxObjectSize: 67108864, // 64 MiB
EpochDuration: 240, // 1 hour with 15s per block
Glagolitics: make([]string, 0, credSize),
tmpl := configTemplate{
Endpoint: "https://neo.rpc.node:30333",
MaxObjectSize: 67108864, // 64 MiB
EpochDuration: 240, // 1 hour with 15s per block
BasicIncomeRate: 1_0000_0000, // 0.0001 GAS per GiB (Fixed12)
AuditFee: 1_0000, // 0.00000001 GAS per audit (Fixed12)
CandidateFee: 100_0000_0000, // 100.0 GAS (Fixed8)
ContainerFee: 1000, // 0.000000001 * 7 GAS per container (Fixed12)
WithdrawFee: 1_0000_0000, // 1.0 GAS (Fixed8)
Glagolitics: make([]string, 0, credSize),
}
appDir, err := filepath.Abs(appDir)
if err != nil {
return "", fmt.Errorf("making absolute path for %s: %w", appDir, err)
}
input.AlphabetDir = path.Join(appDir, "alphabet-wallets")
tmpl.AlphabetDir = path.Join(appDir, "alphabet-wallets")
var i innerring.GlagoliticLetter
for i = 0; i < innerring.GlagoliticLetter(credSize); i++ {
input.Glagolitics = append(input.Glagolitics, i.String())
tmpl.Glagolitics = append(tmpl.Glagolitics, i.String())
}
t, err := template.New("config.yml").Parse(configTxtTemplate)
@ -117,7 +133,7 @@ func generateConfigExample(appDir string, credSize int) (string, error) {
buf := bytes.NewBuffer(nil)
err = t.Execute(buf, input)
err = t.Execute(buf, tmpl)
if err != nil {
return "", fmt.Errorf("generating config from tempalte: %w", err)
}

View File

@ -28,6 +28,11 @@ func TestGenerateConfigExample(t *testing.T) {
require.Equal(t, path.Join(appDir, "alphabet-wallets"), v.GetString("alphabet-wallets"))
require.Equal(t, 67108864, v.GetInt("network.max_object_size"))
require.Equal(t, 240, v.GetInt("network.epoch_duration"))
require.Equal(t, 100000000, v.GetInt("network.basic_income_rate"))
require.Equal(t, 10000, v.GetInt("network.fee.audit"))
require.Equal(t, 10000000000, v.GetInt("network.fee.candidate"))
require.Equal(t, 1000, v.GetInt("network.fee.container"))
require.Equal(t, 100000000, v.GetInt("network.fee.withdraw"))
var i innerring.GlagoliticLetter
for i = 0; i < innerring.GlagoliticLetter(n); i++ {

View File

@ -43,13 +43,8 @@ const (
netmapInnerRingCandidateFeeKey = "InnerRingCandidateFee"
netmapWithdrawFeeKey = "WithdrawFee"
defaultAuditFee = 10000
defaultContainerFee = 1000
defaultEigenTrustIterations = 4
defaultEigenTrustAlpha = "0.1"
defaultBasicIncomeRate = 100000000
defaultInnerRingCandidateFee = 10000000000
defaultWithdrawFee = 100000000
defaultEigenTrustIterations = 4
defaultEigenTrustAlpha = "0.1"
)
var contractList = []string{
@ -272,19 +267,19 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []sm
{Type: smartcontract.StringType, Value: netmapMaxObjectSizeKey},
{Type: smartcontract.IntegerType, Value: viper.GetInt64(maxObjectSizeInitFlag)},
{Type: smartcontract.StringType, Value: netmapAuditFeeKey},
{Type: smartcontract.IntegerType, Value: int64(defaultAuditFee)},
{Type: smartcontract.IntegerType, Value: viper.GetInt64(auditFeeInitFlag)},
{Type: smartcontract.StringType, Value: netmapContainerFeeKey},
{Type: smartcontract.IntegerType, Value: int64(defaultContainerFee)},
{Type: smartcontract.IntegerType, Value: viper.GetInt64(containerFeeInitFlag)},
{Type: smartcontract.StringType, Value: netmapEigenTrustIterationsKey},
{Type: smartcontract.IntegerType, Value: int64(defaultEigenTrustIterations)},
{Type: smartcontract.StringType, Value: netmapEigenTrustAlphaKey},
{Type: smartcontract.StringType, Value: defaultEigenTrustAlpha},
{Type: smartcontract.StringType, Value: netmapBasicIncomeRateKey},
{Type: smartcontract.IntegerType, Value: int64(defaultBasicIncomeRate)},
{Type: smartcontract.IntegerType, Value: viper.GetInt64(incomeRateInitFlag)},
{Type: smartcontract.StringType, Value: netmapInnerRingCandidateFeeKey},
{Type: smartcontract.IntegerType, Value: int64(defaultInnerRingCandidateFee)},
{Type: smartcontract.IntegerType, Value: viper.GetInt64(candidateFeeInitFlag)},
{Type: smartcontract.StringType, Value: netmapWithdrawFeeKey},
{Type: smartcontract.IntegerType, Value: int64(defaultWithdrawFee)},
{Type: smartcontract.IntegerType, Value: viper.GetInt64(withdrawFeeInitFlag)},
}
items = append(items,
newContractParameter(smartcontract.Hash160Type, c.Contracts[balanceContract].Hash),