Skip to content

Commit

Permalink
update to nmt v0.3.1 (#258)
Browse files Browse the repository at this point in the history
Update nmt to latest release v0.3.1
  • Loading branch information
liamsi committed Mar 29, 2021
1 parent 97b7cab commit 1fb7d03
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 19 deletions.
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

0 comments on commit 1fb7d03

Please sign in to comment.