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

update to nmt v0.3.1 #258

Merged
merged 1 commit into from
Mar 29, 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/ipfs/go-path v0.0.9 // indirect
github.com/ipfs/interface-go-ipfs-core v0.4.0
github.com/lazyledger/lazyledger-core/p2p/ipld/plugin v0.0.0-20210219190522-0eccfb24e2aa
github.com/lazyledger/nmt v0.2.1
github.com/lazyledger/nmt v0.3.1
github.com/lazyledger/rsmt2d v0.1.1-0.20210327010029-ef1d6c54461e
github.com/libp2p/go-buffer-pool v0.0.2
github.com/minio/highwayhash v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ github.com/lazyledger/go-verifcid v0.0.1-lazypatch h1:jAVwUw+DhuCzx5IcYpFh6d6HWx
github.com/lazyledger/go-verifcid v0.0.1-lazypatch/go.mod h1:kXPYu0XqTNUKWA1h3M95UHjUqBzDwXVVt/RXZDjKJmQ=
github.com/lazyledger/merkletree v0.0.0-20201214195110-6901c4c3c75f h1:jbyPAH6o6hGte4RtZBaqWs2n4Fl6hS7qJGXX3qnjiy4=
github.com/lazyledger/merkletree v0.0.0-20201214195110-6901c4c3c75f/go.mod h1:10PA0NlnYtB8HrtwIDQAyTKWp8TEZ0zBZCGlYC/7+QE=
github.com/lazyledger/nmt v0.2.1 h1:/gSzFilF/fzykHiDDkwvnoyRdtntosgXP5feJbcTs1o=
github.com/lazyledger/nmt v0.2.1/go.mod h1:tY7ypPX26Sbkt6F8EbPl3AT33B5N0BJe4OVPbq849YI=
github.com/lazyledger/nmt v0.3.1 h1:zP172RR33Es4dhb88GmUr9kBpAkH6Wcl7nQGJ3HQzu4=
github.com/lazyledger/nmt v0.3.1/go.mod h1:tY7ypPX26Sbkt6F8EbPl3AT33B5N0BJe4OVPbq849YI=
github.com/lazyledger/rsmt2d v0.1.1-0.20210327010029-ef1d6c54461e h1:3mwa4b4v9puYIFsfRN6TsXMbUagvhLtIzXWHN2GFHB4=
github.com/lazyledger/rsmt2d v0.1.1-0.20210327010029-ef1d6c54461e/go.mod h1:ORR2U7THCNr1fpUhwYqZN7QCFJ20iR2uiIWfXKz3KJ4=
github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ=
Expand Down
4 changes: 2 additions & 2 deletions p2p/ipld/nmt_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func (w *ErasuredNamespacedMerkleTree) Push(data []byte, idx rsmt2d.SquareIndex)
} else {
copy(nsID, data[:types.NamespaceSize])
}

