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

refactor coalescing logic into its own function, take both cancellation sets into account #5507

Merged
merged 1 commit into from
Feb 10, 2021
Merged
Changes from all commits
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
47 changes: 23 additions & 24 deletions chain/store/coalescer.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,50 +157,49 @@ func (c *HeadChangeCoalescer) coalesce(revert, apply []*types.TipSet) {
// coalesced revert set
// - pending reverts are cancelled by incoming applys
// - incoming reverts are cancelled by pending applys
newRevert := make([]*types.TipSet, 0, len(c.revert)+len(revert))
for _, ts := range c.revert {
_, cancel := applying[ts.Key()]
newRevert := c.merge(c.revert, revert, pendApply, applying)

// coalesced apply set
// - pending applys are cancelled by incoming reverts
// - incoming applys are cancelled by pending reverts
newApply := c.merge(c.apply, apply, pendRevert, reverting)

// commit the coalesced sets
c.revert = newRevert
c.apply = newApply
}

func (c *HeadChangeCoalescer) merge(pend, incoming []*types.TipSet, cancel1, cancel2 map[types.TipSetKey]struct{}) []*types.TipSet {
result := make([]*types.TipSet, 0, len(pend)+len(incoming))
for _, ts := range pend {
_, cancel := cancel1[ts.Key()]
if cancel {
continue
}

newRevert = append(newRevert, ts)
}

for _, ts := range revert {
_, cancel := pendApply[ts.Key()]
_, cancel = cancel2[ts.Key()]
if cancel {
continue
}

newRevert = append(newRevert, ts)
result = append(result, ts)
}

// coalesced apply set
// - pending applys are cancelled by incoming reverts
// - incoming applys are cancelled by pending reverts
newApply := make([]*types.TipSet, 0, len(c.apply)+len(apply))
for _, ts := range c.apply {
_, cancel := reverting[ts.Key()]
for _, ts := range incoming {
_, cancel := cancel1[ts.Key()]
if cancel {
continue
}

newApply = append(newApply, ts)
}

for _, ts := range apply {
_, cancel := pendRevert[ts.Key()]
_, cancel = cancel2[ts.Key()]
if cancel {
continue
}

newApply = append(newApply, ts)
result = append(result, ts)
}

// commit the coalesced sets
c.revert = newRevert
c.apply = newApply
return result
}

func (c *HeadChangeCoalescer) dispatch() {
Expand Down