Skip to content

Commit

Permalink
refactor(share): Consolidate share pkg (#1177)
Browse files Browse the repository at this point in the history
Resolves #878

Co-authored-by: rene <41963722+renaynay@users.noreply.github.com>
  • Loading branch information
walldiss and renaynay committed Oct 12, 2022
1 parent 0d9358b commit 793e2b0
Show file tree
Hide file tree
Showing 61 changed files with 1,543 additions and 1,455 deletions.
4 changes: 1 addition & 3 deletions das/daser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"sync/atomic"
"time"

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

"github.com/ipfs/go-datastore"
logging "github.com/ipfs/go-log/v2"

Expand Down Expand Up @@ -155,7 +153,7 @@ func (d *DASer) sample(ctx context.Context, h *header.ExtendedHeader) error {
if err == context.Canceled {
return err
}
var byzantineErr *ipld.ErrByzantine
var byzantineErr *share.ErrByzantine
if errors.As(err, &byzantineErr) {
log.Warn("Propagating proof...")
sendErr := d.bcast.Broadcast(ctx, fraud.CreateBadEncodingProof(h.Hash(), uint64(h.Height), byzantineErr))
Expand Down
15 changes: 9 additions & 6 deletions das/daser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import (
"testing"
"time"

"github.com/celestiaorg/celestia-node/share/availability/full"
"github.com/celestiaorg/celestia-node/share/availability/light"
availability_test "github.com/celestiaorg/celestia-node/share/availability/test"

"github.com/tendermint/tendermint/types"

"github.com/ipfs/go-blockservice"
Expand All @@ -19,7 +23,6 @@ import (

"github.com/celestiaorg/celestia-node/fraud"
"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/share"
)

var timeout = time.Second * 15
Expand All @@ -29,7 +32,7 @@ var timeout = time.Second * 15
func TestDASerLifecycle(t *testing.T) {
ds := ds_sync.MutexWrap(datastore.NewMapDatastore())
bServ := mdutils.Bserv()
avail := share.TestLightAvailability(bServ)
avail := light.TestAvailability(bServ)
// 15 headers from the past and 15 future headers
mockGet, sub, mockService := createDASerSubcomponents(t, bServ, 15, 15)

Expand Down Expand Up @@ -63,7 +66,7 @@ func TestDASerLifecycle(t *testing.T) {
func TestDASer_Restart(t *testing.T) {
ds := ds_sync.MutexWrap(datastore.NewMapDatastore())
bServ := mdutils.Bserv()
avail := share.TestLightAvailability(bServ)
avail := light.TestAvailability(bServ)
// 15 headers from the past and 15 future headers
mockGet, sub, mockService := createDASerSubcomponents(t, bServ, 15, 15)

Expand Down Expand Up @@ -132,7 +135,7 @@ func TestDASer_stopsAfter_BEFP(t *testing.T) {
ps, err := pubsub.NewGossipSub(ctx, net.Hosts()[0],
pubsub.WithMessageSignaturePolicy(pubsub.StrictNoSign))
require.NoError(t, err)
avail := share.TestFullAvailability(bServ)
avail := full.TestAvailability(bServ)
// 15 headers from the past and 15 future headers
mockGet, sub, _ := createDASerSubcomponents(t, bServ, 15, 15)

Expand Down Expand Up @@ -209,7 +212,7 @@ func (m *mockGetter) fillSubWithHeaders(

index := 0
for i := startHeight; i < endHeight; i++ {
dah := share.RandFillBS(t, 16, bServ)
dah := availability_test.RandFillBS(t, 16, bServ)

randHeader := header.RandExtendedHeader(t)
randHeader.DataHash = dah.Hash()
Expand Down Expand Up @@ -237,7 +240,7 @@ type mockGetter struct {

func (m *mockGetter) generateHeaders(t *testing.T, bServ blockservice.BlockService, startHeight, endHeight int) {
for i := startHeight; i < endHeight; i++ {
dah := share.RandFillBS(t, 16, bServ)
dah := availability_test.RandFillBS(t, 16, bServ)

randHeader := header.RandExtendedHeader(t)
randHeader.DataHash = dah.Hash()
Expand Down
17 changes: 8 additions & 9 deletions fraud/bad_encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import (
"github.com/tendermint/tendermint/pkg/consts"
"github.com/tendermint/tendermint/pkg/wrapper"

"github.com/celestiaorg/rsmt2d"

pb "github.com/celestiaorg/celestia-node/fraud/pb"
"github.com/celestiaorg/celestia-node/header"
"github.com/celestiaorg/celestia-node/ipld"
ipld_pb "github.com/celestiaorg/celestia-node/ipld/pb"
"github.com/celestiaorg/celestia-node/ipld/plugin"
"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/celestia-node/share/ipld"
ipld_pb "github.com/celestiaorg/celestia-node/share/pb"
"github.com/celestiaorg/rsmt2d"
)

func init() {
Expand All @@ -27,7 +26,7 @@ type BadEncodingProof struct {
// ShareWithProof contains all shares from row or col.
// Shares that did not pass verification in rsmt2d will be nil.
// For non-nil shares MerkleProofs are computed.
Shares []*ipld.ShareWithProof
Shares []*share.ShareWithProof
// Index represents the row/col index where ErrByzantineRow/ErrByzantineColl occurred.
Index uint32
// Axis represents the axis that verification failed on.
Expand All @@ -39,7 +38,7 @@ type BadEncodingProof struct {
func CreateBadEncodingProof(
hash []byte,
height uint64,
errByzantine *ipld.ErrByzantine,
errByzantine *share.ErrByzantine,
) Proof {

return &BadEncodingProof{
Expand Down Expand Up @@ -92,7 +91,7 @@ func (p *BadEncodingProof) UnmarshalBinary(data []byte) error {
befp := &BadEncodingProof{
headerHash: in.HeaderHash,
BlockHeight: in.Height,
Shares: ipld.ProtoToShare(in.Shares),
Shares: share.ProtoToShare(in.Shares),
Index: in.Index,
Axis: rsmt2d.Axis(in.Axis),
}
Expand Down Expand Up @@ -141,7 +140,7 @@ func (p *BadEncodingProof) Validate(header *header.ExtendedHeader) error {
continue
}
shares[index] = share.Share
if ok := share.Validate(plugin.MustCidFromNamespacedSha256(root)); !ok {
if ok := share.Validate(ipld.MustCidFromNamespacedSha256(root)); !ok {
return fmt.Errorf("fraud: invalid proof: incorrect share received at index %d", index)
}
}
Expand Down
4 changes: 2 additions & 2 deletions fraud/bad_encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
mdutils "github.com/ipfs/go-merkledag/test"
"github.com/stretchr/testify/require"

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

func TestFraudProofValidation(t *testing.T) {
Expand All @@ -21,7 +21,7 @@ func TestFraudProofValidation(t *testing.T) {
require.NoError(t, err)

faultDAH, err := generateByzantineError(ctx, t, h, bServ)
var errByz *ipld.ErrByzantine
var errByz *share.ErrByzantine
require.True(t, errors.As(err, &errByz))
p := CreateBadEncodingProof([]byte("hash"), uint64(faultDAH.Height), errByz)
err = p.Validate(faultDAH)
Expand Down
6 changes: 4 additions & 2 deletions fraud/pb/proof.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions fraud/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import (
"errors"
"testing"

"github.com/celestiaorg/celestia-node/share/eds"

"github.com/ipfs/go-blockservice"

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

type DummyService struct {
Expand Down Expand Up @@ -66,7 +67,7 @@ func generateByzantineError(
bServ blockservice.BlockService,
) (*header.ExtendedHeader, error) {
faultHeader := header.CreateFraudExtHeader(t, h, bServ)
rtrv := ipld.NewRetriever(bServ)
rtrv := eds.NewRetriever(bServ)
_, err := rtrv.Retrieve(ctx, faultHeader.DAH)
return faultHeader, err
}
Expand Down
6 changes: 3 additions & 3 deletions header/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"context"
"fmt"

"github.com/celestiaorg/celestia-node/share"

"github.com/ipfs/go-blockservice"
logging "github.com/ipfs/go-log/v2"

bts "github.com/tendermint/tendermint/libs/bytes"
"github.com/tendermint/tendermint/pkg/da"
core "github.com/tendermint/tendermint/types"

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

var log = logging.Logger("header")
Expand Down Expand Up @@ -51,7 +51,7 @@ func MakeExtendedHeader(
if err != nil {
return nil, err
}
extended, err := ipld.AddShares(ctx, namespacedShares.RawShares(), bServ)
extended, err := share.AddShares(ctx, namespacedShares.RawShares(), bServ)
if err != nil {
return nil, err
}
Expand Down
11 changes: 6 additions & 5 deletions header/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package header
import (
"context"

"github.com/celestiaorg/celestia-node/share"

mrand "math/rand"
"testing"
"time"
Expand All @@ -22,7 +24,6 @@ import (
tmtime "github.com/tendermint/tendermint/types/time"

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

// TestSuite provides everything you need to test chain of Headers.
Expand Down Expand Up @@ -225,10 +226,10 @@ func FraudMaker(t *testing.T, faultHeight int64) ConstructFn {
}

func CreateFraudExtHeader(t *testing.T, eh *ExtendedHeader, dag blockservice.BlockService) *ExtendedHeader {
extended := ipld.RandEDS(t, 2)
shares := ipld.ExtractEDS(extended)
copy(shares[0][ipld.NamespaceSize:], shares[1][ipld.NamespaceSize:])
extended, err := ipld.ImportShares(context.Background(), shares, dag)
extended := share.RandEDS(t, 2)
shares := share.ExtractEDS(extended)
copy(shares[0][share.NamespaceSize:], shares[1][share.NamespaceSize:])
extended, err := share.ImportShares(context.Background(), shares, dag)
require.NoError(t, err)
dah := da.NewDataAvailabilityHeader(extended)
eh.DAH = &dah
Expand Down
131 changes: 0 additions & 131 deletions ipld/get.go

This file was deleted.

Loading

0 comments on commit 793e2b0

Please sign in to comment.