Fix getGasReward and Trim
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
4da3aedacb
commit
56e3f7da7d
@ -111,13 +111,14 @@ func (mp *MessagePool) selectMessagesOptimal(curTs, ts *types.TipSet, tq float64
|
|||||||
gasLimit := int64(build.BlockGasLimit)
|
gasLimit := int64(build.BlockGasLimit)
|
||||||
for nextChain < len(chains) {
|
for nextChain < len(chains) {
|
||||||
chain := chains[nextChain]
|
chain := chains[nextChain]
|
||||||
partitions[i] = append(partitions[i], chain)
|
|
||||||
nextChain++
|
nextChain++
|
||||||
|
partitions[i] = append(partitions[i], chain)
|
||||||
gasLimit -= chain.gasLimit
|
gasLimit -= chain.gasLimit
|
||||||
if gasLimit < minGas {
|
if gasLimit < minGas {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Compute effective performance for each chain, based on the partition they fall into
|
// 4. Compute effective performance for each chain, based on the partition they fall into
|
||||||
@ -606,11 +607,11 @@ func (mp *MessagePool) getPendingMessages(curTs, ts *types.TipSet) (map[address.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mp *MessagePool) getGasReward(msg *types.SignedMessage, baseFee types.BigInt, ts *types.TipSet) *big.Int {
|
func (mp *MessagePool) getGasReward(msg *types.SignedMessage, baseFee types.BigInt, ts *types.TipSet) *big.Int {
|
||||||
gasReward := abig.Mul(msg.Message.GasPremium, types.NewInt(uint64(msg.Message.GasLimit)))
|
maxPremium := types.BigSub(msg.Message.GasFeeCap, baseFee)
|
||||||
maxReward := types.BigSub(msg.Message.GasFeeCap, baseFee)
|
if types.BigCmp(maxPremium, msg.Message.GasPremium) < 0 {
|
||||||
if types.BigCmp(maxReward, gasReward) < 0 {
|
maxPremium = msg.Message.GasPremium
|
||||||
gasReward = maxReward
|
|
||||||
}
|
}
|
||||||
|
gasReward := abig.Mul(maxPremium, types.NewInt(uint64(msg.Message.GasLimit)))
|
||||||
return gasReward.Int
|
return gasReward.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -795,7 +796,13 @@ func (mc *msgChain) Trim(gasLimit int64, mp *MessagePool, baseFee types.BigInt,
|
|||||||
mc.gasReward = new(big.Int).Sub(mc.gasReward, gasReward)
|
mc.gasReward = new(big.Int).Sub(mc.gasReward, gasReward)
|
||||||
mc.gasLimit -= mc.msgs[i].Message.GasLimit
|
mc.gasLimit -= mc.msgs[i].Message.GasLimit
|
||||||
if mc.gasLimit > 0 {
|
if mc.gasLimit > 0 {
|
||||||
|
bp := 1.0
|
||||||
|
if mc.effPerf != 0 {
|
||||||
|
bp = mc.effPerf / mc.gasPerf
|
||||||
|
}
|
||||||
|
|
||||||
mc.gasPerf = mp.getGasPerf(mc.gasReward, mc.gasLimit)
|
mc.gasPerf = mp.getGasPerf(mc.gasReward, mc.gasLimit)
|
||||||
|
mc.effPerf = bp * mc.gasPerf
|
||||||
} else {
|
} else {
|
||||||
mc.gasPerf = 0
|
mc.gasPerf = 0
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
|
_ "github.com/filecoin-project/lotus/lib/sigs/bls"
|
||||||
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
_ "github.com/filecoin-project/lotus/lib/sigs/secp"
|
||||||
|
logging "github.com/ipfs/go-log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func makeTestMessage(w *wallet.Wallet, from, to address.Address, nonce uint64, gasLimit int64, gasPrice uint64) *types.SignedMessage {
|
func makeTestMessage(w *wallet.Wallet, from, to address.Address, nonce uint64, gasLimit int64, gasPrice uint64) *types.SignedMessage {
|
||||||
@ -930,8 +931,10 @@ func testCompetitiveMessageSelection(t *testing.T, rng *rand.Rand) {
|
|||||||
nMiners = 1
|
nMiners = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logging.SetLogLevel("messagepool", "error")
|
||||||
|
for i := 0; i < 1; i++ {
|
||||||
optMsgs := make(map[cid.Cid]*types.SignedMessage)
|
optMsgs := make(map[cid.Cid]*types.SignedMessage)
|
||||||
for i := 0; i < nMiners; i++ {
|
for j := 0; j < nMiners; j++ {
|
||||||
tq := rng.Float64()
|
tq := rng.Float64()
|
||||||
msgs, err := mp.SelectMessages(ts, tq)
|
msgs, err := mp.SelectMessages(ts, tq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -962,12 +965,14 @@ func testCompetitiveMessageSelection(t *testing.T, rng *rand.Rand) {
|
|||||||
nMinersBig := big.NewInt(int64(nMiners))
|
nMinersBig := big.NewInt(int64(nMiners))
|
||||||
greedyAvgReward, _ := new(big.Rat).SetFrac(greedyReward, nMinersBig).Float64()
|
greedyAvgReward, _ := new(big.Rat).SetFrac(greedyReward, nMinersBig).Float64()
|
||||||
optimalAvgReward, _ := new(big.Rat).SetFrac(optReward, nMinersBig).Float64()
|
optimalAvgReward, _ := new(big.Rat).SetFrac(optReward, nMinersBig).Float64()
|
||||||
t.Logf("greedy reward: %f, optimal reward: %f (x%.1f)", greedyAvgReward,
|
t.Logf("greedy reward: %.0f, optimal reward: %.0f (x%.1f)", greedyAvgReward,
|
||||||
optimalAvgReward, optimalAvgReward/greedyAvgReward)
|
optimalAvgReward, optimalAvgReward/greedyAvgReward)
|
||||||
|
|
||||||
if greedyReward.Cmp(optReward) > 0 {
|
if greedyReward.Cmp(optReward) > 0 {
|
||||||
t.Fatal("greedy reward raw higher than optimal reward; booh")
|
t.Fatal("greedy reward raw higher than optimal reward; booh")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
logging.SetLogLevel("messagepool", "info")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompetitiveMessageSelection(t *testing.T) {
|
func TestCompetitiveMessageSelection(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user