Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chainstore tipset leak #5037

Merged
merged 2 commits into from
Nov 30, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix cs.tipsets being unbounded
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
  • Loading branch information
Jakub Sztandera committed Nov 26, 2020
commit 13ff98416f394f54b0da7bfa63a45fc3bcda6095
18 changes: 16 additions & 2 deletions chain/store/store.go
Original file line number Diff line number Diff line change
@@ -733,11 +733,25 @@ func (cs *ChainStore) AddToTipSetTracker(b *types.BlockHeader) error {
}
}
}
// This function is called 5 times per epoch on average
// It is also called with tipsets that are done with initial validation
// so they cannot be from the future.
// We are guaranteed not to use tipsets older than 900 epochs (fork limit)
// This means that we ideally want to keep only most recent 900 epochs in here
// Golang's map iteration starts at a random point in a map.
// With 5 tries per epoch, and 900 entries to keep, on average we will have
// ~136 garbage entires in the `cs.tipsets` map. (solve for 1-(1-x/(900+x))^5 == 0.5)
// Seems good enough to me

for height := range cs.tipsets {
if height < b.Height-build.Finality {
delete(cs.tipsets, height)
}
break
}

cs.tipsets[b.Height] = append(tss, b.Cid())

// TODO: do we want to look for slashable submissions here? might as well...

return nil
}