Skip to content

Commit 3bfded3

Browse files
authored
Experimental as default (#67)
1 parent 009f99b commit 3bfded3

File tree

6 files changed

+54
-382
lines changed

6 files changed

+54
-382
lines changed

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"request": "launch",
1818
"mode": "auto",
1919
"program": "${workspaceFolder}/cmd/pinner/main.go",
20-
"buildFlags": ["-tags", "experimental"],
20+
// "buildFlags": ["-tags", "experimental"],
2121
"args": [
2222
"--w3-agent-key",
2323
"MgCY1PrWhMRwMBFuRpZMX2Ds7NyoHPnrDY3hrd54kWpS3ue0BR363tSycSPmI1YiaNkek4QXCsUjZ1cx80NcmuiHbsYs=", // sample key - change to your key

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,6 @@ Build binaries:
5858
make
5959
```
6060

61-
Note: To build das-pinner with experimental features (stacking erasure coded cells together), run:
62-
63-
```sh
64-
make build-pinner EXTRA_TAGS="-tags experimental"
65-
```
66-
6761
The binaries will be built in the `bin` directory.
6862

6963
### Clean Up

internal/pinner/ipfs-node/extract.go

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build !experimental
2-
31
package ipfsnode
42

53
import (
@@ -32,26 +30,26 @@ func (ipfsNode *IPFSNode) ExtractData(ctx context.Context, cidStr string) ([]byt
3230

3331
// Start processing each root link in parallel
3432
for i, link := range root.Links {
35-
// wg.Add(1)
36-
// go func(i int, link internal.Link) {
37-
// defer wg.Done()
38-
39-
// Fetch the next set of links (128 cells per link)
40-
var blobLinks []internal.Link
41-
if err := ipfsNode.GetData(ctx, link.CID, &blobLinks); err != nil {
42-
select {
43-
case errorChan <- err:
44-
default:
33+
wg.Add(1)
34+
go func(i int, link internal.Link) {
35+
defer wg.Done()
36+
37+
// Fetch the next set of links (128 cells per link)
38+
var blobLinks []internal.Link
39+
if err := ipfsNode.GetData(ctx, link.CID, &blobLinks); err != nil {
40+
select {
41+
case errorChan <- err:
42+
default:
43+
}
44+
return
4545
}
46-
// return
47-
}
4846

49-
// Download up to 64 cells from the blob links
50-
err := downloadCells(ctx, byteCells, ipfsNode, i, blobLinks, errorChan, 64)
51-
if err != nil {
52-
// return
53-
}
54-
// }(i, link)
47+
// Download up to 64 cells from the blob links
48+
err := downloadCells(ctx, byteCells, ipfsNode, i, blobLinks, errorChan, 64)
49+
if err != nil {
50+
return
51+
}
52+
}(i, link)
5553
}
5654

5755
// Goroutine to close error channel when all downloads are done
@@ -65,13 +63,14 @@ func (ipfsNode *IPFSNode) ExtractData(ctx context.Context, cidStr string) ([]byt
6563
case err := <-errorChan:
6664
// If an error occurs, cancel the remaining operations
6765
cancel()
68-
return nil, err
66+
if err != nil {
67+
return nil, err
68+
}
69+
// If no error, combine them into a block
70+
return combineDownloadedCells(root, byteCells)
6971
case <-ctx.Done():
7072
// If the context is canceled, return an error
7173
return nil, errors.New("context canceled")
72-
case <-errorChan:
73-
// All downloads completed successfully, combine them into a block
74-
return combineDownloadedCells(root, byteCells)
7574
}
7675
}
7776

@@ -103,16 +102,20 @@ func downloadCells(ctx context.Context, byteCells [][][]byte, ipfsNode *IPFSNode
103102
}
104103

105104
// Allocate space for each byte slice within the cell
106-
cellBytes := make([]byte, len(cell.Cell.Nested.Bytes))
105+
cellBytes := make([][2048]byte, len(cell.Cell.Nested.Bytes)/2048)
107106

108107
mu.Lock()
109108
defer mu.Unlock()
110109

111110
// Insert the cell at the correct index and increment the count
112111
if count < limit {
113-
copy(cellBytes, cell.Cell.Nested.Bytes)
114-
byteCells[blobIndex][i] = cellBytes
115-
count++
112+
for z := 0; z < len(cellBytes); z++ {
113+
copy(cellBytes[z][:], cell.Cell.Nested.Bytes[z*2048:(z+1)*2048])
114+
log.Debugf("Downloaded blob [%3d] cell [%3d] byte [%3d] stackSize", blobIndex, i, z, internal.StackSize)
115+
byteCells[blobIndex][i*internal.StackSize+z] = cellBytes[z][:]
116+
117+
count++
118+
}
116119

117120
log.Infof("Downloaded blob [%3d] cell [%3d] total [%3d/%3d]", blobIndex, i, count, limit)
118121
}

internal/pinner/ipfs-node/extract_experimental.go

Lines changed: 0 additions & 142 deletions
This file was deleted.

internal/pinner/ipld-encoder/encoder.go

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//go:build !experimental
2-
31
package ipldencoder
42

53
import (
@@ -59,36 +57,47 @@ func (b *IPLDDataBlock) Encode(block internal.DataBlock) error {
5957

6058
func (b *IPLDDataBlock) encodeDataNodes(block internal.DataBlock) error {
6159
_, nBlobs, nCells := block.Describe()
60+
cellsInNode := nCells / internal.StackSize
6261

6362
b.DataNodes = make([][]datamodel.Node, nBlobs)
6463
for nBlob := uint64(0); nBlob < nBlobs; nBlob++ {
65-
b.DataNodes[nBlob] = make([]datamodel.Node, nCells)
64+
b.DataNodes[nBlob] = make([]datamodel.Node, cellsInNode)
6665

67-
for nCell := uint64(0); nCell < nCells; nCell++ {
68-
proof, cell, err := block.ProofAndCell(nBlob, nCell)
69-
if err != nil {
70-
return err
66+
for nCellStack := uint64(0); nCellStack < cellsInNode; nCellStack++ {
67+
var stackedProof []byte
68+
var stackedCell []byte
69+
70+
for i := uint64(0); i < internal.StackSize; i++ {
71+
proof, cell, err := block.ProofAndCell(nBlob, nCellStack*internal.StackSize+i)
72+
if err != nil {
73+
return err
74+
}
75+
76+
stackedProof = append(stackedProof, proof...)
77+
stackedCell = append(stackedCell, cell...)
7178
}
7279

73-
node, err := createCellNode(proof, cell)
80+
node, err := createCellNode(stackedProof, stackedCell)
7481
if err != nil {
7582
return err
7683
}
7784

78-
b.DataNodes[nBlob][nCell] = node
85+
b.DataNodes[nBlob][nCellStack] = node
7986
}
8087
}
8188

8289
return nil
8390
}
8491

8592
func (b *IPLDDataBlock) encodeLinks(lsys *linking.LinkSystem, block internal.DataBlock) error {
86-
_, nBlobs, nCells := block.Describe()
93+
_, nBlobs, _ := block.Describe()
8794

8895
b.Links = make([][]datamodel.Link, nBlobs)
8996
for i := uint64(0); i < nBlobs; i++ {
97+
nCells := len(b.DataNodes[i])
98+
9099
b.Links[i] = make([]datamodel.Link, nCells)
91-
for j := uint64(0); j < nCells; j++ {
100+
for j := 0; j < nCells; j++ {
92101
link, err := b.createLink(lsys, b.DataNodes[i][j])
93102
if err != nil {
94103
return err
@@ -124,8 +133,8 @@ func (b *IPLDDataBlock) encodeRoot(lsys *linking.LinkSystem, block internal.Data
124133

125134
// Create the root DAG-CBOR object
126135
rootNode, err := qp.BuildMap(basicnode.Prototype.Map, -1, func(ma datamodel.MapAssembler) {
127-
qp.MapEntry(ma, "version", qp.String("v0.1.0"))
128-
qp.MapEntry(ma, "length", qp.Int(int64(nCell)))
136+
qp.MapEntry(ma, "version", qp.String("v0.2.0"))
137+
qp.MapEntry(ma, "length", qp.Int(int64(nCell/internal.StackSize)))
129138
qp.MapEntry(ma, "size", qp.Int(int64(size)))
130139
qp.MapEntry(ma, "commitments", qp.List(int64(nBlob), func(la ipld.ListAssembler) {
131140
for i := uint64(0); i < nBlob; i++ {

0 commit comments

Comments
 (0)