store

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EvmLogDao

type EvmLogDao struct {
	bun.BaseModel  `bun:"table:evm_logs"`
	TxHash         []byte  `bun:"tx_hash,pk,notnull,type:bytea"`
	LogIndex       uint    `bun:"log_index,pk,notnull"`
	Address        []byte  `bun:"address,notnull,type:bytea"`
	Topic0         *[]byte `bun:"topic0,type:bytea"`
	Topic1         *[]byte `bun:"topic1,type:bytea"`
	Topic2         *[]byte `bun:"topic2,type:bytea"`
	Topic3         *[]byte `bun:"topic3,type:bytea"`
	Data           *[]byte `bun:"data,type:bytea"`
	BlockNumber    uint64  `bun:"block_number,notnull"`
	BlockHash      []byte  `bun:"block_hash,notnull,type:bytea"`
	TxIndex        uint    `bun:"tx_index,notnull,default:0"`
	Removed        bool    `bun:"removed,notnull,default:false"`
	BlockTimestamp uint64  `bun:"block_timestamp,notnull,default:0"`
}

EvmLogDao maps to the evm_logs table.

type EvmStateDao

type EvmStateDao struct {
	bun.BaseModel `bun:"table:evm_state"`
	ID            int    `bun:"id,pk"`
	LatestBlock   uint64 `bun:"latest_block,notnull,default:0"`
}

EvmStateDao maps to the evm_state table — a singleton row holding EVM chain state.

type EvmTransactionDao

type EvmTransactionDao struct {
	bun.BaseModel `bun:"table:evm_transactions"`
	TxHash        []byte    `bun:"tx_hash,pk,notnull,type:bytea"`
	FromAddress   string    `bun:"from_address,notnull,type:text"`
	ToAddress     string    `bun:"to_address,notnull,type:text"`
	Nonce         uint64    `bun:"nonce,notnull"`
	Input         []byte    `bun:"input,notnull,type:bytea"`
	ValueWei      string    `bun:"value_wei,notnull,default:'0',type:text"`
	Status        uint8     `bun:"status,notnull,default:1,type:smallint"`
	BlockNumber   uint64    `bun:"block_number,notnull"`
	BlockHash     []byte    `bun:"block_hash,notnull,type:bytea"`
	TxIndex       uint      `bun:"tx_index,notnull,default:0"`
	GasUsed       uint64    `bun:"gas_used,notnull,default:21000"`
	ErrorMessage  *string   `bun:"error_message,type:text"`
	CreatedAt     time.Time `bun:"created_at,notnull,default:current_timestamp"`
}

EvmTransactionDao maps to the evm_transactions table.

type InstrumentedStore

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

InstrumentedStore wraps a PGStore and records Prometheus metrics for every database operation. It satisfies both ethrpc/service.Store and ethrpc/miner.Store.

func NewInstrumentedStore

func NewInstrumentedStore(inner *PGStore, metrics *StoreMetrics) *InstrumentedStore

NewInstrumentedStore returns a metrics-instrumented wrapper around the given PGStore.

func (*InstrumentedStore) CompleteMempoolEntry

func (s *InstrumentedStore) CompleteMempoolEntry(ctx context.Context, txHash []byte) error

func (*InstrumentedStore) FailMempoolEntry

func (s *InstrumentedStore) FailMempoolEntry(ctx context.Context, txHash []byte, errMsg string) error

func (*InstrumentedStore) GetBlockNumberByHash

func (s *InstrumentedStore) GetBlockNumberByHash(ctx context.Context, blockHash []byte) (uint64, error)

func (*InstrumentedStore) GetEvmLogs

func (s *InstrumentedStore) GetEvmLogs(
	ctx context.Context, address []byte, topic0 []byte, fromBlock, toBlock uint64,
) ([]*ethrpc.EvmLog, error)

func (*InstrumentedStore) GetEvmLogsByTxHash

func (s *InstrumentedStore) GetEvmLogsByTxHash(ctx context.Context, txHash []byte) ([]*ethrpc.EvmLog, error)

func (*InstrumentedStore) GetEvmTransaction

