Merge pull request #2795 from filecoin-project/fix/sm-gas-chain-break
Correctly account for gas of included messages
This commit is contained in:
commit
7fa666b0a3
@ -170,3 +170,74 @@ func wrapMsgs(msgs []types.Message) []*types.SignedMessage {
|
|||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMessageFilteringSenderHopping(t *testing.T) {
|
||||||
|
ctx := context.TODO()
|
||||||
|
a1 := mustIDAddr(1)
|
||||||
|
a2 := mustIDAddr(2)
|
||||||
|
|
||||||
|
actors := map[address.Address]*types.Actor{
|
||||||
|
a1: {
|
||||||
|
Nonce: 0,
|
||||||
|
Balance: types.FromFil(1200),
|
||||||
|
},
|
||||||
|
a2: {
|
||||||
|
Nonce: 0,
|
||||||
|
Balance: types.FromFil(1000),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
af := func(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*types.Actor, error) {
|
||||||
|
return actors[addr], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
msgs := []types.Message{
|
||||||
|
{
|
||||||
|
From: a1,
|
||||||
|
To: a1,
|
||||||
|
Nonce: 0,
|
||||||
|
Value: types.FromFil(500),
|
||||||
|
GasLimit: 2_000_000_000,
|
||||||
|
GasPrice: types.NewInt(100),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
From: a1,
|
||||||
|
To: a1,
|
||||||
|
Nonce: 1,
|
||||||
|
Value: types.FromFil(500),
|
||||||
|
GasLimit: 2_000_000_000,
|
||||||
|
GasPrice: types.NewInt(1),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
From: a2,
|
||||||
|
To: a1,
|
||||||
|
Nonce: 0,
|
||||||
|
Value: types.FromFil(1),
|
||||||
|
GasLimit: 1_000_000_000,
|
||||||
|
GasPrice: types.NewInt(10),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
From: a2,
|
||||||
|
To: a1,
|
||||||
|
Nonce: 1,
|
||||||
|
Value: types.FromFil(1),
|
||||||
|
GasLimit: 1_000_000_000,
|
||||||
|
GasPrice: types.NewInt(1),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
From: a2,
|
||||||
|
To: a1,
|
||||||
|
Nonce: 2,
|
||||||
|
Value: types.FromFil(1),
|
||||||
|
GasLimit: 100_000_000,
|
||||||
|
GasPrice: types.NewInt(1),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
outmsgs, err := SelectMessages(ctx, af, &types.TipSet{}, wrapMsgs(msgs))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.Len(t, outmsgs, 5, "filtering didnt work as expected")
|
||||||
|
}
|
||||||
|
@ -87,6 +87,7 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
|
|||||||
getbal += build.Clock.Since(getBalStart)
|
getbal += build.Clock.Since(getBalStart)
|
||||||
|
|
||||||
if inclBalances[from].LessThan(msg.Message.RequiredFunds()) {
|
if inclBalances[from].LessThan(msg.Message.RequiredFunds()) {
|
||||||
|
log.Warnf("message had too low funds: %s %d %s %s %s", from, msg.Message.Nonce, inclBalances[from], msg.Message.Value, msg.Message.RequiredFunds())
|
||||||
tooLowFundMsgs++
|
tooLowFundMsgs++
|
||||||
// todo: drop from mpool
|
// todo: drop from mpool
|
||||||
continue
|
continue
|
||||||
@ -175,17 +176,27 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
|
|||||||
}
|
}
|
||||||
|
|
||||||
if nBest == 0 {
|
if nBest == 0 {
|
||||||
|
log.Warning("nBest is zero: ", gasLimitLeft)
|
||||||
break // block gas limit reached
|
break // block gas limit reached
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
out = append(out, outBySender[bestSender].msgs[:nBest]...)
|
out = append(out, outBySender[bestSender].msgs[:nBest]...)
|
||||||
gasLimitLeft -= outBySender[bestSender].gasLimit[nBest-1]
|
|
||||||
|
seqGasLimit := outBySender[bestSender].gasLimit[nBest-1]
|
||||||
|
seqGasReward := outBySender[bestSender].gasReward[nBest-1]
|
||||||
|
|
||||||
|
gasLimitLeft -= seqGasLimit
|
||||||
|
|
||||||
outBySender[bestSender].msgs = outBySender[bestSender].msgs[nBest:]
|
outBySender[bestSender].msgs = outBySender[bestSender].msgs[nBest:]
|
||||||
outBySender[bestSender].gasLimit = outBySender[bestSender].gasLimit[nBest:]
|
outBySender[bestSender].gasLimit = outBySender[bestSender].gasLimit[nBest:]
|
||||||
outBySender[bestSender].gasReward = outBySender[bestSender].gasReward[nBest:]
|
outBySender[bestSender].gasReward = outBySender[bestSender].gasReward[nBest:]
|
||||||
|
|
||||||
|
for i := range outBySender[bestSender].gasLimit {
|
||||||
|
outBySender[bestSender].gasLimit[i] -= seqGasLimit
|
||||||
|
outBySender[bestSender].gasReward[i] = big.Sub(outBySender[bestSender].gasReward[i], seqGasReward)
|
||||||
|
}
|
||||||
|
|
||||||
if len(outBySender[bestSender].msgs) == 0 {
|
if len(outBySender[bestSender].msgs) == 0 {
|
||||||
delete(outBySender, bestSender)
|
delete(outBySender, bestSender)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user