-
Notifications
You must be signed in to change notification settings - Fork 12
Block Header
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.
- https://github.com/CodeChain-io/foundry/pull/153/files#diff-6d476d8f86559a92f71eac6a9482b1a0R236 - Set the new field(or delete existing code) here (or in some other function in the same file) to whatever you want.
-
core/src/encoded.rs
- obvious. -
core/src/error.rs
- obvious. -
core/src/scheme/genesis.rs
- obvious -
core/src/scheme/scheme.rs
- obvious - https://github.com/CodeChain-io/foundry/pull/153/files#diff-885b9dfa0bbcbd8c9177c31efae56073R268 - You can verify the new field(or delete existing code) here(or in some other function in the same file) with whatever you want.
-
core/src/views/header.rs
- Be careful of the RLP order. -
json/src/scheme/genesis.rs
- Set the genesis value. -
rpc/src/v1/types/block.rs
- Obvious -
types/src/header.rs
- This is the main definition.
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-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
.
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.
To be honest, I still think that a programmatic way of enforcing updates will be much better.