Commit b7d8fdef authored by Jeromy's avatar Jeromy

hotfix: duplicate blocks werent being counted properly, deduped key list before requesting

parent 0c12b7a0
...@@ -180,17 +180,24 @@ func (ds *dagService) GetDAG(ctx context.Context, root *Node) []NodeGetter { ...@@ -180,17 +180,24 @@ func (ds *dagService) GetDAG(ctx context.Context, root *Node) []NodeGetter {
// GetNodes returns an array of 'NodeGetter' promises, with each corresponding // GetNodes returns an array of 'NodeGetter' promises, with each corresponding
// to the key with the same index as the passed in keys // to the key with the same index as the passed in keys
func (ds *dagService) GetNodes(ctx context.Context, keys []u.Key) []NodeGetter { func (ds *dagService) GetNodes(ctx context.Context, keys []u.Key) []NodeGetter {
// Early out if no work to do
if len(keys) == 0 {
return nil
}
promises := make([]NodeGetter, len(keys)) promises := make([]NodeGetter, len(keys))
sendChans := make([]chan<- *Node, len(keys)) sendChans := make([]chan<- *Node, len(keys))
for i, _ := range keys { for i, _ := range keys {
promises[i], sendChans[i] = newNodePromise(ctx) promises[i], sendChans[i] = newNodePromise(ctx)
} }
dedupedKeys := dedupeKeys(keys)
go func() { go func() {
ctx, cancel := context.WithCancel(ctx) ctx, cancel := context.WithCancel(ctx)
defer cancel() defer cancel()
blkchan := ds.Blocks.GetBlocks(ctx, keys) blkchan := ds.Blocks.GetBlocks(ctx, dedupedKeys)
for count := 0; count < len(keys); { for count := 0; count < len(keys); {
select { select {
...@@ -207,8 +214,8 @@ func (ds *dagService) GetNodes(ctx context.Context, keys []u.Key) []NodeGetter { ...@@ -207,8 +214,8 @@ func (ds *dagService) GetNodes(ctx context.Context, keys []u.Key) []NodeGetter {
} }
is := FindLinks(keys, blk.Key(), 0) is := FindLinks(keys, blk.Key(), 0)
for _, i := range is { for _, i := range is {
sendChans[i] <- nd
count++ count++
sendChans[i] <- nd
} }
case <-ctx.Done(): case <-ctx.Done():
return return
...@@ -218,6 +225,19 @@ func (ds *dagService) GetNodes(ctx context.Context, keys []u.Key) []NodeGetter { ...@@ -218,6 +225,19 @@ func (ds *dagService) GetNodes(ctx context.Context, keys []u.Key) []NodeGetter {
return promises return promises
} }
// Remove duplicates from a list of keys
func dedupeKeys(ks []u.Key) []u.Key {
kmap := make(map[u.Key]struct{})
var out []u.Key
for _, k := range ks {
if _, ok := kmap[k]; !ok {
kmap[k] = struct{}{}
out = append(out, k)
}
}
return out
}
func newNodePromise(ctx context.Context) (NodeGetter, chan<- *Node) { func newNodePromise(ctx context.Context) (NodeGetter, chan<- *Node) {
ch := make(chan *Node, 1) ch := make(chan *Node, 1)
return &nodePromise{ return &nodePromise{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment