Skip to content

Commit 9f25d1e

Browse files
committed
Make allowNegativeChains a function
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
1 parent bd6c7f8 commit 9f25d1e

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

chain/messagepool/repub.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ loop:
100100
// check the baseFee lower bound -- only republish messages that can be included in the chain
101101
// within the next 20 blocks.
102102
for _, m := range chain.msgs {
103-
if !allowNegativeChains && m.Message.GasFeeCap.LessThan(baseFeeLowerBound) {
103+
if !allowNegativeChains(ts.Height()) && m.Message.GasFeeCap.LessThan(baseFeeLowerBound) {
104104
chain.Invalidate()
105105
continue loop
106106
}

chain/messagepool/selection.go

+17-14
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ import (
1414
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
1515
"github.com/filecoin-project/lotus/chain/types"
1616
"github.com/filecoin-project/lotus/chain/vm"
17+
"github.com/filecoin-project/specs-actors/actors/abi"
1718
)
1819

1920
var bigBlockGasLimit = big.NewInt(build.BlockGasLimit)
2021

2122
// this is *temporary* mutilation until we have implemented uncapped miner penalties -- it will go
2223
// away in the next fork.
23-
var allowNegativeChains = true
24+
func allowNegativeChains(epoch abi.ChainEpoch) bool {
25+
return epoch < 100000000000
26+
}
2427

2528
const MaxBlocks = 15
2629

@@ -104,7 +107,7 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64
104107
return chains[i].Before(chains[j])
105108
})
106109

107-
if !allowNegativeChains && len(chains) != 0 && chains[0].gasPerf < 0 {
110+
if !allowNegativeChains(curTs.Height()) && len(chains) != 0 && chains[0].gasPerf < 0 {
108111
log.Warnw("all messages in mpool have non-positive gas performance", "bestGasPerf", chains[0].gasPerf)
109112
return result, nil
110113
}
@@ -157,7 +160,7 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64
157160
last := len(chains)
158161
for i, chain := range chains {
159162
// did we run out of performing chains?
160-
if !allowNegativeChains && chain.gasPerf < 0 {
163+
if !allowNegativeChains(curTs.Height()) && chain.gasPerf < 0 {
161164
break
162165
}
163166

@@ -221,7 +224,7 @@ tailLoop:
221224
for gasLimit >= minGas && last < len(chains) {
222225
// trim if necessary
223226
if chains[last].gasLimit > gasLimit {
224-
chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains)
227+
chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains(curTs.Height()))
225228
}
226229

227230
// push down if it hasn't been invalidated
@@ -247,7 +250,7 @@ tailLoop:
247250
}
248251

249252
// if gasPerf < 0 we have no more profitable chains
250-
if !allowNegativeChains && chain.gasPerf < 0 {
253+
if !allowNegativeChains(curTs.Height()) && chain.gasPerf < 0 {
251254
break tailLoop
252255
}
253256

@@ -288,7 +291,7 @@ tailLoop:
288291
}
289292

290293
// dependencies fit, just trim it
291-
chain.Trim(gasLimit-depGasLimit, mp, baseFee, allowNegativeChains)
294+
chain.Trim(gasLimit-depGasLimit, mp, baseFee, allowNegativeChains(curTs.Height()))
292295
last += i
293296
continue tailLoop
294297
}
@@ -353,7 +356,7 @@ func (mp *MessagePool) selectMessagesGreedy(curTs, ts *types.TipSet) ([]*types.S
353356
return chains[i].Before(chains[j])
354357
})
355358

356-
if !allowNegativeChains && len(chains) != 0 && chains[0].gasPerf < 0 {
359+
if !allowNegativeChains(curTs.Height()) && len(chains) != 0 && chains[0].gasPerf < 0 {
357360
log.Warnw("all messages in mpool have non-positive gas performance", "bestGasPerf", chains[0].gasPerf)
358361
return result, nil
359362
}
@@ -364,7 +367,7 @@ func (mp *MessagePool) selectMessagesGreedy(curTs, ts *types.TipSet) ([]*types.S
364367
last := len(chains)
365368
for i, chain := range chains {
366369
// did we run out of performing chains?
367-
if !allowNegativeChains && chain.gasPerf < 0 {
370+
if !allowNegativeChains(curTs.Height()) && chain.gasPerf < 0 {
368371
break
369372
}
370373

@@ -393,7 +396,7 @@ func (mp *MessagePool) selectMessagesGreedy(curTs, ts *types.TipSet) ([]*types.S
393396
tailLoop:
394397
for gasLimit >= minGas && last < len(chains) {
395398
// trim
396-
chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains)
399+
chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains(curTs.Height()))
397400

398401
// push down if it hasn't been invalidated
399402
if chains[last].valid {
@@ -413,7 +416,7 @@ tailLoop:
413416
}
414417

415418
// if gasPerf < 0 we have no more profitable chains
416-
if !allowNegativeChains && chain.gasPerf < 0 {
419+
if !allowNegativeChains(curTs.Height()) && chain.gasPerf < 0 {
417420
break tailLoop
418421
}
419422

@@ -475,15 +478,15 @@ func (mp *MessagePool) selectPriorityMessages(pending map[address.Address]map[ui
475478
return chains[i].Before(chains[j])
476479
})
477480

478-
if !allowNegativeChains && len(chains) != 0 && chains[0].gasPerf < 0 {
481+
if !allowNegativeChains(ts.Height()) && len(chains) != 0 && chains[0].gasPerf < 0 {
479482
log.Warnw("all priority messages in mpool have negative gas performance", "bestGasPerf", chains[0].gasPerf)
480483
return nil, gasLimit
481484
}
482485

483486
// 3. Merge chains until the block limit, as long as they have non-negative gas performance
484487
last := len(chains)
485488
for i, chain := range chains {
486-
if !allowNegativeChains && chain.gasPerf < 0 {
489+
if !allowNegativeChains(ts.Height()) && chain.gasPerf < 0 {
487490
break
488491
}
489492

@@ -501,7 +504,7 @@ func (mp *MessagePool) selectPriorityMessages(pending map[address.Address]map[ui
501504
tailLoop:
502505
for gasLimit >= minGas && last < len(chains) {
503506
// trim, discarding negative performing messages
504-
chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains)
507+
chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains(ts.Height()))
505508

506509
// push down if it hasn't been invalidated
507510
if chains[last].valid {
@@ -521,7 +524,7 @@ tailLoop:
521524
}
522525

523526
// if gasPerf < 0 we have no more profitable chains
524-
if !allowNegativeChains && chain.gasPerf < 0 {
527+
if !allowNegativeChains(ts.Height()) && chain.gasPerf < 0 {
525528
break tailLoop
526529
}
527530

chain/messagepool/selection_test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -729,10 +729,7 @@ func TestPriorityMessageSelection2(t *testing.T) {
729729
}
730730

731731
func TestPriorityMessageSelection3(t *testing.T) {
732-
allowNegativeChains = false
733-
defer func() {
734-
allowNegativeChains = true
735-
}()
732+
t.Skip("reenable after removing allow negative")
736733

737734
mp, tma := makeTestMpool()
738735

0 commit comments

Comments
 (0)