eth

package
v0.5.1-alpha Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PayloadChanBufferSize = 20000 // the max eth sub buffer size
)

Variables

This section is empty.

Functions

func CalcEthBlockReward

func CalcEthBlockReward(header *types.Header, uncles []*types.Header, txs types.Transactions, receipts types.Receipts) *big.Int

func CalcUncleMinerReward

func CalcUncleMinerReward(blockNumber, uncleBlockNumber uint64) *big.Int

func ChainConfig

func ChainConfig(chainID uint64) (*params.ChainConfig, error)

ChainConfig returns the appropriate ethereum chain config for the provided chain id

func ReceiptModelsContainsCID

func ReceiptModelsContainsCID(rcts []ReceiptModel, cid string) bool

ListContainsBytes used to check if a list of byte arrays contains a particular byte array

func ResolveFromNodeType

func ResolveFromNodeType(nodeType statediff.NodeType) int

func TearDownDB

func TearDownDB(db *postgres.DB)

TearDownDB is used to tear down the watcher dbs after tests

func TxModelsContainsCID

func TxModelsContainsCID(txs []TxModel, cid string) bool

TxModelsContainsCID used to check if a list of TxModels contains a specific cid string

Types

type BatchClient

type BatchClient interface {
	BatchCallContext(ctx context.Context, batch []rpc.BatchElem) error
}

BatchClient is an interface to a batch-fetching geth rpc client; created to allow mock insertion

type CIDIndexer

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

Indexer satisfies the Indexer interface for ethereum

func NewCIDIndexer

func NewCIDIndexer(db *postgres.DB) *CIDIndexer

NewCIDIndexer creates a new pointer to a Indexer which satisfies the CIDIndexer interface

func (*CIDIndexer) Index

func (in *CIDIndexer) Index(cids CIDPayload) error

Index indexes a cidPayload in Postgres

type CIDPayload

type CIDPayload struct {
	HeaderCID       HeaderModel
	UncleCIDs       []UncleModel
	TransactionCIDs []TxModel
	ReceiptCIDs     map[common.Hash]ReceiptModel
	StateNodeCIDs   []StateNodeModel
	StateAccounts   map[string]StateAccountModel
	StorageNodeCIDs map[string][]StorageNodeModel
}

CIDPayload is a struct to hold all the CIDs and their associated meta data for indexing in Postgres Returned by IPLDPublisher Passed to CIDIndexer

type Cleaner

type Cleaner interface {
	ResetValidation(rngs [][2]uint64) error
	Clean(rngs [][2]uint64, t shared.DataType) error
}

Cleaner interface to allow substitution of mocks in tests

type ConvertedPayload

type ConvertedPayload struct {
	TotalDifficulty *big.Int
	Block           *types.Block
	TxMetaData      []TxModel
	Receipts        types.Receipts
	ReceiptMetaData []ReceiptModel
	StateNodes      []TrieNode
	StorageNodes    map[string][]TrieNode
}

ConvertedPayload is a custom type which packages raw ETH data for publishing to IPFS and filtering to subscribers Returned by PayloadConverter Passed to IPLDPublisher and ResponseFilterer

type Converter

type Converter interface {
	Convert(payload statediff.Payload) (*ConvertedPayload, error)
}

Converter interface to allow substitution of mocks for testing

type DBCleaner

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

DBCleaner satisfies the Cleaner interface fo ethereum

func NewDBCleaner

func NewDBCleaner(db *postgres.DB) *DBCleaner

NewDBCleaner returns a new DBCleaner struct

func (*DBCleaner) Clean

func (c *DBCleaner) Clean(rngs [][2]uint64, t shared.DataType) error

Clean removes the specified data from the db within the provided block range

func (*DBCleaner) ResetValidation

func (c *DBCleaner) ResetValidation(rngs [][2]uint64) error

ResetValidation resets the validation level to 0 to enable revalidation

type DBGap

type DBGap struct {
	Start uint64 `db:"start"`
	Stop  uint64 `db:"stop"`
}

DBGap type for querying for gaps in db

func MissingHeightsToGaps

func MissingHeightsToGaps(heights []uint64) []DBGap

MissingHeightsToGaps returns a slice of gaps from a slice of missing block heights

type Fetcher

type Fetcher interface {
	FetchAt(blockHeights []uint64) ([]statediff.Payload, error)
}

Fetcher interface for substituting mocks in tests

type GapRetriever

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

GapRetriever type for Ethereum

func NewGapRetriever

func NewGapRetriever(db *postgres.DB) *GapRetriever

NewGapRetriever returns a pointer to a new GapRetriever

func (*GapRetriever) RetrieveFirstBlockNumber

func (ecr *GapRetriever) RetrieveFirstBlockNumber() (int64, error)