func (s *InstrumentedStore) GetEvmTransaction(ctx context.Context, txHash []byte) (*ethrpc.EvmTransaction, error)

func (*InstrumentedStore) GetEvmTransactionCount

func (s *InstrumentedStore) GetEvmTransactionCount(ctx context.Context, fromAddress string) (uint64, error)

func (*InstrumentedStore) GetLatestEvmBlockNumber

func (s *InstrumentedStore) GetLatestEvmBlockNumber(ctx context.Context) (uint64, error)

func (*InstrumentedStore) GetMempoolEntriesByStatus

func (s *InstrumentedStore) GetMempoolEntriesByStatus(
	ctx context.Context, status ethrpc.MempoolStatus, limit int,
) ([]ethrpc.MempoolEntry, error)

func (*InstrumentedStore) InsertMempoolEntry

func (s *InstrumentedStore) InsertMempoolEntry(ctx context.Context, entry *ethrpc.MempoolEntry) error

func (*InstrumentedStore) NewBlock

func (s *InstrumentedStore) NewBlock(ctx context.Context, chainID uint64) (ethrpc.PendingBlock, error)

type MempoolEntryDao

type MempoolEntryDao struct {
	bun.BaseModel    `bun:"table:mempool"`
	ID               int64     `bun:"id,pk,autoincrement"`
	TxHash           []byte    `bun:"tx_hash,notnull,unique,type:bytea"`
	FromAddress      string    `bun:"from_address,notnull,type:text"`
	ContractAddress  string    `bun:"contract_address,notnull,type:text"`
	RecipientAddress string    `bun:"recipient_address,notnull,type:text"`
	Nonce            uint64    `bun:"nonce,notnull"`
	Input            []byte    `bun:"input,notnull,type:bytea"`
	AmountData       []byte    `bun:"amount_data,notnull,type:bytea"`
	Status           string    `bun:"status,notnull,default:'pending',type:text"`
	ErrorMessage     *string   `bun:"error_message,type:text"`
	CreatedAt        time.Time `bun:"created_at,notnull,default:current_timestamp"`
	UpdatedAt        time.Time `bun:"updated_at,notnull,default:current_timestamp"`
}

MempoolEntryDao maps to the mempool table — the intent log for synthetic EVM transfers.

type PGStore

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

PGStore is a PostgreSQL-backed EVM store for EthRPC.

func NewStore

func NewStore(db *bun.DB) *PGStore

NewStore creates a new PostgreSQL-backed EVM store.

func (*PGStore) CompleteMempoolEntry

func (s *PGStore) CompleteMempoolEntry(ctx context.Context, txHash []byte) error

CompleteMempoolEntry transitions a mempool entry from pending → completed after a successful Canton transfer. Only entries with status=pending are affected; entries already completed, failed, or mined are left untouched.

func (*PGStore) FailMempoolEntry

func (s *PGStore) FailMempoolEntry(ctx context.Context, txHash []byte, errMsg string) error

FailMempoolEntry transitions a mempool entry from pending → failed after a Canton transfer error, recording the error message for diagnostics. Only entries with status=pending are affected.

func (*PGStore) GetBlockNumberByHash

func (s *PGStore) GetBlockNumberByHash(ctx context.Context, blockHash []byte) (uint64, error)

GetBlockNumberByHash returns the block number for a given block hash.

func (*PGStore) GetEvmLogs

func (s *PGStore) GetEvmLogs(ctx context.Context, address []byte, topic0 []byte, fromBlock, toBlock uint64) ([]*ethrpc.EvmLog, error)

GetEvmLogs retrieves logs matching address/topic0 and block range.

func (*PGStore) GetEvmLogsByTxHash

func (s *PGStore) GetEvmLogsByTxHash(ctx context.Context, txHash []byte) ([]*ethrpc.EvmLog, error)

GetEvmLogsByTxHash retrieves all logs for a transaction hash, ordered by log index.

func (*PGStore) GetEvmTransaction

func (s *PGStore) GetEvmTransaction(ctx context.Context, txHash []byte) (*ethrpc.EvmTransaction, error)

GetEvmTransaction retrieves a synthetic EVM transaction by hash.

func (*PGStore) GetEvmTransactionCount

