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

Add consensus_decode_from_finite_reader optimization #1023

Merged
merged 1 commit into from Jun 1, 2022
Merged

Add consensus_decode_from_finite_reader optimization #1023

merged 1 commit into from Jun 1, 2022

Commits on May 31, 2022

  1. Add consensus_decode_from_finite_reader optimization

    As things are right now, memory exhaustion protection in `Decodable`
    is based on checking input-decoded lengths against arbitrary limits,
    and ad-hoc wrapping collection deserialization in `Take`.
    
    The problem with that are two-fold:
    
    * Potential consensus bugs due to incorrect limits.
    * Performance degradation when decoding nested structured,
      due to recursive `Take<Take<..>>` readers.
    
    This change introduces a systematic approach to the problem.
    
    A concept of a "size-limited-reader" is introduced to rely on
    the input data to finish at enforced limit and fail deserialization.
    
    Memory exhaustion protection is now achived by capping allocations
    to reasonable values, yet allowing the underlying collections
    to grow to accomodate rare yet legitmately oversized data (with tiny
    performance cost), and reliance on input data size limit.
    
    A set of simple rules allow avoiding recursive `Take` wrappers.
    
    Fix #997
    dpc committed May 31, 2022
    Copy the full SHA
    082e185 View commit details
    Browse the repository at this point in the history