Update gas values, compute correlation coefficient

Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2020-06-30 14:09:03 +02:00
parent 5e7f561133
commit 9ccd25b072
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA
3 changed files with 55 additions and 26 deletions

View File

@ -200,11 +200,12 @@ func (ps pricedSyscalls) VerifyConsensusFault(h1 []byte, h2 []byte, extra []byte
func (ps pricedSyscalls) BatchVerifySeals(inp map[address.Address][]abi.SealVerifyInfo) (map[address.Address][]bool, error) {
var gasChargeSum GasCharge
gasChargeSum.Name = "BatchVerifySeals"
count := 0
count := int64(0)
for _, svis := range inp {
count += len(svis)
count += int64(len(svis))
}
ps.chargeGas(gasChargeSum.WithExtra(count)) // TODO: this is only called by the cron actor. Should we even charge gas?
gasChargeSum = gasChargeSum.WithExtra(count).WithVirtual(129778623*count+716683250, 0)
ps.chargeGas(gasChargeSum) // TODO: this is only called by the cron actor. Should we even charge gas?
defer ps.chargeGas(gasOnActorExec)
return ps.under.BatchVerifySeals(inp)

View File

@ -99,18 +99,26 @@ func (pl *pricelistV0) OnChainReturnValue(dataSize int) GasCharge {
func (pl *pricelistV0) OnMethodInvocation(value abi.TokenAmount, methodNum abi.MethodNum) GasCharge {
ret := pl.sendBase
extra := ""
virtGas := int64(1069512)
if value != abi.NewTokenAmount(0) {
// TODO: fix this, it is comparing pointers instead of values
// see vv
ret += pl.sendTransferFunds
}
if big.Cmp(value, abi.NewTokenAmount(0)) == 0 {
if big.Cmp(value, abi.NewTokenAmount(0)) != 0 {
virtGas += 498173
if methodNum == builtin.MethodSend {
// transfer only
virtGas += 968198
}
extra += "t"
}
if methodNum != builtin.MethodSend {
ret += pl.sendInvokeMethod
extra += "i"
// running actors is cheaper becase we hand over to actors
virtGas += -294632
}
return newGasCharge("OnMethodInvocation", ret, 0).WithVirtual(86315, 0).WithExtra(extra)
}
@ -145,11 +153,19 @@ func (pl *pricelistV0) OnVerifySignature(sigType crypto.SigType, planTextSize in
return GasCharge{}, fmt.Errorf("cost function for signature type %d not supported", sigType)
}
sigName, _ := sigType.Name()
virtGas := int64(0)
switch sigType {
case crypto.SigTypeBLS:
virtGas = 220138570
case crypto.SigTypeSecp256k1:
virtGas = 7053730
}
return newGasCharge("OnVerifySignature", costFn(int64(planTextSize)), 0).
WithExtra(map[string]interface{}{
"type": sigName,
"size": planTextSize,
}), nil
}).WithVirtual(virtGas, 0), nil
}
// OnHashing

View File

@ -233,7 +233,6 @@ type stats struct {
timeTaken meanVar
gasRatio meanVar
extra *meanVar
extraCovar *covar
}
@ -242,19 +241,28 @@ type covar struct {
meanY float64
c float64
n float64
m2 float64
m2x float64
m2y float64
}
func (cov1 *covar) Covariance() float64 {
return cov1.c / (cov1.n - 1)
}
func (cov1 *covar) Variance() float64 {
return cov1.m2 / (cov1.n - 1)
func (cov1 *covar) VarianceX() float64 {
return cov1.m2x / (cov1.n - 1)
}
func (v1 *covar) Stddev() float64 {
return math.Sqrt(v1.Variance())
func (v1 *covar) StddevX() float64 {
return math.Sqrt(v1.VarianceX())
}
func (cov1 *covar) VarianceY() float64 {
return cov1.m2y / (cov1.n - 1)
}
func (v1 *covar) StddevY() float64 {
return math.Sqrt(v1.VarianceY())
}
func (cov1 *covar) AddPoint(x, y float64) {
@ -262,11 +270,15 @@ func (cov1 *covar) AddPoint(x, y float64) {
dx := x - cov1.meanX
cov1.meanX += dx / cov1.n
dx2 := x - cov1.meanX // compute x variance using partial result for covariance
cov1.m2 += dx * dx2
dx2 := x - cov1.meanX
cov1.m2x += dx * dx2
cov1.meanY += (y - cov1.meanY) / cov1.n
cov1.c += dx * (y - cov1.meanY)
dy := y - cov1.meanY
cov1.meanY += dy / cov1.n
dy2 := y - cov1.meanY
cov1.m2y += dy * dy2
cov1.c += dx * dy
}
func (cov1 *covar) Combine(cov2 *covar) {
@ -293,21 +305,25 @@ func (cov1 *covar) Combine(cov2 *covar) {
dx := cov1.meanX - cov2.meanX
out.meanX = cov1.meanX - dx*cov2.n/out.n
out.m2 = cov1.m2 + cov2.m2 + dx*dx*cov1.n*cov2.n/out.n
out.m2x = cov1.m2x + cov2.m2x + dx*dx*cov1.n*cov2.n/out.n
dy := cov1.meanY - cov2.meanY
out.meanY = cov1.meanY - dy*cov2.n/out.n
out.m2y = cov1.m2y + cov2.m2y + dy*dy*cov1.n*cov2.n/out.n
out.c = cov1.c + cov2.c + dx*dy*cov1.n*cov2.n/out.n
*cov1 = out
}
func (cov1 *covar) A() float64 {
return cov1.Covariance() / cov1.Variance()
return cov1.Covariance() / cov1.VarianceX()
}
func (cov1 *covar) B() float64 {
return cov1.meanY - cov1.meanX*cov1.A()
}
func (cov1 *covar) Coerrel() float64 {
return cov1.Covariance() / cov1.VarianceX() / cov1.VarianceY()
}
type meanVar struct {
n float64
@ -417,10 +433,8 @@ func tallyGasCharges(charges map[string]*stats, et types.ExecutionTrace) {
if eSize != nil {
if s.extraCovar == nil {
s.extraCovar = &covar{}
s.extra = &meanVar{}
}
s.extraCovar.AddPoint(*eSize, tt)
s.extra.AddPoint(*eSize)
}
s.timeTaken.AddPoint(tt)
@ -550,12 +564,10 @@ var importAnalyzeCmd = &cli.Command{
s.timeTaken.Combine(&v.timeTaken)
s.gasRatio.Combine(&v.gasRatio)
if v.extra != nil {
if s.extra == nil {
s.extra = &meanVar{}
if v.extraCovar != nil {
if s.extraCovar == nil {
s.extraCovar = &covar{}
}
s.extra.Combine(v.extra)
s.extraCovar.Combine(v.extraCovar)
}
}
@ -573,10 +585,10 @@ var importAnalyzeCmd = &cli.Command{
s := charges[k]
fmt.Printf("%s: incr by %f~%f; tt %f~%f\n", k, s.gasRatio.Mean(), s.gasRatio.Stddev(),
s.timeTaken.Mean(), s.timeTaken.Stddev())
if s.extra != nil {
fmt.Printf("\t covar: %f, tt = %f * extra + %f\n", s.extraCovar.Covariance(),
if s.extraCovar != nil {
fmt.Printf("\t correll: %f, tt = %f * extra + %f\n", s.extraCovar.Coerrel(),
s.extraCovar.A(), s.extraCovar.B())
fmt.Printf("\t extra: %f~%f\n", s.extra.Mean(), s.extra.Stddev())
fmt.Printf("\t extra: %f~%f\n", s.extraCovar.meanX, s.extraCovar.StddevX())
}
}