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

[WIP] Merge interop spec #23607

Closed

Conversation

MariusVanDerWijden
Copy link
Member

@MariusVanDerWijden MariusVanDerWijden commented Sep 20, 2021

This PR contains a first implementation of the interop spec rebased on current master

to test:

./build/bin/geth --dev --catalyst --http --ws -http.api "engine" console
curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"engine_preparePayload","params":[{"parentHash":"0x582ea3ee1731029756c8bd211647e02fb68528a1d0a18a99a413d8b6afbe20b2", "timestamp":"0x1", "random":"0x0000000000000000000000000000000000000000000000000000000000000000", "feeRecipient":"0x0000000000000000000000000000000000000000"}],"id":67}' http://localhost:8545
{"jsonrpc":"2.0","id":67,"result":{"payloadId":"0x0"}}


curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"engine_getPayload","params":["0x0"],"id":67}' http://localhost:8545
{"jsonrpc":"2.0","id":67,"result":{"blockHash":"0xca6fc9b73939ad40c0ebfcab5b93ca81548f690b62d3c54b0fd0bdcbb2ce5872","parentHash":"0x582ea3ee1731029756c8bd211647e02fb68528a1d0a18a99a413d8b6afbe20b2","coinbase":"0xcd3f20468170e3094f09f16ae987e6325634ada1","stateRoot":"0x6cb6d72150ab4f942667c2f3426091b7de8095e08c5e8fc5c92edeb2d804729b","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","random":"0x0000000000000000000000000000000000000000000000000000000000000000","number":"0x1","gasLimit":"0xaf79e0","gasUsed":"0x0","timestamp":"0x1","extraData":null,"baseFeePerGas":"0x0","transactions":[]}}



 curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"engine_executePayload","params":[{"blockHash":"0xca6fc9b73939ad40c0ebfcab5b93ca81548f690b62d3c54b0fd0bdcbb2ce5872","parentHash":"0x582ea3ee1731029756c8bd211647e02fb68528a1d0a18a99a413d8b6afbe20b2","coinbase":"0xcd3f20468170e3094f09f16ae987e6325634ada1","stateRoot":"0x6cb6d72150ab4f942667c2f3426091b7de8095e08c5e8fc5c92edeb2d804729b","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","random":"0x0000000000000000000000000000000000000000000000000000000000000000","number":"0x1","gasLimit":"0xaf79e0","gasUsed":"0x0","timestamp":"0x1","extraData":"","baseFeePerGas":"0x0","transactions":[]}],"id":67}' http://localhost:8545
{"jsonrpc":"2.0","id":67,"result":{"status":"VALID"}}


 curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"engine_consensusValidated","params":[{"blockHash":"0xca6fc9b73939ad40c0ebfcab5b93ca81548f690b62d3c54b0fd0bdcbb2ce5872", "status":"VALID"}],"id":67}' http://localhost:8545
{"jsonrpc":"2.0","id":67,"result":null}


curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"engine_forkChoiceUpdated","params":[{"headBlockHash":"0xca6fc9b73939ad40c0ebfcab5b93ca81548f690b62d3c54b0fd0bdcbb2ce5872", "finalizedBlockHash":"0xca6fc9b73939ad40c0ebfcab5b93ca81548f690b62d3c54b0fd0bdcbb2ce5872"}],"id":67}' http://localhost:8545
{"jsonrpc":"2.0","id":67,"result":null}

eth/catalyst/api.go Outdated Show resolved Hide resolved
@paulhauner
Copy link

paulhauner commented Sep 30, 2021

Hi there, thanks for publishing the test vectors. It's much appreciated!

I have been working on these vectors and have found some discrepancies. I've raised them on TG/Discord, but I thought it might be helpful to have them collated on Github.

