Merge pull request #2024 from filecoin-project/feat/virtual-gas

Add virtual gas
This commit is contained in:
Jakub Sztandera 2020-06-15 18:27:24 +02:00 committed by GitHub
commit 18cf7b046e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 13 deletions

View File

@ -21,10 +21,13 @@ type ExecutionTrace struct {
type GasTrace struct { type GasTrace struct {
Name string Name string
Location []Loc Location []Loc
TotalGas int64 TotalGas int64
ComputeGas int64 ComputeGas int64
StorageGas int64 StorageGas int64
TotalVirtualGas int64
VirtualComputeGas int64
VirtualStorageGas int64
TimeTaken time.Duration TimeTaken time.Duration
Extra interface{} Extra interface{}

View File

@ -21,11 +21,20 @@ type GasCharge struct {
Name string Name string
ComputeGas int64 ComputeGas int64
StorageGas int64 StorageGas int64
VirtualCompute int64
VirtualStorage int64
} }
func (g GasCharge) Total() int64 { func (g GasCharge) Total() int64 {
return g.ComputeGas*GasComputeMulti + g.StorageGas*GasStorageMulti return g.ComputeGas*GasComputeMulti + g.StorageGas*GasStorageMulti
} }
func (g GasCharge) WithVirtual(compute, storage int64) GasCharge {
out := g
out.VirtualCompute = compute
out.VirtualStorage = storage
return out
}
func newGasCharge(name string, computeGas int64, storageGas int64) GasCharge { func newGasCharge(name string, computeGas int64, storageGas int64) GasCharge {
return GasCharge{ return GasCharge{

View File

@ -524,11 +524,14 @@ func (rt *Runtime) chargeGasInternal(gas GasCharge, skip int) aerrors.ActorError
} }
gasTrace := types.GasTrace{ gasTrace := types.GasTrace{
Name: gas.Name, Name: gas.Name,
TotalGas: toUse, TotalGas: toUse,
ComputeGas: gas.ComputeGas, ComputeGas: gas.ComputeGas,
StorageGas: gas.StorageGas, StorageGas: gas.StorageGas,
Callers: callers[:cout], TotalVirtualGas: gas.VirtualCompute*GasComputeMulti + gas.VirtualStorage*GasStorageMulti,
VirtualComputeGas: gas.VirtualCompute,
VirtualStorageGas: gas.VirtualStorage,
Callers: callers[:cout],
} }
rt.executionTrace.GasCharges = append(rt.executionTrace.GasCharges, &gasTrace) rt.executionTrace.GasCharges = append(rt.executionTrace.GasCharges, &gasTrace)
rt.lastGasChargeTime = now rt.lastGasChargeTime = now
@ -536,7 +539,8 @@ func (rt *Runtime) chargeGasInternal(gas GasCharge, skip int) aerrors.ActorError
if rt.gasUsed+toUse > rt.gasAvailable { if rt.gasUsed+toUse > rt.gasAvailable {
rt.gasUsed = rt.gasAvailable rt.gasUsed = rt.gasAvailable
return aerrors.Newf(exitcode.SysErrOutOfGas, "not enough gas: used=%d, available=%d", rt.gasUsed, rt.gasAvailable) return aerrors.Newf(exitcode.SysErrOutOfGas, "not enough gas: used=%d, available=%d",
rt.gasUsed, rt.gasAvailable)
} }
rt.gasUsed += toUse rt.gasUsed += toUse
return nil return nil

View File

@ -971,6 +971,7 @@ var compStateTemplate = `
} }
.slow-true-false { color: #660; } .slow-true-false { color: #660; }
.slow-true-true { color: #f80; } .slow-true-true { color: #f80; }
.deemp { color: #444; }
table { table {
font-size: 12px; font-size: 12px;
border-collapse: collapse; border-collapse: collapse;
@ -1060,8 +1061,20 @@ var compStateMsg = `
<summary>Gas Trace</summary> <summary>Gas Trace</summary>
<table> <table>
<tr><th>Name</th><th>Total/Compute/Storage</th><th>Time Taken</th><th>Location</th></tr> <tr><th>Name</th><th>Total/Compute/Storage</th><th>Time Taken</th><th>Location</th></tr>
{{define "virt" -}}
{{- if . -}}
<span class="deemp">+({{.}})</span>
{{- end -}}
{{- end}}
{{define "gasC" -}}
<td>{{.TotalGas}}{{template "virt" .TotalVirtualGas }}/{{.ComputeGas}}{{template "virt" .VirtualComputeGas}}/{{.StorageGas}}{{template "virt" .VirtualStorageGas}}</td>
{{- end}}
{{range .GasCharges}} {{range .GasCharges}}
<tr><td>{{.Name}}</td><td>{{.TotalGas}}/{{.ComputeGas}}/{{.StorageGas}}</td><td>{{.TimeTaken}}</td> <tr><td>{{.Name}}</td>
{{template "gasC" .}}
<td>{{.TimeTaken}}</td>
<td> <td>
{{ $fImp := FirstImportant .Location }} {{ $fImp := FirstImportant .Location }}
{{ if $fImp }} {{ if $fImp }}
@ -1098,7 +1111,10 @@ var compStateMsg = `
</td></tr> </td></tr>
{{end}} {{end}}
{{with SumGas .GasCharges}} {{with SumGas .GasCharges}}
<tr class="sum"><td><b>Sum</b></td><td>{{.TotalGas}}/{{.ComputeGas}}/{{.StorageGas}}</td><td>{{.TimeTaken}}</td><td></td></tr> <tr class="sum"><td><b>Sum</b></td>
{{template "gasC" .}}
<td>{{.TimeTaken}}</td>
<td></td></tr>
{{end}} {{end}}
</table> </table>
</details> </details>
@ -1201,7 +1217,10 @@ func sumGas(changes []*types.GasTrace) types.GasTrace {
out.TotalGas += gc.TotalGas out.TotalGas += gc.TotalGas
out.ComputeGas += gc.ComputeGas out.ComputeGas += gc.ComputeGas
out.StorageGas += gc.StorageGas out.StorageGas += gc.StorageGas
out.TimeTaken += gc.TimeTaken
out.TotalVirtualGas += gc.TotalVirtualGas
out.VirtualComputeGas += gc.VirtualComputeGas
out.VirtualStorageGas += gc.VirtualStorageGas
} }
return out return out