RetrieveFirstBlockNumber is used to retrieve the first block number in the db

func (*GapRetriever) RetrieveGapsInData

func (ecr *GapRetriever) RetrieveGapsInData(validationLevel int) ([]DBGap, error)

RetrieveGapsInData is used to find the the block numbers at which we are missing data in the db it finds the union of heights where no data exists and where the times_validated is lower than the validation level

func (*GapRetriever) RetrieveLastBlockNumber

func (ecr *GapRetriever) RetrieveLastBlockNumber() (int64, error)

RetrieveLastBlockNumber is used to retrieve the latest block number in the db

type HeaderModel

type HeaderModel struct {
	ID              int64  `db:"id"`
	BlockNumber     string `db:"block_number"`
	BlockHash       string `db:"block_hash"`
	ParentHash      string `db:"parent_hash"`
	CID             string `db:"cid"`
	MhKey           string `db:"mh_key"`
	TotalDifficulty string `db:"td"`
	NodeID          int64  `db:"node_id"`
	Reward          string `db:"reward"`
	StateRoot       string `db:"state_root"`
	UncleRoot       string `db:"uncle_root"`
	TxRoot          string `db:"tx_root"`
	RctRoot         string `db:"receipt_root"`
	Bloom           []byte `db:"bloom"`
	Timestamp       uint64 `db:"timestamp"`
	TimesValidated  int64  `db:"times_validated"`
}

HeaderModel is the db model for eth.header_cids

type IPLDPublisher

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

IPLDPublisher satisfies the IPLDPublisher interface for ethereum It interfaces directly with the public.blocks table of PG-IPFS rather than going through an ipfs intermediary It publishes and indexes IPLDs together in a single sqlx.Tx

func NewIPLDPublisher

func NewIPLDPublisher(db *postgres.DB) *IPLDPublisher

NewIPLDPublisher creates a pointer to a new IPLDPublisher which satisfies the IPLDPublisher interface

func (*IPLDPublisher) Publish

func (pub *IPLDPublisher) Publish(payload ConvertedPayload) error

Publish publishes an IPLDPayload to IPFS and returns the corresponding CIDPayload

type Indexer

type Indexer interface {
	Index(cids CIDPayload) error
}

Indexer interface to allow substituting mocks in tests

type PayloadConverter

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

PayloadConverter satisfies the PayloadConverter interface for ethereum

func NewPayloadConverter

func NewPayloadConverter(chainConfig *params.ChainConfig) *PayloadConverter

NewPayloadConverter creates a pointer to a new PayloadConverter which satisfies the PayloadConverter interface

func (*PayloadConverter) Convert

func (pc *PayloadConverter) Convert(payload statediff.Payload) (*ConvertedPayload, error)

Convert method is used to convert a eth statediff.Payload to an IPLDPayload Satisfies the shared.PayloadConverter interface

type PayloadFetcher

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

PayloadFetcher satisfies the PayloadFetcher interface for ethereum

func NewPayloadFetcher

func NewPayloadFetcher(bc BatchClient, timeout time.Duration) *PayloadFetcher

NewPayloadFetcher returns a PayloadFetcher

func (*PayloadFetcher) FetchAt

func (fetcher *PayloadFetcher) FetchAt(blockHeights []uint64) ([]statediff.Payload, error)

FetchAt fetches the statediff payloads at the given block heights Calls StateDiffAt(ctx context.Context, blockNumber uint64, params Params) (*Payload, error)

type PayloadStreamer

type PayloadStreamer struct {
	Client StreamClient
	// contains filtered or unexported fields
}

PayloadStreamer satisfies the PayloadStreamer interface for ethereum

func NewPayloadStreamer

func NewPayloadStreamer(client StreamClient) *PayloadStreamer

NewPayloadStreamer creates a pointer to a new PayloadStreamer which satisfies the PayloadStreamer interface for ethereum

func (*PayloadStreamer) Stream

func (ps *PayloadStreamer) Stream(payloadChan chan statediff.Payload) (*rpc.ClientSubscription, error)

Stream is the main loop for subscribing to data from the Geth state diff process Satisfies the shared.PayloadStreamer interface

type Publisher

type Publisher interface {
	Publish(payload ConvertedPayload) error
}

Publisher interface for substituting mocks in tests

type ReceiptModel

type ReceiptModel struct {
	ID           int64          `db:"id"`
	TxID         int64          `db:"tx_id"`
	CID          string         `db:"cid"`
	MhKey        string         `db:"mh_key"`
	Contract     string         `db:"contract"`
	ContractHash string         `db:"contract_hash"`
	LogContracts pq.StringArray `db:"log_contracts"`
	Topic0s      pq.StringArray `db:"topic0s"`
	Topic1s      pq.StringArray `db:"topic1s"`
	Topic2s      pq.StringArray `db:"topic2s"`
	Topic3s      pq.StringArray `db:"topic3s"`
}

