Skip to content

Block Header

Junha Yang(양준하) edited this page Jul 20, 2020 · 1 revision

Header of Block has very important data. Here's a guide to modify the header (add a field, remove a field, change the order, change the type, ...)

NOTE: Some of the content here will be obsolete after we introduce a new encoding scheme. (currently RLP)

https://github.com/CodeChain-io/foundry/pull/153

This PR has added a new field next_validator_set_hash in the header.

You must follow the same steps that presented in the PR, at least regarding the Foundry core. (Let's talk about the updates regarding SDK / test / RPC later)

Although the commit itself is compact, it contains some particular code to calculate/verify the new field. Here I point out only essential places to be updated, but please check the PR as well.

Foundry

Foundry tests

e2e.long is the place where block headers are used for tests and are also being tested. If you change block headers, you must apply your changes in foundry-rpc-js first, and then your changes should be either added or eliminated in these two tests: invalidBlockPropagation.help and onChainBlockValid.test. It is worth mentioning that you should consider the type of the new header. For example, if the type is H256, you better cast it to H256.

Foundry RPC

foundry-rpc-js is responsible to send RPC requests to a Foundry node. In the case of the header modification, the type Block in src/chain should be updated. The build directory should also be created upon new changes on the current used branch alpha-2.

SDK

If you modify Block header, you better pay close attention to the BlockData type and BlockJSON in src/core/Block and make the necessary corresponding changes in Block class.

Comment

To be honest, I still think that a programmatic way of enforcing updates will be much better.