Skip to content

Commit

Permalink
Pass resourcesData as pointer because it's a large struct
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldiamant committed Nov 18, 2022
1 parent 5fd5770 commit 56b4a54
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ledger/accountdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions ledger/catchpointtracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ledger/catchpointtracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand All @@ -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
},
Expand Down

0 comments on commit 56b4a54

Please sign in to comment.