Skip to content

Commit

Permalink
address Hlibs comments
Browse files Browse the repository at this point in the history
  • Loading branch information
walldiss committed Mar 28, 2024
1 parent 84241a4 commit eef869d
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 45 deletions.
2 changes: 1 addition & 1 deletion nodebuilder/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ var outdatedConfig = `
PeersLimit = 5
DiscoveryInterval = "30s"
AdvertiseInterval = "30s"
UseShareExchange = true
UseShrEx = true
[Share.ShrExEDSParams]
ServerReadTimeout = "5s"
ServerWriteTimeout = "1m0s"
Expand Down
6 changes: 3 additions & 3 deletions nodebuilder/share/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
}

Expand Down
10 changes: 5 additions & 5 deletions nodebuilder/share/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion nodebuilder/tests/fraud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions nodebuilder/tests/reconstruct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions share/shwap/data_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
32 changes: 5 additions & 27 deletions share/shwap/getter/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions share/shwap/row_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
4 changes: 2 additions & 2 deletions share/shwap/sample_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}

0 comments on commit eef869d

Please sign in to comment.