Skip to content

Commit

Permalink
chore: change nmt node adder ctr arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
vgonkivs committed May 30, 2022
1 parent ea5eb4e commit aa82d55
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 21 deletions.
5 changes: 2 additions & 3 deletions ipld/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/ipfs/go-blockservice"
ipld "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-merkledag"

"github.com/celestiaorg/nmt"
"github.com/celestiaorg/rsmt2d"
Expand All @@ -27,7 +26,7 @@ func AddShares(
squareSize := int(math.Sqrt(float64(len(shares))))
// create nmt adder wrapping batch adder with calculated size
bs := batchSize(squareSize * 2)
batchAdder := NewNmtNodeAdder(ctx, ipld.NewBatch(ctx, merkledag.NewDAGService(adder), ipld.MaxSizeBatchOption(bs)))
batchAdder := NewNmtNodeAdder(ctx, adder, ipld.MaxSizeBatchOption(bs))
// create the nmt wrapper to generate row and col commitments
tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(squareSize), nmt.NodeVisitor(batchAdder.Visit))
// recompute the eds
Expand All @@ -52,7 +51,7 @@ func ImportShares(
squareSize := int(math.Sqrt(float64(len(shares))))
// create nmt adder wrapping batch adder with calculated size
bs := batchSize(squareSize * 2)
batchAdder := NewNmtNodeAdder(ctx, ipld.NewBatch(ctx, merkledag.NewDAGService(adder), ipld.MaxSizeBatchOption(bs)))
batchAdder := NewNmtNodeAdder(ctx, adder, ipld.MaxSizeBatchOption(bs))
// create the nmt wrapper to generate row and col commitments
tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(squareSize/2), nmt.NodeVisitor(batchAdder.Visit))
// recompute the eds
Expand Down
8 changes: 2 additions & 6 deletions ipld/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
blockstore "github.com/ipfs/go-ipfs-blockstore"
offline "github.com/ipfs/go-ipfs-exchange-offline"
format "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-merkledag"
mdutils "github.com/ipfs/go-merkledag/test"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -407,11 +406,8 @@ func TestRetrieveDataFailedWithByzantineError(t *testing.T) {
// import corrupted eds
batchAdder := NewNmtNodeAdder(
ctx,
format.NewBatch(
ctx,
merkledag.NewDAGService(bServ),
format.MaxSizeBatchOption(batchSize(width*2)),
),
bServ,
format.MaxSizeBatchOption(batchSize(width*2)),
)
tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(width), nmt.NodeVisitor(batchAdder.Visit))
attackerEDS, err := rsmt2d.ImportExtendedDataSquare(shares, DefaultRSMT2DCodec(), tree.Constructor)
Expand Down
7 changes: 5 additions & 2 deletions ipld/nmt_adder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package ipld
import (
"context"

"github.com/ipfs/go-blockservice"
"github.com/ipfs/go-merkledag"

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

Expand All @@ -21,9 +24,9 @@ type NmtNodeAdder struct {
// 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, add ipld.NodeAdder) *NmtNodeAdder {
func NewNmtNodeAdder(ctx context.Context, bs blockservice.BlockService, opts ...ipld.BatchOption) *NmtNodeAdder {
return &NmtNodeAdder{
add: add,
add: ipld.NewBatch(ctx, merkledag.NewDAGService(bs), opts...),
ctx: ctx,
leaves: cid.NewSet(),
}
Expand Down
8 changes: 2 additions & 6 deletions ipld/retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/ipfs/go-cid"
format "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log/v2"
"github.com/ipfs/go-merkledag"
"github.com/tendermint/tendermint/pkg/da"
"github.com/tendermint/tendermint/pkg/wrapper"

Expand Down Expand Up @@ -91,11 +90,8 @@ func (r *Retriever) newSession(ctx context.Context, dah *da.DataAvailabilityHead
size := len(dah.RowsRoots)
adder := NewNmtNodeAdder(
ctx,
format.NewBatch(
ctx,
merkledag.NewDAGService(r.bServ),
format.MaxSizeBatchOption(batchSize(size)),
),
r.bServ,
format.MaxSizeBatchOption(batchSize(size)),
)
ses := &retrieverSession{
session: blockservice.NewSession(ctx, r.bServ),
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion node/keyring-test/my_celes_key.info

This file was deleted.

4 changes: 2 additions & 2 deletions service/share/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
dssync "github.com/ipfs/go-datastore/sync"
blockstore "github.com/ipfs/go-ipfs-blockstore"
"github.com/ipfs/go-ipfs-routing/offline"
"github.com/ipfs/go-merkledag"
format "github.com/ipfs/go-ipld-format"
mdutils "github.com/ipfs/go-merkledag/test"
record "github.com/libp2p/go-libp2p-record"
mocknet "github.com/libp2p/go-libp2p/p2p/net/mock"
Expand Down Expand Up @@ -54,7 +54,7 @@ func RandFillDAG(t *testing.T, n int, bServ blockservice.BlockService) *Root {
}

func FillDag(t *testing.T, bServ blockservice.BlockService, shares []Share) *Root {
na := ipld.NewNmtNodeAdder(context.TODO(), merkledag.NewDAGService(bServ))
na := ipld.NewNmtNodeAdder(context.TODO(), bServ, format.MaxSizeBatchOption(len(shares)))

squareSize := uint32(math.Sqrt(float64(len(shares))))
tree := wrapper.NewErasuredNamespacedMerkleTree(uint64(squareSize), nmt.NodeVisitor(na.Visit))
Expand Down

0 comments on commit aa82d55

Please sign in to comment.