Skip to content

Commit

Permalink
prefetcher: enable prefetcher for assets and apps (#4352)
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy authored Oct 31, 2022
1 parent ba9c593 commit e6f396b
Show file tree
Hide file tree
Showing 5 changed files with 680 additions and 151 deletions.
80 changes: 46 additions & 34 deletions ledger/internal/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1558,45 +1558,57 @@ transactionGroupLoop:
if !ok {
break transactionGroupLoop
} else if txgroup.Err != nil {
return ledgercore.StateDelta{}, txgroup.Err
logging.Base().Errorf("eval prefetcher error: %w", txgroup.Err)
}

for _, br := range txgroup.Accounts {
if _, have := base.accounts[*br.Address]; !have {
base.accounts[*br.Address] = *br.Data
}
}
for _, lr := range txgroup.Resources {
if lr.Address == nil {
// we attempted to look for the creator, and failed.
base.creators[creatable{cindex: lr.CreatableIndex, ctype: lr.CreatableType}] =
foundAddress{exists: false}
continue
}
if lr.CreatableType == basics.AssetCreatable {
if lr.Resource.AssetHolding != nil {
base.assets[ledgercore.AccountAsset{Address: *lr.Address, Asset: basics.AssetIndex(lr.CreatableIndex)}] = cachedAssetHolding{value: *lr.Resource.AssetHolding, exists: true}
} else {
base.assets[ledgercore.AccountAsset{Address: *lr.Address, Asset: basics.AssetIndex(lr.CreatableIndex)}] = cachedAssetHolding{exists: false}
if txgroup.Err == nil {
for _, br := range txgroup.Accounts {
if _, have := base.accounts[*br.Address]; !have {
base.accounts[*br.Address] = *br.Data
}
if lr.Resource.AssetParams != nil {
base.assetParams[ledgercore.AccountAsset{Address: *lr.Address, Asset: basics.AssetIndex(lr.CreatableIndex)}] = cachedAssetParams{value: *lr.Resource.AssetParams, exists: true}
base.creators[creatable{cindex: lr.CreatableIndex, ctype: basics.AssetCreatable}] = foundAddress{address: *lr.Address, exists: true}
} else {
base.assetParams[ledgercore.AccountAsset{Address: *lr.Address, Asset: basics.AssetIndex(lr.CreatableIndex)}] = cachedAssetParams{exists: false}

}
} else {
if lr.Resource.AppLocalState != nil {
base.appLocalStates[ledgercore.AccountApp{Address: *lr.Address, App: basics.AppIndex(lr.CreatableIndex)}] = cachedAppLocalState{value: *lr.Resource.AppLocalState, exists: true}
} else {
base.appLocalStates[ledgercore.AccountApp{Address: *lr.Address, App: basics.AppIndex(lr.CreatableIndex)}] = cachedAppLocalState{exists: false}
}
for _, lr := range txgroup.Resources {
if lr.Address == nil {
// we attempted to look for the creator, and failed.
creatableKey := creatable{cindex: lr.CreatableIndex, ctype: lr.CreatableType}
base.creators[creatableKey] = foundAddress{exists: false}
continue
}
if lr.Resource.AppParams != nil {
base.appParams[ledgercore.AccountApp{Address: *lr.Address, App: basics.AppIndex(lr.CreatableIndex)}] = cachedAppParams{value: *lr.Resource.AppParams, exists: true}
base.creators[creatable{cindex: lr.CreatableIndex, ctype: basics.AppCreatable}] = foundAddress{address: *lr.Address, exists: true}
if lr.CreatableType == basics.AssetCreatable {
assetKey := ledgercore.AccountAsset{
Address: *lr.Address,
Asset: basics.AssetIndex(lr.CreatableIndex),
}

if lr.Resource.AssetHolding != nil {
base.assets[assetKey] = cachedAssetHolding{value: *lr.Resource.AssetHolding, exists: true}
} else {
base.assets[assetKey] = cachedAssetHolding{exists: false}
}
if lr.Resource.AssetParams != nil {
creatableKey := creatable{cindex: lr.CreatableIndex, ctype: basics.AssetCreatable}
base.assetParams[assetKey] = cachedAssetParams{value: *lr.Resource.AssetParams, exists: true}
base.creators[creatableKey] = foundAddress{address: *lr.Address, exists: true}
} else {
base.assetParams[assetKey] = cachedAssetParams{exists: false}
}
} else {
base.appParams[ledgercore.AccountApp{Address: *lr.Address, App: basics.AppIndex(lr.CreatableIndex)}] = cachedAppParams{exists: false}
appKey := ledgercore.AccountApp{
Address: *lr.Address,
App: basics.AppIndex(lr.CreatableIndex),
}
if lr.Resource.AppLocalState != nil {
base.appLocalStates[appKey] = cachedAppLocalState{value: *lr.Resource.AppLocalState, exists: true}
} else {
base.appLocalStates[appKey] = cachedAppLocalState{exists: false}
}
if lr.Resource.AppParams != nil {
creatableKey := creatable{cindex: lr.CreatableIndex, ctype: basics.AppCreatable}
base.appParams[appKey] = cachedAppParams{value: *lr.Resource.AppParams, exists: true}
base.creators[creatableKey] = foundAddress{address: *lr.Address, exists: true}
} else {
base.appParams[appKey] = cachedAppParams{exists: false}
}
}
}
}
Expand Down
Loading

0 comments on commit e6f396b

Please sign in to comment.