-
Notifications
You must be signed in to change notification settings - Fork 595
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
[Runtime Epoch Split] (7/n) Split runtime everywhere else #8940
Conversation
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.
Overall the PR looks fine, since it's replacing runtime_adapter with epoch_manager and fixing tests. You don't need to split it more.
chain/chain/src/chain.rs
Outdated
pub runtime_adapter: Arc<dyn RuntimeWithEpochManagerAdapter>, | ||
pub epoch_manager: Arc<dyn EpochManagerAdapter>, | ||
pub shard_tracker: ShardTracker, | ||
pub runtime: Arc<dyn RuntimeAdapter>, |
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.
Could you rename this field back to runtime_adapter? I think that will decrease the number of changed lines in this PR and I don't see a concrete reason for the rename
chain/chain/src/test_utils.rs
Outdated
} | ||
|
||
pub fn setup_with_validators( | ||
vs: ValidatorSchedule, | ||
epoch_length: u64, | ||
tx_validity_period: NumBlocks, | ||
) -> (Chain, Arc<KeyValueRuntime>, Vec<Arc<InMemoryValidatorSigner>>) { | ||
) -> (Chain, Arc<KeyValueEpochManager>, Arc<KeyValueRuntime>, Vec<Arc<InMemoryValidatorSigner>>) { |
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.
Maybe MockEpochManager/SimpleEpochManager is a better name? It doesn't always need to be used together with KeyValueRuntime.
Some Nayduck tests are failing. I'll look into why. https://nayduck.near.org/#/test/455339 |
Latest run is Nayduck-neutral. |
I didn't look into code, but I have questions based on PR description:
Follow-up question: after this it should be easier to test protocol upgrades because we can use mock epoch managers, right? |
@Longarithm thanks for taking a look!
We should NOT use MockEpochManager. It's just soooo incorrect. Same with KeyValueRuntime. Please avoid them. The real EpochManager is actually pretty easy to use because it doesn't have many dependencies and only needs a few store columns, and we can still make it select a predictable set of block producers and chunk-only producers. Let me know if I can help there! |
Ow, it wasn't obvious from description. Thank you! |
I see, you can change the epoch height to be say 5, and then it shouldn't take very long. But in general forcing the protocol to do something that it isn't supposed to do will just break a hundred other things. |
This does the bulk of the remaining split, which is all a bit intertwined. Although there are a ton of changes, the transformations are simple for the most part.
RuntimeWithEpochManagerAdapter was the previous combined trait. There were two implementations of that trait: NightshadeRuntime and KeyValueRuntime.
Now, RuntimeWithEpochManagerAdapter is split into three: EpochManagerAdapter, ShardTracker, and RuntimeAdapter:
Mutex<EpochManager>
). The reason why we cannot use EpochManagerHandle directly instead of a trait is because KeyValueRuntime cannot provide a concrete EpochManager implementation. It has a completely custom validator schedule that is not compatible at all. NightshadeRuntime, on the other hand, contains an embedded EpochManagerHandle.Arc<dyn EpochManagerAdapter>
. It doesn't belong to EpochManagerAdapter because the TrackedConfig is not inherent to the protocol. ShardTracker is responsible for one thing: calculating whether this node itself cares or will care about a specific shard. For querying whether some other validator is supposed to track a shard, use the EpochManagerAdapter, not ShardTracker.get_trie_for_shard
. It does bleed a little bit into the EpochManagerAdapter responsibilities, more on that later.How does this split work for the two implementations: NightshadeRuntime and KeyValueRuntime?
Now, we talk about how users of this split are modified accordingly:
runtime_adapter: Arc<dyn RuntimeWithEpochManagerAdapter>
, it is now split into three fields,epoch_manager: Arc<dyn EpochManagerAdapter>
,shard_tracker: ShardTracker
, andruntime: Arc<dyn RuntimeAdapter>
, but we can omit some of them if they are not actually used. Usages of the old field are individually changed to use only one of the new fields.self.runtime_adapter.cares_about_shard(..., ..., ..., is_me: true)
is changed toself.shard_tracker.care_about_shard(..., ..., ..., true)
whereasself.runtime_adapter.cares_about_shard(..., ..., ..., is_me: false)
is changed toself.epoch_manager.cares_about_shard_from_prev_block
, because the latter does not actually need the ShardTracker.Arc<dyn RuntimeWithEpochManagerAdapter>
argument that was passed in is split into up to three arguments depending on which are actually used..runtime_adapters(Vec<Arc<dyn RuntimeWithEpochManagerAdapter>>)
, but now we don't have the RuntimeWithEpochManagerAdapters anymore. We could split this into three, of course, but this would present a pretty bad inconvenience to any tests that call helpers like create_nightshade_runtimes(...). So, the logic is now the following:create_test_store()
.KeyValueEpochManager
using the stores we have (this is why the stores must be finalized, either default-constructed or overridden, first, thus the partial order)ShardTracker
using the epoch_managers we have, with empty tracking config.KeyValueRuntime
using the stores and epoch_managers we have..track_all_shards()
: constructs shard_trackers that use the epoch_managers we have but with AllShards tracking.real_epoch_managers()
: constructs epoch_managers as NArc<EpochManagerHandle>
s instead of KeyValueEpochManager.nightshade_runtimes()
(this is an extension method that lives in integration-tests, to avoid a dependency cycle): constructs runtimes as NArc<NightshadeRuntime>
s using the stores and epoch_managers we have.