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

Add totalDifficulty field to JSON-RPC schema of Celo1 block #310

Open
wants to merge 3 commits into
base: celo11
Choose a base branch
from

Conversation

Kourin1996
Copy link

Closes https://github.com/celo-org/celo-blockchain-planning/issues/849

This PR adds the totalDifficulty field to the JSON-RPC response for Celo1 blocks.
The totalDifficulty is no longer present in geth and op-geth, as described in the following references:

However, Celo2 requires RPC compatibility support for Celo1 blocks. Therefore, this PR adds totalDifficulty field specifically for Celo1 blocks.

During my investigation, I discovered that snap sync does not store total difficulty into local database. As a result, the totalDifficulty value in the RPC response is derived from the block height

@Kourin1996 Kourin1996 self-assigned this Jan 16, 2025
@Kourin1996 Kourin1996 marked this pull request as ready for review January 16, 2025 11:28
Comment on lines 576 to 606
getExpectedJson := func(t *testing.T, expectedTd string) string {
data := map[string]interface{}{
"difficulty": "0x0",
"extraData": "0x",
"gasLimit": "0x0",
"gasUsed": "0x0",
"hash": "0xd8371db7c48c7538a9cdf3e9211510e423039c0af3e1aa61d0a40960214d2101",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"miner": "0x0000000000000000000000000000000000000000",
"mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"nonce": "0x0000000000000000",
"number": "0x64",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"receiptsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"size": "0x1f7",
"stateRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0x3e8",
"transactionsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"uncles": []interface{}{},
}

if expectedTd != "" {
data["totalDifficulty"] = expectedTd
}

marshaled, err := json.Marshal(&data)
require.NoError(t, err)

return string(marshaled)
}
Copy link

Choose a reason for hiding this comment

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

I don't think we need to be checking the whole marshalled json here. RPCMarshalBlock returns a map of string to interface which is encoded to json in a standard way by the go json package, so we don't need to re-test that. I think it is sufficient to call RPCMarshalBlock and simply check the value of the "totalDifficulty" key.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed 4502e6b

@Kourin1996 Kourin1996 requested a review from piersy January 17, 2025 02:02
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.

2 participants