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: disable minimum balance check when not validating or generating #2149

Merged
merged 4 commits into from
May 18, 2021

Conversation

tolikzinovyev
Copy link
Contributor

Summary

This is needed for indexer that doesn't store AccountData.TotalSchema that allows computing account's minimum balance.

Test Plan

The change is trivial.

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.

Could you call applyTransaction directly instead of disabling the verification logic?

ledger/eval.go Outdated
// Only do those checks if needed. It is useful to skip them if the user cannot provide
// account data that contains enough information to compute the correct minimum balance
// (the case with indexer).
if eval.validate || eval.generate {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please avoid the indentation to match the rest of the code by changing this to

if !eval.validate && !eval.generate {
    continue
}

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 think it's common to have an if statement for eval.validate or eval.generate. I also oppose continue and break. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that we should take one step back here.

This entire for loop could be skipped in case !eval.validate && !eval.generate holds true.
Please take a close look, but if this true, I think that we could extract this for-loop into a separate method. That would address the indentation issue, provide faster code and work for the indexer - all at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, thanks!

@tolikzinovyev
Copy link
Contributor Author

Could you call applyTransaction directly instead of disabling the verification logic?

I think it's not so easy. There is logic outside of applyTransaction().

@tolikzinovyev tolikzinovyev marked this pull request as ready for review May 13, 2021 21:47
ledger/eval.go Outdated
if eval.validate || eval.generate {
err := eval.checkMinBalance(cow)
if err != nil {
return fmt.Errorf("transaction: %v err: %w", txid, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

"transaction: %v err: %w" -> "transaction %v: %w"

just to retain the previous error strings, which might be used elsewhere.

Copy link
Contributor

@tsachiherman tsachiherman left a comment

Choose a reason for hiding this comment

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

run make fmt to format your changes.

@tsachiherman tsachiherman dismissed their stale review May 17, 2021 19:44

requested changes applied.

@tsachiherman tsachiherman changed the title Disable minimum balance check when not validating or generating. ledger: disable minimum balance check when not validating or generating May 18, 2021
@tsachiherman tsachiherman merged commit 9f926d8 into algorand:master May 18, 2021
tsachiherman pushed a commit to tsachiherman/go-algorand that referenced this pull request Jul 7, 2021
…ng (algorand#2149)

ledger: disable minimum balance check when not validating or generating
@tolikzinovyev tolikzinovyev deleted the minimum-balance-check branch January 6, 2022 21:38
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