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.

72 lines
2.3 KiB

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