Update gas values, compute correlation coefficient
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
parent
5e7f561133
commit
9ccd25b072
@ -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) {
|
func (ps pricedSyscalls) BatchVerifySeals(inp map[address.Address][]abi.SealVerifyInfo) (map[address.Address][]bool, error) {
|
||||||
var gasChargeSum GasCharge
|
var gasChargeSum GasCharge
|
||||||
gasChargeSum.Name = "BatchVerifySeals"
|
gasChargeSum.Name = "BatchVerifySeals"
|
||||||
count := 0
|
count := int64(0)
|
||||||
for _, svis := range inp {
|
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)
|
defer ps.chargeGas(gasOnActorExec)
|
||||||
|
|
||||||
return ps.under.BatchVerifySeals(inp)
|
return ps.under.BatchVerifySeals(inp)
|
||||||
|
@ -99,18 +99,26 @@ func (pl *pricelistV0) OnChainReturnValue(dataSize int) GasCharge {
|
|||||||
func (pl *pricelistV0) OnMethodInvocation(value abi.TokenAmount, methodNum abi.MethodNum) GasCharge {
|
func (pl *pricelistV0) OnMethodInvocation(value abi.TokenAmount, methodNum abi.MethodNum) GasCharge {
|
||||||
ret := pl.sendBase
|
ret := pl.sendBase
|
||||||
extra := ""
|
extra := ""
|
||||||
|
virtGas := int64(1069512)
|
||||||
|
|
||||||
if value != abi.NewTokenAmount(0) {
|
if value != abi.NewTokenAmount(0) {
|
||||||
// TODO: fix this, it is comparing pointers instead of values
|
// TODO: fix this, it is comparing pointers instead of values
|
||||||
// see vv
|
// see vv
|
||||||
ret += pl.sendTransferFunds
|
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"
|
extra += "t"
|
||||||
}
|
}
|
||||||
if methodNum != builtin.MethodSend {
|
if methodNum != builtin.MethodSend {
|
||||||
ret += pl.sendInvokeMethod
|
ret += pl.sendInvokeMethod
|
||||||
extra += "i"
|
extra += "i"
|
||||||
|
// running actors is cheaper becase we hand over to actors
|
||||||
|
virtGas += -294632
|
||||||
}
|
}
|
||||||
return newGasCharge("OnMethodInvocation", ret, 0).WithVirtual(86315, 0).WithExtra(extra)
|
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)
|
return GasCharge{}, fmt.Errorf("cost function for signature type %d not supported", sigType)
|
||||||
}
|
}
|
||||||
sigName, _ := sigType.Name()
|
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).
|
return newGasCharge("OnVerifySignature", costFn(int64(planTextSize)), 0).
|
||||||
WithExtra(map[string]interface{}{
|
WithExtra(map[string]interface{}{
|
||||||
"type": sigName,
|
"type": sigName,
|
||||||
"size": planTextSize,
|
"size": planTextSize,
|
||||||
}), nil
|
}).WithVirtual(virtGas, 0), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnHashing
|
// OnHashing
|
||||||
|
@ -233,7 +233,6 @@ type stats struct {
|
|||||||
timeTaken meanVar
|
timeTaken meanVar
|
||||||
gasRatio meanVar
|
gasRatio meanVar
|
||||||
|
|
||||||
extra *meanVar
|
|
||||||
extraCovar *covar
|
extraCovar *covar
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,19 +241,28 @@ type covar struct {
|
|||||||
meanY float64
|
meanY float64
|
||||||
c float64
|
c float64
|
||||||
n float64
|
n float64
|
||||||
m2 float64
|
m2x float64
|
||||||
|
m2y float64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cov1 *covar) Covariance() float64 {
|
func (cov1 *covar) Covariance() float64 {
|
||||||
return cov1.c / (cov1.n - 1)
|
return cov1.c / (cov1.n - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cov1 *covar) Variance() float64 {
|
func (cov1 *covar) VarianceX() float64 {
|
||||||
return cov1.m2 / (cov1.n - 1)
|
return cov1.m2x / (cov1.n - 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v1 *covar) Stddev() float64 {
|
func (v1 *covar) StddevX() float64 {
|
||||||
return math.Sqrt(v1.Variance())
|
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) {
|
func (cov1 *covar) AddPoint(x, y float64) {
|
||||||
@ -262,11 +270,15 @@ func (cov1 *covar) AddPoint(x, y float64) {
|
|||||||
dx := x - cov1.meanX
|
dx := x - cov1.meanX
|
||||||
cov1.meanX += dx / cov1.n
|
cov1.meanX += dx / cov1.n
|
||||||
|
|
||||||
dx2 := x - cov1.meanX // compute x variance using partial result for covariance
|
dx2 := x - cov1.meanX
|
||||||
cov1.m2 += dx * dx2
|
cov1.m2x += dx * dx2
|
||||||
|
|
||||||
cov1.meanY += (y - cov1.meanY) / cov1.n
|
dy := y - cov1.meanY
|
||||||
cov1.c += dx * (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) {
|
func (cov1 *covar) Combine(cov2 *covar) {
|
||||||
@ -293,21 +305,25 @@ func (cov1 *covar) Combine(cov2 *covar) {
|
|||||||
|
|
||||||
dx := cov1.meanX - cov2.meanX
|
dx := cov1.meanX - cov2.meanX
|
||||||
out.meanX = cov1.meanX - dx*cov2.n/out.n
|
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
|
dy := cov1.meanY - cov2.meanY
|
||||||
out.meanY = cov1.meanY - dy*cov2.n/out.n
|
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
|
out.c = cov1.c + cov2.c + dx*dy*cov1.n*cov2.n/out.n
|
||||||
*cov1 = out
|
*cov1 = out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cov1 *covar) A() float64 {
|
func (cov1 *covar) A() float64 {
|
||||||
return cov1.Covariance() / cov1.Variance()
|
return cov1.Covariance() / cov1.VarianceX()
|
||||||
}
|
}
|
||||||
func (cov1 *covar) B() float64 {
|
func (cov1 *covar) B() float64 {
|
||||||
return cov1.meanY - cov1.meanX*cov1.A()
|
return cov1.meanY - cov1.meanX*cov1.A()
|
||||||
}
|
}
|
||||||
|
func (cov1 *covar) Coerrel() float64 {
|
||||||
|
return cov1.Covariance() / cov1.VarianceX() / cov1.VarianceY()
|
||||||
|
}
|
||||||
|
|
||||||
type meanVar struct {
|
type meanVar struct {
|
||||||
n float64
|
n float64
|
||||||
@ -417,10 +433,8 @@ func tallyGasCharges(charges map[string]*stats, et types.ExecutionTrace) {
|
|||||||
if eSize != nil {
|
if eSize != nil {
|
||||||
if s.extraCovar == nil {
|
if s.extraCovar == nil {
|
||||||
s.extraCovar = &covar{}
|
s.extraCovar = &covar{}
|
||||||
s.extra = &meanVar{}
|
|
||||||
}
|
}
|
||||||
s.extraCovar.AddPoint(*eSize, tt)
|
s.extraCovar.AddPoint(*eSize, tt)
|
||||||
s.extra.AddPoint(*eSize)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.timeTaken.AddPoint(tt)
|
s.timeTaken.AddPoint(tt)
|
||||||
@ -550,12 +564,10 @@ var importAnalyzeCmd = &cli.Command{
|
|||||||
s.timeTaken.Combine(&v.timeTaken)
|
s.timeTaken.Combine(&v.timeTaken)
|
||||||
s.gasRatio.Combine(&v.gasRatio)
|
s.gasRatio.Combine(&v.gasRatio)
|
||||||
|
|
||||||
if v.extra != nil {
|
if v.extraCovar != nil {
|
||||||
if s.extra == nil {
|
if s.extraCovar == nil {
|
||||||
s.extra = &meanVar{}
|
|
||||||
s.extraCovar = &covar{}
|
s.extraCovar = &covar{}
|
||||||
}
|
}
|
||||||
s.extra.Combine(v.extra)
|
|
||||||
s.extraCovar.Combine(v.extraCovar)
|
s.extraCovar.Combine(v.extraCovar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -573,10 +585,10 @@ var importAnalyzeCmd = &cli.Command{
|
|||||||
s := charges[k]
|
s := charges[k]
|
||||||
fmt.Printf("%s: incr by %f~%f; tt %f~%f\n", k, s.gasRatio.Mean(), s.gasRatio.Stddev(),
|
fmt.Printf("%s: incr by %f~%f; tt %f~%f\n", k, s.gasRatio.Mean(), s.gasRatio.Stddev(),
|
||||||
s.timeTaken.Mean(), s.timeTaken.Stddev())
|
s.timeTaken.Mean(), s.timeTaken.Stddev())
|
||||||
if s.extra != nil {
|
if s.extraCovar != nil {
|
||||||
fmt.Printf("\t covar: %f, tt = %f * extra + %f\n", s.extraCovar.Covariance(),
|
fmt.Printf("\t correll: %f, tt = %f * extra + %f\n", s.extraCovar.Coerrel(),
|
||||||
s.extraCovar.A(), s.extraCovar.B())
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user