From 820acebb7d57ded7075bb2e68a6f18ce9b941727 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Thu, 16 Jun 2022 14:25:55 +0300 Subject: [PATCH] [#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 --- pkg/morph/client/netmap/config.go | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pkg/morph/client/netmap/config.go b/pkg/morph/client/netmap/config.go index 77cf95b657..aa4e2565af 100644 --- a/pkg/morph/client/netmap/config.go +++ b/pkg/morph/client/netmap/config.go @@ -222,27 +222,27 @@ type NetworkConfiguration struct { } // 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.SetMethod(configListMethod) items, err := c.client.TestInvoke(prm) 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) } 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]) 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)) - var res NetworkConfiguration res.Raw = make([]RawNetworkParameter, 0, len(arr)) err = iterateRecords(arr, func(name string, value []byte) error { @@ -286,11 +286,8 @@ func (c *Client) ReadNetworkConfiguration() (*NetworkConfiguration, error) { return nil }) - if err != nil { - return nil, err - } - return &res, nil + return res, err } func bytesToUint64(val []byte) uint64 {