fix republishing chain selection to account for edge case of inordinately long chains
This commit is contained in:
parent
7b16fe3792
commit
472e502218
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/filecoin-project/go-address"
|
"github.com/filecoin-project/go-address"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/chain/messagepool/gasguess"
|
||||||
"github.com/filecoin-project/lotus/chain/types"
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -68,26 +69,50 @@ func (mp *MessagePool) republishPendingMessages() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gasLimit := int64(build.BlockGasLimit)
|
gasLimit := int64(build.BlockGasLimit)
|
||||||
|
minGas := int64(gasguess.MinGas)
|
||||||
var msgs []*types.SignedMessage
|
var msgs []*types.SignedMessage
|
||||||
for _, chain := range chains {
|
for i := 0; i < len(chains); {
|
||||||
|
chain := chains[i]
|
||||||
|
|
||||||
// we can exceed this if we have picked (some) longer chain already
|
// we can exceed this if we have picked (some) longer chain already
|
||||||
if len(msgs) > repubMsgLimit {
|
if len(msgs) > repubMsgLimit {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// there is not enough gas for any message
|
||||||
|
if gasLimit <= minGas {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// we don't republish negative performing chains, as they won't be included in
|
// we don't republish negative performing chains, as they won't be included in
|
||||||
// a block anyway
|
// a block anyway
|
||||||
if chain.gasPerf < 0 {
|
if chain.gasPerf < 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// we don't exceed the block gasLimit in our republish endeavor
|
// has the chain been invalidated?
|
||||||
if chain.gasLimit > gasLimit {
|
if !chain.valid {
|
||||||
break
|
i++
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
gasLimit -= chain.gasLimit
|
// does it fit in a block?
|
||||||
msgs = append(msgs, chain.msgs...)
|
if chain.gasLimit <= gasLimit {
|
||||||
|
gasLimit -= chain.gasLimit
|
||||||
|
msgs = append(msgs, chain.msgs...)
|
||||||
|
i++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// we can't fit the current chain but there is gas to spare
|
||||||
|
// trim it and push it down
|
||||||
|
chain.Trim(gasLimit, mp, baseFee, ts, false)
|
||||||
|
for j := i; j < len(chains)-1; j++ {
|
||||||
|
if chains[j].Before(chains[j+1]) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
chains[j], chains[j+1] = chains[j+1], chains[j]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("republishing %d messages", len(msgs))
|
log.Infof("republishing %d messages", len(msgs))
|
||||||
|
Loading…
Reference in New Issue
Block a user