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

temporarily allow negative chains #3625

Merged
merged 5 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion chain/messagepool/messagepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ const (
localUpdates = "update"
)

// this is *temporary* mutilation until we have implemented uncapped miner penalties -- it will go
// away in the next fork.
var strictBaseFeeValidation = false

func init() {
// if the republish interval is too short compared to the pubsub timecache, adjust it
minInterval := pubsub.TimeCacheDuration + time.Duration(build.PropagationDelaySecs)
Expand Down Expand Up @@ -389,7 +393,7 @@ func (mp *MessagePool) verifyMsgBeforeAdd(m *types.SignedMessage, curTs *types.T
// Note that for local messages, we always add them so that they can be accepted and republished
// automatically.
publish := local
if len(curTs.Blocks()) > 0 {
if strictBaseFeeValidation && len(curTs.Blocks()) > 0 {
baseFee := curTs.Blocks()[0].ParentBaseFee
baseFeeLowerBound := types.BigDiv(baseFee, baseFeeLowerBoundFactor)
if m.Message.GasFeeCap.LessThan(baseFeeLowerBound) {
Expand Down
2 changes: 1 addition & 1 deletion chain/messagepool/repub.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ loop:
// check the baseFee lower bound -- only republish messages that can be included in the chain
// within the next 20 blocks.
for _, m := range chain.msgs {
if m.Message.GasFeeCap.LessThan(baseFeeLowerBound) {
if !allowNegativeChains(ts.Height()) && m.Message.GasFeeCap.LessThan(baseFeeLowerBound) {
chain.Invalidate()
continue loop
}
Expand Down
33 changes: 20 additions & 13 deletions chain/messagepool/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"golang.org/x/xerrors"

"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
tbig "github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/build"
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
Expand All @@ -18,6 +19,12 @@ import (

var bigBlockGasLimit = big.NewInt(build.BlockGasLimit)

// this is *temporary* mutilation until we have implemented uncapped miner penalties -- it will go
// away in the next fork.
func allowNegativeChains(epoch abi.ChainEpoch) bool {
return epoch < build.BreezeGasTampingDuration+5
}

const MaxBlocks = 15

type msgChain struct {
Expand Down Expand Up @@ -100,7 +107,7 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64
return chains[i].Before(chains[j])
})

if 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)
return result, nil
}
Expand Down Expand Up @@ -153,7 +160,7 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64
last := len(chains)
for i, chain := range chains {
// did we run out of performing chains?
if chain.gasPerf < 0 {
if !allowNegativeChains(curTs.Height()) && chain.gasPerf < 0 {
break
}

Expand Down Expand Up @@ -217,7 +224,7 @@ tailLoop:
for gasLimit >= minGas && last < len(chains) {
// trim if necessary
if chains[last].gasLimit > gasLimit {
chains[last].Trim(gasLimit, mp, baseFee, false)
chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains(curTs.Height()))
}

// push down if it hasn't been invalidated
Expand All @@ -243,7 +250,7 @@ tailLoop:
}

// if gasPerf < 0 we have no more profitable chains
if chain.gasPerf < 0 {
if !allowNegativeChains(curTs.Height()) && chain.gasPerf < 0 {
break tailLoop
}

Expand Down Expand Up @@ -284,7 +291,7 @@ tailLoop:
}

// dependencies fit, just trim it
chain.Trim(gasLimit-depGasLimit, mp, baseFee, false)
chain.Trim(gasLimit-depGasLimit, mp, baseFee, allowNegativeChains(curTs.Height()))
last += i
continue tailLoop
}
Expand Down Expand Up @@ -349,7 +356,7 @@ func (mp *MessagePool) selectMessagesGreedy(curTs, ts *types.TipSet) ([]*types.S
return chains[i].Before(chains[j])
})

if 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)
return result, nil
}
Expand All @@ -360,7 +367,7 @@ func (mp *MessagePool) selectMessagesGreedy(curTs, ts *types.TipSet) ([]*types.S
last := len(chains)
for i, chain := range chains {
// did we run out of performing chains?
if chain.gasPerf < 0 {
if !allowNegativeChains(curTs.Height()) && chain.gasPerf < 0 {
break
}

Expand Down Expand Up @@ -389,7 +396,7 @@ func (mp *MessagePool) selectMessagesGreedy(curTs, ts *types.TipSet) ([]*types.S
tailLoop:
for gasLimit >= minGas && last < len(chains) {
// trim
chains[last].Trim(gasLimit, mp, baseFee, false)
chains[last].Trim(gasLimit, mp, baseFee, allowNegativeChains(curTs.Height()))

// push down if it hasn't been invalidated
if chains[last].valid {
Expand All @@ -409,7 +416,7 @@ tailLoop:
}

// if gasPerf < 0 we have no more profitable chains
if chain.gasPerf < 0 {
if !allowNegativeChains(curTs.Height()) && chain.gasPerf < 0 {
break tailLoop
}

Expand Down Expand Up @@ -471,15 +478,15 @@ func (mp *MessagePool) selectPriorityMessages(pending map[address.Address]map[ui
return chains[i].Before(chains[j])
})

if 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)
return nil, gasLimit
}

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

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

// push down if it hasn't been invalidated
if chains[last].valid {
Expand All @@ -517,7 +524,7 @@ tailLoop:
}

// if gasPerf < 0 we have no more profitable chains
if chain.gasPerf < 0 {
if !allowNegativeChains(ts.Height()) && chain.gasPerf < 0 {
break tailLoop
}

Expand Down
2 changes: 2 additions & 0 deletions chain/messagepool/selection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,8 @@ func TestPriorityMessageSelection2(t *testing.T) {
}

func TestPriorityMessageSelection3(t *testing.T) {
t.Skip("reenable after removing allow negative")

mp, tma := makeTestMpool()

// the actors
Expand Down