-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: celo11
Are you sure you want to change the base?
Add totalDifficulty field to JSON-RPC schema of Celo1 block #310
Conversation
internal/ethapi/celo_api_test.go
Outdated
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) | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed 4502e6b
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 ingeth
andop-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