Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefetcher: enable prefetcher for assets and apps #4352

Merged
merged 8 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 46 additions & 34 deletions ledger/internal/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1549,45 +1549,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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be flattened/simplified?

if !ok {
  break
}
if txGroup.Err != nil {
  // log it
} else {
  // for loop
}

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