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

ledger: refactor evaluator into an internal package #2983

Merged

Conversation

tsachiherman
Copy link
Contributor

@tsachiherman tsachiherman commented Oct 1, 2021

Summary

This PR reorganize the files inside the ledger package by move the evaluator related files into its own internal package.
The files in the internal package cannot access the root ledger files, and therefore using the shared ledgercore as a place to share interfaces.

ledger/
├── apply/
├── internal/
├── ledgercore/
└── testing/

Test Plan

use existing test, and update existing tests.

@tsachiherman tsachiherman changed the title ledger: refactor evaluator ledger: refactor evaluator into an internal package Oct 4, 2021
@tsachiherman
Copy link
Contributor Author

fyi: @algorandskiy

data/basics/compactcert.go Outdated Show resolved Hide resolved
ledger/ledger.go Outdated Show resolved Hide resolved
ledger/accountdb_test.go Show resolved Hide resolved
@@ -37,11 +48,158 @@ func main(source string) string {
end: int 1`, source)
}

// newTestLedger creates a in memory Ledger that is as realistic as
// possible. It has Rewards and FeeSink properly configured.
func newTestLedger(t testing.TB, balances bookkeeping.GenesisBalances) *Ledger {
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like this also need to go into testing since these functions are generic and not app-specific

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't do that due to circular dependencies between the "testing" and the "ledger".

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like the only problem is `Ledger at

type testingEvaluator struct {
	*internal.BlockEvaluator
	ledger *Ledger
}

and ledger. genesisProto, ledger.lookup usages. The former is implemented as GenesisProto() in #2984, the latter most likely is Lookup* function. So defining a new LedgerForTesting (well, I know) interface might make the trick.

ledger/evalIndexer.go Show resolved Hide resolved
ledger/internal/eval.go Outdated Show resolved Hide resolved
ledger/internal/eval.go Show resolved Hide resolved
ledger/internal/eval.go Outdated Show resolved Hide resolved
ledger/internal/eval.go Outdated Show resolved Hide resolved
ledger/internal/eval.go Outdated Show resolved Hide resolved
@algorandskiy
Copy link
Contributor

btw, maybe move block eval into eval subpackage?

@tsachiherman
Copy link
Contributor Author

btw, maybe move block eval into eval subpackage?

I think that doing so would be much easier after this PR is done.

@codecov-commenter
Copy link

codecov-commenter commented Oct 5, 2021

Codecov Report

Merging #2983 (f9e8a46) into master (ff8139a) will decrease coverage by 0.20%.
The diff coverage is 34.14%.

❗ Current head f9e8a46 differs from pull request most recent head b645bac. Consider uploading reports for the commit b645bac to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2983      +/-   ##
==========================================
- Coverage   43.83%   43.62%   -0.21%     
==========================================
  Files         385      390       +5     
  Lines       86754    86750       -4     
==========================================
- Hits        38026    37849     -177     
- Misses      42716    42875     +159     
- Partials     6012     6026      +14     
Impacted Files Coverage Δ
catchup/service.go 69.35% <0.00%> (ø)
cmd/tealdbg/localLedger.go 62.67% <ø> (ø)
compactcert/worker.go 90.00% <ø> (ø)
crypto/compactcert/builder.go 63.63% <ø> (ø)
crypto/compactcert/msgp_gen.go 39.47% <ø> (-0.79%) ⬇️
crypto/compactcert/structs.go 100.00% <ø> (ø)
daemon/algod/api/server/v2/dryrun.go 66.56% <ø> (ø)
data/basics/ccertpart.go 0.00% <0.00%> (ø)
ledger/internal/appcow.go 80.71% <ø> (ø)
ledger/internal/applications.go 36.75% <ø> (ø)
... and 35 more

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 ff8139a...b645bac. Read the comment docs.

@tsachiherman tsachiherman marked this pull request as ready for review October 6, 2021 16:02
Copy link
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

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

Looks good to me but I have some opinionated remarks.

@@ -31,6 +31,7 @@ import (
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/txntest"
"github.com/algorand/go-algorand/ledger/ledgercore"
ledgertesting "github.com/algorand/go-algorand/ledger/testing"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: ledgertesting looks way too long, maybe ltesting or something?

@@ -37,11 +48,158 @@ func main(source string) string {
end: int 1`, source)
}

// newTestLedger creates a in memory Ledger that is as realistic as
// possible. It has Rewards and FeeSink properly configured.
func newTestLedger(t testing.TB, balances bookkeeping.GenesisBalances) *Ledger {
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like the only problem is `Ledger at

type testingEvaluator struct {
	*internal.BlockEvaluator
	ledger *Ledger
}

and ledger. genesisProto, ledger.lookup usages. The former is implemented as GenesisProto() in #2984, the latter most likely is Lookup* function. So defining a new LedgerForTesting (well, I know) interface might make the trick.

ledger/ledger.go Outdated
}

// MakeDebugBalances creates a ledger suitable for dryrun and debugger
func MakeDebugBalances(l ledgercore.LedgerForCowBase, round basics.Round, proto protocol.ConsensusVersion, prevTimestamp int64) apply.Balances {
Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts/comments?

@algorandskiy algorandskiy requested a review from cce October 7, 2021 00:25
@tsachiherman tsachiherman merged commit 239921a into algorand:master Oct 8, 2021
@tsachiherman tsachiherman deleted the tsachi/ledger_refactor_step1 branch October 8, 2021 21:30
tsachiherman added a commit that referenced this pull request Oct 9, 2021
## Summary

This PR addresses a regression introduced in #2983. 
The culprit is that an interface might contain a nil pointer, which makes it insufficient to test the interface pointer itself.

Fail cases: https://app.circleci.com/pipelines/github/algorand/go-algorand/2451/workflows/8807ced7-89ae-4b6b-96b0-1bc5bdf9d84c/jobs/27259/tests#failed-test-0

## Test Plan

Use existing unit testing. In particular TestCatchupOverGossip.
cce pushed a commit to cce/go-algorand that referenced this pull request Oct 28, 2021
This PR reorganize the files inside the ledger package by move the evaluator related files into its own `internal` package.
The files in the internal package cannot access the root ledger files, and therefore using the shared `ledgercore` as a place to share interfaces.

```
ledger/
├── apply/
├── internal/
├── ledgercore/
└── testing/
```

use existing test, and update existing tests.
cce pushed a commit to cce/go-algorand that referenced this pull request Oct 28, 2021
## Summary

This PR addresses a regression introduced in algorand#2983. 
The culprit is that an interface might contain a nil pointer, which makes it insufficient to test the interface pointer itself.

Fail cases: https://app.circleci.com/pipelines/github/algorand/go-algorand/2451/workflows/8807ced7-89ae-4b6b-96b0-1bc5bdf9d84c/jobs/27259/tests#failed-test-0

## Test Plan

Use existing unit testing. In particular TestCatchupOverGossip.
@egieseke egieseke mentioned this pull request Nov 23, 2021
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.

3 participants