Skip to content

Commit

Permalink
Merge pull request #299 from lazyledger/hlib/empty-block-retrieve
Browse files Browse the repository at this point in the history
  • Loading branch information
Wondertan authored Apr 27, 2021
2 parents 47d6c96 + 354e9a4 commit 1a08b43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
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

0 comments on commit 1a08b43

Please sign in to comment.