[#1513] morph/netmap: Return result by value from net config reader

Make `ReadNetworkConfiguration` method to return `NetworkConfiguration`
by value in order to follow storage engine improvements and prevent heap
escaping.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-06-16 14:25:55 +03:00 committed by LeL
parent 808ba87e82
commit 820acebb7d

View file

@ -222,27 +222,27 @@ type NetworkConfiguration struct {
} }
// ReadNetworkConfiguration reads NetworkConfiguration from the NeoFS Sidechain. // ReadNetworkConfiguration reads NetworkConfiguration from the NeoFS Sidechain.
func (c *Client) ReadNetworkConfiguration() (*NetworkConfiguration, error) { func (c *Client) ReadNetworkConfiguration() (NetworkConfiguration, error) {
var res NetworkConfiguration
prm := client.TestInvokePrm{} prm := client.TestInvokePrm{}
prm.SetMethod(configListMethod) prm.SetMethod(configListMethod)
items, err := c.client.TestInvoke(prm) items, err := c.client.TestInvoke(prm)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not perform test invocation (%s): %w", return res, fmt.Errorf("could not perform test invocation (%s): %w",
configListMethod, err) configListMethod, err)
} }
if ln := len(items); ln != 1 { if ln := len(items); ln != 1 {
return nil, fmt.Errorf("unexpected stack item count (%s): %d", configListMethod, ln) return res, fmt.Errorf("unexpected stack item count (%s): %d", configListMethod, ln)
} }
arr, err := client.ArrayFromStackItem(items[0]) arr, err := client.ArrayFromStackItem(items[0])
if err != nil { if err != nil {
return nil, fmt.Errorf("record list (%s): %w", configListMethod, err) return res, fmt.Errorf("record list (%s): %w", configListMethod, err)
} }
m := make(map[string]struct{}, len(arr)) m := make(map[string]struct{}, len(arr))
var res NetworkConfiguration
res.Raw = make([]RawNetworkParameter, 0, len(arr)) res.Raw = make([]RawNetworkParameter, 0, len(arr))
err = iterateRecords(arr, func(name string, value []byte) error { err = iterateRecords(arr, func(name string, value []byte) error {
@ -286,11 +286,8 @@ func (c *Client) ReadNetworkConfiguration() (*NetworkConfiguration, error) {
return nil return nil
}) })
if err != nil {
return nil, err
}
return &res, nil return res, err
} }
func bytesToUint64(val []byte) uint64 { func bytesToUint64(val []byte) uint64 {