Skip to content

Commit

Permalink
adding ipld stuff from hlibs block-propagation branch on core
Browse files Browse the repository at this point in the history
  • Loading branch information
renaynay committed Oct 5, 2021
1 parent d490144 commit 5d9c2be
Show file tree
Hide file tree
Showing 9 changed files with 1,223 additions and 87 deletions.
50 changes: 43 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,66 @@ module github.com/celestiaorg/celestia-node

go 1.16

replace github.com/ipfs/go-verifcid => github.com/lazyledger/go-verifcid v0.0.1-lazypatch

require (
github.com/BurntSushi/toml v0.4.1
github.com/celestiaorg/celestia-core v0.0.2-0.20210924001615-488ac31b4b3c
github.com/celestiaorg/nmt v0.7.0
github.com/celestiaorg/rsmt2d v0.3.0
github.com/ipfs/go-bitswap v0.4.0
github.com/ipfs/go-blockservice v0.1.7
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/huin/goupnp v1.0.2 // indirect
github.com/ipfs/go-bitswap v0.3.4
github.com/ipfs/go-block-format v0.0.3
github.com/ipfs/go-blockservice v0.0.3
github.com/ipfs/go-cid v0.0.7
github.com/ipfs/go-datastore v0.4.6
github.com/ipfs/go-ds-badger2 v0.1.1
github.com/ipfs/go-ipfs-blockstore v0.1.6
github.com/ipfs/go-ipfs-exchange-interface v0.0.1
github.com/ipfs/go-ipld-cbor v0.0.5 // indirect
github.com/ipfs/go-ipld-format v0.2.0
github.com/ipfs/go-log v1.0.5 // indirect
github.com/ipfs/go-log/v2 v2.3.0
github.com/ipfs/go-merkledag v0.4.0
github.com/libp2p/go-libp2p v0.15.0
github.com/ipfs/go-merkledag v0.0.3
github.com/ipfs/go-peertaskqueue v0.4.0 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/koron/go-ssdp v0.0.2 // indirect
github.com/libp2p/go-addr-util v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.14.2
github.com/libp2p/go-libp2p-connmgr v0.2.4
github.com/libp2p/go-libp2p-core v0.9.0
github.com/libp2p/go-libp2p-kad-dht v0.13.1
github.com/libp2p/go-libp2p-peerstore v0.2.8
github.com/libp2p/go-libp2p-pubsub v0.5.4
github.com/libp2p/go-libp2p-discovery v0.5.1 // indirect
github.com/libp2p/go-libp2p-kad-dht v0.11.1
github.com/libp2p/go-libp2p-noise v0.2.2 // indirect
github.com/libp2p/go-libp2p-peerstore v0.2.7
github.com/libp2p/go-libp2p-pubsub v0.5.0
github.com/libp2p/go-libp2p-quic-transport v0.11.2 // indirect
github.com/libp2p/go-libp2p-routing-helpers v0.2.3
github.com/libp2p/go-libp2p-tls v0.2.0 // indirect
github.com/libp2p/go-libp2p-transport-upgrader v0.4.6 // indirect
github.com/libp2p/go-reuseport-transport v0.0.5 // indirect
github.com/libp2p/go-ws-transport v0.5.0 // indirect
github.com/miekg/dns v1.1.43 // indirect
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/multiformats/go-base32 v0.0.4
github.com/multiformats/go-multiaddr v0.4.0
github.com/multiformats/go-multihash v0.0.14
github.com/polydawn/refmt v0.0.0-20201211092308-30ac6d18308e // indirect
github.com/prometheus/common v0.30.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942
github.com/warpfork/go-wish v0.0.0-20200122115046-b9ea61034e4a // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/fx v1.14.2
go.uber.org/multierr v1.7.0 // indirect
go.uber.org/zap v1.19.0
golang.org/x/crypto v0.0.0-20210813211128-0a44fdfbc16e // indirect
golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/grpc v1.40.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
)
162 changes: 82 additions & 80 deletions go.sum

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions ipld/nmt_adder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package ipld

import (
"context"

"github.com/ipfs/go-cid"
ipld "github.com/ipfs/go-ipld-format"

"github.com/celestiaorg/celestia-node/ipld/plugin"
)

// NmtNodeAdder adds ipld.Nodes to the underlying ipld.Batch if it is inserted
// into an nmt tree
type NmtNodeAdder struct {
ctx context.Context
batch *ipld.Batch
leaves *cid.Set
err error
}

// NewNmtNodeAdder returns a new NmtNodeAdder with the provided context and
// batch. Note that the context provided should have a timeout
// It is not thread-safe.
func NewNmtNodeAdder(ctx context.Context, batch *ipld.Batch) *NmtNodeAdder {
return &NmtNodeAdder{
batch: batch,
ctx: ctx,
leaves: cid.NewSet(),
}
}

// Visit can be inserted into an nmt tree to create ipld.Nodes while computing the root
func (n *NmtNodeAdder) Visit(hash []byte, children ...[]byte) {
if n.err != nil {
return // protect from further visits if there is an error
}

id := plugin.MustCidFromNamespacedSha256(hash)
switch len(children) {
case 1:
if n.leaves.Visit(id) {
n.err = n.batch.Add(n.ctx, plugin.NewNMTLeafNode(id, children[0]))
}
case 2:
n.err = n.batch.Add(n.ctx, plugin.NewNMTNode(id, children[0], children[1]))
default:
panic("expected a binary tree")
}
}

// Batch return the ipld.Batch originally provided to the NmtNodeAdder
func (n *NmtNodeAdder) Batch() *ipld.Batch {
return n.batch
}

// Commit checks for errors happened during Visit and if absent commits data to inner Batch.
func (n *NmtNodeAdder) Commit() error {
if n.err != nil {
return n.err
}

return n.batch.Commit()
}
Loading

0 comments on commit 5d9c2be

Please sign in to comment.