From 7bbf1c7db2f5c6c2284f3911b1cf7ce3f2a41776 Mon Sep 17 00:00:00 2001 From: vyzo Date: Thu, 13 Aug 2020 10:28:56 +0300 Subject: [PATCH] don't mix negative performing chains with their parent, add some comments Signed-off-by: Jakub Sztandera --- chain/messagepool/selection.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chain/messagepool/selection.go b/chain/messagepool/selection.go index e38daf150..d1295afd4 100644 --- a/chain/messagepool/selection.go +++ b/chain/messagepool/selection.go @@ -177,6 +177,7 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64 for i := len(chainDeps) - 1; i >= 0; i-- { curChain := chainDeps[i] curChain.merged = true + // adjust the next chain for the parent, which is being merged if next := curChain.next; next != nil { next.effPerf += next.parentOffset } @@ -190,6 +191,7 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64 result = append(result, chain.msgs...) gasLimit -= chainGasLimit + // resort to account for already merged chains and effective performance adjustments sort.Slice(chains[i+1:], func(i, j int) bool { return chains[i].BeforeEffective(chains[j]) }) @@ -862,7 +864,7 @@ func (mc *msgChain) SetEffectivePerf(bp float64) { func (mc *msgChain) setEffPerf() { effPerf := mc.gasPerf * mc.bp - if mc.prev != nil { + if effPerf > 0 && mc.prev != nil { effPerfWithParent := (effPerf*float64(mc.gasLimit) + mc.prev.effPerf*float64(mc.prev.gasLimit)) / float64(mc.gasLimit+mc.prev.gasLimit) mc.parentOffset = effPerf - effPerfWithParent effPerf = effPerfWithParent @@ -880,7 +882,7 @@ func (mc *msgChain) SetNullEffectivePerf() { } func (mc *msgChain) BeforeEffective(other *msgChain) bool { - // moved merged chains to the front so we can discard them earlier + // move merged chains to the front so we can discard them earlier return (mc.merged && !other.merged) || mc.effPerf > other.effPerf || (mc.effPerf == other.effPerf && mc.gasPerf > other.gasPerf) || (mc.effPerf == other.effPerf && mc.gasPerf == other.gasPerf && mc.gasReward.Cmp(other.gasReward) > 0)