gas

package
v0.5.1-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 6 Imported by: 4

Documentation

Index

Constants

View Source
const (
	MaxGasPerBlock         = uint64(1_000_000_000)
	MinGasPerRequest       = uint64(10000)
	MaxGasPerRequest       = MaxGasPerBlock / 20 // one request cannot use more than 5% of maximum block gas
	MaxGasExternalViewCall = MaxGasPerRequest
)
View Source
const (
	BurnCodeStorage1P = BurnCode(iota)
	BurnCodeReadFromState1P
	BurnCodeCallTargetNotFound
	BurnCodeGetContext
	BurnCodeGetCallerData
	BurnCodeGetAllowance
	BurnCodeGetStateAnchorInfo
	BurnCodeGetBalance
	BurnCodeGetNFTData
	BurnCodeCallContract
	BurnCodeDeployContract
	BurnCodeEmitEventFixed
	BurnCodeTransferAllowance
	BurnCodeEstimateStorageDepositCost
	BurnCodeSendL1Request

	BurnCodeUtilsHashingBlake2b
	BurnCodeUtilsHashingSha3
	BurnCodeUtilsHashingHname
	BurnCodeUtilsHexEncode
	BurnCodeUtilsHexDecode
	BurnCodeUtilsED25519ValidSig
	BurnCodeUtilsED25519AddrFromPubKey
	BurnCodeUtilsBLSValidSignature
	BurnCodeUtilsBLSAddrFromPubKey
	BurnCodeUtilsBLSAggregateBLS1P

	BurnCodeWasm1P
	BurnCodeMinimumGasPerRequest1P

	BurnCodeEVM1P
)
View Source
const (
	Coef1Send        = 200
	CoefBLSAggregate = 400
)
View Source
const GasPolicyByteSize = util.RatioByteSize + serializer.OneByte + util.RatioByteSize

GasPerToken + ValidatorFeeShare + EVMGasRatio

Variables

View Source
var DefaultEVMGasRatio = util.Ratio32{A: 1, B: 1}

<ISC gas> = <EVM Gas> * <A> / <B>

View Source
var DefaultGasPerToken = util.Ratio32{A: 100, B: 1}

By default each token pays for 100 units of gas

View Source
var ErrInvalidRatio = errors.New("ratio must have both components != 0")
View Source
var ErrUnknownBurnCode = errors.New("unknown gas burn code")

Functions

func EVMBlockGasLimit added in v1.0.3

func EVMBlockGasLimit(gasRatio *util.Ratio32) uint64

EVMBlockGasLimit returns the ISC block gas limit converted to EVM gas units

func EVMCallGasLimit added in v1.0.3

func EVMCallGasLimit(gasRatio *util.Ratio32) uint64

EVMCallGasLimit returns the maximum gas limit accepted for an EVM tx

func EVMGasToISC added in v1.0.3

func EVMGasToISC(evmGas uint64, gasRatio *util.Ratio32) uint64

func FeeFromGas added in v1.0.3

func FeeFromGas(gasUnits uint64, gasPerToken util.Ratio32) uint64

func ISCGasBudgetToEVM added in v1.0.3

func ISCGasBudgetToEVM(iscGasBudget uint64, gasRatio *util.Ratio32) uint64

func ISCGasBurnedToEVM added in v1.0.3

func ISCGasBurnedToEVM(iscGasBurned uint64, gasRatio *util.Ratio32) uint64

func ReadRatio32

func ReadRatio32(mu *marshalutil.MarshalUtil) (ret util.Ratio32, err error)

Types

type BurnCode

type BurnCode uint16

func (BurnCode) Cost

func (c BurnCode) Cost(p ...uint64) uint64

func (BurnCode) Name

func (c BurnCode) Name() string

type BurnCodeRecord

type BurnCodeRecord struct {
	Name string
	BurnFunction
}

type BurnFunction

type BurnFunction func(x uint64) uint64

type BurnLog

type BurnLog struct {
	Records []BurnRecord `json:"records" swagger:"required"`
}

func NewGasBurnLog

func NewGasBurnLog() *BurnLog

func (*BurnLog) Record

func (h *BurnLog) Record(code BurnCode, gas uint64)

func (*BurnLog) String

func (h *BurnLog) String() string

type BurnRecord

type BurnRecord struct {
	Code      BurnCode `json:"code" swagger:"required"`
	GasBurned uint64   `json:"gasBurned" swagger:"required"`
}

type BurnTable

type BurnTable map[BurnCode]BurnCodeRecord

type FeePolicy added in v1.0.3

type FeePolicy struct {
	// GasPerToken specifies how many gas units are paid for each token.
	GasPerToken util.Ratio32

	// EVMGasRatio expresses the ratio at which EVM gas is converted to ISC gas
	EVMGasRatio util.Ratio32 // X = ISC gas, Y = EVM gas => ISC gas = EVM gas * A/B

	// ValidatorFeeShare Validator/Governor fee split: percentage of fees which goes to Validator
	// 0 mean all goes to Governor
	// >=100 all goes to Validator
	ValidatorFeeShare uint8
}

func DefaultFeePolicy added in v1.0.3

func DefaultFeePolicy() *FeePolicy

func FeePolicyFromBytes

func FeePolicyFromBytes(data []byte) (*FeePolicy, error)

func FeePolicyFromMarshalUtil

func FeePolicyFromMarshalUtil(mu *marshalutil.MarshalUtil) (*FeePolicy, error)

func MustFeePolicyFromBytes added in v1.0.3

func MustFeePolicyFromBytes(data []byte) *FeePolicy

func (*FeePolicy) Bytes added in v1.0.3

func (p *FeePolicy) Bytes() []byte

func (*FeePolicy) FeeFromGas added in v1.0.3

func (p *FeePolicy) FeeFromGas(gasUnits uint64) uint64

func (*FeePolicy) FeeFromGasBurned added in v1.0.3

func (p *FeePolicy) FeeFromGasBurned(gasUnits, availableTokens uint64) (sendToOwner, sendToValidator uint64)

FeeFromGasBurned calculates the how many tokens to take and where to deposit them.

func (*FeePolicy) GasBudgetFromTokens added in v1.0.3

func (p *FeePolicy) GasBudgetFromTokens(availableTokens uint64) uint64

func (*FeePolicy) IsEnoughForMinimumFee added in v1.0.3

func (p *FeePolicy) IsEnoughForMinimumFee(availableTokens uint64) bool

func (*FeePolicy) MinFee added in v1.0.3

func (p *FeePolicy) MinFee() uint64

func (*FeePolicy) String added in v1.0.3

func (p *FeePolicy) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL