Fix incorrect ID CID optimization

Blocks inlined into CIDs can technically contain CIDs themselves. I'm guessing
this check was trying to skip "actor" CIDs (inline cids with raw blocks).
This commit is contained in:
Steven Allen 2020-07-23 23:15:26 -07:00
parent b7a4dbb07f
commit bb54dc97b6

View File

@ -547,6 +547,9 @@ func linksForObj(blk block.Block, cb func(cid.Cid)) error {
return xerrors.Errorf("cbg.ScanForLinks: %w", err) return xerrors.Errorf("cbg.ScanForLinks: %w", err)
} }
return nil return nil
case cid.Raw:
// We implicitly have all children of raw blocks.
return nil
default: default:
return xerrors.Errorf("vm flush copy method only supports dag cbor") return xerrors.Errorf("vm flush copy method only supports dag cbor")
} }
@ -596,17 +599,27 @@ func copyRec(from, to blockstore.Blockstore, root cid.Cid, cp func(block.Block)
return return
} }
if link.Prefix().MhType == mh.IDENTITY || link.Prefix().Codec == cid.FilCommitmentSealed || link.Prefix().Codec == cid.FilCommitmentUnsealed { prefix := link.Prefix()
if prefix.Codec == cid.FilCommitmentSealed || prefix.Codec == cid.FilCommitmentUnsealed {
return return
} }
has, err := to.Has(link) // We always have blocks inlined into CIDs, but we may not have their children.
if err != nil { if prefix.MhType == mh.IDENTITY {
lerr = xerrors.Errorf("has: %w", err) // Unless the inlined block has no children.
return if prefix.Codec == cid.Raw {
} return
if has { }
return } else {
// If we have an object, we already have its children, skip the object.
has, err := to.Has(link)
if err != nil {
lerr = xerrors.Errorf("has: %w", err)
return
}
if has {
return
}
} }
if err := copyRec(from, to, link, cp); err != nil { if err := copyRec(from, to, link, cp); err != nil {