You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.4 KiB

6 years ago
6 years ago
6 years ago
  1. # ADR 020: Limiting txs size inside a block
  2. ## Changelog
  3. 13-08-2018: Initial Draft
  4. 15-08-2018: Second version after Dev's comments
  5. 28-08-2018: Third version after Ethan's comments
  6. 30-08-2018: AminoOverheadForBlock => MaxAminoOverheadForBlock
  7. 31-08-2018: Bounding evidence and chain ID
  8. ## Context
  9. We currently use MaxTxs to reap txs from the mempool when proposing a block,
  10. but enforce MaxBytes when unmarshalling a block, so we could easily propose a
  11. block thats too large to be valid.
  12. We should just remove MaxTxs all together and stick with MaxBytes, and have a
  13. `mempool.ReapMaxBytes`.
  14. But we can't just reap BlockSize.MaxBytes, since MaxBytes is for the entire block,
  15. not for the txs inside the block. There's extra amino overhead + the actual
  16. headers on top of the actual transactions + evidence + last commit.
  17. ## Proposed solution
  18. Therefore, we should
  19. 1) Get rid of MaxTxs.
  20. 2) Rename MaxTxsBytes to MaxBytes.
  21. When we need to ReapMaxBytes from the mempool, we calculate the upper bound as follows:
  22. ```
  23. ExactLastCommitBytes = {number of validators currently enabled} * {MaxVoteBytes}
  24. MaxEvidenceBytesPerBlock = MaxBytes / 10
  25. ExactEvidenceBytes = cs.evpool.PendingEvidence(MaxEvidenceBytesPerBlock) * MaxEvidenceBytes
  26. mempool.ReapMaxBytes(MaxBytes - MaxAminoOverheadForBlock - ExactLastCommitBytes - ExactEvidenceBytes - MaxHeaderBytes)
  27. ```
  28. where MaxVoteBytes, MaxEvidenceBytes, MaxHeaderBytes and MaxAminoOverheadForBlock
  29. are constants defined inside the `types` package:
  30. - MaxVoteBytes - 170 bytes
  31. - MaxEvidenceBytes - 364 bytes
  32. - MaxHeaderBytes - 476 bytes (~276 bytes hashes + 200 bytes - 50 UTF-8 encoded
  33. symbols of chain ID 4 bytes each in the worst case + amino overhead)
  34. - MaxAminoOverheadForBlock - 8 bytes (assuming MaxHeaderBytes includes amino
  35. overhead for encoding header, MaxVoteBytes - for encoding vote, etc.)
  36. ChainID needs to bound to 50 symbols max.
  37. When reaping evidence, we use MaxBytes to calculate the upper bound (e.g. 1/10)
  38. to save some space for transactions.
  39. NOTE while reaping the `max int` bytes in mempool, we should account that every
  40. transaction will take `len(tx)+aminoOverhead`, where aminoOverhead=1-4 bytes.
  41. We should write a test that fails if the underlying structs got changed, but
  42. MaxXXX stayed the same.
  43. ## Status
  44. Proposed.
  45. ## Consequences
  46. ### Positive
  47. * one way to limit the size of a block
  48. * less variables to configure
  49. ### Negative
  50. * constants that need to be adjusted if the underlying structs got changed
  51. ### Neutral