Skip to content

Commit 17f4c17

Browse files
committed
dedup keys in GetMany
Otherwise, GetMany on the children of a node with duplicate links may fail License: MIT Signed-off-by: Steven Allen <[email protected]>
1 parent 5044152 commit 17f4c17

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

merkledag.go

+13
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,20 @@ func (n *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.
201201
return getNodesFromBG(ctx, n.Blocks, keys)
202202
}
203203

204+
func dedupKeys(keys []*cid.Cid) []*cid.Cid {
205+
set := cid.NewSet()
206+
for _, c := range keys {
207+
set.Add(c)
208+
}
209+
if set.Len() == len(keys) {
210+
return keys
211+
}
212+
return set.Keys()
213+
}
214+
204215
func getNodesFromBG(ctx context.Context, bs bserv.BlockGetter, keys []*cid.Cid) <-chan *ipld.NodeOption {
216+
keys = dedupKeys(keys)
217+
205218
out := make(chan *ipld.NodeOption, len(keys))
206219
blocks := bs.GetBlocks(ctx, keys)
207220
var count int

0 commit comments

Comments
 (0)