[#315] netmap: Add maintenance mode network setting

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-09-15 08:45:51 +03:00 committed by LeL
parent 4662d39886
commit 3dad44232e
2 changed files with 39 additions and 2 deletions

View file

@ -75,7 +75,8 @@ func (x *NetworkInfo) readFromV2(m netmap.NetworkInfo, checkFieldPresence bool)
configMaxObjSize, configMaxObjSize,
configWithdrawalFee: configWithdrawalFee:
_, err = decodeConfigValueUint64(prm.GetValue()) _, err = decodeConfigValueUint64(prm.GetValue())
case configHomomorphicHashingDisabled: case configHomomorphicHashingDisabled,
configMaintenanceModeAllowed:
_, err = decodeConfigValueBool(prm.GetValue()) _, err = decodeConfigValueBool(prm.GetValue())
} }
@ -247,7 +248,8 @@ func (x *NetworkInfo) IterateRawNetworkParameters(f func(name string, value []by
configIRCandidateFee, configIRCandidateFee,
configMaxObjSize, configMaxObjSize,
configWithdrawalFee, configWithdrawalFee,
configHomomorphicHashingDisabled: configHomomorphicHashingDisabled,
configMaintenanceModeAllowed:
} }
return false return false
@ -522,3 +524,20 @@ func (x *NetworkInfo) DisableHomomorphicHashing() {
func (x NetworkInfo) HomomorphicHashingDisabled() bool { func (x NetworkInfo) HomomorphicHashingDisabled() bool {
return x.configBool(configHomomorphicHashingDisabled) return x.configBool(configHomomorphicHashingDisabled)
} }
const configMaintenanceModeAllowed = "MaintenanceModeAllowed"
// AllowMaintenanceMode sets the flag allowing nodes to go into maintenance mode.
//
// See also MaintenanceModeAllowed.
func (x *NetworkInfo) AllowMaintenanceMode() {
x.setConfigBool(configMaintenanceModeAllowed, true)
}
// MaintenanceModeAllowed returns true iff network config allows
// maintenance mode for storage nodes.
//
// Zero NetworkInfo has disallows maintenance mode.
func (x NetworkInfo) MaintenanceModeAllowed() bool {
return x.configBool(configMaintenanceModeAllowed)
}

View file

@ -233,3 +233,21 @@ func TestNetworkInfo_HomomorphicHashingDisabled(t *testing.T) {
}, },
) )
} }
func TestNetworkInfo_MaintenanceModeAllowed(t *testing.T) {
testConfigValue(t,
func(x NetworkInfo) interface{} { return x.MaintenanceModeAllowed() },
func(info *NetworkInfo, val interface{}) {
if val.(bool) {
info.AllowMaintenanceMode()
}
},
true, true,
"MaintenanceModeAllowed", func(val interface{}) []byte {
if val.(bool) {
return []byte{1}
}
return []byte{0}
},
)
}