don't mix negative performing chains with their parent, add some comments

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
vyzo 2020-08-13 10:28:56 +03:00 committed by Jakub Sztandera
parent f35555964d
commit 7bbf1c7db2
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA

View File

@ -177,6 +177,7 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64
for i := len(chainDeps) - 1; i >= 0; i-- { for i := len(chainDeps) - 1; i >= 0; i-- {
curChain := chainDeps[i] curChain := chainDeps[i]
curChain.merged = true curChain.merged = true
// adjust the next chain for the parent, which is being merged
if next := curChain.next; next != nil { if next := curChain.next; next != nil {
next.effPerf += next.parentOffset next.effPerf += next.parentOffset
} }
@ -190,6 +191,7 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64
result = append(result, chain.msgs...) result = append(result, chain.msgs...)
gasLimit -= chainGasLimit gasLimit -= chainGasLimit
// resort to account for already merged chains and effective performance adjustments
sort.Slice(chains[i+1:], func(i, j int) bool { sort.Slice(chains[i+1:], func(i, j int) bool {
return chains[i].BeforeEffective(chains[j]) return chains[i].BeforeEffective(chains[j])
}) })
@ -862,7 +864,7 @@ func (mc *msgChain) SetEffectivePerf(bp float64) {
func (mc *msgChain) setEffPerf() { func (mc *msgChain) setEffPerf() {
effPerf := mc.gasPerf * mc.bp 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) effPerfWithParent := (effPerf*float64(mc.gasLimit) + mc.prev.effPerf*float64(mc.prev.gasLimit)) / float64(mc.gasLimit+mc.prev.gasLimit)
mc.parentOffset = effPerf - effPerfWithParent mc.parentOffset = effPerf - effPerfWithParent
effPerf = effPerfWithParent effPerf = effPerfWithParent
@ -880,7 +882,7 @@ func (mc *msgChain) SetNullEffectivePerf() {
} }
func (mc *msgChain) BeforeEffective(other *msgChain) bool { 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 || 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.effPerf == other.effPerf && mc.gasPerf == other.gasPerf && mc.gasReward.Cmp(other.gasReward) > 0) (mc.effPerf == other.effPerf && mc.gasPerf == other.gasPerf && mc.gasReward.Cmp(other.gasReward) > 0)