Skip to content

Add NextReader to BlockReader #603

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add NextReader to BlockReader #603

wants to merge 2 commits into from

Conversation

Kubuxu
Copy link
Contributor

@Kubuxu Kubuxu commented Aug 20, 2025

BlockReader.NextReader facilities reading larger blocks from the CAR file.

This is necessary for the support of the Filecoin snapshot format extension (FRC-108, lotus issue), where a large block is used to transfer data about F3.

BlockReader.NextReader facilities reading larger blocks from the CAR
file.

Signed-off-by: Jakub Sztandera <[email protected]>
@BigLep BigLep moved this to 🔎 Awaiting Review in nv27 Track Board Aug 20, 2025
@BigLep BigLep moved this to Todo in F3 Aug 20, 2025
@BigLep BigLep added this to F3 Aug 20, 2025
@BigLep BigLep moved this from Todo to In review in F3 Aug 20, 2025
Comment on lines 52 to 54
if size > math.MaxInt64 {
return cid.Cid{}, 0, ErrHeaderTooLarge
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if size > math.MaxInt64 {
return cid.Cid{}, 0, ErrHeaderTooLarge
}

this is unnecessary, it's what LdReadSize does with its third arg for you to generate a uniform error pattern

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also if this really is necessary, ErrSectionTooLarge cause this isn't actually a header.

Copy link
Contributor Author

@Kubuxu Kubuxu Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this because the int64 cast for LimitReader (don't want to cast to negatives)

// on the BlockReader.
// The returned length might be larger than MaxAllowedSectionSize, it is up to the user to check before loading the data into memory.
func (br *BlockReader) NextReader() (cid.Cid, io.Reader, uint64, error) {
c, length, err := util.ReadNodeHeader(br.r, br.opts.ZeroLengthSectionAsEOF, math.MaxUint64)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
c, length, err := util.ReadNodeHeader(br.r, br.opts.ZeroLengthSectionAsEOF, math.MaxUint64)
c, length, err := util.ReadNodeHeader(br.r, br.opts.ZeroLengthSectionAsEOF, math.MaxInt64)

Or is there a reason you're using MaxUint64 but then capping it at MaxInt64 inside ReadNodeHeader? Why not just use MaxInt64 all the way through.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the maxsize param is uint64 everywhere, so from an external API viewpoint, I'm passing unlimited (maximum allowed value). Then the function internally caps to what it is able to handle.

Both perspectives make sense though

Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, except for the maxuint vs maxint question

This was referenced Aug 21, 2025
Signed-off-by: Jakub Sztandera <[email protected]>
@BigLep
Copy link
Contributor

BigLep commented Aug 21, 2025

@rvagg : will you be ok to merge and cut a release at your convenience as filecoin-project/lotus#13129 will be depending on it (being worked on next week).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants