feat(mirror): Pass epoch config overrides on forknet init #12421
+132
−10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context
Forknet is initialized by provisioning a host with a setup directory containing the source data folder. The following commands are executed to prepare the network:
neard init
– generates the configs and keys.neard fork-network set-validators
– amends the database, inserts the specified set of validators, and creates the genesis config for the new network.neard fork-network finalize
– completes the forking process.In this PR, we focus on the first two steps. If we need to override the epoch configs, they will be generated by neard init and then modified by the neard-runner process with the provided overrides. We first apply the general overrides under the "all" key, followed by protocol version-specific ones.
When overriding an epoch config that does not exist, the contents are copied from the previously available epoch config and then overwritten. i.e. let's assume that
mainnet
only has epoch configs for protocol 72 and 74. If you want to add overrides for p.v. 75, they will be applied on top of the original epoch config for p.v. 74.When creating the genesis in set-validators, we read the epoch config corresponding to the genesis protocol version.
How to use it
When calling
mirror new-test
add the--epoch-config-overrides
.This will accept a JSON formatted string that has the protocol version as keys and a list of
jq
styled overrides sepparated by|
.By protocol version
For example, if you need to update the
num_block_producer_seats
,num_chunk_validator_seats
andnum_chunk_producer_seats
for protocol version73
, you would use the following argument:{ "74": ".num_block_producer_seats = 3 | .validator_selection_config.num_chunk_validator_seats = 22 | .validator_selection_config.num_chunk_producer_seats = 3"}
With
all
keyA protocol version override only affects a specific epoch config. If you want to apply a change to all epoch configs, add that change under the
all
key instead.Priority
Use the
all
key to apply overrides across all configs simultaneously. Protocol version-specific overrides will then be applied afterward.Testing
For testing, I used a 6 node forknet with different scenarios:
For backwards compatibility: old binary(
2.3.0
), newneard-runner
Result: network progessed ok with all 6 ndoes as validators.
New binary, new
neard-runner
, with overridesmirror new-test --epoch-length 20 --genesis-protocol-version 73 --num-validators 6 --num-seats 6 --stateless-setup --new-chain-id modknet --epoch-config-overrides '{"all": ".validator_selection_config.num_chunk_validator_seats = 22 | .validator_selection_config.num_chunk_producer_seats = 3 | .num_block_producer_seats = 3 | .validator_selection_config.shuffle_shard_assignment_for_chunk_producers = true"}'
Result:
This was for testing purposes. The same result could have been achieved by using the
--num-seats 3
parameter and overriding only theshuffle_shard_assignment_for_chunk_producers parameter
.New binary, new
neard-runner
, with overrides onall
and on version73
mirror new-test --epoch-length 20 --genesis-protocol-version 71 --num-validators 6 --num-seats 6 --stateless-setup --new-chain-id modknet --epoch-config-overrides '{"all": ".validator_selection_config.num_chunk_validator_seats = 22 | .validator_selection_config.num_chunk_producer_seats = 3 | .num_block_producer_seats = 3", "73": ".validator_selection_config.num_chunk_producer_seats = 6"}'
Result:
The network starts at protocol version 71. In the image, it is in the first epoch after the genesis epoch. In the next epoch, protocol version 73 will take effect, along with the
num_chunk_producer_seats = 6
override.