func (s *PGStore) GetEvmTransactionCount(ctx context.Context, fromAddress string) (uint64, error)

GetEvmTransactionCount returns the next nonce for the given from-address.

func (*PGStore) GetLatestEvmBlockNumber

func (s *PGStore) GetLatestEvmBlockNumber(ctx context.Context) (uint64, error)

GetLatestEvmBlockNumber returns the latest committed synthetic EVM block number.

func (*PGStore) GetMempoolEntriesByStatus

func (s *PGStore) GetMempoolEntriesByStatus(ctx context.Context, status ethrpc.MempoolStatus, limit int) ([]ethrpc.MempoolEntry, error)

GetMempoolEntriesByStatus returns mempool entries with the given status, ordered by insertion ID. limit caps how many rows are returned (limit <= 0 means no limit). The submitter passes its batch size so a backlog after Canton downtime never loads the entire pending queue into memory.

func (*PGStore) InsertMempoolEntry

func (s *PGStore) InsertMempoolEntry(ctx context.Context, entry *ethrpc.MempoolEntry) error

InsertMempoolEntry records a new transfer intent with status=pending. DO NOTHING on tx_hash conflict so duplicate submissions are safe.

func (*PGStore) NewBlock

func (s *PGStore) NewBlock(ctx context.Context, chainID uint64) (ethrpc.PendingBlock, error)

NewBlock opens a DB transaction and takes an explicit exclusive row lock on the evm_state singleton (SELECT … FOR UPDATE). The lock is held until the caller calls Finalize or Abort on the returned PendingBlock, which serializes concurrent miner instances at the database level. The block number is only persisted to evm_state inside Finalize, so a rolled-back transaction does not consume a number and creates no gaps.

type StoreMetrics

type StoreMetrics struct {
	QueryDuration *prometheus.HistogramVec
	Errors        *prometheus.CounterVec
}

StoreMetrics holds Prometheus collectors for the ethrpc store.

func NewNopStoreMetrics

func NewNopStoreMetrics() *StoreMetrics

NewNopStoreMetrics returns a StoreMetrics instance backed by a throwaway registry. Use in tests where metric values are not asserted.

func NewStoreMetrics

func NewStoreMetrics(reg sharedmetrics.NamespacedRegisterer) *StoreMetrics

NewStoreMetrics registers ethrpc store metrics against the given registerer.

func (*StoreMetrics) IncErrors

func (m *StoreMetrics) IncErrors(op StoreOperation)

IncErrors increments the error counter for the given operation.

func (*StoreMetrics) ObserveQueryDuration

func (m *StoreMetrics) ObserveQueryDuration(op StoreOperation) prometheus.Observer

ObserveQueryDuration returns the observer for the given operation.

type StoreOperation

type StoreOperation string

StoreOperation identifies a database operation for metrics labeling.

const (
	// Store operations.
	OpNewBlock                StoreOperation = "new_block"
	OpGetLatestEvmBlockNumber StoreOperation = "get_latest_evm_block_number"
	OpGetEvmTransactionCount  StoreOperation = "get_evm_transaction_count"
	OpGetEvmTransaction       StoreOperation = "get_evm_transaction"
	OpGetEvmLogsByTxHash      StoreOperation = "get_evm_logs_by_tx_hash"
	OpGetEvmLogs              StoreOperation = "get_evm_logs"
	OpGetBlockNumberByHash    StoreOperation = "get_block_number_by_hash"
	OpInsertMempoolEntry      StoreOperation = "insert_mempool_entry"
	OpCompleteMempoolEntry    StoreOperation = "complete_mempool_entry"
	OpFailMempoolEntry        StoreOperation = "fail_mempool_entry"
	OpGetMempoolEntries       StoreOperation = "get_mempool_entries_by_status"

	// PendingBlock operations.
	OpClaimMempoolEntries StoreOperation = "claim_mempool_entries"
	OpAddEvmTransaction   StoreOperation = "add_evm_transaction"
	OpAddEvmLog           StoreOperation = "add_evm_log"
	OpFinalize            StoreOperation = "finalize"
	OpAbort               StoreOperation = "abort"
)

Jump to

Keyboard shortcuts

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