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

chore: refactor share splitting and merging #637

Merged
merged 13 commits into from
Aug 29, 2022
Merged

Conversation

evan-forbes
Copy link
Member

@evan-forbes evan-forbes commented Aug 18, 2022

Description

This PR refactors splitting and merging. It incorporates the changes found in celestiaorg/celestia-core#820, please see the second commit that addresses the remaining feedback from that PR. The rest of the changes involves splitting up the existing code into different files and adding backwards compatibility with blocks that use and don't use wrapped txs for non-interactive defaults (pointed out below).

part of: #382
closes: #632

Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

[optional][proposal] with respect to naming consistency

Currently

  • parseMsgShares in merge_message_shares.go
  • processContiguousShares in merge_contiguous_shares.go

It may help if similar behavior was named consistently. I think parse may be a better fit so proposal

  • parseMsgShares in parse_message_shares.go
  • parseContiguousShares in parse_contiguous_shares.go

^ this doesn't necessarily need to be addressed in this PR

app/split_shares.go Show resolved Hide resolved
pkg/shares/merge_contiguous_shares.go Outdated Show resolved Hide resolved
pkg/shares/merge_contiguous_shares.go Outdated Show resolved Hide resolved
pkg/shares/merge_contiguous_shares.go Outdated Show resolved Hide resolved
type shareStack struct {
shares [][]byte
txLen uint64
txs [][]byte
Copy link
Collaborator

Choose a reason for hiding this comment

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

[optional][proposal] since this variable may also contain intermediate state roots or evidence

// shareStack hold variables for peel
type shareStack struct {
	shares [][]byte
	dataLen  uint64
	// data may be transactions, intermediate state roots, or evidence depending
	// on the namespace ID for this share
	data    [][]byte
	cursor int
}

a side benefit is that the comment below is now more precise

// intermediate state root, or evidence) and adds it to the underlying slice of data.

Copy link
Member Author

Choose a reason for hiding this comment

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

good idea, df122c8

pkg/shares/split_contiguous_shares.go Outdated Show resolved Hide resolved
pkg/shares/split_message_shares.go Outdated Show resolved Hide resolved
pkg/shares/split_message_shares.go Outdated Show resolved Hide resolved
pkg/shares/split_message_shares.go Outdated Show resolved Hide resolved
Comment on lines 37 to 42
func powerOf2(v uint64) bool {
if v&(v-1) == 0 && v != 0 {
return true
}
return false
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

[optional][proposal]

func isPowerOf2(v uint64) bool {
	return v&(v-1) == 0 && v != 0
}

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 721e31e

@rootulp
Copy link
Collaborator

rootulp commented Aug 19, 2022

this refactor is a herculean effort 💪 great work! @evan-forbes

Co-authored-by: Rootul Patel <rootulp@gmail.com>
@codecov-commenter
Copy link

codecov-commenter commented Aug 19, 2022

Codecov Report

Merging #637 (a22a810) into main (9e01bd3) will increase coverage by 5.98%.
The diff coverage is 58.46%.

@@            Coverage Diff             @@
##             main     #637      +/-   ##
==========================================
+ Coverage   29.89%   35.87%   +5.98%     
==========================================
  Files          16       24       +8     
  Lines        2054     2620     +566     
==========================================
+ Hits          614      940     +326     
- Misses       1380     1595     +215     
- Partials       60       85      +25     
Impacted Files Coverage Δ
pkg/shares/utils.go 0.00% <0.00%> (ø)
pkg/shares/share_splitting.go 13.25% <13.25%> (ø)
pkg/shares/shares.go 50.00% <50.00%> (ø)
pkg/shares/split_message_shares.go 69.51% <69.51%> (ø)
pkg/shares/split_contiguous_shares.go 70.40% <70.40%> (ø)
pkg/shares/share_merging.go 70.78% <70.78%> (ø)
pkg/shares/parse_contiguous_shares.go 77.77% <77.77%> (ø)
pkg/shares/parse_message_shares.go 88.60% <88.60%> (ø)
x/payment/types/payfordata.go 74.81% <100.00%> (-2.50%) ⬇️

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

rootulp
rootulp previously approved these changes Aug 25, 2022
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Great work! The typos are non-blocking but indicative that something is wrong with our misspell config, I'll investigate

UPDATE: it looks like misspell isn't as accurate as I would've hoped. It only flagged 3 issues on this branch and none are the ones I flagged so it wouldn't help reduce PR churn here.

$ gco evan/refactor-shares-pkg
$ misspell .
third_party/proto/tendermint/crypto/proof.proto:30:49: "nessecary" is a misspelling of "necessary"
third_party/proto/confio/proofs.proto:48:57: "collission" is a misspelling of "collisions"
x/payment/spec/docs.md:147:57: "contians" is a misspelling of "contains"

it's not clear to me why these 3 violations weren't flagged when misspell was run via golangci-lint run. It's possible the version of my misspell binary (latest) flags more issues than the version of misspell golangci-lint run uses

Comment on lines +14 to +17
// exactMsgShareSize is the length of message that will fit exactly into a single
// share, accounting for namespace id and the length delimiter prepended to
// each message
const exactMsgShareSize = consts.MsgShareSize - 2
Copy link
Collaborator

Choose a reason for hiding this comment

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

[no change needed] because this was present in the test prior to the refactor but since consts.MsgShareSize already accounts for the 8 byte namespace id, this assumes that the length delimiter is 2 bytes. Since length delimiter is a varint, isn't it possible that the delimiter is > 2 bytes?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah! it could be more, but not for this test? tbh I'd need to go check if there are large enough messages

pkg/shares/message_shares_test.go Outdated Show resolved Hide resolved
pkg/shares/message_shares_test.go Outdated Show resolved Hide resolved
pkg/shares/message_shares_test.go Outdated Show resolved Hide resolved
pkg/shares/split_contiguous_shares.go Outdated Show resolved Hide resolved
review feedback

Co-authored-by: Rootul Patel <rootulp@gmail.com>
@@ -275,227 +274,6 @@ func TestFuzz_Merge(t *testing.T) {
}
}

func Test_processContiguousShares(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

[for reviewers] this was moved to pkg/shares/contiguous_shares_test.go

@evan-forbes
Copy link
Member Author

merging now, even tho we're planning on moving this to its own repo as per this comment

@evan-forbes evan-forbes merged commit 13076a6 into main Aug 29, 2022
@evan-forbes evan-forbes deleted the evan/refactor-shares-pkg branch August 29, 2022 19:25
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.

Test compatibility of SplitMessages with/without share index
3 participants