Merge pull request from filecoin-project/fix/sm-gas-chain-break

Correctly account for gas of included messages
This commit is contained in:
Łukasz Magiera 2020-08-04 14:52:32 +02:00 committed by GitHub
commit 7fa666b0a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 83 additions and 1 deletions

View File

@ -170,3 +170,74 @@ func wrapMsgs(msgs []types.Message) []*types.SignedMessage {
}
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")
}

View File

@ -87,6 +87,7 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
getbal += build.Clock.Since(getBalStart)
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++
// todo: drop from mpool
continue
@ -175,17 +176,27 @@ func SelectMessages(ctx context.Context, al gasguess.ActorLookup, ts *types.TipS
}
if nBest == 0 {
log.Warning("nBest is zero: ", gasLimitLeft)
break // block gas limit reached
}
{
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].gasLimit = outBySender[bestSender].gasLimit[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 {
delete(outBySender, bestSender)
}