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

challenges_root #1957

Merged
merged 5 commits into from
Jan 15, 2020
Merged

challenges_root #1957

merged 5 commits into from
Jan 15, 2020

Conversation

Kouprin
Copy link
Member

@Kouprin Kouprin commented Jan 15, 2020

Fixes #1921

@@ -596,6 +607,11 @@ impl Block {
.0
}

pub fn compute_challenges_root(challenges: &Challenges) -> CryptoHash {
merklize(&challenges.iter().map(|challenges| challenges.hash).collect::<Vec<CryptoHash>>())
Copy link
Member Author

Choose a reason for hiding this comment

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

@bowenwang1996 can I rely that challenges are sorted?

Copy link
Member Author

Choose a reason for hiding this comment

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

no they don't

@codecov
Copy link

codecov bot commented Jan 15, 2020

Codecov Report

❗ No coverage uploaded for pull request base (staging@b07fbda). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             staging    #1957   +/-   ##
==========================================
  Coverage           ?   86.67%           
==========================================
  Files              ?      167           
  Lines              ?    31605           
  Branches           ?        0           
==========================================
  Hits               ?    27395           
  Misses             ?     4210           
  Partials           ?        0

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b07fbda...9254644. Read the comment docs.

@Kouprin Kouprin marked this pull request as ready for review January 15, 2020 02:26
pub fn compute_challenges_root(challenges: &Challenges) -> CryptoHash {
let mut arr =
challenges.iter().map(|challenges| challenges.hash).collect::<Vec<CryptoHash>>();
arr.sort();
Copy link
Collaborator

Choose a reason for hiding this comment

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

What does sort do here?

Copy link
Member Author

Choose a reason for hiding this comment

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

What does sort do here?

I've added test_elements_order to merkle to show you. Should block hash be depended on order of challenges?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it should because a block is produced by a given block producer and what we want to make sure is that other people cannot also produce blocks that have the same hash.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, we can leave them unsorted.
Is it okay that having Block header, chunks and challenges it may be impossible to get same block hash because of order of challenges?

@Kouprin Kouprin requested a review from bowenwang1996 January 15, 2020 16:51
core/primitives/src/block.rs Outdated Show resolved Hide resolved
@nearprotocol-bulldozer nearprotocol-bulldozer bot merged commit 16dc2d3 into staging Jan 15, 2020
@nearprotocol-bulldozer nearprotocol-bulldozer bot deleted the challenges_root branch January 15, 2020 18:12
SkidanovAlex pushed a commit that referenced this pull request Jan 29, 2020
* challenges_root
* test_elements_order
* don't sort challenges
* challenges -> challenge in closure
* Merge branch 'staging' into challenges_root
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.

3 participants