Skip to content

Use incremental JSON parser and checksum hasher in genesis doc provider #1302

Open

Description

@mzabaluev

Rework the built-in GenesisDocProvider implementation for streamability: the provider should not need to store the whole file content in RAM to parse the JSON or calculate the checksum.

DoD: The implementation uses an incremental parser (e.g. json.Decoder from the standard library) and an incremental SHA-256 hasher, so that the entire file content is not read into memory at once.

Originally posted by @mzabaluev in #1293 (comment)

Activity

  1. added
    P:tech-debt
    on Sep 4, 2023
  2. odeke-em commented on Jan 2, 2024

    @odeke-em
    Contributor

    Thank you for this bug report @mzabaluev!
    So the fix for this can be performed elegantly only if libs/json had a JSON parser that took in an io.Reader (as requested in the issue) by using io.TeeReader hypothetically like this

    sha2 := sha256.New()
    tr := io.TeeReader(r, sha2)
    genDoc, err := cmtjson.FGenesisDoc(tr)
    if err != nil {
        return nil, fmt.Errorf("parsing genesisDoc: %w", err)
    }
    
    return ChecksummedGenesisDoc{GenesisDoc: genDoc, Sha256Checksum: sha2.Sum(nil)}, nil

    Demand

    The big question though is how much demand and interest is there for the incremental parser? I can help out if there is demand deemed for this issue and I actually built a large part of go-amino JSON parsing some almost 7 years ago https://github.com/tendermint/go-amino/commits?author=odeke-em so am quite familiar. I know for sure a buffered parser will reduce the amount of RAM consumed but if that cost is incurred only one time and if not many resources are dedicated towards this task it might be futile.

  3. sergio-mena commented on Jan 9, 2024

    @sergio-mena
    Collaborator

    @odeke-em The problem that motivated this issue in the first place is that some chains have a very big genesis file (mostly due to hard-forked chains), and that means the whole JSON needs to be held in memory at some point. This may enforce some stringent hardware requirements for nodes that want to sync from genesis (agreed it's not very common ATM, but that may change in the future when we tackle the "allow sync from Genesis" problem).

    Polygon folks (Polygon runs an SDK-based chain as part of its architecture) have recently been hitting OOM in their tests related to this.

  4. self-assigned this
    on Jul 12, 2024
  5. moved this from Todo to In Progress in CometBFTon Jul 12, 2024
  6. moved this from In Progress to Approved in CometBFTon Jul 15, 2024
  7. moved this from Approved to In Progress in CometBFTon Jul 15, 2024
  8. removed their assignment
    on Jul 15, 2024
  9. moved this from In Progress to Todo in CometBFTon Jul 15, 2024
  10. self-assigned this
    on Aug 19, 2024
  11. added this to the 2024-Q3 milestone on Aug 19, 2024
  12. andynog commented on Sep 23, 2024

    @andynog
    Contributor

    @alesforz can you please take this one over since yo are already working on related logic?

  13. modified the milestones: 2024-Q3, 2024-Q4 on Oct 28, 2024
  14. assigned and unassigned on Oct 28, 2024
  15. removed this from the 2024-Q4 milestone on Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P:tech-debt

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions