From d1008ac8a1eff86a574880840cd8c31406d5eeaa Mon Sep 17 00:00:00 2001 From: Gary Malouf <982483+gmalouf@users.noreply.github.com> Date: Sat, 30 Dec 2023 21:56:16 -0500 Subject: [PATCH 1/2] Potential fix for panic on call to block w/ group resource sharing. --- api/converter_utils.go | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/api/converter_utils.go b/api/converter_utils.go index 23eae4fd4..a3bb57001 100644 --- a/api/converter_utils.go +++ b/api/converter_utils.go @@ -518,20 +518,16 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen } if len(stxn.ApplyData.EvalDelta.LocalDeltas) > 0 { keys := make([]tuple, 0) + for k := range stxn.ApplyData.EvalDelta.LocalDeltas { - if k == 0 { - keys = append(keys, tuple{ - key: 0, - address: stxn.Txn.Sender, - }) - } else { - addr := sdk.Address{} - copy(addr[:], stxn.Txn.Accounts[k-1][:]) - keys = append(keys, tuple{ - key: k, - address: addr, - }) + addr, err := edIndexToAddress(k, stxn.Txn, stxn.ApplyData.EvalDelta.SharedAccounts) + if err != nil { + return generated.Transaction{}, err } + keys = append(keys, tuple{ + key: k, + address: addr, + }) } sort.Slice(keys, func(i, j int) bool { return keys[i].key < keys[j].key }) d := make([]generated.AccountStateDelta, 0) @@ -629,6 +625,20 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen return txn, nil } +func edIndexToAddress(index uint64, txn sdk.Transaction, shared []sdk.Address) (sdk.Address, error) { + // index into [Sender, txn.Accounts[0], txn.Accounts[1], ..., shared[0], shared[1], ...] + switch { + case index == 0: + return txn.Sender, nil + case int(index-1) < len(txn.Accounts): + return txn.Accounts[index-1], nil + case int(index-1)-len(txn.Accounts) < len(shared): + return shared[int(index-1)-len(txn.Accounts)], nil + default: + return sdk.Address{}, fmt.Errorf("invalid Account Index %d in LocalDelta", index) + } +} + func (si *ServerImplementation) assetParamsToAssetQuery(params generated.SearchForAssetsParams) (idb.AssetsQuery, error) { creator, errorArr := decodeAddress(params.Creator, "creator", make([]string, 0)) if len(errorArr) != 0 { From 50a40d712204d36c8981ff11e4f7a5e759be1601 Mon Sep 17 00:00:00 2001 From: Gary Malouf <982483+gmalouf@users.noreply.github.com> Date: Sat, 30 Dec 2023 22:15:25 -0500 Subject: [PATCH 2/2] Typo fix. --- api/converter_utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/converter_utils.go b/api/converter_utils.go index a3bb57001..4bc704115 100644 --- a/api/converter_utils.go +++ b/api/converter_utils.go @@ -520,7 +520,7 @@ func signedTxnWithAdToTransaction(stxn *sdk.SignedTxnWithAD, extra rowData) (gen keys := make([]tuple, 0) for k := range stxn.ApplyData.EvalDelta.LocalDeltas { - addr, err := edIndexToAddress(k, stxn.Txn, stxn.ApplyData.EvalDelta.SharedAccounts) + addr, err := edIndexToAddress(k, stxn.Txn, stxn.ApplyData.EvalDelta.SharedAccts) if err != nil { return generated.Transaction{}, err }