Skip to content

Commit

Permalink
Merge pull request #6347 from filecoin-project/feat/agg-gas-price
Browse files Browse the repository at this point in the history
Introduce gas prices for aggregate verifications
  • Loading branch information
magik6k authored May 28, 2021
2 parents 54e4cf5 + cb59daf commit dd79c2c
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 7 deletions.
31 changes: 29 additions & 2 deletions chain/vm/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,35 @@ var prices = map[abi.ChainEpoch]Pricelist{

hashingBase: 31355,
computeUnsealedSectorCidBase: 98647,
verifySealBase: 2000, // TODO gas , it VerifySeal syscall is not used
verifyAggregateSealBase: 400_000_000, // TODO (~40ms, I think)
verifySealBase: 2000, // TODO gas, it VerifySeal syscall is not used

verifyAggregateSealPer: map[abi.RegisteredSealProof]int64{
abi.RegisteredSealProof_StackedDrg32GiBV1_1: 449900,
abi.RegisteredSealProof_StackedDrg64GiBV1_1: 359272,
},
verifyAggregateSealSteps: map[abi.RegisteredSealProof]stepCost{
abi.RegisteredSealProof_StackedDrg32GiBV1_1: {
{4, 103994170},
{7, 112356810},
{13, 122912610},
{26, 137559930},
{52, 162039100},
{103, 210960780},
{205, 318351180},
{410, 528274980},
},
abi.RegisteredSealProof_StackedDrg64GiBV1_1: {
{4, 102581240},
{7, 110803030},
{13, 120803700},
{26, 134642130},
{52, 157357890},
{103, 203017690},
{205, 304253590},
{410, 509880640},
},
},

verifyPostLookup: map[abi.RegisteredPoStProof]scalingCost{
abi.RegisteredPoStProof_StackedDrgWindow512MiBV1: {
flat: 117680921,
Expand Down
45 changes: 40 additions & 5 deletions chain/vm/gas_v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ type scalingCost struct {
scale int64
}

type stepCost []step

type step struct {
start int64
cost int64
}

func (sc stepCost) Lookup(x int64) int64 {
i := 0
for ; i < len(sc); i++ {
if sc[i].start > x {
break
}
}
i-- // look at previous item
if i < 0 {
return 0
}

return sc[i].cost
}

type pricelistV0 struct {
computeGasMulti int64
storageGasMulti int64
Expand Down Expand Up @@ -93,9 +115,12 @@ type pricelistV0 struct {
computeUnsealedSectorCidBase int64
verifySealBase int64
verifyAggregateSealBase int64
verifyPostLookup map[abi.RegisteredPoStProof]scalingCost
verifyPostDiscount bool
verifyConsensusFault int64
verifyAggregateSealPer map[abi.RegisteredSealProof]int64
verifyAggregateSealSteps map[abi.RegisteredSealProof]stepCost

verifyPostLookup map[abi.RegisteredPoStProof]scalingCost
verifyPostDiscount bool
verifyConsensusFault int64
}

var _ Pricelist = (*pricelistV0)(nil)
Expand Down Expand Up @@ -189,8 +214,18 @@ func (pl *pricelistV0) OnVerifySeal(info proof2.SealVerifyInfo) GasCharge {

// OnVerifyAggregateSeals
func (pl *pricelistV0) OnVerifyAggregateSeals(aggregate proof5.AggregateSealVerifyProofAndInfos) GasCharge {
// TODO: this needs more cost tunning
return newGasCharge("OnVerifyAggregateSeals", pl.verifyAggregateSealBase, 0)
proofType := aggregate.SealProof
perProof, ok := pl.verifyAggregateSealPer[proofType]
if !ok {
perProof = pl.verifyAggregateSealPer[abi.RegisteredSealProof_StackedDrg32GiBV1_1]
}

step, ok := pl.verifyAggregateSealSteps[proofType]
if !ok {
step = pl.verifyAggregateSealSteps[abi.RegisteredSealProof_StackedDrg32GiBV1_1]
}
num := int64(len(aggregate.Infos))
return newGasCharge("OnVerifyAggregateSeals", perProof*num+step.Lookup(num), 0)
}

// OnVerifyPost
Expand Down
32 changes: 32 additions & 0 deletions chain/vm/gas_v0_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package vm

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestStepGasCost(t *testing.T) {
s := stepCost{
{4, 103994170},
{7, 112356810},
{13, 122912610},
{26, 137559930},
{52, 162039100},
{103, 210960780},
{205, 318351180},
{410, 528274980},
}

assert.EqualValues(t, 0, s.Lookup(0))
assert.EqualValues(t, 0, s.Lookup(3))
assert.EqualValues(t, 103994170, s.Lookup(4))
assert.EqualValues(t, 103994170, s.Lookup(6))
assert.EqualValues(t, 112356810, s.Lookup(7))
assert.EqualValues(t, 210960780, s.Lookup(103))
assert.EqualValues(t, 210960780, s.Lookup(204))
assert.EqualValues(t, 318351180, s.Lookup(205))
assert.EqualValues(t, 318351180, s.Lookup(409))
assert.EqualValues(t, 528274980, s.Lookup(410))
assert.EqualValues(t, 528274980, s.Lookup(10000000000))
}

0 comments on commit dd79c2c

Please sign in to comment.