2020-03-19 16:27:42 +00:00
|
|
|
package vm
|
|
|
|
|
|
|
|
import (
|
2020-04-23 16:45:52 +00:00
|
|
|
"fmt"
|
2020-06-11 18:37:14 +00:00
|
|
|
|
2020-03-19 16:27:42 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi"
|
2020-06-30 00:31:39 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/abi/big"
|
2020-03-19 16:27:42 +00:00
|
|
|
"github.com/filecoin-project/specs-actors/actors/builtin"
|
|
|
|
"github.com/filecoin-project/specs-actors/actors/crypto"
|
|
|
|
)
|
|
|
|
|
2020-07-28 20:30:59 +00:00
|
|
|
type scalingCost struct {
|
|
|
|
flat int64
|
|
|
|
scale int64
|
|
|
|
}
|
|
|
|
|
2020-03-19 16:27:42 +00:00
|
|
|
type pricelistV0 struct {
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// System operations
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Gas cost charged to the originator of an on-chain message (regardless of
|
|
|
|
// whether it succeeds or fails in application) is given by:
|
|
|
|
// OnChainMessageBase + len(serialized message)*OnChainMessagePerByte
|
|
|
|
// Together, these account for the cost of message propagation and validation,
|
|
|
|
// up to but excluding any actual processing by the VM.
|
|
|
|
// This is the cost a block producer burns when including an invalid message.
|
2020-07-10 13:12:27 +00:00
|
|
|
onChainMessageComputeBase int64
|
|
|
|
onChainMessageStorageBase int64
|
|
|
|
onChainMessageStoragePerByte int64
|
2020-03-19 16:27:42 +00:00
|
|
|
|
|
|
|
// Gas cost charged to the originator of a non-nil return value produced
|
|
|
|
// by an on-chain message is given by:
|
|
|
|
// len(return value)*OnChainReturnValuePerByte
|
|
|
|
onChainReturnValuePerByte int64
|
|
|
|
|
|
|
|
// Gas cost for any message send execution(including the top-level one
|
|
|
|
// initiated by an on-chain message).
|
|
|
|
// This accounts for the cost of loading sender and receiver actors and
|
|
|
|
// (for top-level messages) incrementing the sender's sequence number.
|
|
|
|
// Load and store of actor sub-state is charged separately.
|
|
|
|
sendBase int64
|
|
|
|
|
|
|
|
// Gas cost charged, in addition to SendBase, if a message send
|
|
|
|
// is accompanied by any nonzero currency amount.
|
|
|
|
// Accounts for writing receiver's new balance (the sender's state is
|
|
|
|
// already accounted for).
|
|
|
|
sendTransferFunds int64
|
|
|
|
|
2020-07-10 13:12:27 +00:00
|
|
|
// Gsa cost charged, in addition to SendBase, if message only transfers funds.
|
|
|
|
sendTransferOnlyPremium int64
|
|
|
|
|
2020-03-19 16:27:42 +00:00
|
|
|
// Gas cost charged, in addition to SendBase, if a message invokes
|
|
|
|
// a method on the receiver.
|
|
|
|
// Accounts for the cost of loading receiver code and method dispatch.
|
|
|
|
sendInvokeMethod int64
|
|
|
|
|
2020-07-10 13:12:27 +00:00
|
|
|
// Gas cost for any Get operation to the IPLD store
|
2020-03-19 16:27:42 +00:00
|
|
|
// in the runtime VM context.
|
2020-07-10 13:12:27 +00:00
|
|
|
ipldGetBase int64
|
2020-03-19 16:27:42 +00:00
|
|
|
|
|
|
|
// Gas cost (Base + len*PerByte) for any Put operation to the IPLD store
|
|
|
|
// in the runtime VM context.
|
|
|
|
//
|
|
|
|
// Note: these costs should be significantly higher than the costs for Get
|
|
|
|
// operations, since they reflect not only serialization/deserialization
|
|
|
|
// but also persistent storage of chain data.
|
|
|
|
ipldPutBase int64
|
|
|
|
ipldPutPerByte int64
|
|
|
|
|
|
|
|
// Gas cost for creating a new actor (via InitActor's Exec method).
|
|
|
|
//
|
|
|
|
// Note: this costs assume that the extra will be partially or totally refunded while
|
|
|
|
// the base is covering for the put.
|
2020-07-10 13:12:27 +00:00
|
|
|
createActorCompute int64
|
|
|
|
createActorStorage int64
|
2020-03-19 16:27:42 +00:00
|
|
|
|
|
|
|
// Gas cost for deleting an actor.
|
|
|
|
//
|
|
|
|
// Note: this partially refunds the create cost to incentivise the deletion of the actors.
|
|
|
|
deleteActor int64
|
|
|
|
|
2020-07-10 13:12:27 +00:00
|
|
|
verifySignature map[crypto.SigType]int64
|
2020-03-19 16:27:42 +00:00
|
|
|
|
2020-07-10 13:12:27 +00:00
|
|
|
hashingBase int64
|
2020-03-19 16:27:42 +00:00
|
|
|
|
|
|
|
computeUnsealedSectorCidBase int64
|
|
|
|
verifySealBase int64
|
2020-07-28 20:30:59 +00:00
|
|
|
verifyPostLookup map[abi.RegisteredPoStProof]scalingCost
|
2020-03-19 16:27:42 +00:00
|
|
|
verifyConsensusFault int64
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Pricelist = (*pricelistV0)(nil)
|
|
|
|
|
|
|
|
// OnChainMessage returns the gas used for storing a message of a given size in the chain.
|
2020-06-11 18:37:14 +00:00
|
|
|
func (pl *pricelistV0) OnChainMessage(msgSize int) GasCharge {
|
2020-07-10 13:12:27 +00:00
|
|
|
return newGasCharge("OnChainMessage", pl.onChainMessageComputeBase,
|
|
|
|
pl.onChainMessageStorageBase+pl.onChainMessageStoragePerByte*int64(msgSize))
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnChainReturnValue returns the gas used for storing the response of a message in the chain.
|
2020-06-11 18:37:14 +00:00
|
|
|
func (pl *pricelistV0) OnChainReturnValue(dataSize int) GasCharge {
|
2020-07-10 13:12:27 +00:00
|
|
|
return newGasCharge("OnChainReturnValue", 0, int64(dataSize)*pl.onChainReturnValuePerByte)
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnMethodInvocation returns the gas used when invoking a method.
|
2020-06-11 18:37:14 +00:00
|
|
|
func (pl *pricelistV0) OnMethodInvocation(value abi.TokenAmount, methodNum abi.MethodNum) GasCharge {
|
2020-03-19 16:27:42 +00:00
|
|
|
ret := pl.sendBase
|
2020-06-29 17:19:02 +00:00
|
|
|
extra := ""
|
2020-06-30 00:31:39 +00:00
|
|
|
|
2020-06-30 12:09:03 +00:00
|
|
|
if big.Cmp(value, abi.NewTokenAmount(0)) != 0 {
|
2020-07-10 13:12:27 +00:00
|
|
|
ret += pl.sendTransferFunds
|
2020-06-30 12:09:03 +00:00
|
|
|
if methodNum == builtin.MethodSend {
|
|
|
|
// transfer only
|
2020-07-10 13:12:27 +00:00
|
|
|
ret += pl.sendTransferOnlyPremium
|
2020-06-30 12:09:03 +00:00
|
|
|
}
|
2020-06-29 17:19:02 +00:00
|
|
|
extra += "t"
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
2020-07-10 13:12:27 +00:00
|
|
|
|
2020-03-19 16:27:42 +00:00
|
|
|
if methodNum != builtin.MethodSend {
|
2020-06-29 17:19:02 +00:00
|
|
|
extra += "i"
|
2020-06-30 12:09:03 +00:00
|
|
|
// running actors is cheaper becase we hand over to actors
|
2020-07-10 13:12:27 +00:00
|
|
|
ret += pl.sendInvokeMethod
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
2020-07-10 13:12:27 +00:00
|
|
|
return newGasCharge("OnMethodInvocation", ret, 0).WithExtra(extra)
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnIpldGet returns the gas used for storing an object
|
2020-07-15 19:40:49 +00:00
|
|
|
func (pl *pricelistV0) OnIpldGet() GasCharge {
|
2020-07-10 13:12:27 +00:00
|
|
|
return newGasCharge("OnIpldGet", pl.ipldGetBase, 0)
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnIpldPut returns the gas used for storing an object
|
2020-06-11 18:37:14 +00:00
|
|
|
func (pl *pricelistV0) OnIpldPut(dataSize int) GasCharge {
|
2020-06-30 00:31:39 +00:00
|
|
|
return newGasCharge("OnIpldPut", pl.ipldPutBase, int64(dataSize)*pl.ipldPutPerByte).
|
2020-07-10 13:12:27 +00:00
|
|
|
WithExtra(dataSize)
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnCreateActor returns the gas used for creating an actor
|
2020-06-11 18:37:14 +00:00
|
|
|
func (pl *pricelistV0) OnCreateActor() GasCharge {
|
2020-07-10 13:12:27 +00:00
|
|
|
return newGasCharge("OnCreateActor", pl.createActorCompute, pl.createActorStorage)
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnDeleteActor returns the gas used for deleting an actor
|
2020-06-11 18:37:14 +00:00
|
|
|
func (pl *pricelistV0) OnDeleteActor() GasCharge {
|
|
|
|
return newGasCharge("OnDeleteActor", 0, pl.deleteActor)
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnVerifySignature
|
2020-06-29 16:46:50 +00:00
|
|
|
|
2020-06-11 18:37:14 +00:00
|
|
|
func (pl *pricelistV0) OnVerifySignature(sigType crypto.SigType, planTextSize int) (GasCharge, error) {
|
2020-07-10 13:12:27 +00:00
|
|
|
cost, ok := pl.verifySignature[sigType]
|
2020-03-19 16:27:42 +00:00
|
|
|
if !ok {
|
2020-06-11 18:37:14 +00:00
|
|
|
return GasCharge{}, fmt.Errorf("cost function for signature type %d not supported", sigType)
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
2020-06-30 12:09:03 +00:00
|
|
|
|
2020-07-10 13:12:27 +00:00
|
|
|
sigName, _ := sigType.Name()
|
|
|
|
return newGasCharge("OnVerifySignature", cost, 0).
|
2020-06-30 00:31:39 +00:00
|
|
|
WithExtra(map[string]interface{}{
|
|
|
|
"type": sigName,
|
|
|
|
"size": planTextSize,
|
2020-07-10 13:12:27 +00:00
|
|
|
}), nil
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnHashing
|
2020-06-11 18:37:14 +00:00
|
|
|
func (pl *pricelistV0) OnHashing(dataSize int) GasCharge {
|
2020-07-10 13:12:27 +00:00
|
|
|
return newGasCharge("OnHashing", pl.hashingBase, 0).WithExtra(dataSize)
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnComputeUnsealedSectorCid
|
2020-06-15 16:30:49 +00:00
|
|
|
func (pl *pricelistV0) OnComputeUnsealedSectorCid(proofType abi.RegisteredSealProof, pieces []abi.PieceInfo) GasCharge {
|
2020-07-10 13:12:27 +00:00
|
|
|
return newGasCharge("OnComputeUnsealedSectorCid", pl.computeUnsealedSectorCidBase, 0)
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnVerifySeal
|
2020-06-11 18:37:14 +00:00
|
|
|
func (pl *pricelistV0) OnVerifySeal(info abi.SealVerifyInfo) GasCharge {
|
2020-03-19 16:27:42 +00:00
|
|
|
// TODO: this needs more cost tunning, check with @lotus
|
2020-07-10 13:12:27 +00:00
|
|
|
// this is not used
|
|
|
|
return newGasCharge("OnVerifySeal", pl.verifySealBase, 0)
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnVerifyPost
|
2020-06-11 18:37:14 +00:00
|
|
|
func (pl *pricelistV0) OnVerifyPost(info abi.WindowPoStVerifyInfo) GasCharge {
|
2020-07-28 13:11:41 +00:00
|
|
|
sectorSize := "unknown"
|
2020-07-28 20:30:59 +00:00
|
|
|
var proofType abi.RegisteredPoStProof
|
|
|
|
|
|
|
|
if len(info.Proofs) != 0 {
|
|
|
|
proofType = info.Proofs[0].PoStProof
|
|
|
|
ss, err := info.Proofs[0].PoStProof.SectorSize()
|
2020-07-28 13:11:41 +00:00
|
|
|
if err == nil {
|
|
|
|
sectorSize = ss.ShortString()
|
|
|
|
}
|
|
|
|
}
|
2020-07-28 20:30:59 +00:00
|
|
|
|
|
|
|
cost, ok := pl.verifyPostLookup[proofType]
|
|
|
|
if !ok {
|
|
|
|
cost = pl.verifyPostLookup[abi.RegisteredPoStProof_StackedDrgWindow512MiBV1]
|
|
|
|
}
|
|
|
|
|
2020-07-31 19:38:23 +00:00
|
|
|
gasUsed := cost.flat + int64(len(info.ChallengedSectors))*cost.scale
|
|
|
|
gasUsed /= 2 // XXX: this is an artificial discount
|
|
|
|
|
|
|
|
return newGasCharge("OnVerifyPost", gasUsed, 0).
|
2020-07-28 13:11:41 +00:00
|
|
|
WithExtra(map[string]interface{}{
|
|
|
|
"type": sectorSize,
|
|
|
|
"size": len(info.ChallengedSectors),
|
|
|
|
})
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// OnVerifyConsensusFault
|
2020-06-11 18:37:14 +00:00
|
|
|
func (pl *pricelistV0) OnVerifyConsensusFault() GasCharge {
|
2020-07-10 13:12:27 +00:00
|
|
|
return newGasCharge("OnVerifyConsensusFault", pl.verifyConsensusFault, 0)
|
2020-03-19 16:27:42 +00:00
|
|
|
}
|