-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Construct Collation and Merklize Chunks into chunkRoot #133
Construct Collation and Merklize Chunks into chunkRoot #133
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.
Couple fixes on the comments. Are we covering these changes in the tests?
sharding/collation.go
Outdated
|
||
|
||
// Chunks is a wrapper around a chunk array to implement DerivableList, | ||
// which allows us to Merklize the chunks into the chunkRoot |
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.
missing a period after chunkRoot
sharding/shard.go
Outdated
col := NewCollation(header, body, nil) | ||
txs, err := Deserialize(body) | ||
if err != nil { | ||
return nil, fmt.Errorf("cannot deserialize body", err) |
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.
"cannot deserialize body:"
sharding/shard.go
Outdated
@@ -78,7 +79,11 @@ func (s *Shard) CollationByHash(headerHash *common.Hash) (*Collation, error) { | |||
} | |||
// TODO: deserializes the body into a txs slice instead of using |
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.
Take off the todo
don't forget to add package name to the commit message |
lint and tests failed, we should look into that |
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.
Tests?
sharding/shard.go
Outdated
// right now we will just take the raw keccak256 of the body until #92 is merged. | ||
chunkRoot := common.BytesToHash(body) | ||
// check if body is empty and throw error. | ||
if body == nil { |
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.
This only checks if the body is nil, did you also want to check len(body) == 0? I think that is the true condition for an empty body.
Any update on this @elihanover? Do you have a timeframe for finishing the PR? |
Yes, focusing back on this tomorrow |
// CalculateChunkRoot updates the collation header's chunk root based on the body.
func (c *Collation) CalculateChunkRoot() {
// TODO: this needs to be based on blob serialization.
// For proof of custody we need to split chunks (body) into chunk + salt and
// take the merkle root of that.
chunkRoot := common.BytesToHash(c.body)
c.header.data.ChunkRoot = &chunkRoot
} Could someone point me to any resources on "salt"? Not sure how that fits in. |
I think salt is referring to Proof of Custody. You can take a look at #112 for context on it |
Here is another good thread on Proof of Custody: Utilize Proof of Custody and construct chunk root with salt may be out of the scope for this PR. You are more than welcome to skip that and open another PR down the line |
sharding/shard.go
Outdated
return fmt.Errorf("body is empty") | ||
} | ||
|
||
chunks := Chunks(body) // wrapper allowing us to merklizing the chunks |
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.
you forgot a period after the comment
sharding/shard.go
Outdated
// right now we will just take the raw keccak256 of the body until #92 is merged. | ||
chunkRoot := common.BytesToHash(body) | ||
// check if body is empty and throw error. | ||
if body == nil || len(body) == 0 { // is this check strict enough? |
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.
the check looks good to me
sharding/shard.go
Outdated
// nil as the third arg to MakeCollation. | ||
col := NewCollation(header, body, nil) | ||
txs, err := DeserializeBlobToTx(body) |
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.
Why does this have to do with construct collation and merklize chunks into chunk root?
@terenc3t just let me know. Either way, I'll work on that either today or this weekend. |
@rauljordan thanks for the feedback. I'll make changes today. |
sharding/collation_test.go
Outdated
|
||
c.CalculateChunkRoot() | ||
salt := []byte{1, 0x9f} | ||
fmt.Printf("%x\n", c.header.data.ChunkRoot) |
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.
Please remove all of these print statements from this test
…er/go-ethereum into construct-collation
…er/go-ethereum into construct-collation
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.
Very nice, thank you for doing this @elihanover!
LGTM. Thanks for the PR @elihanover! |
sharding/shard.go
Outdated
// right now we will just take the raw keccak256 of the body until #92 is merged. | ||
chunkRoot := common.BytesToHash(body) | ||
if len(body) == 0 { | ||
return fmt.Errorf("body is empty") |
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.
Please do not use fmt if not formatting. Use errors.New
Pulled the most recent code and ran the whisperv6 test. It worked for me, so not sure why it's failing with Travis.. |
Restarted Travis. It's flaky |
} | ||
|
||
// ConvertBackToTx converts raw blobs back to their original transactions. | ||
func ConvertBackToTx(rawBlobs []utils.RawBlob) ([]*types.Transaction, error) { |
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.
There's an identical function, convertRawBlobToTx
below
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.
Good catch. Let's delete one of them
Construct Collation and Merklize Chunks into chunkRoot
Construct Collation and Merklize Chunks into chunkRoot Former-commit-id: 1c70ba6
* Init Week0 * Added week 0 updates * republish hackmd public link * Week 1 and name updates * EPF Week 2 Updates --------- Co-authored-by: Mário Havel <61149543+taxmeifyoucan@users.noreply.github.com>
This is a PR referencing #125 to construct collation instances from serialized blobs as well as merklizing the blobs to get the chunkRoot.
Details
NewCollation
functionChunks
in order to usetypes.DeriveSha
functionSaveBody