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

Fix empty block retrieval #299

Merged
merged 5 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions p2p/ipld/nmt_wrapper.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package ipld

import (
"bytes"
"crypto/sha256"

"github.com/lazyledger/lazyledger-core/types"
"github.com/lazyledger/nmt"
"github.com/lazyledger/nmt/namespace"
"github.com/lazyledger/rsmt2d"

"github.com/lazyledger/lazyledger-core/types"
)

// Fulfills the rsmt2d.Tree interface and rsmt2d.TreeConstructorFn function
Expand Down Expand Up @@ -50,12 +52,16 @@ func (w *ErasuredNamespacedMerkleTree) Push(data []byte, idx rsmt2d.SquareIndex)
panic("pushed past predetermined square size")
}

// use the parity namespace if the cell is not in Q0 of the extended
// datasquare
// use the parity namespace if the cell is not in Q0 of the extended datasquare
// if the cell is empty it means we got an empty block so we need to use TailPaddingNamespaceID
if idx.Axis+1 > uint(w.squareSize) || idx.Cell+1 > uint(w.squareSize) {
copy(nsID, types.ParitySharesNamespaceID)
} else {
copy(nsID, data[:types.NamespaceSize])
if bytes.Equal(data[:types.NamespaceSize], nsID) {
copy(nsID, types.TailPaddingNamespaceID)
} else {
copy(nsID, data[:types.NamespaceSize])
}
}
nidAndData := append(append(make([]byte, 0, types.NamespaceSize+len(data)), nsID...), data...)
// push to the underlying tree
Expand Down
4 changes: 4 additions & 0 deletions p2p/ipld/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func TestRetrieveBlockData(t *testing.T) {
adjustedMsgSize := types.MsgShareSize - 2

tests := []test{
{"Empty block", 1, false, ""},
{"4 KB block", 4, false, ""},
{"16 KB block", 8, false, ""},
{"16 KB block timeout expected", 8, true, "timeout"},
Expand Down Expand Up @@ -391,6 +392,9 @@ func rootsToDigests(roots [][]byte) []namespace.IntervalDigest {

func generateRandomBlockData(msgCount, msgSize int) types.Data {
var out types.Data
if msgCount == 1 {
return out
}
out.Messages = generateRandomMessages(msgCount-1, msgSize)
out.Txs = generateRandomContiguousShares(1)
return out
Expand Down