diff --git a/nodebuilder/config_test.go b/nodebuilder/config_test.go index e7b64b0aed..3b98664025 100644 --- a/nodebuilder/config_test.go +++ b/nodebuilder/config_test.go @@ -97,7 +97,7 @@ var outdatedConfig = ` PeersLimit = 5 DiscoveryInterval = "30s" AdvertiseInterval = "30s" - UseShareExchange = true + UseShrEx = true [Share.ShrExEDSParams] ServerReadTimeout = "5s" ServerWriteTimeout = "1m0s" diff --git a/nodebuilder/share/config.go b/nodebuilder/share/config.go index aff8c27bb4..970cac8238 100644 --- a/nodebuilder/share/config.go +++ b/nodebuilder/share/config.go @@ -17,8 +17,8 @@ type Config struct { // EDSStoreParams sets eds store configuration parameters EDSStoreParams *store.Parameters - UseShareExchange bool - UseShareSwap bool + UseShrEx bool + UseShwap bool // ShrExEDSParams sets shrexeds client and server configuration parameters ShrExEDSParams *shrexeds.Parameters // ShrExNDParams sets shrexnd client and server configuration parameters @@ -36,7 +36,7 @@ func DefaultConfig(tp node.Type) Config { Discovery: discovery.DefaultParameters(), ShrExEDSParams: shrexeds.DefaultParameters(), ShrExNDParams: shrexnd.DefaultParameters(), - UseShareExchange: true, + UseShrEx: true, PeerManagerParams: peers.DefaultParameters(), } diff --git a/nodebuilder/share/constructors.go b/nodebuilder/share/constructors.go index 4885d47a20..097f267490 100644 --- a/nodebuilder/share/constructors.go +++ b/nodebuilder/share/constructors.go @@ -45,10 +45,10 @@ func lightGetter( cfg Config, ) share.Getter { var cascade []share.Getter - if cfg.UseShareExchange { + if cfg.UseShrEx { cascade = append(cascade, shrexGetter) } - if cfg.UseShareSwap { + if cfg.UseShwap { cascade = append(cascade, shwapGetter) } cascade = append(cascade, reconstructGetter) @@ -66,7 +66,7 @@ func bridgeGetter( ) share.Getter { var cascade []share.Getter cascade = append(cascade, storeGetter) - if cfg.UseShareExchange { + if cfg.UseShrEx { cascade = append(cascade, shrexGetter) } return getters.NewCascadeGetter(cascade) @@ -81,10 +81,10 @@ func fullGetter( ) share.Getter { var cascade []share.Getter cascade = append(cascade, storeGetter) - if cfg.UseShareExchange { + if cfg.UseShrEx { cascade = append(cascade, shrexGetter) } - if cfg.UseShareSwap { + if cfg.UseShwap { cascade = append(cascade, shwapGetter) } cascade = append(cascade, reconstructGetter) diff --git a/nodebuilder/tests/fraud_test.go b/nodebuilder/tests/fraud_test.go index 03999de7f9..1296fab39f 100644 --- a/nodebuilder/tests/fraud_test.go +++ b/nodebuilder/tests/fraud_test.go @@ -79,7 +79,7 @@ func TestFraudProofHandling(t *testing.T) { addrs, err := peer.AddrInfoToP2pAddrs(host.InfoFromHost(bridge.Host)) require.NoError(t, err) cfg.Header.TrustedPeers = append(cfg.Header.TrustedPeers, addrs[0].String()) - cfg.Share.UseShareExchange = false + cfg.Share.UseShrEx = false store := nodebuilder.MockStore(t, cfg) full := sw.NewNodeWithStore(node.Full, store) diff --git a/nodebuilder/tests/reconstruct_test.go b/nodebuilder/tests/reconstruct_test.go index d047182669..6b45d90dfa 100644 --- a/nodebuilder/tests/reconstruct_test.go +++ b/nodebuilder/tests/reconstruct_test.go @@ -58,7 +58,7 @@ func TestFullReconstructFromBridge(t *testing.T) { require.NoError(t, err) cfg := nodebuilder.DefaultConfig(node.Full) - cfg.Share.UseShareExchange = false + cfg.Share.UseShrEx = false cfg.Header.TrustedPeers = append(cfg.Header.TrustedPeers, getMultiAddr(t, bridge.Host)) full := sw.NewNodeWithConfig(node.Full, cfg) err = full.Start(ctx) @@ -170,7 +170,7 @@ func TestFullReconstructFromFulls(t *testing.T) { cfg := nodebuilder.DefaultConfig(node.Full) setTimeInterval(cfg, defaultTimeInterval) - cfg.Share.UseShareExchange = false + cfg.Share.UseShrEx = false cfg.Share.Discovery.PeersLimit = 0 cfg.Header.TrustedPeers = []string{lnBootstrapper1[0].String()} full1 := sw.NewNodeWithConfig(node.Full, cfg) @@ -301,7 +301,7 @@ func TestFullReconstructFromLights(t *testing.T) { cfg = nodebuilder.DefaultConfig(node.Full) setTimeInterval(cfg, defaultTimeInterval) - cfg.Share.UseShareExchange = false + cfg.Share.UseShrEx = false cfg.Header.TrustedPeers = append(cfg.Header.TrustedPeers, addrsBridge[0].String()) nodesConfig := nodebuilder.WithBootstrappers([]peer.AddrInfo{*bootstrapperAddr}) full := sw.NewNodeWithConfig(node.Full, cfg, nodesConfig) diff --git a/share/shwap/data_id.go b/share/shwap/data_id.go index e8b8a83687..9266fb139f 100644 --- a/share/shwap/data_id.go +++ b/share/shwap/data_id.go @@ -125,6 +125,7 @@ func (s DataID) Verify(root *share.Root) error { return nil } +// BlockFromFile returns the IPLD block of the DataID from the given file. func (s DataID) BlockFromFile(ctx context.Context, f file.EdsFile) (blocks.Block, error) { data, err := f.Data(ctx, s.Namespace(), int(s.RowIndex)) if err != nil { @@ -138,3 +139,8 @@ func (s DataID) BlockFromFile(ctx context.Context, f file.EdsFile) (blocks.Block } return blk, nil } + +// Release releases the verifier of the DataID. +func (s DataID) Release() { + dataVerifiers.Delete(s) +} diff --git a/share/shwap/getter/getter.go b/share/shwap/getter/getter.go index 28f640899c..782cac26b2 100644 --- a/share/shwap/getter/getter.go +++ b/share/shwap/getter/getter.go @@ -72,13 +72,6 @@ func (g *Getter) GetShares(ctx context.Context, hdr *header.ExtendedHeader, smpl return nil, fmt.Errorf("getting blocks: %w", err) } - if len(blks) != len(smplIdxs) { - if ctx.Err() != nil { - return nil, ctx.Err() - } - return nil, fmt.Errorf("not all shares were found") - } - // ensure we persist samples/blks and make them available for Bitswap err = g.bstore.PutMany(ctx, blks) if err != nil { @@ -91,19 +84,19 @@ func (g *Getter) GetShares(ctx context.Context, hdr *header.ExtendedHeader, smpl } // ensure we return shares in the requested order - shrs := make(map[int]share.Share, len(blks)) + shares := make(map[int]share.Share, len(blks)) for _, blk := range blks { sample, err := shwap.SampleFromBlock(blk) if err != nil { return nil, fmt.Errorf("getting sample from block: %w", err) } shrIdx := int(sample.SampleID.RowIndex)*len(hdr.DAH.RowRoots) + int(sample.SampleID.ShareIndex) - shrs[shrIdx] = sample.SampleShare + shares[shrIdx] = sample.SampleShare } - ordered := make([]share.Share, len(shrs)) + ordered := make([]share.Share, len(shares)) for i, shrIdx := range smplIdxs { - sh, ok := shrs[shrIdx] + sh, ok := shares[shrIdx] if !ok { return nil, fmt.Errorf("missing share for index %d", shrIdx) } @@ -137,23 +130,12 @@ func (g *Getter) GetEDS(ctx context.Context, hdr *header.ExtendedHeader) (*rsmt2 } - if len(blks) != sqrLn/2 { - if ctx.Err() != nil { - return nil, ctx.Err() - } - return nil, fmt.Errorf("not all rows were found") - } - rows := make([]*shwap.Row, len(blks)) for _, blk := range blks { row, err := shwap.RowFromBlock(blk) if err != nil { return nil, fmt.Errorf("getting row from block: %w", err) } - if row.RowIndex >= uint16(sqrLn/2) { - // should never happen, because rows should be verified against root by the time they are returned - return nil, fmt.Errorf("row index out of bounds: %d", row.RowIndex) - } rows[row.RowIndex] = row } @@ -219,10 +201,6 @@ func (g *Getter) GetSharesByNamespace( return nil, fmt.Errorf("getting row from block: %w", err) } - if data.RowIndex < uint16(from) || data.RowIndex >= uint16(to) { - // should never happen, because rows should be verified against root by the time they are returned - return nil, fmt.Errorf("row index out of bounds: %d", data.RowIndex) - } nShrs[int(data.RowIndex)-from] = share.NamespacedRow{ Shares: data.DataShares, Proof: &data.DataProof, @@ -251,7 +229,7 @@ func (g *Getter) getBlocks(ctx context.Context, cids []cid.Cid) ([]block.Block, if ctx.Err() != nil { return nil, ctx.Err() } - return nil, fmt.Errorf("not all shares were found") + return nil, fmt.Errorf("not all blocks were found") } return blks, nil diff --git a/share/shwap/row_id.go b/share/shwap/row_id.go index 5dd706f915..29309a3968 100644 --- a/share/shwap/row_id.go +++ b/share/shwap/row_id.go @@ -15,8 +15,6 @@ import ( "github.com/celestiaorg/celestia-node/share/store/file" ) -// TODO(@walldiss): maybe move into separate subpkg? - // RowIDSize is the size of the RowID in bytes const RowIDSize = EdsIDSize + 2 @@ -55,7 +53,6 @@ func RowIDFromCID(cid cid.Cid) (id RowID, err error) { if err != nil { return id, fmt.Errorf("while unmarhaling RowID: %w", err) } - return id, nil } @@ -123,6 +120,7 @@ func (rid RowID) Verify(root *share.Root) error { return nil } +// BlockFromFile returns the IPLD block of the RowID from the given file. func (rid RowID) BlockFromFile(ctx context.Context, f file.EdsFile) (blocks.Block, error) { axisHalf, err := f.AxisHalf(ctx, rsmt2d.Row, int(rid.RowIndex)) if err != nil { @@ -147,6 +145,7 @@ func (rid RowID) BlockFromFile(ctx context.Context, f file.EdsFile) (blocks.Bloc return blk, nil } +// Release releases the verifier of the RowID. func (rid RowID) Release() { rowVerifiers.Delete(rid) } diff --git a/share/shwap/sample_id.go b/share/shwap/sample_id.go index 36c8cdaf0b..63de58cb77 100644 --- a/share/shwap/sample_id.go +++ b/share/shwap/sample_id.go @@ -13,8 +13,6 @@ import ( "github.com/celestiaorg/celestia-node/share/store/file" ) -// TODO(@walldiss): maybe move into separate subpkg? - // SampleIDSize is the size of the SampleID in bytes const SampleIDSize = RowIDSize + 2 @@ -117,6 +115,7 @@ func (sid SampleID) Verify(root *share.Root) error { return sid.RowID.Verify(root) } +// BlockFromFile returns the IPLD block of the Sample. func (sid SampleID) BlockFromFile(ctx context.Context, f file.EdsFile) (blocks.Block, error) { shr, err := f.Share(ctx, int(sid.ShareIndex), int(sid.RowID.RowIndex)) if err != nil { @@ -131,6 +130,7 @@ func (sid SampleID) BlockFromFile(ctx context.Context, f file.EdsFile) (blocks.B return blk, nil } +// Release releases the verifier of the SampleID. func (sid SampleID) Release() { sampleVerifiers.Delete(sid) }