[#768] adm: Do not change frostfsid admin on update

Behave similarly to the netmap contract.
Close #768

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
pull/921/head
Evgenii Stratonikov 2024-01-24 11:19:18 +03:00 committed by Evgenii Stratonikov
parent d2d850786d
commit d13e37f70b
1 changed files with 40 additions and 1 deletions

View File

@ -550,7 +550,17 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
nnsCs.Hash, nnsCs.Hash,
"container") "container")
case frostfsIDContract: 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 { if err != nil {
return nil, err return nil, err
} }
@ -588,6 +598,35 @@ func (c *initializeContext) getContractDeployData(ctrName string, keysParam []an
return items, nil 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) { func (c *initializeContext) getNetConfigFromNetmapContract() ([]stackitem.Item, error) {
r := management.NewReader(c.ReadOnlyInvoker) r := management.NewReader(c.ReadOnlyInvoker)
cs, err := r.GetContractByID(1) cs, err := r.GetContractByID(1)