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

feat: new ParseShare API #828

Merged
merged 4 commits into from
Oct 5, 2022
Merged

Conversation

rootulp
Copy link
Collaborator

@rootulp rootulp commented Oct 3, 2022

Closes #723
Opens #839

@codecov-commenter
Copy link

codecov-commenter commented Oct 3, 2022

Codecov Report

Merging #828 (c184932) into main (6b86e91) will increase coverage by 2.10%.
The diff coverage is 90.32%.

@@            Coverage Diff             @@
##             main     #828      +/-   ##
==========================================
+ Coverage   23.38%   25.49%   +2.10%     
==========================================
  Files          71       75       +4     
  Lines        8846     9261     +415     
==========================================
+ Hits         2069     2361     +292     
- Misses       6601     6679      +78     
- Partials      176      221      +45     
Impacted Files Coverage Δ
pkg/shares/share_merging.go 74.78% <88.46%> (+3.99%) ⬆️
pkg/shares/shares.go 40.00% <100.00%> (+17.14%) ⬆️
testutil/testnode/node_interaction_api.go 60.22% <0.00%> (ø)
testutil/testnode/rpc_client.go 81.81% <0.00%> (ø)
testutil/testnode/full_node.go 75.00% <0.00%> (ø)
testutil/testnode/node_init.go 65.92% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

[question]
should we also be checking that the length delimiter matches the sequence length?

Comment on lines 167 to 168
if !infoByte.IsMessageStart() {
if !bytes.Equal(currentSequence.NamespaceID, share.NamespaceID()) {
Copy link
Member

@evan-forbes evan-forbes Oct 3, 2022

Choose a reason for hiding this comment

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

[comment for other reviewers/posterity]
this isn't actually consensus breaking (see below comment) I don't think, even tho we weren't previously checking for this, because is order for this to be hit, the incorrect info byte has to be used which won't happen due to validators inserting it themselves and comparing the data root.

Copy link
Member

@evan-forbes evan-forbes Oct 3, 2022

Choose a reason for hiding this comment

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

on second thought, once we start using this, it could be consensus breaking with a dishonest majority. Honest full nodes will reject blocks that hit this error where we previously were not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

once we start using this

I thought ParseShares was for celestia-node consumption. Do we expect the state machine to invoke this API? I didn't expect this API to be consensus breaking because I assumed the state machine would not call it.

Copy link
Member

Choose a reason for hiding this comment

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

even if light clients are the only ones rejecting a block, then that is still consensus breaking (just like a change to fraud proofs)

Copy link
Member

Choose a reason for hiding this comment

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

at least, I think its consensus breaking... 😅

imo, it makes sense to eventually use this code when we merge shares. It keeps things consistent and can possibly even inform other implementations on how to use universal shares.

@rootulp
Copy link
Collaborator Author

rootulp commented Oct 3, 2022

should we also be checking that the length delimiter matches the sequence length?

It's possible to add this check to the contents of ParseShares(). In order to do so, it must trim padding from the last share of the sequence to calculate the true total length. If this approach is recommended:

  1. How do we differentiate padding bytes (0) from intentionally added zero bytes (i.e. a user included 3 trailing 0 bytes in their message)?
  2. Should this API return an error if the true total data length doesn't match the total data length varint?

@evan-forbes
Copy link
Member

evan-forbes commented Oct 3, 2022

In order to do so, it must trim padding from the last share of the sequence to calculate the true total length.

do we need to trim if we're only checking sequence length, not the exact length of bytes?

edit: like, we should use something similar to

// MsgSharesUsed calculates the minimum number of shares a message will take up.
// It accounts for the necessary delimiter and potential padding.
func MsgSharesUsed(msgSize int) int {
// add the delimiter to the message size
msgSize = DelimLen(uint64(msgSize)) + msgSize
shareCount := msgSize / appconsts.SparseShareContentSize
// increment the share count if the message overflows the last counted share
if msgSize%appconsts.SparseShareContentSize != 0 {
shareCount++
}
return shareCount
}

@rootulp
Copy link
Collaborator Author

rootulp commented Oct 3, 2022

do we need to trim if we're only checking sequence length, not the exact length of bytes?

We need to trim the last share of padding if we want to compare the total data length varint to the exact sequence length. We don't need to trim if we want this check to compare the total data length varint to an approximate sequence length (i.e. for message shares)

(len(shareSequence.Shares) - 1) * appconsts. SparseShareContentSize <= varint <= len(shareSequence.Shares) * appconsts. SparseShareContentSize

@rootulp rootulp marked this pull request as ready for review October 4, 2022 19:35
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

left one remaining change request for the testing we're using.

While I still think we should check for the length of the sequence (len(shareSequence.Shares)), that would require a large enough change to the existing code that doing this in a different PR makes sense

pkg/shares/share_merging_test.go Outdated Show resolved Hide resolved
pkg/shares/share_merging.go Outdated Show resolved Hide resolved
pkg/shares/share_merging_test.go Outdated Show resolved Hide resolved
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

dope! thanks! preapprooovvviinnngggggg

@rootulp rootulp merged commit 9d7e856 into celestiaorg:main Oct 5, 2022
@rootulp rootulp deleted the rp/parse-shares branch October 5, 2022 18:49
rach-id pushed a commit to rach-id/celestia-app that referenced this pull request Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Define a ParseShares API
3 participants