Skip to content

Commit

Permalink
refactor(ipld): removing nmt hasher (celestiaorg#1651)
Browse files Browse the repository at this point in the history
  • Loading branch information
distractedm1nd authored and renaynay committed Feb 2, 2023
1 parent 64f83cc commit fa776f3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 187 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/alecthomas/jsonschema v0.0.0-20200530073317-71f438968921
github.com/celestiaorg/celestia-app v0.12.0-rc4
github.com/celestiaorg/go-libp2p-messenger v0.1.0
github.com/celestiaorg/nmt v0.12.0
github.com/celestiaorg/nmt v0.14.0
github.com/celestiaorg/rsmt2d v0.8.0
github.com/cosmos/cosmos-sdk v0.46.7
github.com/cosmos/cosmos-sdk/api v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ github.com/celestiaorg/go-verifcid v0.0.1-lazypatch h1:9TSe3w1cmJmbWlweCwCTIZkan
github.com/celestiaorg/go-verifcid v0.0.1-lazypatch/go.mod h1:kXPYu0XqTNUKWA1h3M95UHjUqBzDwXVVt/RXZDjKJmQ=
github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n5MFP2MwK0gSRcOVlDlFdQJO1p+FqdxYzmvc=
github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4/go.mod h1:fzuHnhzj1pUygGz+1ZkB3uQbEUL4htqCGJ4Qs2LwMZA=
github.com/celestiaorg/nmt v0.12.0 h1:6CmaMPri9FdSiytZP7yCrEq3ewebFiIEjlJhasrS6oQ=
github.com/celestiaorg/nmt v0.12.0/go.mod h1:NN3W8EEoospv8EHCw50DDNWwPLpJkFHoEFiqCEcNCH4=
github.com/celestiaorg/nmt v0.14.0 h1:ET1PXBm8f3KHCAB7+sRVMTmvejkpQp6HAQsGLjIRtcY=
github.com/celestiaorg/nmt v0.14.0/go.mod h1:b+pwd9cGTSSYLZnUIQSJl07pusJdFeEvCVsVfSRH9gA=
github.com/celestiaorg/quantum-gravity-bridge v1.3.0 h1:9zPIp7w1FWfkPnn16y3S4FpFLnQtS7rm81CUVcHEts0=
github.com/celestiaorg/quantum-gravity-bridge v1.3.0/go.mod h1:6WOajINTDEUXpSj5UZzod16UZ96ZVB/rFNKyM+Mt1gI=
github.com/celestiaorg/rsmt2d v0.8.0 h1:ZUxTCELZCM9zMGKNF3cT+rUqMddXMeiuyleSJPZ3Wn4=
Expand Down
95 changes: 0 additions & 95 deletions share/ipld/namespace_hasher.go

This file was deleted.

89 changes: 0 additions & 89 deletions share/ipld/namespace_hasher_test.go

This file was deleted.

12 changes: 12 additions & 0 deletions share/ipld/nmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/sha256"
"errors"
"fmt"
"hash"
"math/rand"

blocks "github.com/ipfs/go-block-format"
Expand All @@ -13,10 +14,12 @@ import (
ipld "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log/v2"
mh "github.com/multiformats/go-multihash"
mhcore "github.com/multiformats/go-multihash/core"
"go.opentelemetry.io/otel"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/pkg/da"
"github.com/celestiaorg/nmt"
)

var (
Expand Down Expand Up @@ -62,6 +65,15 @@ const (
NMTIgnoreMaxNamespace = true
)

func init() {
// required for Bitswap to hash and verify inbound data correctly
mhcore.Register(sha256Namespace8Flagged, func() hash.Hash {
nh := nmt.NewNmtHasher(sha256.New(), NamespaceSize, true)
nh.Reset()
return nh
})
}

func GetNode(ctx context.Context, bGetter blockservice.BlockGetter, root cid.Cid) (ipld.Node, error) {
block, err := bGetter.GetBlock(ctx, root)
if err != nil {
Expand Down

0 comments on commit fa776f3

Please sign in to comment.