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

Erasure namespaces #235

Merged
merged 32 commits into from
Mar 29, 2021
Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
51d310d
types: erasure namespaces
evan-forbes Mar 18, 2021
ddbaa9c
use methods instead of fields
evan-forbes Mar 18, 2021
ed06600
remove unnecessary compteShares call
evan-forbes Mar 18, 2021
1ff8b30
test block recovery
evan-forbes Mar 18, 2021
a4c6eaf
don't mess things up by using power of two
evan-forbes Mar 19, 2021
a2f2ba1
use better const names
evan-forbes Mar 19, 2021
dd6d65f
types: erasure namespaces
evan-forbes Mar 18, 2021
f390524
use methods instead of fields
evan-forbes Mar 18, 2021
43ad1fa
remove unnecessary compteShares call
evan-forbes Mar 18, 2021
9bec234
test block recovery
evan-forbes Mar 18, 2021
3d45d8a
don't mess things up by using power of two
evan-forbes Mar 19, 2021
964e8fc
use better const names
evan-forbes Mar 19, 2021
3482ebb
remove print statements
evan-forbes Mar 19, 2021
4de5bb6
add docs to AdjustedMessageSize
evan-forbes Mar 22, 2021
c8c4667
used the types.AdjustedMessageSize instead of the local
evan-forbes Mar 22, 2021
d9ce75b
Merge branch 'evan/erasure-namespaces' of github.com:lazyledger/lazyl…
evan-forbes Mar 27, 2021
772ae43
moving out consts to avoid import cycle
evan-forbes Mar 28, 2021
2724fe8
re applying stashed changes
evan-forbes Mar 28, 2021
3f63b02
return new instances of the wrapper per call of the constructor
evan-forbes Mar 29, 2021
173ddd7
implement tests for recovering data from a square using the new nmt w…
evan-forbes Mar 29, 2021
e4e0c74
fix sneaky append bug
evan-forbes Mar 29, 2021
001ada7
Merge branch 'evan/erasure-namespaces-II' into evan/erasure-namespaces
evan-forbes Mar 29, 2021
b1bc22d
remove moved test
evan-forbes Mar 29, 2021
d882848
remove uneeded function
evan-forbes Mar 29, 2021
b7bdfb7
remove comment
evan-forbes Mar 29, 2021
d84fc3d
clean up
evan-forbes Mar 29, 2021
f708503
fix imports
evan-forbes Mar 29, 2021
efdd4f0
linter gods
evan-forbes Mar 29, 2021
43a6bd7
more linter fixes
evan-forbes Mar 29, 2021
6baddea
use appendCopy instead of manually copying
evan-forbes Mar 29, 2021
64e5bfd
change name of generateRandomData to generateRandomMsgOnlyData
evan-forbes Mar 29, 2021
8bba9d9
use append instead of a utiltiy function
evan-forbes Mar 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions types/shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ func (m Message) MarshalDelimited() ([]byte, error) {

// appendToShares appends raw data as shares.
// Used for messages.
func appendToShares(shares []NamespacedShare, id namespace.ID, rawData []byte) []NamespacedShare {
nid := make([]byte, len(id))
copy(nid, id)
func appendToShares(shares []NamespacedShare, nid namespace.ID, rawData []byte) []NamespacedShare {
if len(rawData) <= MsgShareSize {
rawShare := append(nid, rawData...)
rawShare := appendCopy(nid, rawData)
liamsi marked this conversation as resolved.
Show resolved Hide resolved
paddedShare := zeroPadIfNecessary(rawShare, ShareSize)
share := NamespacedShare{paddedShare, nid}
shares = append(shares, share)
Expand All @@ -73,19 +71,17 @@ func appendToShares(shares []NamespacedShare, id namespace.ID, rawData []byte) [

// splitContiguous splits multiple raw data contiguously as shares.
// Used for transactions, intermediate state roots, and evidence.
func splitContiguous(id namespace.ID, rawDatas [][]byte) []NamespacedShare {
func splitContiguous(nid namespace.ID, rawDatas [][]byte) []NamespacedShare {
shares := make([]NamespacedShare, 0)
// Index into the outer slice of rawDatas
outerIndex := 0
// Index into the inner slice of rawDatas
innerIndex := 0
for outerIndex < len(rawDatas) {
var rawData []byte
nid := make([]byte, len(id))
copy(nid, id)
startIndex := 0
rawData, outerIndex, innerIndex, startIndex = getNextChunk(rawDatas, outerIndex, innerIndex, TxShareSize)
rawShare := append(append(nid, byte(startIndex)), rawData...)
rawShare := append(appendCopy(nid, []byte{byte(startIndex)}), rawData...)
paddedShare := zeroPadIfNecessary(rawShare, ShareSize)
share := NamespacedShare{paddedShare, nid}
shares = append(shares, share)
Expand All @@ -102,9 +98,7 @@ func split(rawData []byte, nid namespace.ID) []NamespacedShare {
rawData = rawData[MsgShareSize:]
for len(rawData) > 0 {
shareSizeOrLen := min(MsgShareSize, len(rawData))
rawShare := make([]byte, NamespaceSize)
copy(rawShare, nid)
rawShare = append(rawShare, rawData[:shareSizeOrLen]...)
rawShare := appendCopy(nid, rawData[:shareSizeOrLen])
paddedShare := zeroPadIfNecessary(rawShare, ShareSize)
share := NamespacedShare{paddedShare, nid}
shares = append(shares, share)
Expand Down Expand Up @@ -174,3 +168,15 @@ func zeroPadIfNecessary(share []byte, width int) []byte {
}
return share
}

// appendCopy makes a copy of slice a and appends slices b to that copy
func appendCopy(a []byte, b ...[]byte) []byte {
c := make([]byte, len(a))
copy(c, a)

for _, bi := range b {
c = append(c, bi...)
liamsi marked this conversation as resolved.
Show resolved Hide resolved
}

return c
}