Fix collectHeaders when incoming is partially built on latest tipset

This commit is contained in:
Aayush Rajasekaran 2020-08-06 02:24:29 -04:00
parent e372e7dc63
commit 6e8d51af02
2 changed files with 16 additions and 1 deletions

View File

@ -1265,7 +1265,7 @@ loop:
}
// base is the tipset in the candidate chain at the height equal to our known tipset height.
if base := blockSet[len(blockSet)-1]; !types.CidArrsEqual(base.Parents().Cids(), known.Cids()) {
if base := blockSet[len(blockSet)-1]; !types.CidArrsSubset(base.Parents().Cids(), known.Cids()) {
if base.Parents() == known.Parents() {
// common case: receiving a block thats potentially part of the same tipset as our best block
return blockSet, nil

View File

@ -175,6 +175,21 @@ func CidArrsEqual(a, b []cid.Cid) bool {
return true
}
func CidArrsSubset(a, b []cid.Cid) bool {
// order ignoring compare...
s := make(map[cid.Cid]bool)
for _, c := range b {
s[c] = true
}
for _, c := range a {
if !s[c] {
return false
}
}
return true
}
func CidArrsContains(a []cid.Cid, b cid.Cid) bool {
for _, elem := range a {
if elem.Equals(b) {