go-spacemesh icon indicating copy to clipboard operation
go-spacemesh copied to clipboard

Add validation for configuration parameters of a node

Open fasmat opened this issue 2 years ago • 3 comments

Description

At the moment there is no validation of config parameters being done to ensure that they are valid and/or reasonable for running a spacemesh node.

Some basic checks for configuration that can be set via a file, preset, or cli parameters should be performed to make sure that they are reasonable.

Example config checks:

  • PoST config parameters generally should adhere to the following: LabelsPerUnit*MinNumUnits >= k1 >= k2
  • ...

Implementation hints

Fastnet is currently configured with the following PoST settings in config/presets/fastnet.go:

conf.POST.BitsPerLabel = 8
conf.POST.K1 = 2000
conf.POST.K2 = 4
conf.POST.LabelsPerUnit = 32
conf.POST.MaxNumUnits = 4
conf.POST.MinNumUnits = 2

These settings need to be updated to pass the config check stated above

fasmat avatar Aug 30 '22 15:08 fasmat

@noamnelke @moshababo In your opinion, what should the correct values for fastnet be? Which value should I increase or decrease to make them fulfil the constraint?

Suggestion: decrease k1 to 8

fasmat avatar Sep 07 '22 14:09 fasmat

@fasmat I was looking for options to validate structures for my other PR and I stumbled upon https://github.com/go-playground/validator. It allows for a declarative definition of validation rules for each struct field via tags. Example:

type User struct {
  Age uint8 `validate:"gte=0,lte=130"`
}

What do You think about using it for configs validation?

poszu avatar Sep 19 '22 19:09 poszu

I don't have strong feelings for or against it.

If it can do checks like one field larger than another in the same struct it could be useful. I'm right now not sure if we store all our configuration in structs, so maybe some restructuring is necessary first.

If you think it will make te code easier to read and maintain go for it 😊

fasmat avatar Sep 19 '22 19:09 fasmat

@fasmat I was looking for options to validate structures for my other PR and I stumbled upon https://github.com/go-playground/validator. It allows for a declarative definition of validation rules for each struct field via tags. Example:

type User struct {
  Age uint8 `validate:"gte=0,lte=130"`
}

What do You think about using it for configs validation?

@poszu it make sense for simple value check. but since we still have some app-specific value validation, it seems simpler to code up the validation logic that does both (vs use this lib and then also have explicit validation). one example https://github.com/spacemeshos/go-spacemesh/blob/779f6e04f0f13ae16699f98d45cc4a650d92267d/cmd/node/node.go#L308

countvonzero avatar Sep 22 '22 06:09 countvonzero

proving opts also should be validated.

I think we should split "network" vs "user settable" parameters.

pigmej avatar Jul 25 '23 14:07 pigmej