Merge pull request #1388 from filecoin-project/fix/nonce-before-gas

Check for correct nonce before taking gas
This commit is contained in:
Whyrusleeping 2020-03-10 23:58:28 -07:00 committed by GitHub
commit 9bad73b995

View File

@ -297,6 +297,15 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
return nil, xerrors.Errorf("failed to look up from actor: %w", err)
}
if msg.Nonce != fromActor.Nonce {
return &ApplyRet{
MessageReceipt: types.MessageReceipt{
ExitCode: exitcode.SysErrInvalidCallSeqNum,
GasUsed: msg.GasLimit,
},
}, nil
}
gascost := types.BigMul(msg.GasLimit, msg.GasPrice)
totalCost := types.BigAdd(gascost, msg.Value)
if fromActor.Balance.LessThan(totalCost) {
@ -313,14 +322,6 @@ func (vm *VM) ApplyMessage(ctx context.Context, msg *types.Message) (*ApplyRet,
return nil, xerrors.Errorf("failed to withdraw gas funds: %w", err)
}
if msg.Nonce != fromActor.Nonce {
return &ApplyRet{
MessageReceipt: types.MessageReceipt{
ExitCode: exitcode.SysErrInvalidCallSeqNum,
GasUsed: msg.GasLimit,
},
}, nil
}
fromActor.Nonce++
ret, actorErr, rt := vm.send(ctx, msg, nil, msgGasCost)