Fix charge gas in case of overcharge

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-04-01 22:55:10 +02:00
parent f6c260c49f
commit 013f441658

View File

@ -426,10 +426,11 @@ func (rt *Runtime) ChargeGas(toUse int64) {
}
func (rt *Runtime) chargeGasSafe(toUse int64) aerrors.ActorError {
rt.gasUsed += toUse
if rt.gasUsed > rt.gasAvailable {
if rt.gasUsed+toUse > rt.gasAvailable {
rt.gasUsed = rt.gasAvailable
return aerrors.Newf(uint8(exitcode.SysErrOutOfGas), "not enough gas: used=%d, available=%d", rt.gasUsed, rt.gasAvailable)
}
rt.gasUsed += toUse
return nil
}