fix a regression caused by #3800.

This commit is contained in:
Raúl Kripalani 2020-09-16 10:53:15 +01:00
parent e04331b07c
commit 362fc180ec
2 changed files with 27 additions and 22 deletions

View File

@ -22,6 +22,17 @@ type GasOutputs struct {
GasBurned int64 GasBurned int64
} }
// ZeroGasOutputs returns a logically zeroed GasOutputs.
func ZeroGasOutputs() GasOutputs {
return GasOutputs{
BaseFeeBurn: big.Zero(),
OverEstimationBurn: big.Zero(),
MinerPenalty: big.Zero(),
MinerTip: big.Zero(),
Refund: big.Zero(),
}
}
// ComputeGasOverestimationBurn computes amount of gas to be refunded and amount of gas to be burned // ComputeGasOverestimationBurn computes amount of gas to be refunded and amount of gas to be burned
// Result is (refund, burn) // Result is (refund, burn)
func ComputeGasOverestimationBurn(gasUsed, gasLimit int64) (int64, int64) { func ComputeGasOverestimationBurn(gasUsed, gasLimit int64) (int64, int64) {
@ -58,13 +69,7 @@ func ComputeGasOverestimationBurn(gasUsed, gasLimit int64) (int64, int64) {
func ComputeGasOutputs(gasUsed, gasLimit int64, baseFee, feeCap, gasPremium abi.TokenAmount) GasOutputs { func ComputeGasOutputs(gasUsed, gasLimit int64, baseFee, feeCap, gasPremium abi.TokenAmount) GasOutputs {
gasUsedBig := big.NewInt(gasUsed) gasUsedBig := big.NewInt(gasUsed)
out := GasOutputs{ out := ZeroGasOutputs()
BaseFeeBurn: big.Zero(),
OverEstimationBurn: big.Zero(),
MinerPenalty: big.Zero(),
MinerTip: big.Zero(),
Refund: big.Zero(),
}
baseFeeToPay := baseFee baseFeeToPay := baseFee
if baseFee.Cmp(feeCap.Int) > 0 { if baseFee.Cmp(feeCap.Int) > 0 {

View File

@ -355,14 +355,14 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet,
msgGasCost := msgGas.Total() msgGasCost := msgGas.Total()
// this should never happen, but is currently still exercised by some tests // this should never happen, but is currently still exercised by some tests
if msgGasCost > msg.GasLimit { if msgGasCost > msg.GasLimit {
gasOutputs := ZeroGasOutputs()
gasOutputs.MinerPenalty = types.BigMul(vm.baseFee, abi.NewTokenAmount(msgGasCost))
return &ApplyRet{ return &ApplyRet{
MessageReceipt: types.MessageReceipt{ MessageReceipt: types.MessageReceipt{
ExitCode: exitcode.SysErrOutOfGas, ExitCode: exitcode.SysErrOutOfGas,
GasUsed: 0, GasUsed: 0,
}, },
GasCosts: GasOutputs{ GasCosts: gasOutputs,
MinerPenalty: types.BigMul(vm.baseFee, abi.NewTokenAmount(msgGasCost)),
},
Duration: time.Since(start), Duration: time.Since(start),
}, nil }, nil
} }
@ -374,15 +374,15 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet,
// this should never happen, but is currently still exercised by some tests // this should never happen, but is currently still exercised by some tests
if err != nil { if err != nil {
if xerrors.Is(err, types.ErrActorNotFound) { if xerrors.Is(err, types.ErrActorNotFound) {
gasOutputs := ZeroGasOutputs()
gasOutputs.MinerPenalty = minerPenaltyAmount
return &ApplyRet{ return &ApplyRet{
MessageReceipt: types.MessageReceipt{ MessageReceipt: types.MessageReceipt{
ExitCode: exitcode.SysErrSenderInvalid, ExitCode: exitcode.SysErrSenderInvalid,
GasUsed: 0, GasUsed: 0,
}, },
ActorErr: aerrors.Newf(exitcode.SysErrSenderInvalid, "actor not found: %s", msg.From), ActorErr: aerrors.Newf(exitcode.SysErrSenderInvalid, "actor not found: %s", msg.From),
GasCosts: GasOutputs{ GasCosts: gasOutputs,
MinerPenalty: minerPenaltyAmount,
},
Duration: time.Since(start), Duration: time.Since(start),
}, nil }, nil
} }
@ -391,20 +391,22 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet,
// this should never happen, but is currently still exercised by some tests // this should never happen, but is currently still exercised by some tests
if !fromActor.Code.Equals(builtin.AccountActorCodeID) { if !fromActor.Code.Equals(builtin.AccountActorCodeID) {
gasOutputs := ZeroGasOutputs()
gasOutputs.MinerPenalty = minerPenaltyAmount
return &ApplyRet{ return &ApplyRet{
MessageReceipt: types.MessageReceipt{ MessageReceipt: types.MessageReceipt{
ExitCode: exitcode.SysErrSenderInvalid, ExitCode: exitcode.SysErrSenderInvalid,
GasUsed: 0, GasUsed: 0,
}, },
ActorErr: aerrors.Newf(exitcode.SysErrSenderInvalid, "send from not account actor: %s", fromActor.Code), ActorErr: aerrors.Newf(exitcode.SysErrSenderInvalid, "send from not account actor: %s", fromActor.Code),
GasCosts: GasOutputs{ GasCosts: gasOutputs,
MinerPenalty: minerPenaltyAmount,
},
Duration: time.Since(start), Duration: time.Since(start),
}, nil }, nil
} }
if msg.Nonce != fromActor.Nonce { if msg.Nonce != fromActor.Nonce {
gasOutputs := ZeroGasOutputs()
gasOutputs.MinerPenalty = minerPenaltyAmount
return &ApplyRet{ return &ApplyRet{
MessageReceipt: types.MessageReceipt{ MessageReceipt: types.MessageReceipt{
ExitCode: exitcode.SysErrSenderStateInvalid, ExitCode: exitcode.SysErrSenderStateInvalid,
@ -413,15 +415,15 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet,
ActorErr: aerrors.Newf(exitcode.SysErrSenderStateInvalid, ActorErr: aerrors.Newf(exitcode.SysErrSenderStateInvalid,
"actor nonce invalid: msg:%d != state:%d", msg.Nonce, fromActor.Nonce), "actor nonce invalid: msg:%d != state:%d", msg.Nonce, fromActor.Nonce),
GasCosts: GasOutputs{ GasCosts: gasOutputs,
MinerPenalty: minerPenaltyAmount,
},
Duration: time.Since(start), Duration: time.Since(start),
}, nil }, nil
} }
gascost := types.BigMul(types.NewInt(uint64(msg.GasLimit)), msg.GasFeeCap) gascost := types.BigMul(types.NewInt(uint64(msg.GasLimit)), msg.GasFeeCap)
if fromActor.Balance.LessThan(gascost) { if fromActor.Balance.LessThan(gascost) {
gasOutputs := ZeroGasOutputs()
gasOutputs.MinerPenalty = minerPenaltyAmount
return &ApplyRet{ return &ApplyRet{
MessageReceipt: types.MessageReceipt{ MessageReceipt: types.MessageReceipt{
ExitCode: exitcode.SysErrSenderStateInvalid, ExitCode: exitcode.SysErrSenderStateInvalid,
@ -429,9 +431,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet,
}, },
ActorErr: aerrors.Newf(exitcode.SysErrSenderStateInvalid, ActorErr: aerrors.Newf(exitcode.SysErrSenderStateInvalid,
"actor balance less than needed: %s < %s", types.FIL(fromActor.Balance), types.FIL(gascost)), "actor balance less than needed: %s < %s", types.FIL(fromActor.Balance), types.FIL(gascost)),
GasCosts: GasOutputs{ GasCosts: gasOutputs,
MinerPenalty: minerPenaltyAmount,
},
Duration: time.Since(start), Duration: time.Since(start),
}, nil }, nil
} }