nidAndData := append(append(make([]byte, 0, types.NamespaceSize+len(data)), nsID...), data...)
// push to the underlying tree
err := w.tree.Push(nsID, data)
err := w.tree.Push(nidAndData)
// panic on error
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion p2p/ipld/nmt_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestRootErasuredNamespacedMerkleTree(t *testing.T) {

for i, d := range data {
tree.Push(d, rsmt2d.SquareIndex{Axis: uint(0), Cell: uint(i)})
err := nmtTree.Push(d[:types.NamespaceSize], d[types.NamespaceSize:])
err := nmtTree.Push(d)
if err != nil {
t.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/ipld/plugin/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/ipfs/go-ipfs-api v0.2.0
github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-verifcid v0.0.1
github.com/lazyledger/nmt v0.2.1
github.com/lazyledger/nmt v0.3.1
// rsmt2d is only used in tests:
github.com/lazyledger/rsmt2d v0.1.1-0.20210327010029-ef1d6c54461e
github.com/multiformats/go-multihash v0.0.14
Expand Down
4 changes: 2 additions & 2 deletions p2p/ipld/plugin/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ github.com/lazyledger/go-verifcid v0.0.1-lazypatch h1:jAVwUw+DhuCzx5IcYpFh6d6HWx
github.com/lazyledger/go-verifcid v0.0.1-lazypatch/go.mod h1:kXPYu0XqTNUKWA1h3M95UHjUqBzDwXVVt/RXZDjKJmQ=
github.com/lazyledger/merkletree v0.0.0-20201214195110-6901c4c3c75f h1:jbyPAH6o6hGte4RtZBaqWs2n4Fl6hS7qJGXX3qnjiy4=
github.com/lazyledger/merkletree v0.0.0-20201214195110-6901c4c3c75f/go.mod h1:10PA0NlnYtB8HrtwIDQAyTKWp8TEZ0zBZCGlYC/7+QE=
github.com/lazyledger/nmt v0.2.1 h1:/gSzFilF/fzykHiDDkwvnoyRdtntosgXP5feJbcTs1o=
github.com/lazyledger/nmt v0.2.1/go.mod h1:tY7ypPX26Sbkt6F8EbPl3AT33B5N0BJe4OVPbq849YI=
github.com/lazyledger/nmt v0.3.1 h1:zP172RR33Es4dhb88GmUr9kBpAkH6Wcl7nQGJ3HQzu4=
github.com/lazyledger/nmt v0.3.1/go.mod h1:tY7ypPX26Sbkt6F8EbPl3AT33B5N0BJe4OVPbq849YI=
github.com/lazyledger/rsmt2d v0.1.1-0.20210327010029-ef1d6c54461e h1:3mwa4b4v9puYIFsfRN6TsXMbUagvhLtIzXWHN2GFHB4=
github.com/lazyledger/rsmt2d v0.1.1-0.20210327010029-ef1d6c54461e/go.mod h1:ORR2U7THCNr1fpUhwYqZN7QCFJ20iR2uiIWfXKz3KJ4=
github.com/libp2p/go-addr-util v0.0.1/go.mod h1:4ac6O7n9rIAKB1dnd+s8IbbMXkt+oBpzX4/+RACcnlQ=
Expand Down
2 changes: 1 addition & 1 deletion p2p/ipld/plugin/nodes/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func DataSquareRowOrColumnRawInputParser(r io.Reader, _mhType uint64, _mhLen int
}
return nil, err
}
if err := n.Push(namespacedLeaf[:namespaceSize], namespacedLeaf[namespaceSize:]); err != nil {
if err := n.Push(namespacedLeaf); err != nil {
return nil, err
}
}
Expand Down
4 changes: 2 additions & 2 deletions p2p/ipld/plugin/nodes/nodes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestNodeCollector(t *testing.T) {
n := nmt.New(sha256.New(), nmt.NamespaceIDSize(namespaceSize), nmt.NodeVisitor(collector.visit))

for _, share := range tt.leafData {
err := n.Push(share[:namespaceSize], share[namespaceSize:])
err := n.Push(share)
if err != nil {
t.Errorf("nmt.Push() unexpected error = %v", err)
return
Expand Down Expand Up @@ -138,7 +138,7 @@ func TestDagPutWithPlugin(t *testing.T) {
t.Logf("first leaf, nid: %x, data: %x...", data[0][:namespaceSize], data[0][namespaceSize:namespaceSize+printFirst])
n := nmt.New(sha256.New())
for _, share := range data {
err := n.Push(share[:namespaceSize], share[namespaceSize:])
err := n.Push(share)
if err != nil {
t.Errorf("nmt.Push() unexpected error = %v", err)
return
Expand Down
2 changes: 1 addition & 1 deletion p2p/ipld/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func createNmtTree(
na := nodes.NewNmtNodeAdder(ctx, batch)
tree := nmt.New(sha256.New(), nmt.NamespaceIDSize(types.NamespaceSize), nmt.NodeVisitor(na.Visit))
for _, leaf := range namespacedData {
err := tree.Push(leaf[:types.NamespaceSize], leaf[types.NamespaceSize:])
err := tree.Push(leaf)
if err != nil {
return tree, err
}
Expand Down
12 changes: 6 additions & 6 deletions types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,18 +274,18 @@ func (b *Block) fillDataAvailabilityHeader() {
func nmtCommitment(namespacedData [][]byte) namespace.IntervalDigest {
tree := nmt.New(newBaseHashFunc(), nmt.NamespaceIDSize(NamespaceSize))
for _, leaf := range namespacedData {
mustPush(tree, leaf[:NamespaceSize], leaf[NamespaceSize:])
mustPush(tree, leaf)
}
return tree.Root()
}

func mustPush(rowTree *nmt.NamespacedMerkleTree, id namespace.ID, data []byte) {
if err := rowTree.Push(id, data); err != nil {
func mustPush(rowTree *nmt.NamespacedMerkleTree, nidAndData []byte) {
if err := rowTree.Push(nidAndData); err != nil {
panic(
fmt.Sprintf(
"invalid data; could not push share to tree, id: %v, data: %v, err: %v",
id,
data,
nidAndData[:NamespaceSize],
nidAndData[NamespaceSize:],
err,
),
)
Expand Down Expand Up @@ -323,7 +323,7 @@ func (b *Block) PutBlock(ctx context.Context, nodeAdder format.NodeAdder) error
batchAdder := nodes.NewNmtNodeAdder(ctx, format.NewBatch(ctx, nodeAdder))
tree := nmt.New(sha256.New(), nmt.NodeVisitor(batchAdder.Visit))
for _, share := range leafSet {
err = tree.Push(share[:NamespaceSize], share[NamespaceSize:])
err = tree.Push(share)
if err != nil {
return err
}
Expand Down