Make allowNegativeChains a function

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-09-07 21:41:23 +02:00
parent 172ff846fd
commit 835b7eb6f7
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
3 changed files with 19 additions and 19 deletions

View File

@ -100,7 +100,7 @@ loop:
// check the baseFee lower bound -- only republish messages that can be included in the chain // check the baseFee lower bound -- only republish messages that can be included in the chain
// within the next 20 blocks. // within the next 20 blocks.
for _, m := range chain.msgs { for _, m := range chain.msgs {
if !allowNegativeChains && m.Message.GasFeeCap.LessThan(baseFeeLowerBound) { if !allowNegativeChains(ts.Height()) && m.Message.GasFeeCap.LessThan(baseFeeLowerBound) {
chain.Invalidate() chain.Invalidate()
continue loop continue loop
} }

View File

@ -14,13 +14,16 @@ import (
"github.com/filecoin-project/lotus/chain/messagepool/gasguess" "github.com/filecoin-project/lotus/chain/messagepool/gasguess"
"github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/vm" "github.com/filecoin-project/lotus/chain/vm"
"github.com/filecoin-project/specs-actors/actors/abi"
) )
var bigBlockGasLimit = big.NewInt(build.BlockGasLimit) var bigBlockGasLimit = big.NewInt(build.BlockGasLimit)
// this is *temporary* mutilation until we have implemented uncapped miner penalties -- it will go // this is *temporary* mutilation until we have implemented uncapped miner penalties -- it will go
// away in the next fork. // away in the next fork.
var allowNegativeChains = true func allowNegativeChains(epoch abi.ChainEpoch) bool {
return epoch < 100000000000
}
const MaxBlocks = 15 const MaxBlocks = 15
@ -104,7 +107,7 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64
return chains[i].Before(chains[j]) return chains[i].Before(chains[j])
}) })
if !allowNegativeChains && len(chains) != 0 && chains[0].gasPerf < 0 { if !allowNegativeChains(curTs.Height()) && len(chains) != 0 && chains[0].gasPerf < 0 {
log.Warnw("all messages in mpool have non-positive gas performance", "bestGasPerf", chains[0].gasPerf) log.Warnw("all messages in mpool have non-positive gas performance", "bestGasPerf", chains[0].gasPerf)
return result, nil return result, nil
} }
@ -157,7 +160,7 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64
last := len(chains) last := len(chains)
for i, chain := range chains { for i, chain := range chains {
// did we run out of performing chains? // did we run out of performing chains?
if !allowNegativeChains && chain.gasPerf < 0 { if !allowNegativeChains(curTs.Height()) && chain.gasPerf < 0 {
break break
} }
@ -221,7 +224,7 @@ tailLoop:
for gasLimit >= minGas && last < len(chains) { for gasLimit >= minGas && last < len(chains) {
// trim if necessary // trim if necessary
if chains[last].gasLimit > gasLimit { if chains[last].gasLimit > gasLimit {
chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains) chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains(curTs.Height()))
} }
// push down if it hasn't been invalidated // push down if it hasn't been invalidated
@ -247,7 +250,7 @@ tailLoop:
} }
// if gasPerf < 0 we have no more profitable chains // if gasPerf < 0 we have no more profitable chains
if !allowNegativeChains && chain.gasPerf < 0 { if !allowNegativeChains(curTs.Height()) && chain.gasPerf < 0 {
break tailLoop break tailLoop
} }
@ -288,7 +291,7 @@ tailLoop:
} }
// dependencies fit, just trim it // dependencies fit, just trim it
chain.Trim(gasLimit-depGasLimit, mp, baseFee, allowNegativeChains) chain.Trim(gasLimit-depGasLimit, mp, baseFee, allowNegativeChains(curTs.Height()))
last += i last += i
continue tailLoop continue tailLoop
} }
@ -353,7 +356,7 @@ func (mp *MessagePool) selectMessagesGreedy(curTs, ts *types.TipSet) ([]*types.S
return chains[i].Before(chains[j]) return chains[i].Before(chains[j])
}) })
if !allowNegativeChains && len(chains) != 0 && chains[0].gasPerf < 0 { if !allowNegativeChains(curTs.Height()) && len(chains) != 0 && chains[0].gasPerf < 0 {
log.Warnw("all messages in mpool have non-positive gas performance", "bestGasPerf", chains[0].gasPerf) log.Warnw("all messages in mpool have non-positive gas performance", "bestGasPerf", chains[0].gasPerf)
return result, nil return result, nil
} }
@ -364,7 +367,7 @@ func (mp *MessagePool) selectMessagesGreedy(curTs, ts *types.TipSet) ([]*types.S
last := len(chains) last := len(chains)
for i, chain := range chains { for i, chain := range chains {
// did we run out of performing chains? // did we run out of performing chains?
if !allowNegativeChains && chain.gasPerf < 0 { if !allowNegativeChains(curTs.Height()) && chain.gasPerf < 0 {
break break
} }
@ -393,7 +396,7 @@ func (mp *MessagePool) selectMessagesGreedy(curTs, ts *types.TipSet) ([]*types.S
tailLoop: tailLoop:
for gasLimit >= minGas && last < len(chains) { for gasLimit >= minGas && last < len(chains) {
// trim // trim
chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains) chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains(curTs.Height()))
// push down if it hasn't been invalidated // push down if it hasn't been invalidated
if chains[last].valid { if chains[last].valid {
@ -413,7 +416,7 @@ tailLoop:
} }
// if gasPerf < 0 we have no more profitable chains // if gasPerf < 0 we have no more profitable chains
if !allowNegativeChains && chain.gasPerf < 0 { if !allowNegativeChains(curTs.Height()) && chain.gasPerf < 0 {
break tailLoop break tailLoop
} }
@ -475,7 +478,7 @@ func (mp *MessagePool) selectPriorityMessages(pending map[address.Address]map[ui
return chains[i].Before(chains[j]) return chains[i].Before(chains[j])
}) })
if !allowNegativeChains && len(chains) != 0 && chains[0].gasPerf < 0 { if !allowNegativeChains(ts.Height()) && len(chains) != 0 && chains[0].gasPerf < 0 {
log.Warnw("all priority messages in mpool have negative gas performance", "bestGasPerf", chains[0].gasPerf) log.Warnw("all priority messages in mpool have negative gas performance", "bestGasPerf", chains[0].gasPerf)
return nil, gasLimit return nil, gasLimit
} }
@ -483,7 +486,7 @@ func (mp *MessagePool) selectPriorityMessages(pending map[address.Address]map[ui
// 3. Merge chains until the block limit, as long as they have non-negative gas performance // 3. Merge chains until the block limit, as long as they have non-negative gas performance
last := len(chains) last := len(chains)
for i, chain := range chains { for i, chain := range chains {
if !allowNegativeChains && chain.gasPerf < 0 { if !allowNegativeChains(ts.Height()) && chain.gasPerf < 0 {
break break
} }
@ -501,7 +504,7 @@ func (mp *MessagePool) selectPriorityMessages(pending map[address.Address]map[ui
tailLoop: tailLoop:
for gasLimit >= minGas && last < len(chains) { for gasLimit >= minGas && last < len(chains) {
// trim, discarding negative performing messages // trim, discarding negative performing messages
chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains) chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains(ts.Height()))
// push down if it hasn't been invalidated // push down if it hasn't been invalidated
if chains[last].valid { if chains[last].valid {
@ -521,7 +524,7 @@ tailLoop:
} }
// if gasPerf < 0 we have no more profitable chains // if gasPerf < 0 we have no more profitable chains
if !allowNegativeChains && chain.gasPerf < 0 { if !allowNegativeChains(ts.Height()) && chain.gasPerf < 0 {
break tailLoop break tailLoop
} }

View File

@ -729,10 +729,7 @@ func TestPriorityMessageSelection2(t *testing.T) {
} }
func TestPriorityMessageSelection3(t *testing.T) { func TestPriorityMessageSelection3(t *testing.T) {
allowNegativeChains = false t.Skip("reenable after removing allow negative")
defer func() {
allowNegativeChains = true
}()
mp, tma := makeTestMpool() mp, tma := makeTestMpool()