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

New Feature: Indexer Application Box Ingestion #1067

Merged
merged 117 commits into from
Aug 9, 2022

Conversation

tzaffi
Copy link
Contributor

@tzaffi tzaffi commented Jun 27, 2022

Adding Box Information to Indexer

Summary

The proposed app_box postgres table with all the insertion/update/deletion logic in place.

Additional test recommendations welcome!

Related PRs

Test Plan

TODO (move this to the integration branch once merged)

  • Incorporate the prunings of Enhancement: remove import validator utility and obsolete ledger for evaluator #1146 when it has been merged and figure out what to do with idb/postgres/postgres_rand_test.go
  • Manual test of network that creates 125 apps with 1000 boxes and verify directly on IndexerDB that app_box is populated as expected
  • Ingest go-algorand/data/basics/userBalance.go::AcccountData's TotalBoxes and TotalBoxBytes into account.account_data JSONB
  • Validate the ingestion of the summary data in the previous step in all relevant tests
  • Unit tests
  • Integration
  • End-to-end test
    • is passing against network that includes boxes
    • has been re-pointed to rel-nightly once that job includes boxes (cf. misc/docker-compose.yml)
  • Re-point the third_party/go-algorand submodule to
    • go-algorand
    • a released commit containing boxes
  • Has go-algorand's feature/avm-box been merged?

An Aside about Minimum Balance Calculation and App-Boxes

CF: The previous (partially wrong) version of this aside.

It would be nice to solve the long-standing issue #808 and provide minimum balance information for accounts, including app-accounts. App-Boxes affect the min balance calculation for an app-account holding boxes, and as this PR introduces their basic information to indexer.

Here's a brief description of how to add min-balance for apps in indexer:

The New Minimum Balance Calculation

The new boxes-included min-balance calculation requires knowing:

  • the number of boxes for an app (totalBoxes)
  • the total storage utilized in those boxes (totalBoxBytes) which is comprised of bytes used for keys and values
    The current PR allows calculating this information for a particular app.

Here's some pseudo-SQL:

WITH box_stats AS (
    SELECT account_data->>'tbx' AS total_boxes, account_data->>'tbxb' AS total_box_bytes 
    FROM account
    WHERE addr = {$appIndex.Addres()}
) 
SELECT {$BoxFlatMinbalance} * total_boxes + {$BoxByteMinbalance} * total_box_bytes AS app_box_cost
FROM box_stats;

shiqizng and others added 12 commits June 8, 2022 09:59
* integrate block processor
* add simple local ledger migration
* add fast catchup
* return empty lists from fetchApplications and fetchAppLocalStates (#1010)

* Update model to converge with algod (#1005)

* New Feature: Adds Data Directory Support (#1012)

- Updates the go-algorand submodule hash to point to rel/beta
- Moves the cpu profiling file, pid file and indexer configuration file
  to be options of only the daemon sub-command
- Changes os.Exit() to be a panic with a special handler.  This is so
  that defer's are handled instead of being ignored.
- Detects auto-loading configuration files in the data directory and
  issues errors if equivalent command line arguments are supplied.
- Updates the README with instructions on how to use the auto-loading
  configuration files and the data directory.

* Update mockery version

Co-authored-by: erer1243 <[email protected]>
Co-authored-by: AlgoStephenAkiki <[email protected]>
* handle ledger recovery scenario
* refactor create genesis block
* Adds Local Ledger Readme

Resolves #4109

Starts Readme docs

* Update docs/LocalLedger.md

Co-authored-by: Will Winder <[email protected]>

* Update docs/LocalLedger.md

Co-authored-by: Will Winder <[email protected]>

* Update docs/LocalLedger.md

Co-authored-by: Will Winder <[email protected]>

* Removed troubleshooting section

Co-authored-by: Will Winder <[email protected]>
Part 1

    cleanup genesis file access.
    put node catchup into a function that can be swapped out with the catchup service.
    pass the indexer logger into the block processor.
    move open ledger into a util function, and move the initial state util function into a new ledger util file.
    add initial catchupservice implementation.
    move ledger init from daemon.go to constructor.
    Merge multiple read genesis functions.

Part 2

    Merge local_ledger migration package into blockprocessor.
    Rename Migration to Initialize
    Use logger in catchup service catchup

Part 3

    Update submodule and use NewWrappedLogger.
    Make util.CreateInitState private
@tzaffi tzaffi marked this pull request as draft June 27, 2022 14:00
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
accounting/eval_preload.go Outdated Show resolved Hide resolved
accounting/eval_preload.go Outdated Show resolved Hide resolved
@@ -7,6 +7,7 @@ services:
dockerfile: ./misc/Dockerfile
environment:
CONNECTION_STRING: "host=e2e-db port=5432 user=algorand password=algorand dbname=indexer_db sslmode=disable"
CI_E2E_FILENAME: "tzaffi-box-e2e-improvements"
Copy link
Contributor Author

@tzaffi tzaffi Aug 3, 2022

Choose a reason for hiding this comment

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

^^^^ TODO: revert CI_E2E_FILENAME to "rel-nightly" before merging to develop ^^^^

@tzaffi tzaffi requested a review from shiqizng August 3, 2022 19:32
-- For looking up app box storage
CREATE TABLE IF NOT EXISTS app_box (
app bigint NOT NULL,
name bytea NOT NULL,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these names expected to be human readable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. They can be any bytestring whatsoever. We're not sure what the usage pattern will be, but I personally expect many of the names to be human readable, if not the values.

return delta, kvUpdated, boxTotals
}

// CompareAppBoxesAgainstLedger uses LedgerForEvaluator to assert that provided app boxes can be retrieved as expected
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

// BuildAccountDeltasFromKvsAndMods simulates keeping track of the evolution of the box statistics
func BuildAccountDeltasFromKvsAndMods(t *testing.T, kvOriginals, kvMods map[string]*string) (
Copy link
Contributor

Choose a reason for hiding this comment

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

I slightly prefer putting this in writer_test.go, or a utils_test.go file in the writer package. It's possible for files that don't end in _test.go to slip into a production binary, so unless they're really used across packages it is best to avoid using real packages.

This is a long time pet peeve for me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I appreciate your valiant attempt to fight the machine. I'll investigate refactoring along the lines suggested. The most frustration for me during this PR has been working around go's import restrictions for testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

BTW. There is a significant refactor of testing code in the upcoming followup #1117. It might be worthwhile to punt the discussion of where tests should live exactly till that PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In particular, as part of the refactor this file has been deleted:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@winder I've analyzed my refactoring for upcoming #1117. That one is not yet ready for review. However, one of the refactorings was doing exactly what you suggested. Moving BuildAccountDeltasFromKvsAndMods to writer_test.go. Thus I ask that we punt the final refactoring discussion to that PR.

@tzaffi tzaffi requested a review from winder August 9, 2022 14:31
@tzaffi tzaffi merged commit 4d86e74 into integration/boxes Aug 9, 2022
@tzaffi tzaffi deleted the tzaffi/box-ingest branch August 9, 2022 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants