From 56b4a54868b913bfec8ec6a9803e2d156dafebf8 Mon Sep 17 00:00:00 2001 From: michaeldiamant Date: Fri, 18 Nov 2022 12:54:07 -0500 Subject: [PATCH] Pass resourcesData as pointer because it's a large struct --- ledger/accountdb.go | 4 ++-- ledger/catchpointtracker.go | 8 ++++---- ledger/catchpointtracker_test.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ledger/accountdb.go b/ledger/accountdb.go index ba33fdfac0..b2a01b9704 100644 --- a/ledger/accountdb.go +++ b/ledger/accountdb.go @@ -478,7 +478,7 @@ func prepareNormalizedBalancesV6(bals []encodedBalanceRecordV6, proto config.Con if err != nil { return nil, err } - normalizedAccountBalances[i].accountHashes[curHashIdx], err = resourcesHashBuilderV6(resData, balance.Address, basics.CreatableIndex(cidx), resData.UpdateRound, res) + normalizedAccountBalances[i].accountHashes[curHashIdx], err = resourcesHashBuilderV6(&resData, balance.Address, basics.CreatableIndex(cidx), resData.UpdateRound, res) if err != nil { return nil, err } @@ -4822,7 +4822,7 @@ func (iterator *orderedAccountsIter) Next(ctx context.Context) (acct []accountAd resCb := func(addr basics.Address, cidx basics.CreatableIndex, resData *resourcesData, encodedResourceData []byte, lastResource bool) error { if resData != nil { - hash, err := resourcesHashBuilderV6(*resData, addr, cidx, resData.UpdateRound, encodedResourceData) + hash, err := resourcesHashBuilderV6(resData, addr, cidx, resData.UpdateRound, encodedResourceData) if err != nil { return err } diff --git a/ledger/catchpointtracker.go b/ledger/catchpointtracker.go index 91fc11ec62..584a9447d8 100644 --- a/ledger/catchpointtracker.go +++ b/ledger/catchpointtracker.go @@ -971,7 +971,7 @@ func (ct *catchpointTracker) accountsUpdateBalances(accountsDeltas compactAccoun resDelta := resourcesDeltas.getByIdx(i) addr := resDelta.address if !resDelta.oldResource.data.IsEmpty() { - deleteHash, err := resourcesHashBuilderV6(resDelta.oldResource.data, addr, resDelta.oldResource.aidx, resDelta.oldResource.data.UpdateRound, protocol.Encode(&resDelta.oldResource.data)) + deleteHash, err := resourcesHashBuilderV6(&resDelta.oldResource.data, addr, resDelta.oldResource.aidx, resDelta.oldResource.data.UpdateRound, protocol.Encode(&resDelta.oldResource.data)) if err != nil { return err } @@ -987,7 +987,7 @@ func (ct *catchpointTracker) accountsUpdateBalances(accountsDeltas compactAccoun } if !resDelta.newResource.IsEmpty() { - addHash, err := resourcesHashBuilderV6(resDelta.newResource, addr, resDelta.oldResource.aidx, resDelta.newResource.UpdateRound, protocol.Encode(&resDelta.newResource)) + addHash, err := resourcesHashBuilderV6(&resDelta.newResource, addr, resDelta.oldResource.aidx, resDelta.newResource.UpdateRound, protocol.Encode(&resDelta.newResource)) if err != nil { return err } @@ -1462,7 +1462,7 @@ const ( // encoded. const hashKindEncodingIndex = 4 -func rdGetCreatableHashKind(rd resourcesData, a basics.Address, ci basics.CreatableIndex) (hashKind, error) { +func rdGetCreatableHashKind(rd *resourcesData, a basics.Address, ci basics.CreatableIndex) (hashKind, error) { if rd.IsAsset() { return assetHK, nil } else if rd.IsApp() { @@ -1472,7 +1472,7 @@ func rdGetCreatableHashKind(rd resourcesData, a basics.Address, ci basics.Creata } // resourcesHashBuilderV6 calculates the hash key used for the trie by combining the creatable's resource data and its index -func resourcesHashBuilderV6(rd resourcesData, addr basics.Address, cidx basics.CreatableIndex, updateRound uint64, encodedResourceData []byte) ([]byte, error) { +func resourcesHashBuilderV6(rd *resourcesData, addr basics.Address, cidx basics.CreatableIndex, updateRound uint64, encodedResourceData []byte) ([]byte, error) { hk, err := rdGetCreatableHashKind(rd, addr, cidx) if err != nil { return nil, err diff --git a/ledger/catchpointtracker_test.go b/ledger/catchpointtracker_test.go index a4948fc158..7e9b4d19a4 100644 --- a/ledger/catchpointtracker_test.go +++ b/ledger/catchpointtracker_test.go @@ -1419,7 +1419,7 @@ func TestHashContract(t *testing.T) { Manager: a, } - bytes, err := resourcesHashBuilderV6(r, a, 7, 1024, protocol.Encode(&r)) + bytes, err := resourcesHashBuilderV6(&r, a, 7, 1024, protocol.Encode(&r)) require.NoError(t, err) return bytes }, @@ -1437,7 +1437,7 @@ func TestHashContract(t *testing.T) { GlobalStateSchemaNumUint: 2, } - bytes, err := resourcesHashBuilderV6(r, a, 7, 1024, protocol.Encode(&r)) + bytes, err := resourcesHashBuilderV6(&r, a, 7, 1024, protocol.Encode(&r)) require.NoError(t, err) return bytes },