Skip to content
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

fix: simulator doesn't fail with long chains #385

Merged
merged 3 commits into from
Apr 29, 2021
Merged

Conversation

matklad
Copy link
Contributor

@matklad matklad commented Apr 28, 2021

The core issue is that Block is essentially a linked list, so:

  • dropping it may SO
  • cloning it is linear and may SO

Fix the drop manually and optimize the clone to be O(1)

closes #379

The core issue is that Block is essentially a linked list, so:

* dropping it may SO
* cloning it is linear and may SO

Fix the drop manually and optimize the clone to be O(1)

closes #379
Copy link
Contributor

@willemneal willemneal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@ailisp
Copy link
Member

ailisp commented Apr 28, 2021

Awesome+1!

@@ -87,7 +87,7 @@ impl GenesisConfig {

#[derive(Debug, Default, Clone)]
pub struct Block {
prev_block: Option<Box<Block>>,
prev_block: Option<Arc<Block>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need Arc here? Would Rc suffice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I haven't actually thought about this. I'd say that:

  • both would probably work
  • it doesn't really matter which one we pick here (like, this worked before by just copying the whole thing)
  • Arc seems to be a better default choice, as that preserves Sync-ness of the Block

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we use Box recursively somewhere in nearcore as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evgenykuzyakov nerdsniped! Here's the list of recursive types from nearcore:

rust-lang/rust-analyzer@ffd9283

Nothing there seems problematic.

Though, the tool is rather simplistic, it might've misssed some

@evgenykuzyakov evgenykuzyakov merged commit 1951284 into master Apr 29, 2021
@evgenykuzyakov evgenykuzyakov deleted the simblocks branch April 29, 2021 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

produce more than 5640 blocks in simulator cause SIGSEGV: invalid memory reference
6 participants