Skip to content

Commit

Permalink
Preload asset/app creators before evaluation.
Browse files Browse the repository at this point in the history
  • Loading branch information
tolikzinovyev committed Oct 23, 2021
1 parent 936e52e commit 242e05f
Showing 1 changed file with 62 additions and 3 deletions.
65 changes: 62 additions & 3 deletions idb/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/ledger"
"github.com/algorand/go-algorand/ledger/ledgercore"
"github.com/algorand/go-algorand/protocol"

"github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
Expand Down Expand Up @@ -187,15 +188,73 @@ func getBlockAddresses(block *bookkeeping.Block) map[basics.Address]struct{} {
}

func prepareEvalResources(l *ledger_for_evaluator.LedgerForEvaluator, block *bookkeeping.Block) (ledger.EvalForIndexerResources, error) {
accountDataMap, err := l.LookupWithoutRewards(getBlockAddresses(block))
addresses := getBlockAddresses(block)
assets := make(map[basics.AssetIndex]struct{})
apps := make(map[basics.AppIndex]struct{})

for _, stib := range block.Payset {
switch stib.Txn.Type {
case protocol.AssetConfigTx:
if stib.Txn.ConfigAsset != 0 {
assets[stib.Txn.ConfigAsset] = struct{}{}
}
case protocol.AssetTransferTx:
if stib.Txn.XferAsset != 0 {
assets[stib.Txn.XferAsset] = struct{}{}
}
case protocol.AssetFreezeTx:
if stib.Txn.FreezeAsset != 0 {
assets[stib.Txn.FreezeAsset] = struct{}{}
}
case protocol.ApplicationCallTx:
if stib.Txn.ApplicationID != 0 {
apps[stib.Txn.ApplicationID] = struct{}{}
}
}
}

var res ledger.EvalForIndexerResources

assetCreators, err := l.GetAssetCreator(assets)
if err != nil {
return ledger.EvalForIndexerResources{},
fmt.Errorf("prepareEvalResources() err: %w", err)
}
for index, foundAddress := range assetCreators {
creatable := ledger.Creatable{
Index: basics.CreatableIndex(index),
Type: basics.AssetCreatable,
}
res.Creators[creatable] = foundAddress

res := ledger.EvalForIndexerResources{
Accounts: accountDataMap,
if foundAddress.Exists {
addresses[foundAddress.Address] = struct{}{}
}
}

appCreators, err := l.GetAppCreator(apps)
if err != nil {
return ledger.EvalForIndexerResources{},
fmt.Errorf("prepareEvalResources() err: %w", err)
}
for index, foundAddress := range appCreators {
creatable := ledger.Creatable{
Index: basics.CreatableIndex(index),
Type: basics.AppCreatable,
}
res.Creators[creatable] = foundAddress

if foundAddress.Exists {
addresses[foundAddress.Address] = struct{}{}
}
}

res.Accounts, err = l.LookupWithoutRewards(addresses)
if err != nil {
return ledger.EvalForIndexerResources{},
fmt.Errorf("prepareEvalResources() err: %w", err)
}

return res, nil
}

Expand Down

0 comments on commit 242e05f

Please sign in to comment.