Skip to content

Commit

Permalink
chore: update branch to latest main
Browse files Browse the repository at this point in the history
  • Loading branch information
rach-id authored and vgonkivs committed Dec 9, 2024
1 parent dbe15c8 commit 1df0217
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 34 deletions.
13 changes: 11 additions & 2 deletions blob/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/cosmos/cosmos-sdk/types"
logging "github.com/ipfs/go-log/v2"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
core "github.com/tendermint/tendermint/types"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -659,9 +660,17 @@ func (s *Service) retrieveBlobProof(
if err != nil {
return nil, nil, err
}

tmShareToRowRootProofs := make([]*tmproto.NMTProof, 0, len(shareToRowRootProofs))
for _, proof := range shareToRowRootProofs {
tmShareToRowRootProofs = append(tmShareToRowRootProofs, &tmproto.NMTProof{
Start: proof.Start,
End: proof.End,
Nodes: proof.Nodes,
LeafHash: proof.LeafHash,
})
}
proof := Proof{
ShareToRowRootProof: shareToRowRootProofs,
ShareToRowRootProof: tmShareToRowRootProofs,
RowToDataRootProof: core.RowProof{
RowRoots: rowRoots,
Proofs: rowProofs,
Expand Down
84 changes: 64 additions & 20 deletions blob/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types"
"github.com/celestiaorg/go-header/store"
"github.com/celestiaorg/go-square/merkle"
libsquare "github.com/celestiaorg/go-square/v2"
"github.com/celestiaorg/go-square/v2/inclusion"
libshare "github.com/celestiaorg/go-square/v2/share"
"github.com/celestiaorg/nmt"
Expand Down Expand Up @@ -407,8 +408,8 @@ func TestBlobService_Get(t *testing.T) {
GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()).
DoAndReturn(
func(
ctx context.Context, h *header.ExtendedHeader, ns share.Namespace,
) (share.NamespacedShares, error) {
ctx context.Context, h *header.ExtendedHeader, ns libshare.Namespace,
) (shwap.NamespaceData, error) {
if ns.Equals(blobsWithDiffNamespaces[0].Namespace()) {
return nil, errors.New("internal error")
}
Expand Down Expand Up @@ -437,7 +438,7 @@ func TestBlobService_Get(t *testing.T) {
name: "get blob internal error",
doFn: func() (interface{}, error) {
ctrl := gomock.NewController(t)
shareGetterMock := shareMock.NewMockModule(ctrl)
shareGetterMock := mock.NewMockGetter(ctrl)
shareGetterMock.EXPECT().
GetEDS(gomock.Any(), gomock.Any()).
DoAndReturn(
Expand Down Expand Up @@ -852,9 +853,10 @@ func BenchmarkGetByCommitment(b *testing.B) {

func createServiceWithSub(ctx context.Context, t *testing.T, blobs []*Blob) *Service {
acc := "test"
kr := testfactory.GenerateKeyring(acc)
signer := blobtypes.NewKeyringSigner(kr, acc, "test")
addr, err := signer.GetSignerInfo().GetAddress()
config := encoding.MakeConfig(app.ModuleEncodingRegisters...)
keyring := testfactory.TestKeyring(config.Codec, acc)
account := user.NewAccount(acc, 0, 0)
signer, err := user.NewSigner(keyring, config.TxConfig, testfactory.ChainID, appconsts.LatestVersion, account)
require.NoError(t, err)

bs := ipld.NewMemBlockservice()
Expand All @@ -864,20 +866,16 @@ func createServiceWithSub(ctx context.Context, t *testing.T, blobs []*Blob) *Ser
edsses := make([]*rsmt2d.ExtendedDataSquare, len(blobs))

for i, blob := range blobs {
msg, err := blobtypes.NewMsgPayForBlobs(
addr.String(),
&blob.Blob,
)
require.NoError(t, err)
coreTx := edstest.BuildCoreTx(t, signer, msg, &blob.Blob)
dataSquare, err := square.Construct(
coreTx := edstest.BuildCoreTx(t, signer, acc, blob.Blob)
dataSquare, err := libsquare.Construct(
coretypes.Txs{coreTx}.ToSliceOfBytes(),
appconsts.LatestVersion,
appconsts.SquareSizeUpperBound(appconsts.LatestVersion),
appconsts.SubtreeRootThreshold(appconsts.LatestVersion),
)
require.NoError(t, err)

eds, err := ipld.AddShares(ctx, shares.ToBytes(dataSquare), bs)
eds, err := ipld.AddShares(ctx, dataSquare, bs)
require.NoError(t, err)
edsses[i] = eds
}
Expand Down Expand Up @@ -937,6 +935,10 @@ func createService(ctx context.Context, t testing.TB, shares []libshare.Share) *
s, err := accessor.Sample(ctx, row, col)
return s.Share, err
})
shareGetter.EXPECT().GetEDS(gomock.Any(), gomock.Any()).AnyTimes().
DoAndReturn(func(context.Context, *header.ExtendedHeader) (*rsmt2d.ExtendedDataSquare, error) {
return square, nil
})

// create header and put it into the store
h := headertest.ExtendedHeaderFromEDS(t, 1, square)
Expand Down Expand Up @@ -1066,7 +1068,7 @@ func generateCommitmentProofFromBlock(
ranges, err := nmt.ToLeafRanges(
int(proof.Start),
int(proof.End),
inclusion.SubTreeWidth(len(blobShares), subtreeRootThreshold),
inclusion.SubTreeWidth(len(blobShares), appconsts.DefaultSubtreeRootThreshold),
)
require.NoError(t, err)
roots, err := computeSubtreeRoots(
Expand Down Expand Up @@ -1141,9 +1143,20 @@ func TestBlobVerify(t *testing.T) {
require.NoError(t, err)
require.NoError(t, sharesProof.Validate(dataRoot))

tmShareToRowRootProofs := make([]*types.NMTProof, 0, len(sharesProof.ShareProofs))
for _, proof := range sharesProof.ShareProofs {
tmShareToRowRootProofs = append(tmShareToRowRootProofs, &types.NMTProof{
Start: proof.Start,
End: proof.End,
Nodes: proof.Nodes,
LeafHash: proof.LeafHash,
})
}

coreRowProof := toCoreRowProof(sharesProof.RowProof)
blobProof := Proof{
ShareToRowRootProof: sharesProof.ShareProofs,
RowToDataRootProof: sharesProof.RowProof,
ShareToRowRootProof: tmShareToRowRootProofs,
RowToDataRootProof: coreRowProof,
}
tests := []struct {
name string
Expand Down Expand Up @@ -1222,14 +1235,25 @@ func TestBlobVerify(t *testing.T) {
sharesProof, err := pkgproof.NewShareInclusionProofFromEDS(
eds,
nss[5],
shares.NewRange(startShareIndex, startShareIndex+len(blobShares)),
libshare.NewRange(startShareIndex, startShareIndex+len(blobShares)),
)
require.NoError(t, err)
require.NoError(t, sharesProof.Validate(dataRoot))

tmShareToRowRootProofs := make([]*types.NMTProof, 0, len(sharesProof.ShareProofs))
for _, proof := range sharesProof.ShareProofs {
tmShareToRowRootProofs = append(tmShareToRowRootProofs, &types.NMTProof{
Start: proof.Start,
End: proof.End,
Nodes: proof.Nodes,
LeafHash: proof.LeafHash,
})
}

coreRowProof := toCoreRowProof(sharesProof.RowProof)
return Proof{
ShareToRowRootProof: sharesProof.ShareProofs,
RowToDataRootProof: sharesProof.RowProof,
ShareToRowRootProof: tmShareToRowRootProofs,
RowToDataRootProof: coreRowProof,
}
}(),
},
Expand All @@ -1247,3 +1271,23 @@ func TestBlobVerify(t *testing.T) {
})
}
}

func toCoreRowProof(proof *pkgproof.RowProof) coretypes.RowProof {
tmRowRoots := make([]bytes2.HexBytes, 0, len(proof.RowRoots))
tmRowProofs := make([]*merkle.Proof, 0, len(proof.RowRoots))
for index, root := range proof.RowRoots {
tmRowRoots = append(tmRowRoots, root)
tmRowProofs = append(tmRowProofs, &merkle.Proof{
Total: proof.Proofs[index].Total,
Index: proof.Proofs[index].Index,
LeafHash: proof.Proofs[index].LeafHash,
Aunts: proof.Proofs[index].Aunts,
})
}
return coretypes.RowProof{
RowRoots: tmRowRoots,
Proofs: tmRowProofs,
StartRow: proof.StartRow,
EndRow: proof.EndRow,
}
}
17 changes: 5 additions & 12 deletions share/eds/edstest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
coretypes "github.com/tendermint/tendermint/types"

"github.com/celestiaorg/celestia-app/v3/app"
Expand Down Expand Up @@ -192,8 +191,7 @@ func createTestBlobTransaction(
ns := libshare.RandomBlobNamespace()
account := signer.Account(accountName)
msg, b := blobfactory.RandMsgPayForBlobsWithNamespaceAndSigner(account.Address().String(), ns, size)
cTx, _, err := signer.CreatePayForBlobs(accountName, []*libshare.Blob{b})
require.NoError(t, err)
cTx := BuildCoreTx(t, signer, accountName, b)
return ns, msg, b, cTx
}

Expand All @@ -202,16 +200,11 @@ func createTestBlobTransaction(
// into the square builder.
func BuildCoreTx(
t *testing.T,
signer *types.KeyringSigner,
msg *types.MsgPayForBlobs,
blob *tmproto.Blob,
signer *user.Signer,
accountName string,
b *libshare.Blob,
) coretypes.Tx {
builder := signer.NewTxBuilder()
stx, err := signer.BuildSignedTx(builder, msg)
require.NoError(t, err)
rawTx, err := encoding.MakeConfig(app.ModuleEncodingRegisters...).TxConfig.TxEncoder()(stx)
require.NoError(t, err)
cTx, err := coretypes.MarshalBlobTx(rawTx, blob)
cTx, _, err := signer.CreatePayForBlobs(accountName, []*libshare.Blob{b})
require.NoError(t, err)
return cTx
}

0 comments on commit 1df0217

Please sign in to comment.