near / nearcore

Reference client for NEAR Protocol
https://near.org
GNU General Public License v3.0
2.3k stars 597 forks source link

post-state-root: implement block production #9618

Closed pugachAG closed 7 months ago

pugachAG commented 9 months ago

Extend block production logic to support post-state-root version

Longarithm commented 9 months ago

My summary of necessary changes:

Not that necessary changes - we can remove challenges_root and challenges_result, as we don't plan to implement challenges anymore. We could consider the same about block_ordinal and epoch_sync_data_hash.

Full fields description:

BlockHeaderInnerLite

BlockHeaderInnerRestV5

Longarithm commented 9 months ago

After a bit of discussions, I think that there are no necessary fields to change.

Explanation

Validator proposals

Let's stop caring about what's the name of the field. Focus on invariant instead, which is:

Validator proposals must be applied at the same time to EpochManager (during add_validator_proposals) and State (during chunk processing) This is handled by 2-staged processing of proposals: 1) Stake Action is processed during applying chunk. Its result is saved as "validator proposal" and stored to ApplyChunkResult, which then goes to ChunkExtra. 2) On applying next block we take these previously saved proposals and: 2a) apply them to EpochManager 2b) apply them to State during processing of respective chunk

So nothing changes here. With post-state-root, we can just pass proposals using chunk header itself (new validator_proposals field), not chunk extra. Changing block header contents would be actually a mistake.

Gas price

I assumed that in pre-state-root, for applying chunk, gas price is taken from the block which contains this chunk, as we already know the block. But it’s not the case. We take gas price from previous block: https://github.com/near/nearcore/blob/9c8d0bbec6a71876bb3317db2ade425f0077a184/chain/chain/src/chain.rs#L4120 I don't know why. But in both pre and post state roots previous block exists anyway, so we can avoid any changes there. (@pugachAG: we can still just rename this field to next_gas_price to avoid further confusion)