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

Implement debug_setHead #3811

Merged
merged 13 commits into from
Dec 16, 2024
Merged

Implement debug_setHead #3811

merged 13 commits into from
Dec 16, 2024

Conversation

scorbajio
Copy link
Contributor

This change provides an implementation for debug_setHead as a part of the work being done in #3781 in order to integrate, develop, and provide an ethereumjs repl console. This work also relates to #1114 and increasing JSON-RPC API coverage.

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

Attention: Patch coverage is 47.61905% with 11 lines in your changes missing coverage. Please review.

Project coverage is 75.65%. Comparing base (662af35) to head (bdd8edd).

Additional details and impacted files

Impacted file tree graph

Flag Coverage Δ
block 73.74% <ø> (ø)
blockchain 83.23% <ø> (ø)
client 73.66% <47.61%> (+0.02%) ⬆️
common 89.93% <ø> (ø)
devp2p 71.95% <ø> (ø)
evm 64.72% <ø> (ø)
genesis 100.00% <ø> (ø)
mpt 52.34% <ø> (+0.25%) ⬆️
rlp 95.11% <ø> (ø)
statemanager 67.81% <ø> (ø)
tx 76.56% <ø> (ø)
util 72.81% <ø> (ø)
vm 57.30% <ø> (ø)
wallet 79.67% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@@ -0,0 +1,96 @@
import { Block, createBlock, createBlockHeader } from '@ethereumjs/block'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied these helpers from the blockchain package test helpers in packages/blockchain/test/util.ts. Any thoughts on extracting these out to the util package so that they can be imported for testing and maybe production use cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While looking more into this, I realized this is not possible since it would introduce circular dependencies.

Copy link
Member

@jochem-brouwer jochem-brouwer left a comment

Choose a reason for hiding this comment

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

2 comments.

I would have assumed we have some blockchain generators for tests in the client, but it appears not? 🤔 I'm not sure if we want to export those from the blockchain package for production use-cases though (for testing - absolutely! 👍 )

const oldHead = headHash ? bytesToHex(headHash!) : undefined
const block = await getBlockByOption(blockOpt, this.chain)
try {
await this.service.skeleton?.setHead(block, true)
Copy link
Member

Choose a reason for hiding this comment

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

This sets the skeleton head. Should the vm execution part also not be updated? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated it to set the execution head as well. 🙂

Copy link
Member

Choose a reason for hiding this comment

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

Cool, can you also add this check in the tests? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the tests to include it.

/**
* Sets the current head of the local chain by block number. Note, this is a
* destructive action and may severely damage your chain. Use with extreme
* caution.
Copy link
Member

Choose a reason for hiding this comment

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

This looks like the docs from geth, are these also applicable here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it is implemented with force=true, I'd say it can be destructive, so it would be good to know in the docs.

headHash = await this.service.skeleton?.headHash()
const newHead = headHash ? bytesToHex(headHash!) : undefined

return `oldHead: ${oldHead} - newHead: ${newHead}`
Copy link
Contributor

Choose a reason for hiding this comment

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

One thought I had here is it would be worth making our response value match Geth's as well. Strings like above are pretty non-standard for RPC responses and you can't parse them programmatically without having to do fancy string parsing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yea, I think you're right will remove. It was a convenient way to develop, but will change it to match.

Copy link
Contributor

@acolytec3 acolytec3 left a comment

Choose a reason for hiding this comment

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

LGTM

@acolytec3 acolytec3 merged commit 4da1f03 into master Dec 16, 2024
40 of 41 checks passed
@acolytec3 acolytec3 deleted the debug-setHead-rpc-implementation branch December 16, 2024 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants