From 0e6a558689eb4487e96d52d6d5e019589fa06cde Mon Sep 17 00:00:00 2001 From: Wondertan Date: Wed, 12 Jun 2024 19:36:50 +0200 Subject: [PATCH] migrate to Accessor --- share/shwap/p2p/bitswap/block.go | 7 ++++--- share/shwap/p2p/bitswap/block_fetch_test.go | 12 +++++++----- share/shwap/p2p/bitswap/row_block.go | 13 ++++++++++--- share/shwap/p2p/bitswap/row_namespace_data_block.go | 11 ++++++----- share/shwap/p2p/bitswap/sample_block.go | 11 ++++++----- 5 files changed, 33 insertions(+), 21 deletions(-) diff --git a/share/shwap/p2p/bitswap/block.go b/share/shwap/p2p/bitswap/block.go index 7afc083451..4a293876ba 100644 --- a/share/shwap/p2p/bitswap/block.go +++ b/share/shwap/p2p/bitswap/block.go @@ -1,6 +1,7 @@ package bitswap import ( + "context" "fmt" "github.com/gogo/protobuf/proto" @@ -8,9 +9,9 @@ import ( "github.com/ipfs/go-cid" logger "github.com/ipfs/go-log/v2" - bitswappb "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap/pb" + eds "github.com/celestiaorg/celestia-node/share/new_eds" - "github.com/celestiaorg/rsmt2d" + bitswappb "github.com/celestiaorg/celestia-node/share/shwap/p2p/bitswap/pb" "github.com/celestiaorg/celestia-node/share" ) @@ -29,7 +30,7 @@ type Block interface { CID() cid.Cid // BlockFromEDS extract Bitswap Block out of the EDS. // TODO: Split into MarshalBinary and Populate - BlockFromEDS(*rsmt2d.ExtendedDataSquare) (blocks.Block, error) + BlockFromEDS(context.Context, eds.Accessor) (blocks.Block, error) // IsEmpty reports whether the Block been populated with Shwap container. // If the Block is empty, it can be populated with Fetch. diff --git a/share/shwap/p2p/bitswap/block_fetch_test.go b/share/shwap/p2p/bitswap/block_fetch_test.go index fa1594499d..0a27475e64 100644 --- a/share/shwap/p2p/bitswap/block_fetch_test.go +++ b/share/shwap/p2p/bitswap/block_fetch_test.go @@ -23,6 +23,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + eds "github.com/celestiaorg/celestia-node/share/new_eds" + "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -102,14 +104,14 @@ func fetcher(ctx context.Context, t *testing.T, bstore blockstore.Blockstore) ex } type testBlockstore struct { - eds *rsmt2d.ExtendedDataSquare + eds eds.Accessor } -func newTestBlockstore(eds *rsmt2d.ExtendedDataSquare) *testBlockstore { - return &testBlockstore{eds: eds} +func newTestBlockstore(rsmt2sEds *rsmt2d.ExtendedDataSquare) *testBlockstore { + return &testBlockstore{eds: eds.Rsmt2D{ExtendedDataSquare: rsmt2sEds}} } -func (b *testBlockstore) Get(_ context.Context, cid cid.Cid) (blocks.Block, error) { +func (b *testBlockstore) Get(ctx context.Context, cid cid.Cid) (blocks.Block, error) { spec, ok := specRegistry[cid.Prefix().MhType] if !ok { return nil, fmt.Errorf("unsupported codec") @@ -120,7 +122,7 @@ func (b *testBlockstore) Get(_ context.Context, cid cid.Cid) (blocks.Block, erro return nil, err } - return bldr.BlockFromEDS(b.eds) + return bldr.BlockFromEDS(ctx, b.eds) } func (b *testBlockstore) GetSize(ctx context.Context, cid cid.Cid) (int, error) { diff --git a/share/shwap/p2p/bitswap/row_block.go b/share/shwap/p2p/bitswap/row_block.go index 60f03f0eda..f334229634 100644 --- a/share/shwap/p2p/bitswap/row_block.go +++ b/share/shwap/p2p/bitswap/row_block.go @@ -1,12 +1,15 @@ package bitswap import ( + "context" "fmt" "sync/atomic" blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" + eds "github.com/celestiaorg/celestia-node/share/new_eds" + "github.com/celestiaorg/rsmt2d" "github.com/celestiaorg/celestia-node/share" @@ -68,9 +71,13 @@ func (rb *RowBlock) CID() cid.Cid { return encodeCID(rb.ID, rowMultihashCode, rowCodec) } -func (rb *RowBlock) BlockFromEDS(eds *rsmt2d.ExtendedDataSquare) (blocks.Block, error) { - row := shwap.RowFromEDS(eds, rb.ID.RowIndex, shwap.Left) - blk, err := toBlock(rb.CID(), row.ToProto()) +func (rb *RowBlock) BlockFromEDS(ctx context.Context, eds eds.Accessor) (blocks.Block, error) { + half, err := eds.AxisHalf(ctx, rsmt2d.Row, rb.ID.RowIndex) + if err != nil { + return nil, fmt.Errorf("getting Row AxisHalf: %w", err) + } + + blk, err := toBlock(rb.CID(), half.ToRow().ToProto()) if err != nil { return nil, fmt.Errorf("converting Row to Bitswap block: %w", err) } diff --git a/share/shwap/p2p/bitswap/row_namespace_data_block.go b/share/shwap/p2p/bitswap/row_namespace_data_block.go index 79d5be0191..fa71bae863 100644 --- a/share/shwap/p2p/bitswap/row_namespace_data_block.go +++ b/share/shwap/p2p/bitswap/row_namespace_data_block.go @@ -1,15 +1,16 @@ package bitswap import ( + "context" "fmt" "sync/atomic" blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" - shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" + eds "github.com/celestiaorg/celestia-node/share/new_eds" - "github.com/celestiaorg/rsmt2d" + shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/shwap" @@ -75,10 +76,10 @@ func (rndb *RowNamespaceDataBlock) CID() cid.Cid { return encodeCID(rndb.ID, rowNamespaceDataMultihashCode, rowNamespaceDataCodec) } -func (rndb *RowNamespaceDataBlock) BlockFromEDS(eds *rsmt2d.ExtendedDataSquare) (blocks.Block, error) { - rnd, err := shwap.RowNamespaceDataFromEDS(eds, rndb.ID.DataNamespace, rndb.ID.RowIndex) +func (rndb *RowNamespaceDataBlock) BlockFromEDS(ctx context.Context, eds eds.Accessor) (blocks.Block, error) { + rnd, err := eds.RowNamespaceData(ctx, rndb.ID.DataNamespace, rndb.ID.RowIndex) if err != nil { - return nil, err + return nil, fmt.Errorf("getting RowNamespaceData: %w", err) } blk, err := toBlock(rndb.CID(), rnd.ToProto()) diff --git a/share/shwap/p2p/bitswap/sample_block.go b/share/shwap/p2p/bitswap/sample_block.go index a9c574edba..9192441e54 100644 --- a/share/shwap/p2p/bitswap/sample_block.go +++ b/share/shwap/p2p/bitswap/sample_block.go @@ -1,15 +1,16 @@ package bitswap import ( + "context" "fmt" "sync/atomic" blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" - shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" + eds "github.com/celestiaorg/celestia-node/share/new_eds" - "github.com/celestiaorg/rsmt2d" + shwappb "github.com/celestiaorg/celestia-node/share/shwap/pb" "github.com/celestiaorg/celestia-node/share" "github.com/celestiaorg/celestia-node/share/shwap" @@ -70,10 +71,10 @@ func (sb *SampleBlock) CID() cid.Cid { return encodeCID(sb.ID, sampleMultihashCode, sampleCodec) } -func (sb *SampleBlock) BlockFromEDS(eds *rsmt2d.ExtendedDataSquare) (blocks.Block, error) { - smpl, err := shwap.SampleFromEDS(eds, rsmt2d.Row, sb.ID.RowIndex, sb.ID.ShareIndex) +func (sb *SampleBlock) BlockFromEDS(ctx context.Context, eds eds.Accessor) (blocks.Block, error) { + smpl, err := eds.Sample(ctx, sb.ID.RowIndex, sb.ID.ShareIndex) if err != nil { - return nil, err + return nil, fmt.Errorf("getting Sample: %w", err) } blk, err := toBlock(sb.CID(), smpl.ToProto())