Skip to content

rlp: add back Iterator.Count, with fixes#33841

Merged
fjl merged 1 commit into
ethereum:masterfrom
fjl:rlp-countvalues-fix
Feb 13, 2026
Merged

rlp: add back Iterator.Count, with fixes#33841
fjl merged 1 commit into
ethereum:masterfrom
fjl:rlp-countvalues-fix

Conversation

@fjl
Copy link
Copy Markdown
Contributor

@fjl fjl commented Feb 13, 2026

I removed Iterator.Count in #33840, because it appeared to be unused and did not provide the documented invariant: the returned count should always be an upper bound on the number of iterations allowed by Next.

In order to make Count work, the semantics of CountValues has to change to return the number of items up and including the invalid one. I have reviewed all callsites of CountValues to assess if changing this is safe. There aren't that many, and the only call that doesn't check the error and return is in the trie node parser, trie.decodeNodeUnsafe. There, we distinguish the node type based on the number of items, and it previously returned an error for item count zero. In order to avoid any potential issue that could result from this change, I'm adding an error check in that function, though it isn't necessary.

I removed Iterator.Count in ethereum#33840, because it appeared to be unused
and did not provide the documented invariant: the returned Count should
always be an upper bound on the number of iterations allowed by Next().

In order to make Count work, the semantics of CountValues has to change to return the
number of items up and including the invalid one. I have reviewed all callsites of
CountValues to assess if changing this is safe. There aren't that many, and the only call
that doesn't check the error and return is in the trie node parser, trie.decodeNodeUnsafe.
There, we distinguish the node type based on the number of items, and it previously
returned an error for item count zero. In order to avoid any potential issue that could
result from this change, I'm adding an error check in that function.
Copy link
Copy Markdown
Contributor

@jrhea jrhea left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Copy Markdown
Member

@lightclient lightclient left a comment

Choose a reason for hiding this comment

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

SGTM

@fjl fjl merged commit ac85a6f into ethereum:master Feb 13, 2026
9 of 10 checks passed
@fjl fjl added this to the 1.17.0 milestone Feb 13, 2026
sduchesneau pushed a commit to streamingfast/go-ethereum that referenced this pull request Apr 7, 2026
I removed `Iterator.Count` in ethereum#33840, because it appeared to be unused
and did not provide the documented invariant: the returned count should
always be an upper bound on the number of iterations allowed by `Next`.

In order to make `Count` work, the semantics of `CountValues` has to
change to return the number of items up and including the invalid one. I
have reviewed all callsites of `CountValues` to assess if changing this
is safe. There aren't that many, and the only call that doesn't check
the error and return is in the trie node parser,
`trie.decodeNodeUnsafe`. There, we distinguish the node type based on
the number of items, and it previously returned an error for item count
zero. In order to avoid any potential issue that could result from this
change, I'm adding an error check in that function, though it isn't
necessary.
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