Skip to content

Commit

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

Co-authored-by: rene <41963722+renaynay@users.noreply.github.com>
  • Loading branch information
2 people authored and Wondertan committed Apr 12, 2023
1 parent 603c1f0 commit 22b12e9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
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

0 comments on commit 22b12e9

Please sign in to comment.