Documentation ¶
Index ¶
- Constants
- type AddressIndexedLog
- type AddressIndexedLogFilter
- type AddressIndexedLogStore
- func (ls *AddressIndexedLogStore) AddAddressIndexedLogs(dbTx *gorm.DB, data *store.EpochData, bigContractIds map[uint64]bool) error
- func (ls *AddressIndexedLogStore) CreatePartitionedTables() (int, error)
- func (ls *AddressIndexedLogStore) DeleteAddressIndexedLogs(dbTx *gorm.DB, epochFrom, epochTo uint64) error
- func (ls *AddressIndexedLogStore) GetAddressIndexedLogs(filter AddressIndexedLogFilter, contract string) ([]*AddressIndexedLog, error)
- func (ls *AddressIndexedLogStore) GetPartitionedTableName(contract string) string
- type Config
- type Contract
- type ContractStore
- func (cs *ContractStore) AddContract(contracts map[string]bool) (int, error)
- func (cs *ContractStore) AddContractByEpochData(slice ...*store.EpochData) (int, error)
- func (cs *ContractStore) AddContractIfAbsent(address string) (uint64, bool, error)
- func (bs ContractStore) Close() error
- func (bs ContractStore) DB() *gorm.DB
- func (cs *ContractStore) GetContractAddressById(id uint64) (string, bool, error)
- func (cs *ContractStore) GetContractById(cid uint64) (*Contract, bool, error)
- func (cs *ContractStore) GetContractIdByAddress(address string) (uint64, bool, error)
- func (cs *ContractStore) GetUpdatedContractsSinceEpoch(epoch uint64) ([]*Contract, error)
- func (ContractStore) IsRecordNotFound(err error) bool
- func (cs *ContractStore) UpdateContractStats(dbTx *gorm.DB, cid uint64, countDelta int, latestUpdatedEpoch uint64) error
- type LogFilter
- type MysqlStore
- func (e2bms MysqlStore) BlockRange(epoch uint64) (citypes.RangeUint64, bool, error)
- func (bs MysqlStore) Close() error
- func (bs MysqlStore) DB() *gorm.DB
- func (cs MysqlStore) DelNodeRouteGroup(group string) error
- func (cs MysqlStore) DeleteConfig(confName string) (bool, error)
- func (bs MysqlStore) GetBlockByBlockNumber(ctx context.Context, blockNumber uint64) (*store.Block, error)
- func (bs MysqlStore) GetBlockByEpoch(ctx context.Context, epochNumber uint64) (*store.Block, error)
- func (bs MysqlStore) GetBlockByHash(ctx context.Context, blockHash types.Hash) (*store.Block, error)
- func (bs MysqlStore) GetBlockSummaryByBlockNumber(ctx context.Context, blockNumber uint64) (*store.BlockSummary, error)
- func (bs MysqlStore) GetBlockSummaryByEpoch(ctx context.Context, epochNumber uint64) (*store.BlockSummary, error)
- func (bs MysqlStore) GetBlockSummaryByHash(ctx context.Context, blockHash types.Hash) (*store.BlockSummary, error)
- func (bs MysqlStore) GetBlocksByEpoch(ctx context.Context, epochNumber uint64) ([]types.Hash, error)
- func (ms *MysqlStore) GetLogs(ctx context.Context, storeFilter store.LogFilter) ([]*store.Log, error)
- func (ts MysqlStore) GetReceipt(ctx context.Context, txHash types.Hash) (*store.TransactionReceipt, error)
- func (cs MysqlStore) GetReorgVersion() (int, error)
- func (ts MysqlStore) GetTransaction(ctx context.Context, txHash types.Hash) (*store.Transaction, error)
- func (MysqlStore) IsRecordNotFound(err error) bool
- func (cs MysqlStore) LoadAclAllowList(name string) (*acl.AllowList, error)
- func (cs MysqlStore) LoadAclAllowListById(aclID uint32) (*acl.AllowList, error)
- func (cs MysqlStore) LoadAclAllowListConfigs() (map[uint32]*acl.AllowList, map[uint32][md5.Size]byte, error)
- func (cs MysqlStore) LoadConfig(confNames ...string) (map[string]interface{}, error)
- func (cs MysqlStore) LoadNodeRouteGroups(inclusiveGroups ...string) (res map[string]*NodeRouteGroup, err error)
- func (cs MysqlStore) LoadRateLimitConfigs() (*rate.Config, error)
- func (cs MysqlStore) LoadRateLimitStrategy(name string) (*rate.Strategy, error)
- func (cs MysqlStore) LoadRateLimitStrategyConfigs() (map[uint32]*rate.Strategy, map[uint32][md5.Size]byte, error)
- func (e2bms MysqlStore) MaxEpoch() (uint64, bool, error)
- func (e2bms MysqlStore) PivotHash(epoch uint64) (string, bool, error)
- func (ms *MysqlStore) Popn(epochUntil uint64) error
- func (ms *MysqlStore) PopnWithFinalizer(epochUntil uint64, finalizer func(*gorm.DB) error) error
- func (ms *MysqlStore) Prune()
- func (ms *MysqlStore) Push(data *store.EpochData) error
- func (ms *MysqlStore) Pushn(dataSlice []*store.EpochData) error
- func (ms *MysqlStore) PushnWithFinalizer(dataSlice []*store.EpochData, finalizer func(*gorm.DB) error) error
- func (cs MysqlStore) StoreConfig(confName string, confVal interface{}) error
- func (cs MysqlStore) StoreNodeRouteGroup(routeGrp *NodeRouteGroup) error
- type NodeRoute
- type NodeRouteFilter
- type NodeRouteGroup
- type NodeRouteStore
- func (nrs *NodeRouteStore) AddNodeRoute(routeKey, routeGroup string) error
- func (bs NodeRouteStore) Close() error
- func (bs NodeRouteStore) DB() *gorm.DB
- func (nrs *NodeRouteStore) DeleteNodeRoute(routeKey string) (bool, error)
- func (nrs *NodeRouteStore) FindNodeRoute(routeKey string) (*NodeRoute, error)
- func (NodeRouteStore) IsRecordNotFound(err error) bool
- func (nrs *NodeRouteStore) LoadNodeRoutes(filter NodeRouteFilter) (res []*NodeRoute, err error)
- type RateLimit
- type RateLimitStore
- func (rls *RateLimitStore) AddRateLimit(sid uint32, aclId uint32, limitType rate.LimitType, limitKey string, ...) error
- func (bs RateLimitStore) Close() error
- func (bs RateLimitStore) DB() *gorm.DB
- func (rls *RateLimitStore) DeleteRateLimit(limitKey string) (bool, error)
- func (RateLimitStore) IsRecordNotFound(err error) bool
- func (rls *RateLimitStore) LoadRateLimitKeyInfos(filter *rate.KeysetFilter) (res []*rate.KeyInfo, err error)
- func (rls *RateLimitStore) LoadRateLimitKeyset(filter *rate.KeysetFilter) (res []*RateLimit, err error)
- type StoreOption
- type User
- type UserStore
- type VirtualFilterLog
- type VirtualFilterLogStore
- func (vfls *VirtualFilterLogStore) Append(fid string, logs []VirtualFilterLog, partition bnPartition) error
- func (vfls *VirtualFilterLogStore) DeletePartitions(fid string) error
- func (vfls *VirtualFilterLogStore) GC(fid string) error
- func (vfls *VirtualFilterLogStore) GetLogs(ctx context.Context, fid string, sfilter store.LogFilter, ...) ([]VirtualFilterLog, error)
- func (vfls *VirtualFilterLogStore) PreparePartition(fid string) (bnPartition, bool, error)
Constants ¶
const ( MysqlConfKeyReorgVersion = "reorg.version" // pre-defined ratelimit strategy config key prefix RateLimitStrategyConfKeyPrefix = "ratelimit.strategy." // pre-defined access control config key prefix AclAllowListConfKeyPrefix = "acl.allowlist." // pre-defined node route group config key prefix NodeRouteGroupConfKeyPrefix = "noderoute.group." )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddressIndexedLog ¶
type AddressIndexedLog struct { ID uint64 ContractID uint64 `gorm:"column:cid;size:64;not null;index:idx_cid_bn,priority:1"` BlockNumber uint64 `gorm:"column:bn;not null;index:idx_cid_bn,priority:2"` Epoch uint64 `gorm:"not null;index"` // to support pop logs when reorg Topic0 string `gorm:"size:66;not null"` Topic1 string `gorm:"size:66"` Topic2 string `gorm:"size:66"` Topic3 string `gorm:"size:66"` LogIndex uint64 `gorm:"not null"` Extra []byte `gorm:"type:mediumText"` // extention json field }
func (AddressIndexedLog) TableName ¶
func (AddressIndexedLog) TableName() string
type AddressIndexedLogFilter ¶
AddressIndexedLogFilter is used to query event logs that indexed by contract id and block number.
func (*AddressIndexedLogFilter) Find ¶
func (filter *AddressIndexedLogFilter) Find(db *gorm.DB) ([]*AddressIndexedLog, error)
type AddressIndexedLogStore ¶
type AddressIndexedLogStore struct {
// contains filtered or unexported fields
}
AddressIndexedLogStore is used to store address indexed event logs in N partitions, e.g. logs_1, logs_2, ..., logs_n.
func NewAddressIndexedLogStore ¶
func NewAddressIndexedLogStore(db *gorm.DB, cs *ContractStore, partitions uint32) *AddressIndexedLogStore
func (*AddressIndexedLogStore) AddAddressIndexedLogs ¶
func (ls *AddressIndexedLogStore) AddAddressIndexedLogs(dbTx *gorm.DB, data *store.EpochData, bigContractIds map[uint64]bool) error
AddAddressIndexedLogs adds event logs of specified epoch (with that of big contract ignored) into different partitioned tables.
func (*AddressIndexedLogStore) CreatePartitionedTables ¶
func (ls *AddressIndexedLogStore) CreatePartitionedTables() (int, error)
CreatePartitionedTables initializes partitioned tables.
func (*AddressIndexedLogStore) DeleteAddressIndexedLogs ¶
func (ls *AddressIndexedLogStore) DeleteAddressIndexedLogs(dbTx *gorm.DB, epochFrom, epochTo uint64) error
DeleteAddressIndexedLogs removes event logs of specified epoch number range.
Generally, this is used when pivot chain switched for confirmed blocks.
func (*AddressIndexedLogStore) GetAddressIndexedLogs ¶
func (ls *AddressIndexedLogStore) GetAddressIndexedLogs( filter AddressIndexedLogFilter, contract string, ) ([]*AddressIndexedLog, error)
GetAddressIndexedLogs returns event logs for the specified filter.
func (*AddressIndexedLogStore) GetPartitionedTableName ¶
func (ls *AddressIndexedLogStore) GetPartitionedTableName(contract string) string
GetPartitionedTableName returns partitioned table name with specified contract address hashed partition index
type Config ¶
type Config struct { Enabled bool Host string `default:"127.0.0.1:3306"` Username string Password string Database string Dsn string // to support one line config ConnMaxLifetime time.Duration `default:"3m"` MaxOpenConns int `default:"10"` MaxIdleConns int `default:"10"` AddressIndexedLogEnabled bool `default:"true"` AddressIndexedLogPartitions uint32 `default:"100"` MaxBnRangedArchiveLogPartitions uint32 `default:"5"` }
Config represents the mysql configurations to open a database instance.
func MustNewConfigFromViper ¶
func MustNewConfigFromViper() *Config
MustNewConfigFromViper creates an instance of Config from Viper or panic on error.
func MustNewEthStoreConfigFromViper ¶
func MustNewEthStoreConfigFromViper() *Config
func (*Config) MustOpenOrCreate ¶
func (config *Config) MustOpenOrCreate(option StoreOption) *MysqlStore
MustOpenOrCreate creates an instance of store or exits on any erorr.
type Contract ¶
type Contract struct { // id and address are immutable once created. ID uint64 // contract id Address string `gorm:"size:64;not null;unique"` // num of persisted event logs LogCount int `gorm:"not null;default:0"` // latest updated epoch height LatestUpdatedEpoch uint64 `gorm:"index:index_lue;not null;default:0"` }
type ContractStore ¶
type ContractStore struct {
// contains filtered or unexported fields
}
func NewContractStore ¶
func NewContractStore(db *gorm.DB, cacheSize ...int) *ContractStore
func (*ContractStore) AddContract ¶
func (cs *ContractStore) AddContract(contracts map[string]bool) (int, error)
AddContract adds absent contracts in batch and returns the number of new added contracts.
func (*ContractStore) AddContractByEpochData ¶
func (cs *ContractStore) AddContractByEpochData(slice ...*store.EpochData) (int, error)
AddContract adds contract for the specified epoch data slice and returns the number of new added contracts.
func (*ContractStore) AddContractIfAbsent ¶
func (cs *ContractStore) AddContractIfAbsent(address string) (uint64, bool, error)
AddContractIfAbsent add new contract if absent. Note, this method is thread unsafe. Generally, it is used by data sync thread.
func (*ContractStore) GetContractAddressById ¶
func (cs *ContractStore) GetContractAddressById(id uint64) (string, bool, error)
GetContractAddressById gets contract address by id from cache or db if not found.
func (*ContractStore) GetContractById ¶
func (cs *ContractStore) GetContractById(cid uint64) (*Contract, bool, error)
GetContractById gets contract by id from db and also loads the cache.
For contract `LogCount` and `LastUpdatedEpoch` fields, they are quite mutable while cache maybe rarely updated.
func (*ContractStore) GetContractIdByAddress ¶
func (cs *ContractStore) GetContractIdByAddress(address string) (uint64, bool, error)
GetContractIdByAddress gets contract id by address from cache or db if not found.
func (*ContractStore) GetUpdatedContractsSinceEpoch ¶
func (cs *ContractStore) GetUpdatedContractsSinceEpoch(epoch uint64) ([]*Contract, error)
GetContractsByEpoch gets all contracts that have been updated since the specified epoch.
func (ContractStore) IsRecordNotFound ¶
func (*ContractStore) UpdateContractStats ¶
func (cs *ContractStore) UpdateContractStats( dbTx *gorm.DB, cid uint64, countDelta int, latestUpdatedEpoch uint64, ) error
UpdateContractStats updates statistics (log count/latest updated epoch) of the specified contract.
type LogFilter ¶
type LogFilter struct { TableName string // always indexed by block number BlockFrom uint64 BlockTo uint64 // event hash and indexed data 1, 2, 3 Topics []store.VariadicValue }
logFilter is used to query event logs with specified table, block number range and topics.
type MysqlStore ¶
type MysqlStore struct { *UserStore *RateLimitStore *VirtualFilterLogStore *NodeRouteStore // contains filtered or unexported fields }
MysqlStore aggregation store for chain data persistence operation.
func (MysqlStore) BlockRange ¶
func (e2bms MysqlStore) BlockRange(epoch uint64) (citypes.RangeUint64, bool, error)
blockRange returns the spanning block range for the give epoch.
func (MysqlStore) DelNodeRouteGroup ¶
func (MysqlStore) DeleteConfig ¶
func (MysqlStore) GetBlockByBlockNumber ¶
func (MysqlStore) GetBlockByEpoch ¶
func (MysqlStore) GetBlockByHash ¶
func (MysqlStore) GetBlockSummaryByBlockNumber ¶
func (MysqlStore) GetBlockSummaryByEpoch ¶
func (MysqlStore) GetBlockSummaryByHash ¶
func (MysqlStore) GetBlocksByEpoch ¶
func (MysqlStore) GetReceipt ¶
func (MysqlStore) GetReorgVersion ¶
func (MysqlStore) GetTransaction ¶
func (MysqlStore) IsRecordNotFound ¶
func (MysqlStore) LoadAclAllowList ¶
access control config
func (MysqlStore) LoadAclAllowListById ¶
func (MysqlStore) LoadAclAllowListConfigs ¶
func (MysqlStore) LoadConfig ¶
func (MysqlStore) LoadNodeRouteGroups ¶
func (cs MysqlStore) LoadNodeRouteGroups(inclusiveGroups ...string) (res map[string]*NodeRouteGroup, err error)
func (MysqlStore) LoadRateLimitConfigs ¶
func (MysqlStore) LoadRateLimitStrategy ¶
func (MysqlStore) LoadRateLimitStrategyConfigs ¶
func (*MysqlStore) Popn ¶
func (ms *MysqlStore) Popn(epochUntil uint64) error
Popn pops multiple epoch data from database.
func (*MysqlStore) PopnWithFinalizer ¶
Popn pops multiple epoch data from database with an extra finalizer to commit or rollback the transaction.
func (*MysqlStore) PushnWithFinalizer ¶
func (ms *MysqlStore) PushnWithFinalizer(dataSlice []*store.EpochData, finalizer func(*gorm.DB) error) error
Popn saves multiple epoch data into db with an extra finalizer to commit or rollback the transaction.
func (MysqlStore) StoreConfig ¶
func (MysqlStore) StoreNodeRouteGroup ¶
func (cs MysqlStore) StoreNodeRouteGroup(routeGrp *NodeRouteGroup) error
type NodeRoute ¶
type NodeRoute struct { ID uint32 // route key such as access token RouteKey string `gorm:"unique;size:128;not null"` // desingated route group such as `cfxvip` Group string `gorm:"size:64;not null"` CreatedAt time.Time UpdatedAt time.Time }
NodeRoute node route configurations
type NodeRouteFilter ¶
type NodeRouteGroup ¶
type NodeRouteStore ¶
type NodeRouteStore struct {
// contains filtered or unexported fields
}
func NewNodeRouteStore ¶
func NewNodeRouteStore(db *gorm.DB) *NodeRouteStore
func (*NodeRouteStore) AddNodeRoute ¶
func (nrs *NodeRouteStore) AddNodeRoute(routeKey, routeGroup string) error
func (*NodeRouteStore) DeleteNodeRoute ¶
func (nrs *NodeRouteStore) DeleteNodeRoute(routeKey string) (bool, error)
func (*NodeRouteStore) FindNodeRoute ¶
func (nrs *NodeRouteStore) FindNodeRoute(routeKey string) (*NodeRoute, error)
func (NodeRouteStore) IsRecordNotFound ¶
func (*NodeRouteStore) LoadNodeRoutes ¶
func (nrs *NodeRouteStore) LoadNodeRoutes(filter NodeRouteFilter) (res []*NodeRoute, err error)
type RateLimit ¶
type RateLimit struct { ID uint32 SID uint32 `gorm:"index"` // strategy ID AclID uint32 `gorm:"index"` // allow list ID LimitType int `gorm:"default:0;not null"` // limit type LimitKey string `gorm:"unique;size:128;not null"` // limit key Memo string `gorm:"size:128"` // memo CreatedAt time.Time UpdatedAt time.Time }
RateLimit rate limit keyset table
type RateLimitStore ¶
type RateLimitStore struct {
// contains filtered or unexported fields
}
func NewRateLimitStore ¶
func NewRateLimitStore(db *gorm.DB) *RateLimitStore
func (*RateLimitStore) AddRateLimit ¶
func (*RateLimitStore) DeleteRateLimit ¶
func (rls *RateLimitStore) DeleteRateLimit(limitKey string) (bool, error)
func (RateLimitStore) IsRecordNotFound ¶
func (*RateLimitStore) LoadRateLimitKeyInfos ¶
func (rls *RateLimitStore) LoadRateLimitKeyInfos(filter *rate.KeysetFilter) (res []*rate.KeyInfo, err error)
func (*RateLimitStore) LoadRateLimitKeyset ¶
func (rls *RateLimitStore) LoadRateLimitKeyset(filter *rate.KeysetFilter) (res []*RateLimit, err error)
type StoreOption ¶
type StoreOption struct {
Disabler store.StoreDisabler
}
type User ¶
type User struct { ID uint32 Name string `gorm:"size:256;not null;unique"` Description string `gorm:"size:1024"` ApiKey string `gorm:"size:256;not null;unique"` NodeUrl string `gorm:"size:256;not null"` }
User represents a VIP user that provide specific archive node to query historical event logs.
type UserStore ¶
type UserStore struct {
// contains filtered or unexported fields
}
func (UserStore) IsRecordNotFound ¶
type VirtualFilterLog ¶
type VirtualFilterLog struct { ID uint64 BlockNumber uint64 `gorm:"column:bn;not null;index:idx_bn"` BlockHash string `gorm:"column:bh;size:66;not null"` ContractAddress string `gorm:"size:66;not null"` Topic0 string `gorm:"size:66;not null"` Topic1 string `gorm:"size:66"` Topic2 string `gorm:"size:66"` Topic3 string `gorm:"size:66"` LogIndex uint64 `gorm:"not null"` JsonRepr []byte `gorm:"type:mediumText"` // marshalled json representation IsDel bool `gorm:"default:false"` // soft delete flag // contains filtered or unexported fields }
VirtualFilterLog virtual filter event logs
func (VirtualFilterLog) TableName ¶
func (l VirtualFilterLog) TableName() string
type VirtualFilterLogStore ¶
type VirtualFilterLogStore struct {
// contains filtered or unexported fields
}
VirtualFilterLogStore partitioned store for virtual filter which polls filter changed data instantly.
func NewVirtualFilterLogStore ¶
func NewVirtualFilterLogStore(db *gorm.DB) *VirtualFilterLogStore
func (*VirtualFilterLogStore) Append ¶
func (vfls *VirtualFilterLogStore) Append(fid string, logs []VirtualFilterLog, partition bnPartition) error
Append appends incoming filter changed event logs, if some old ones of same block hashes already existed in the db, they will be soft deleted at first then the new ones will be inserted to the specified partition table.
func (*VirtualFilterLogStore) DeletePartitions ¶
func (vfls *VirtualFilterLogStore) DeletePartitions(fid string) error
DeletePartitions deletes all table partitions for the virtual filter with specified id.
func (*VirtualFilterLogStore) GC ¶
func (vfls *VirtualFilterLogStore) GC(fid string) error
GC garbage collects archive partitions exceeded the max archive partition limit starting from the oldest partiton.
func (*VirtualFilterLogStore) GetLogs ¶
func (vfls *VirtualFilterLogStore) GetLogs( ctx context.Context, fid string, sfilter store.LogFilter, blockHashes ...string, ) ([]VirtualFilterLog, error)
GetLogs gets event logs for the specified virtual filter.
func (*VirtualFilterLogStore) PreparePartition ¶
func (vfls *VirtualFilterLogStore) PreparePartition(fid string) (bnPartition, bool, error)
PreparePartitions createa new log partition for the virtual filter if necessary.
Source Files ¶
- common_partition.go
- config.go
- store.go
- store_block.go
- store_common.go
- store_common_partition.go
- store_common_partition_bn.go
- store_conf.go
- store_contract.go
- store_log.go
- store_log_addr.go
- store_log_big_contract.go
- store_log_filter.go
- store_log_virtual_filter.go
- store_map_epoch_block.go
- store_node_route.go
- store_pruner.go
- store_ratelimit.go
- store_tx.go
- store_user.go