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

ADR 004 Implementation #5519

Closed
4 tasks done
alexanderbez opened this issue Jan 14, 2020 · 11 comments · Fixed by #5572
Closed
4 tasks done

ADR 004 Implementation #5519

alexanderbez opened this issue Jan 14, 2020 · 11 comments · Fixed by #5572
Assignees
Labels
C:x/auth C:x/bank T: API Breaking Breaking changes that impact APIs and the SDK only (not state machine). T: State Machine Breaking State machine breaking changes (impacts consensus).

Comments

@alexanderbez
Copy link
Contributor

alexanderbez commented Jan 14, 2020

Summary

Implement ADR 004.

Please cross-reference to any other issues/milestones as necessary.

/cc @cwgoes @fedekunze @jackzampolin


For Admin Use

  • Not duplicate issue
  • Appropriate labels applied
  • Appropriate contributors tagged
  • Contributor assigned/self-assigned
@alexanderbez alexanderbez added T: API Breaking Breaking changes that impact APIs and the SDK only (not state machine). T: State Machine Breaking State machine breaking changes (impacts consensus). C:x/bank C:x/auth labels Jan 14, 2020
@alexanderbez alexanderbez self-assigned this Jan 14, 2020
@cwgoes
Copy link
Contributor

cwgoes commented Jan 15, 2020

Thanks @alexanderbez - glad to review and/or update the ADR if anything needs to be revised.

@dshulyak
Copy link
Contributor

dshulyak commented Jan 16, 2020

quoting from ADR

enabling O(1) read & write access to the balance of a particular account in a particular denomination.

this is not really a O(1). The amount of leaves in the tree increases iavl height and the complexity of the query. i was doing some profiling while working on this issue #5461, and the difference can be significant. note that inserting multiple values also degrades iavl write performance.

so the described griefing vector is still there, it is not straightforward to say what would be worth, storing a single object with all denominations or allow the creation of unlimited separate objects. it definitely makes sense to benchmark proposed change.

@cwgoes
Copy link
Contributor

cwgoes commented Jan 16, 2020

#5494 (comment)

Agreed on benchmarking. This is a DoS vector we don't consider in general, I suspect it might also appear in other places.

@ValarDragon
Copy link
Contributor

#2860

@dshulyak
Copy link
Contributor

Hmm, yeah. I was thinking primarily w.r.t. gas costs, which don't incorporate this difference (but perhaps they should, though it seems like it would be complex). At least the complexity is logarithmic, not linear. Regardless, we should clarify this in the ADR.

i was looking at different merkle trees wrt write perf, and iavl doesn't seem to scale well when when tree grows in size, e.g if one can find a cheap way to insert multiple unique keys into the same tree - blockchain performance will decrease significantly. Below is a plot for the time it takes to commit 10,000 entries with a key of size 30 bytes, value 100 bytes. Only at 2 mil unique keys it takes 12s to commit 10,000 keys. And beyond that it even worse. Reads degrade as well, i don't have plots for them though.

it is a bit speculative, and i don't know how practical such DoS scenario is but maybe you can find it interesting.

iavl

more at https://github.com/dshulyak/merklecmp, but you can also get similar results by tweaking benchmark in iavl repo.

@alexanderbez
Copy link
Contributor Author

Nice stats @dshulyak! It is well known that amino and IAVL are the two biggest culprits by far in terms of performance and IO bottlenecks, with us already starting to address the former. I would love to see more discussion around IAVL alternatives.

@sunnya97
Copy link
Member

2 Points that I should have made at ADR stage, but:

  1. SpendableCoinsVestingAccount() and TrackDelegation() shouldn't take in a bank Keeper, as bank types shouldn't be stateful. Instead, they should be passed in the currentBalance as a paramater when called from the bank module.

  2. This will also require a refactor of the supply module because its total supply balance is also vulnerable to the same DoS as account balances.

@cwgoes
Copy link
Contributor

cwgoes commented Jan 20, 2020

This will also require a refactor of the supply module because its total supply balance is also vulnerable to the same DoS as account balances.

This is just an invariant check, right? Or does the state machine use the total balance (as calculated by iteration) in a transaction directly? If the former, it doesn't seem substantially different to me than the existent DoS vector of just making many accounts (though the gas costs likely differ somewhat).

@fedekunze
Copy link
Collaborator

This is just an invariant check, right?

Correct, these are just the invariants for the total balance and per-coin balances

@cwgoes
Copy link
Contributor

cwgoes commented Jan 20, 2020

This is just an invariant check, right?

Correct, these are just the invariants for the total balance and per-coin balances

Do full nodes / validators run the invariants by default?

I'm trying to understand the precise DoS concern and/or change from the current state of affairs.

@fedekunze
Copy link
Collaborator

Do full nodes / validators run the invariants by default?

No, there is an invariant mode for nodes. The default is to not run the invariants.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/auth C:x/bank T: API Breaking Breaking changes that impact APIs and the SDK only (not state machine). T: State Machine Breaking State machine breaking changes (impacts consensus).
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants