Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewSisley committed Sep 23, 2024
1 parent 0b2a90d commit e587fe0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 16 additions & 0 deletions internal/core/block/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ type Encryption struct {
type Block struct {
// Delta is the CRDT delta that is stored in the block.
Delta crdt.CRDT

Heads []cidlink.Link

// Links are the links to other blocks in the DAG.
Links []DAGLink
// Encryption contains the encryption information for the block's delta.
Expand All @@ -142,6 +145,18 @@ func (block *Block) Clone() *Block {
}
}

func (block *Block) Links2() []cidlink.Link {
result := make([]cidlink.Link, 0, len(block.Heads)+len(block.Links))

result = append(result, block.Heads...)

for _, link := range block.Links {
result = append(result, link.Link)
}

return result
}

// GetHeadLinks returns the CIDs of the previous blocks. There can be more than 1 with multiple heads.
func (block *Block) GetHeadLinks() []cid.Cid {
var heads []cid.Cid
Expand All @@ -160,6 +175,7 @@ func (block *Block) IPLDSchemaBytes() []byte {
return []byte(`
type Block struct {
delta CRDT
heads [Link]
links [DAGLink]
encryption optional Link
}
Expand Down
4 changes: 2 additions & 2 deletions net/sync_dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func loadBlockLinks(ctx context.Context, lsys linking.LinkSystem, block *coreblo
cancel()
}

for _, lnk := range block.Links {
for _, lnk := range block.Links2() {
wg.Add(1)
go func(lnk coreblock.DAGLink) {
go func(lnk cidlink.Link) {
defer wg.Done()
if ctx.Err() != nil {
return
Expand Down

0 comments on commit e587fe0

Please sign in to comment.