Conversation
Currently, calling NewReadOnlyBlockView() incurs the overhead and computation cost of always reading a register from storage, and potentially also writing a register to the storage. Specifically, Emulator.NewReadOnlyBlockView() receives BlockContext param without actually using it. Creating BlockContext requires reading BlockProposal from storage, which incurs GetValue and potentially SetValue computation cost. This commit removes the unnecessary BlockContext param. This optimization reduces computation cost in these four EVM functions: - EVMAddress.balance() - EVMAddress.code() - EVMAddress.codeHash() - EVMAddress.nonce()
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
📝 WalkthroughWalkthroughThis PR removes the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
fvm/evm/emulator/emulator.go (1)
61-66: Optional: returnnilon error for consistency.
newProcedure()(line 332) correctly returnsnil, errwhenstate.NewStateDBfails.NewReadOnlyBlockViewreturns a non-nil*ReadOnlyBlockViewalongside the error — a pre-existing inconsistency that could silently bite callers who don't check the error.♻️ Suggested fix
func (em *Emulator) NewReadOnlyBlockView() (types.ReadOnlyBlockView, error) { execState, err := state.NewStateDB(em.ledger, em.rootAddr) + if err != nil { + return nil, err + } return &ReadOnlyBlockView{ state: execState, - }, err + }, nil }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@fvm/evm/emulator/emulator.go` around lines 61 - 66, Emulator.NewReadOnlyBlockView currently returns a non-nil *ReadOnlyBlockView even when state.NewStateDB fails; change it to mirror newProcedure() by checking err immediately after calling state.NewStateDB and returning nil, err if non-nil, otherwise construct and return &ReadOnlyBlockView{state: execState}, nil so callers never receive a non-nil view alongside an error.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@fvm/evm/emulator/emulator.go`:
- Around line 61-66: Emulator.NewReadOnlyBlockView currently returns a non-nil
*ReadOnlyBlockView even when state.NewStateDB fails; change it to mirror
newProcedure() by checking err immediately after calling state.NewStateDB and
returning nil, err if non-nil, otherwise construct and return
&ReadOnlyBlockView{state: execState}, nil so callers never receive a non-nil
view alongside an error.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Updates #8401
Currently, calling
NewReadOnlyBlockView()incurs the overhead and computation cost of always reading a register from storage, and potentially also writing a register to the storage.Specifically,
Emulator.NewReadOnlyBlockView()receivesBlockContextparam without actually using it. CreatingBlockContextrequires readingBlockProposalfrom storage, which incursGetValueand potentiallySetValuecomputation cost.This PR removes the unnecessary
BlockContextparam inEmulator.NewReadOnlyBlockView(). This optimization avoids reading a register and reduces computation cost in these EVM functions:EVMAddress.balance()EVMAddress.code()EVMAddress.codeHash()EVMAddress.nonce()Summary by CodeRabbit