cache

package
v1.6.11-testnet Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CfxDefault = NewCfx()

Functions

func MustInitFromViper

func MustInitFromViper()

Types

type CfxCache

type CfxCache struct {
	*StatusCache
	// contains filtered or unexported fields
}

CfxCache memory cache for some core space RPC methods

func NewCfx

func NewCfx() *CfxCache

func (*CfxCache) GetClientVersion

func (cache *CfxCache) GetClientVersion(cfx sdk.ClientOperator) (string, bool, error)

func (*CfxCache) GetClientVersionWithFunc

func (cache *CfxCache) GetClientVersionWithFunc(rawGetter func() (string, error)) (string, bool, error)

func (*CfxCache) GetGasPrice

func (cache *CfxCache) GetGasPrice(cfx sdk.ClientOperator) (*hexutil.Big, bool, error)

func (*CfxCache) GetGasPriceWithFunc

func (cache *CfxCache) GetGasPriceWithFunc(rawGetter func() (*hexutil.Big, error)) (*hexutil.Big, bool, error)

type EthCache

type EthCache struct {
	EthCacheConfig
	// contains filtered or unexported fields
}

EthCache memory cache for some evm space RPC methods

var (
	EthDefault *EthCache = newEthCache(newEthCacheConfig())
)

func (*EthCache) AddPendingTransaction

func (cache *EthCache) AddPendingTransaction(txnHash common.Hash)

func (*EthCache) Call

func (cache *EthCache) Call(
	nodeName string,
	eth *client.RpcEthClient,
	callRequest types.CallRequest,
	blockNum *types.BlockNumberOrHash,
	overrides *types.StateOverride,
	blockOverrides *types.BlockOverrides,
) (RPCResult, bool, error)

func (*EthCache) CallWithFunc

func (cache *EthCache) CallWithFunc(
	nodeName string,
	callRequest types.CallRequest,
	blockNum *types.BlockNumberOrHash,
	overrides *types.StateOverride,
	blockOverrides *types.BlockOverrides,
	rawGetter func() ([]byte, error),
) (RPCResult, bool, error)

func (*EthCache) GetBlockNumber

func (cache *EthCache) GetBlockNumber(
	nodeName string, eth *client.RpcEthClient, blockNums ...types.BlockNumber) (*big.Int, bool, error)

func (*EthCache) GetBlockNumberWithFunc

func (cache *EthCache) GetBlockNumberWithFunc(
	nodeName string,
	blockNum types.BlockNumber,
	rawGetter func() (*big.Int, error),
) (*big.Int, bool, error)

func (*EthCache) GetChainId

func (cache *EthCache) GetChainId(eth *client.RpcEthClient) (*uint64, bool, error)

func (*EthCache) GetChainIdWithFunc

func (cache *EthCache) GetChainIdWithFunc(rawGetter func() (*uint64, error)) (*uint64, bool, error)

func (*EthCache) GetClientVersion

func (cache *EthCache) GetClientVersion(eth *client.RpcEthClient) (string, bool, error)

func (*EthCache) GetClientVersionWithFunc

func (cache *EthCache) GetClientVersionWithFunc(rawGetter func() (string, error)) (string, bool, error)

func (*EthCache) GetGasPrice

func (cache *EthCache) GetGasPrice(eth *client.RpcEthClient) (*big.Int, bool, error)

func (*EthCache) GetGasPriceWithFunc

func (cache *EthCache) GetGasPriceWithFunc(rawGetter func() (*big.Int, error)) (*big.Int, bool, error)

func (*EthCache) GetNetVersion

func (cache *EthCache) GetNetVersion(eth *client.RpcEthClient) (string, bool, error)

func (*EthCache) GetNetVersionWithFunc

func (cache *EthCache) GetNetVersionWithFunc(rawGetter func() (string, error)) (string, bool, error)

func (*EthCache) GetPendingTransaction

func (cache *EthCache) GetPendingTransaction(txHash common.Hash) (pendingTxn *ethPendingTxn, loaded, expired bool)

func (*EthCache) RemovePendingTransaction

func (cache *EthCache) RemovePendingTransaction(txHash common.Hash) bool

type EthCacheConfig

type EthCacheConfig struct {
	NetVersionExpiration      time.Duration `default:"1m"`
	ClientVersionExpiration   time.Duration `default:"1m"`
	ChainIdExpiration         time.Duration `default:"8760h"`
	BlockNumberExpiration     time.Duration `default:"1s"`
	PriceExpiration           time.Duration `default:"3s"`
	CallCacheExpiration       time.Duration `default:"1s"`
	CallCacheSize             int           `default:"1024"`
	PendingTxnCacheExpiration time.Duration `default:"3m"`
	PendingTxnCacheSize       int           `default:"1024"`
	PendingTxnCheckExemption  time.Duration `default:"3s"`
	PendingTxnCheckInterval   time.Duration `default:"1s"`
}

type RPCResult

type RPCResult struct {
	Data     any
	RpcError error
}

RPCResult represents the result of an RPC call, containing the response data or a potential JSON-RPC error.

type StatusCache

type StatusCache struct {
	// contains filtered or unexported fields
}

StatusCache memory cache for core space status related RPC method suites.

func NewStatusCache

func NewStatusCache() *StatusCache

func (*StatusCache) GetBestBlockHash

func (c *StatusCache) GetBestBlockHash(nodeName string, cfx sdk.ClientOperator) (types.Hash, bool, error)

func (*StatusCache) GetBestBlockHashWithFunc

func (c *StatusCache) GetBestBlockHashWithFunc(nodeName string, rawGetter func() (types.Hash, error)) (types.Hash, bool, error)

func (*StatusCache) GetEpochNumber

func (c *StatusCache) GetEpochNumber(nodeName string, cfx sdk.ClientOperator, epoch *types.Epoch) (*hexutil.Big, bool, error)

func (*StatusCache) GetEpochNumberWithFunc

func (c *StatusCache) GetEpochNumberWithFunc(
	nodeName string,
	epoch *types.Epoch,
	rawGetter func(epoch ...*types.Epoch) (*hexutil.Big, error),
) (*hexutil.Big, bool, error)

func (*StatusCache) GetStatus

func (c *StatusCache) GetStatus(nodeName string, cfx sdk.ClientOperator) (types.Status, bool, error)

func (*StatusCache) GetStatusWithFunc

func (c *StatusCache) GetStatusWithFunc(nodeName string, rawGetter func() (types.Status, error)) (types.Status, bool, error)

Jump to

Keyboard shortcuts

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