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 (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) 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) LoadConfig(confNames ...string) (map[string]interface{}, error)
- func (cs MysqlStore) LoadRateLimitConfigs() *rate.Config
- 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) Prune()
- func (ms *MysqlStore) Push(data *store.EpochData) error
- func (ms *MysqlStore) Pushn(dataSlice []*store.EpochData) error
- func (cs MysqlStore) StoreConfig(confName string, confVal interface{}) error
- type RateLimit
- type RateLimitStore
- type StoreOption
- type User
- type UserStore
Constants ¶
const (
MysqlConfKeyReorgVersion = "reorg.version"
)
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 // 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) 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) LoadConfig ¶
func (MysqlStore) LoadRateLimitConfigs ¶
func (*MysqlStore) Popn ¶
func (ms *MysqlStore) Popn(epochUntil uint64) error
Popn pops multiple epoch data from database.
func (MysqlStore) StoreConfig ¶
type RateLimit ¶
type RateLimit struct { ID uint32 SID uint32 // strategy ID LimitType int `gorm:"default:0;not null"` // limit type LimitKey string `gorm:"unique;size:128;not null"` // limit key 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) IsRecordNotFound ¶
func (*RateLimitStore) LoadRateLimitKeyset ¶
func (rls *RateLimitStore) LoadRateLimitKeyset(filter *rate.KeysetFilter) (res []*rate.KeyInfo, 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 ¶
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_map_epoch_block.go
- store_pruner.go
- store_ratelimit.go
- store_tx.go
- store_user.go