ReceiptModel is the db model for eth.receipt_cids

type Retriever

type Retriever interface {
	RetrieveFirstBlockNumber() (int64, error)
	RetrieveLastBlockNumber() (int64, error)
	RetrieveGapsInData(validationLevel int) ([]DBGap, error)
}

Retriever interface for substituting mocks in tests

type StateAccountModel

type StateAccountModel struct {
	ID          int64  `db:"id"`
	StateID     int64  `db:"state_id"`
	Balance     string `db:"balance"`
	Nonce       uint64 `db:"nonce"`
	CodeHash    []byte `db:"code_hash"`
	StorageRoot string `db:"storage_root"`
}

StateAccountModel is a db model for an eth state account (decoded value of state leaf node)

type StateDiffTransformer

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

StateDiffTransformer satisfies the Transformer interface for ethereum statediff objects

func NewStateDiffTransformer

func NewStateDiffTransformer(chainConfig *params.ChainConfig, db *postgres.DB) *StateDiffTransformer

NewStateDiffTransformer creates a pointer to a new PayloadConverter which satisfies the PayloadConverter interface

func (*StateDiffTransformer) Transform

func (sdt *StateDiffTransformer) Transform(workerID int, payload statediff.Payload) (uint64, error)

Transform method is used to process statediff.Payload objects It performs the necessary data conversions and database persistence

type StateNodeModel

type StateNodeModel struct {
	ID       int64  `db:"id"`
	HeaderID int64  `db:"header_id"`
	Path     []byte `db:"state_path"`
	StateKey string `db:"state_leaf_key"`
	NodeType int    `db:"node_type"`
	CID      string `db:"cid"`
	MhKey    string `db:"mh_key"`
	Diff     bool   `db:"diff"`
}

StateNodeModel is the db model for eth.state_cids

type StorageNodeModel

type StorageNodeModel struct {
	ID         int64  `db:"id"`
	StateID    int64  `db:"state_id"`
	Path       []byte `db:"storage_path"`
	StorageKey string `db:"storage_leaf_key"`
	NodeType   int    `db:"node_type"`
	CID        string `db:"cid"`
	MhKey      string `db:"mh_key"`
	Diff       bool   `db:"diff"`
}

StorageNodeModel is the db model for eth.storage_cids

type StorageNodeWithStateKeyModel

type StorageNodeWithStateKeyModel struct {
	ID         int64  `db:"id"`
	StateID    int64  `db:"state_id"`
	Path       []byte `db:"storage_path"`
	StateKey   string `db:"state_leaf_key"`
	StorageKey string `db:"storage_leaf_key"`
	NodeType   int    `db:"node_type"`
	CID        string `db:"cid"`
	MhKey      string `db:"mh_key"`
	Diff       bool   `db:"diff"`
}

StorageNodeWithStateKeyModel is a db model for eth.storage_cids + eth.state_cids.state_key

type StreamClient

type StreamClient interface {
	Subscribe(ctx context.Context, namespace string, payloadChan interface{}, args ...interface{}) (*rpc.ClientSubscription, error)
}

StreamClient is an interface for subscribing and streaming from geth

type Streamer

type Streamer interface {
	Stream(payloadChan chan statediff.Payload) (*rpc.ClientSubscription, error)
}

Streamer interface for substituting mocks in tests

type Transformer

type Transformer interface {
	Transform(workerID int, payload statediff.Payload) (uint64, error)
}

Transformer interface to allow substitution of mocks for testing

type TrieNode

type TrieNode struct {
	Path    []byte
	LeafKey common.Hash
	Value   []byte
	Type    statediff.NodeType
}

Trie struct used to flag node as leaf or not

type TxModel

type TxModel struct {
	ID         int64  `db:"id"`
	HeaderID   int64  `db:"header_id"`
	Index      int64  `db:"index"`
	TxHash     string `db:"tx_hash"`
	CID        string `db:"cid"`
	MhKey      string `db:"mh_key"`
	Dst        string `db:"dst"`
	Src        string `db:"src"`
	Data       []byte `db:"tx_data"`
	Deployment bool   `db:"deployment"`
}

TxModel is the db model for eth.transaction_cids

type UncleModel

type UncleModel struct {
	ID         int64  `db:"id"`
	HeaderID   int64  `db:"header_id"`
	BlockHash  string `db:"block_hash"`
	ParentHash string `db:"parent_hash"`
	CID        string `db:"cid"`
	MhKey      string `db:"mh_key"`
	Reward     string `db:"reward"`
}

UncleModel is the db model for eth.uncle_cids

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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