Skip to content
This repository has been archived by the owner on Jun 6, 2023. It is now read-only.

Porep Gas charge reduced 4x past v7 #1301

Merged
merged 2 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions actors/builtin/power/power_actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package power

import (
"bytes"

addr "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/cbor"
Expand Down Expand Up @@ -257,12 +258,17 @@ func (a Actor) UpdatePledgeTotal(rt Runtime, pledgeDelta *abi.TokenAmount) *abi.

// GasOnSubmitVerifySeal is amount of gas charged for SubmitPoRepForBulkVerify
// This number is empirically determined
const GasOnSubmitVerifySeal = 34721049
const GasOnSubmitVerifySeal = power0.GasOnSubmitVerifySeal

// GasOnSubmitVerifySealV7 is the amount of gas charged for SubmitPoRepForBulkVerify
// after v7 corresponding to 4x speedup in porep.
const GasOnSubmitVerifySealV7 = 8509249

func (a Actor) SubmitPoRepForBulkVerify(rt Runtime, sealInfo *proof.SealVerifyInfo) *abi.EmptyValue {
rt.ValidateImmediateCallerType(builtin.StorageMinerActorCodeID)

minerAddr := rt.Caller()
nv := rt.NetworkVersion()

var st State
rt.StateTransaction(&st, func() {
Expand Down Expand Up @@ -290,7 +296,11 @@ func (a Actor) SubmitPoRepForBulkVerify(rt Runtime, sealInfo *proof.SealVerifyIn
mmrc, err := mmap.Root()
builtin.RequireNoErr(rt, err, exitcode.ErrIllegalState, "failed to flush proof batch")

rt.ChargeGas("OnSubmitVerifySeal", GasOnSubmitVerifySeal, 0)
if nv < network.Version7 {
rt.ChargeGas("OnSubmitVerifySeal", GasOnSubmitVerifySeal, 0)
} else {
rt.ChargeGas("OnSubmitVerifySeal", GasOnSubmitVerifySealV7, 0)
}
st.ProofValidationBatch = &mmrc
})

Expand Down
36 changes: 34 additions & 2 deletions actors/builtin/power/power_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"bytes"
"context"
"fmt"
"github.com/filecoin-project/go-state-types/network"
"strconv"
"strings"
"testing"

"github.com/filecoin-project/go-state-types/network"

addr "github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
Expand Down Expand Up @@ -863,6 +864,37 @@ func TestSubmitPoRepForBulkVerify(t *testing.T) {
UnsealedCID: commD,
}
actor.submitPoRepForBulkVerify(rt, miner, sealInfo)
rt.ExpectGasCharged(power.GasOnSubmitVerifySealV7)
st := getState(rt)
store := rt.AdtStore()
require.NotNil(t, st.ProofValidationBatch)
mmap, err := adt.AsMultimap(store, *st.ProofValidationBatch)
require.NoError(t, err)
arr, found, err := mmap.Get(abi.AddrKey(miner))
require.NoError(t, err)
require.True(t, found)
assert.Equal(t, uint64(1), arr.Length())
var storedSealInfo proof.SealVerifyInfo
found, err = arr.Get(0, &storedSealInfo)
require.NoError(t, err)
require.True(t, found)
assert.Equal(t, commR, storedSealInfo.SealedCID)
actor.checkState(rt)
})

t.Run("charges 4x for gas before network version 7", func(t *testing.T) {
rt := builder.Build(t)
rt.SetNetworkVersion(network.Version6)
actor.constructAndVerify(rt)
actor.createMinerBasic(rt, owner, owner, miner)
commR := tutil.MakeCID("commR", &mineract.SealedCIDPrefix)
commD := tutil.MakeCID("commD", &market.PieceCIDPrefix)
sealInfo := &proof.SealVerifyInfo{
SealProof: actor.sealProof,
SealedCID: commR,
UnsealedCID: commD,
}
actor.submitPoRepForBulkVerify(rt, miner, sealInfo)
rt.ExpectGasCharged(power.GasOnSubmitVerifySeal)
st := getState(rt)
store := rt.AdtStore()
Expand Down Expand Up @@ -903,7 +935,7 @@ func TestSubmitPoRepForBulkVerify(t *testing.T) {
})

// Gas only charged for successful submissions
rt.ExpectGasCharged(power.GasOnSubmitVerifySeal * power.MaxMinerProveCommitsPerEpoch)
rt.ExpectGasCharged(power.GasOnSubmitVerifySealV7 * power.MaxMinerProveCommitsPerEpoch)
})

t.Run("aborts when miner has no claim", func(t *testing.T) {
Expand Down