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

Local Ledger #1011

Merged
merged 38 commits into from
Jun 8, 2022
Merged

Local Ledger #1011

merged 38 commits into from
Jun 8, 2022

Conversation

shiqizng
Copy link
Contributor

Summary

This PR integrates BlockProcessor to daemon and and AddBlock. And AddBlock is refactored to take a validated block.

Test Plan

Regression tests passing.

@codecov
Copy link

codecov bot commented May 26, 2022

Codecov Report

Merging #1011 (664bdd0) into localledger/integration (f26fca1) will decrease coverage by 0.36%.
The diff coverage is 65.11%.

@@                     Coverage Diff                     @@
##           localledger/integration    #1011      +/-   ##
===========================================================
- Coverage                    59.58%   59.21%   -0.37%     
===========================================================
  Files                           45       46       +1     
  Lines                         8353     8523     +170     
===========================================================
+ Hits                          4977     5047      +70     
- Misses                        2918     3012      +94     
- Partials                       458      464       +6     
Impacted Files Coverage Δ
idb/dummy/dummy.go 0.00% <0.00%> (ø)
idb/idb.go 71.66% <ø> (ø)
importer/helper.go 8.92% <0.00%> (-0.51%) ⬇️
importer/importer.go 0.00% <0.00%> (ø)
idb/postgres/postgres.go 61.37% <70.49%> (-1.98%) ⬇️
processor/blockprocessor/block_processor.go 72.66% <71.30%> (-10.68%) ⬇️
processor/eval/ledger_for_evaluator.go 78.02% <78.02%> (ø)
fetcher/fetcher.go 34.64% <0.00%> (-1.32%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f26fca1...664bdd0. Read the comment docs.

@shiqizng shiqizng self-assigned this May 26, 2022
README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@Eric-Warehime Eric-Warehime left a comment

Choose a reason for hiding this comment

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

Made it about halfway through. Left some questions. Overall it's quite a large PR.

// validated block
var vb ledgercore.ValidatedBlock
vb = ledgercore.MakeValidatedBlock(blockCert.Block, delta)
if protoChanged {
Copy link
Contributor

Choose a reason for hiding this comment

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

I see https://github.com/algorand/go-algorand/blob/master/ledger/evalindexer.go which seems to be the reason we need to modify the consensus properties. Is there a reason we need this block just to reconstruct the vb with the updated consensus property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this block is trying to reproduce the logic implemented in previous version of AddBlock, here. AssetCloseAmount field was added in Algod 2.5.4 release from a year ago, PR #1886, and this override was put in place to support transactions before that release.

processor/eval/ledger_for_evaluator.go Outdated Show resolved Hide resolved

// LookupResources is part of go-algorand's indexerLedgerForEval interface.
func (l LedgerForEvaluator) LookupResources(input map[basics.Address]map[ledger.Creatable]struct{}) (map[basics.Address]map[ledger.Creatable]ledgercore.AccountResource, error) {
// Initialize the result `res` with the same structure as `input`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to create a copy instead of mutating the input?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

input type doesn't match the return type.

Copy link
Contributor

@winder winder left a comment

Choose a reason for hiding this comment

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

Some initial feedback. I still need to take a closer look at AddBlock

Comment on lines 114 to 119
l := test.MakeTestLedger("ledger")
defer l.Close()
proc, err := blockprocessor.MakeProcessor(l, db.AddBlock)
require.NoError(t, err, "failed to open ledger")
blockCert := rpcs.EncodedBlockCert{Block: block}
err = proc.Process(&blockCert)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this go in setupIdb instead? Returning a new addBlock callback would be one way to get the tests to behave similar to before, and avoid the duplicate code block. Another way would be to return the processor along with the IndexerDb implementation.

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 don't think an addBlock callback would work in this case since addBlock takes a validated block. I'll go with the second option.

cmd/algorand-indexer/daemon.go Outdated Show resolved Hide resolved
cmd/import-validator/core/service.go Outdated Show resolved Hide resolved
@@ -263,115 +263,96 @@ func (db *IndexerDb) AddBlock(block *bookkeeping.Block) error {
if err != nil {
return fmt.Errorf("AddBlock() err: %w", err)
}
if block.Round() != basics.Round(importstate.NextRoundToAccount) {
if block.Round() > basics.Round(importstate.NextRoundToAccount) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why aren't these equal anymore? We're ignoring the case where old blocks are submitted more than once?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah. I'm making it ignore blocks with older rounds. this change was partly because this test was failing with local ledger, https://github.com/algorand/indexer/blob/develop/idb/postgres/postgres_integration_test.go#L2109. setupIdb calls AddBlock to add genesisBlock but it was already added when calling Makeprocessor().

Comment on lines 178 to 183
l := test.MakeTestLedger("ledger")
defer l.Close()
proc, err := blockprocessor.MakeProcessor(l, db.AddBlock)
require.NoError(t, err, "failed to open ledger")
blockCert := rpcs.EncodedBlockCert{Block: block}
err = proc.Process(&blockCert)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as before, can we figure out how to streamline this?

processor/blockprocessor/block_processor.go Outdated Show resolved Hide resolved
processor/eval/ledger_for_evaluator_test.go Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@shiqizng shiqizng requested a review from winder June 6, 2022 14:30

imp := importer.NewImporter(db)
handler := blockHandler(imp, 1*time.Second)
proc, err := blockprocessor.MakeProcessor(initState, indexerDataDir, imp.ImportBlock)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this constructor work with MakeProcessor(&genesis, indexerDataDir, imp.ImportBlock)? It seems like we would want to start fetcher from round 0, so AddBlock could create the initial state when that occurs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

how about pass an algod client to MakeProcessor and skip passing block 0 to handler in MakeProcessor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated the method to accept a genesis and a genesis block.

Copy link
Contributor

@winder winder left a comment

Choose a reason for hiding this comment

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

Just left a little more feedback

@shiqizng shiqizng requested a review from winder June 7, 2022 22:45
}

// MakeLedgerForEvaluator creates a LedgerForEvaluator object.
func MakeLedgerForEvaluator(ld *ledger.Ledger) (LedgerForEvaluator, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since error is always nil, consider not returning error at all

"github.com/algorand/indexer/processor"
iledger "github.com/algorand/indexer/processor/eval"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: consider renaming iledgerindexerLedger or something a bit more verbose. Through my own misjudgment, I kept on thinking that iledger.xyz are interfaces of some sort.

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'll include these changes in another related pr.

@shiqizng shiqizng merged commit 12f8c2f into localledger/integration Jun 8, 2022
@shiqizng shiqizng deleted the shiqi/localledger branch June 16, 2022 20:49
Eric-Warehime added a commit that referenced this pull request Jul 21, 2022
* Local Ledger (#1011)

* integrate block processor

* Local Ledger Deployment (#1013)

* add simple local ledger migration

* add deleted opts

* fast catchup (#1023)

* add fast catchup

* Localledger merge (#1036)

* 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]>

* recovery scenario (#1024)

* handle ledger recovery scenario

* refactor create genesis block (#1026)

* refactor create genesis block

* Adds Local Ledger Readme (#1035)

* 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]>

* update ledger file path and migration (#1042)

* LocalLedger Refactoring + Catchpoint Service (#1049)

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

* build: merge develop into localledger/integration (#1062)

* Ledger init status (#1058)

* Generate an error if the catchpoint is not valid for initialization. (#1075)

* Use main logger in handler and fetcher. (#1077)

* Switch from fullNode catchup to catchpoint catchup service. (#1076)

* Refactor daemon, add more tests (#1039)

Refactors daemon cmd into separate, testable pieces.

* Merge develop into localledger/integration (#1083)

* Misc Local Ledger cleanup (#1086)

* Update processor/blockprocessor/initialize.go

Co-authored-by: Zeph Grunschlag <[email protected]>

* commit

* fix function call args

* RFC-0001: Rfc 0001 impl (#1069)

Adds an Exporter interface and a noop exporter implementation with factory methods for construction

* Fix test errors

* Add/fix tests

* Add postgresql_exporter tests

* Update config loading

* Change BlockExportData to pointers

* Move and rename ExportData

* Add Empty func to BlockData

* Add comment

Co-authored-by: shiqizng <[email protected]>
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: erer1243 <[email protected]>
Co-authored-by: AlgoStephenAkiki <[email protected]>
Co-authored-by: Will Winder <[email protected]>
Co-authored-by: Zeph Grunschlag <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants