From d91619aa914b66d5df88aa076573a3106b76d248 Mon Sep 17 00:00:00 2001 From: Ismail Khoffi Date: Mon, 29 Mar 2021 21:37:06 +0200 Subject: [PATCH] update to nmt v0.3.1 --- go.mod | 2 +- go.sum | 4 ++-- p2p/ipld/nmt_wrapper.go | 4 ++-- p2p/ipld/nmt_wrapper_test.go | 2 +- p2p/ipld/plugin/go.mod | 2 +- p2p/ipld/plugin/go.sum | 4 ++-- p2p/ipld/plugin/nodes/nodes.go | 2 +- p2p/ipld/plugin/nodes/nodes_test.go | 4 ++-- p2p/ipld/read_test.go | 2 +- types/block.go | 12 ++++++------ 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index 91f9b5308f..fbfc8bce0e 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 87576c448e..cf47a97370 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/p2p/ipld/nmt_wrapper.go b/p2p/ipld/nmt_wrapper.go index 62abbb5958..e772acd5fd 100644 --- a/p2p/ipld/nmt_wrapper.go +++ b/p2p/ipld/nmt_wrapper.go @@ -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) diff --git a/p2p/ipld/nmt_wrapper_test.go b/p2p/ipld/nmt_wrapper_test.go index 3b683163c3..975340ad36 100644 --- a/p2p/ipld/nmt_wrapper_test.go +++ b/p2p/ipld/nmt_wrapper_test.go @@ -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) } diff --git a/p2p/ipld/plugin/go.mod b/p2p/ipld/plugin/go.mod index 1ec95ccb1c..2afd16e4a9 100644 --- a/p2p/ipld/plugin/go.mod +++ b/p2p/ipld/plugin/go.mod @@ -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 diff --git a/p2p/ipld/plugin/go.sum b/p2p/ipld/plugin/go.sum index 44d150a949..ecd30d4fa4 100644 --- a/p2p/ipld/plugin/go.sum +++ b/p2p/ipld/plugin/go.sum @@ -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= diff --git a/p2p/ipld/plugin/nodes/nodes.go b/p2p/ipld/plugin/nodes/nodes.go index e465c2361b..a7493e6232 100644 --- a/p2p/ipld/plugin/nodes/nodes.go +++ b/p2p/ipld/plugin/nodes/nodes.go @@ -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 } } diff --git a/p2p/ipld/plugin/nodes/nodes_test.go b/p2p/ipld/plugin/nodes/nodes_test.go index a28a2a32a5..ea65182f0f 100644 --- a/p2p/ipld/plugin/nodes/nodes_test.go +++ b/p2p/ipld/plugin/nodes/nodes_test.go @@ -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 @@ -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 diff --git a/p2p/ipld/read_test.go b/p2p/ipld/read_test.go index 014642bfd8..827c2582f8 100644 --- a/p2p/ipld/read_test.go +++ b/p2p/ipld/read_test.go @@ -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 } diff --git a/types/block.go b/types/block.go index cce0828c31..69c7d20a58 100644 --- a/types/block.go +++ b/types/block.go @@ -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, ), ) @@ -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 }