Here are the discrepancies:

  • For the ExecutionPayload object, the test vectors use receiptsRoot whilst the spec uses receiptRoot.
  • Also for ExecutionPayload, the test vectors use number whilst the spec uses blockNumber.
  • For engine_preparePayload, the test vectors state {"jsonrpc":"2.0","id":67,"result":{"payloadId":"0x0"} whist I understand that the spec declares {"jsonrpc":"2.0","id":67,"result":"0x0"} (return a QUANTITY not an Object).
    • Credit to @tersec for first raising this, who reports that Geth returns as per the spec, not as per the vectors.
    • As per the main branch of the specs, engine_preparePayload returns an Object with a payloadId field. This means the test vectors are indeed correct.
  • Test test vectors use engine_forkChoiceUpdated whilst the spec declares engine_forkchoiceUpdated (no capital C).

@MariusVanDerWijden
Copy link
Member Author

Thank you for looking into it! Most of the issues were already fixed in code.
I've now updated the test vectors to be in line with the implementation.
And I've updated engine_forkChoiceUpdated -> engine_forkchoiceUpdated

@paulhauner
Copy link

I just ran the Lighthouse tests against Geth and I can confirm all those previous issues have been fixed. Thank you 🎉

There are still two things remaining:

  • Geth doesn't return an Object for the engine_preparePayload as per the v1.0.0.alpha.2 changes. That's totally understandable, it was only released hours ago. I thought I'd just make a note of it.
  • Geth doesn't accept "finalizedBlockHash":"0x0000000000000000000000000000000000000000000000000000000000000000" on engine_forkchoiceUpdated. (More below)

According to EIP-3675:

A POS_FORKCHOICE_UPDATED event contains references to the head of the canonical chain and to the most recent finalized block. Before the first finalized block occurs in the system the finalized block hash provided by this event is stubbed with 0x0000000000000000000000000000000000000000000000000000000000000000.

This issue can be recreated with a modified version of the test vectors:

Request:

curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"engine_forkchoiceUpdated","params":[{"headBlockHash":"0xb084c10440f05f5a23a55d1d7ebcb1b3892935fb56f23cdc9a7f42c348eed174", "finalizedBlockHash":"0x0000000000000000000000000000000000000000000000000000000000000000"}],"id":67}' 

Response:

http://localhost:8545 {"jsonrpc":"2.0","id":67,"error":{"code":4,"message":"unknown header"}}

}
parent := api.eth.BlockChain().GetBlockByHash(params.ParentHash)
if parent == nil {
return INVALID, fmt.Errorf("could not find parent %x", params.ParentHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this will work. Our RPC server implementation, AFAIK, when dealing with a non-nil return and a non-nil error, will discard the return vaue and return only the error. This might even be a 'feature' of json rpc: either you return a response XOR an error. Our server chooses the error.

vmConfig vm.Config

shouldPreserve func(*types.Block) bool // Function used to determine whether should preserve the given block.
shouldPreserve func(*types.Block) bool // Function used to determine whether should preserve the given block.
terminateInsert func(common.Hash, uint64) bool // Testing hook used to terminate ancient receipt chain insertion.
Copy link
Contributor

Choose a reason for hiding this comment

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

stale code? I don't see any references to this elsewhere.

// (b) the timestamp is not verified anymore
func (beacon *Beacon) verifyHeader(chain consensus.ChainHeaderReader, header, parent *types.Header) error {
// Ensure that the header's extra-data section is of a reasonable size
if len(header.Extra) > 32 {

Choose a reason for hiding this comment

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

32 should go to enum or const

return fmt.Errorf("invalid difficulty: have %v, want %v", header.Difficulty, beaconDifficulty)
}
// Verify that the gas limit is <= 2^63-1
cap := uint64(0x7fffffffffffffff)

Choose a reason for hiding this comment

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

same here, it could be extracted outside the function

// to a chain, so the difficulty will be left unset (nil). Set it here to the
// correct value.
if b.header.Difficulty == nil {
b.header.Difficulty = big.NewInt(2)

Choose a reason for hiding this comment

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

2 could be extracted to enum/const with proper name

@MariusVanDerWijden MariusVanDerWijden deleted the merge-interop-spec branch November 30, 2021 15:28
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.

10 participants