[#768] adm: Do not change frostfsid admin on update
All checks were successful
DCO action / DCO (pull_request) Successful in 1m44s
Vulncheck / Vulncheck (pull_request) Successful in 3m13s
Build / Build Components (1.21) (pull_request) Successful in 4m22s
Build / Build Components (1.20) (pull_request) Successful in 4m36s
Tests and linters / Staticcheck (pull_request) Successful in 5m55s
Tests and linters / Lint (pull_request) Successful in 6m33s
Tests and linters / Tests (1.21) (pull_request) Successful in 8m33s
Tests and linters / Tests (1.20) (pull_request) Successful in 8m42s
Tests and linters / Tests with -race (pull_request) Successful in 8m38s

Behave similarly to the netmap contract.
Close #768

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-01-24 11:19:18 +03:00
parent 1332346ee8
commit 65fe3e4e6f

View file

@ -550,7 +550,17 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
nnsCs.Hash,
"container")
case frostfsIDContract:
h, found, err := getFrostfsIDAdmin(viper.GetViper())
var (
h util.Uint160
found bool
err error
)
if method == updateMethodName {
h, found, err = c.getFrostfsIDAdminFromContract()
}
if method != updateMethodName || err == nil && !found {
h, found, err = getFrostfsIDAdmin(viper.GetViper())
}
if err != nil {
return nil, err
}
@ -588,6 +598,35 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
return items, nil
}
func (c *initializeContext) getFrostfsIDAdminFromContract() (util.Uint160, bool, error) {
r := management.NewReader(c.ReadOnlyInvoker)
cs, err := r.GetContractByID(1)
if err != nil {
return util.Uint160{}, false, fmt.Errorf("get nns contract: %w", err)
}
fidHash, err := nnsResolveHash(c.ReadOnlyInvoker, cs.Hash, domainOf(frostfsIDContract))
if err != nil {
return util.Uint160{}, false, fmt.Errorf("resolve frostfsid contract hash: %w", err)
}
item, err := unwrap.Item(c.ReadOnlyInvoker.Call(fidHash, "getAdmin"))
if err != nil {
return util.Uint160{}, false, fmt.Errorf("getAdmin: %w", err)
}
if _, ok := item.(stackitem.Null); ok {
return util.Uint160{}, false, nil
}
bs, err := item.TryBytes()
if err != nil {
return util.Uint160{}, true, fmt.Errorf("getAdmin: decode result: %w", err)
}
h, err := util.Uint160DecodeBytesBE(bs)
if err != nil {
return util.Uint160{}, true, fmt.Errorf("getAdmin: decode result: %w", err)
}
return h, true, nil
}
func (c *initializeContext) getNetConfigFromNetmapContract() ([]stackitem.Item, error) {
r := management.NewReader(c.ReadOnlyInvoker)
cs, err := r.GetContractByID(1)