database

package
v0.0.0-...-011bec4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Database module defines the data DB struct which wraps specific DB interfaces for L1/L2 block headers, contract events, bridging schemas.

Index

Constants

This section is empty.

Variables

View Source
var (
	ETHTokenPair = TokenPair{LocalTokenAddress: predeploys.LegacyERC20NativeTokenAddr, RemoteTokenAddress: predeploys.LegacyERC20NativeTokenAddr}
)
View Source
var (
	SlowThresholdMilliseconds int64 = 500
)

Functions

This section is empty.

Types

type BlockHeader

type BlockHeader struct {
	Hash       common.Hash `gorm:"primaryKey;serializer:bytes"`
	ParentHash common.Hash `gorm:"serializer:bytes"`
	Number     *big.Int    `gorm:"serializer:u256"`
	Timestamp  uint64

	RLPHeader *RLPHeader `gorm:"serializer:rlp;column:rlp_bytes"`
}

func BlockHeaderFromHeader

func BlockHeaderFromHeader(header *types.Header) BlockHeader

func (BlockHeader) String

func (b BlockHeader) String() string

type BlocksDB

type BlocksDB interface {
	BlocksView

	StoreL1BlockHeaders([]L1BlockHeader) error
	StoreL2BlockHeaders([]L2BlockHeader) error

	DeleteReorgedState(uint64) error
}

type BlocksView

type BlocksView interface {
	L1BlockHeader(common.Hash) (*L1BlockHeader, error)
	L1BlockHeaderWithFilter(BlockHeader) (*L1BlockHeader, error)
	L1BlockHeaderWithScope(func(db *gorm.DB) *gorm.DB) (*L1BlockHeader, error)
	L1LatestBlockHeader() (*L1BlockHeader, error)

	L2BlockHeader(common.Hash) (*L2BlockHeader, error)
	L2BlockHeaderWithFilter(BlockHeader) (*L2BlockHeader, error)
	L2BlockHeaderWithScope(func(db *gorm.DB) *gorm.DB) (*L2BlockHeader, error)
	L2LatestBlockHeader() (*L2BlockHeader, error)
}

type BridgeMessage

type BridgeMessage struct {
	MessageHash common.Hash `gorm:"primaryKey;serializer:bytes"`
	Nonce       *big.Int    `gorm:"serializer:u256"`

	SentMessageEventGUID    uuid.UUID
	RelayedMessageEventGUID *uuid.UUID

	Tx       Transaction `gorm:"embedded"`
	GasLimit *big.Int    `gorm:"serializer:u256"`
}

type BridgeMessagesDB

type BridgeMessagesDB interface {
	BridgeMessagesView

	StoreL1BridgeMessages([]L1BridgeMessage) error
	MarkRelayedL1BridgeMessage(common.Hash, uuid.UUID) error

	StoreL2BridgeMessages([]L2BridgeMessage) error
	MarkRelayedL2BridgeMessage(common.Hash, uuid.UUID) error

	StoreL2BridgeMessageV1MessageHashes([]L2BridgeMessageVersionedMessageHash) error
}

type BridgeMessagesView

type BridgeMessagesView interface {
	L1BridgeMessage(common.Hash) (*L1BridgeMessage, error)
	L1BridgeMessageWithFilter(BridgeMessage) (*L1BridgeMessage, error)

	L2BridgeMessage(common.Hash) (*L2BridgeMessage, error)
	L2BridgeMessageWithFilter(BridgeMessage) (*L2BridgeMessage, error)
}

type BridgeTransactionsDB

type BridgeTransactionsDB interface {
	BridgeTransactionsView

	StoreL1TransactionDeposits([]L1TransactionDeposit) error

	StoreL2TransactionWithdrawals([]L2TransactionWithdrawal) error
	MarkL2TransactionWithdrawalProvenEvent(common.Hash, uuid.UUID) error
	MarkL2TransactionWithdrawalFinalizedEvent(common.Hash, uuid.UUID, bool) error
}

type BridgeTransactionsView

type BridgeTransactionsView interface {
	L1TransactionDeposit(common.Hash) (*L1TransactionDeposit, error)
	L1LatestBlockHeader() (*L1BlockHeader, error)
	L1LatestFinalizedBlockHeader() (*L1BlockHeader, error)

	L2TransactionWithdrawal(common.Hash) (*L2TransactionWithdrawal, error)
	L2LatestBlockHeader() (*L2BlockHeader, error)
	L2LatestFinalizedBlockHeader() (*L2BlockHeader, error)
}

type BridgeTransfer

type BridgeTransfer struct {
	CrossDomainMessageHash *common.Hash `gorm:"serializer:bytes"`

	Tx        Transaction `gorm:"embedded"`
	TokenPair TokenPair   `gorm:"embedded"`
}

type BridgeTransfersDB

type BridgeTransfersDB interface {
	BridgeTransfersView

	StoreL1BridgeDeposits([]L1BridgeDeposit) error
	StoreL2BridgeWithdrawals([]L2BridgeWithdrawal) error
}

type BridgeTransfersView

type BridgeTransfersView interface {
	L1BridgeDeposit(common.Hash) (*L1BridgeDeposit, error)
	L1TxDepositSum() (float64, error)
	L1BridgeDepositWithFilter(BridgeTransfer) (*L1BridgeDeposit, error)
	L1BridgeDepositsByAddress(common.Address, string, int) (*L1BridgeDepositsResponse, error)

	L2BridgeWithdrawal(common.Hash) (*L2BridgeWithdrawal, error)
	L2BridgeWithdrawalSum(filter WithdrawFilter) (float64, error)
	L2BridgeWithdrawalWithFilter(BridgeTransfer) (*L2BridgeWithdrawal, error)
	L2BridgeWithdrawalsByAddress(common.Address, string, int) (*L2BridgeWithdrawalsResponse, error)
}

type Bytes

type Bytes []byte

func (Bytes) Bytes

func (b Bytes) Bytes() []byte

func (*Bytes) SetBytes

func (b *Bytes) SetBytes(bytes []byte)

type ContractEvent

type ContractEvent struct {
	GUID uuid.UUID `gorm:"primaryKey"`

	// Some useful derived fields
	BlockHash       common.Hash    `gorm:"serializer:bytes"`
	ContractAddress common.Address `gorm:"serializer:bytes"`
	TransactionHash common.Hash    `gorm:"serializer:bytes"`
	LogIndex        uint64

	EventSignature common.Hash `gorm:"serializer:bytes"`
	Timestamp      uint64

	// NOTE: NOT ALL THE DERIVED FIELDS ON `types.Log` ARE
	// AVAILABLE. FIELDS LISTED ABOVE ARE FILLED IN
	RLPLog *types.Log `gorm:"serializer:rlp;column:rlp_bytes"`
}

func ContractEventFromLog

func ContractEventFromLog(log *types.Log, timestamp uint64) ContractEvent

func (*ContractEvent) AfterFind

func (c *ContractEvent) AfterFind(tx *gorm.DB) error

type ContractEventsDB

type ContractEventsDB interface {
	ContractEventsView

	StoreL1ContractEvents([]L1ContractEvent) error
	StoreL2ContractEvents([]L2ContractEvent) error
}

type ContractEventsView

type ContractEventsView interface {
	L1ContractEvent(uuid.UUID) (*L1ContractEvent, error)
	L1ContractEventWithFilter(ContractEvent) (*L1ContractEvent, error)
	L1ContractEventsWithFilter(ContractEvent, *big.Int, *big.Int) ([]L1ContractEvent, error)
	L1LatestContractEventWithFilter(ContractEvent) (*L1ContractEvent, error)

	L2ContractEvent(uuid.UUID) (*L2ContractEvent, error)
	L2ContractEventWithFilter(ContractEvent) (*L2ContractEvent, error)
	L2ContractEventsWithFilter(ContractEvent, *big.Int, *big.Int) ([]L2ContractEvent, error)
	L2LatestContractEventWithFilter(ContractEvent) (*L2ContractEvent, error)

	ContractEventsWithFilter(ContractEvent, string, *big.Int, *big.Int) ([]ContractEvent, error)
}

type DB

type DB struct {
	Blocks             BlocksDB
	ContractEvents     ContractEventsDB
	BridgeTransfers    BridgeTransfersDB
	BridgeMessages     BridgeMessagesDB
	BridgeTransactions BridgeTransactionsDB
	// contains filtered or unexported fields
}

func NewDB

func NewDB(ctx context.Context, log log.Logger, dbConfig config.DBConfig) (*DB, error)

NewDB connects to the configured DB, and provides client-bindings to it. The initial connection may fail, or the dial may be cancelled with the provided context.

func (*DB) Close

func (db *DB) Close() error

func (*DB) ExecuteSQLMigration

func (db *DB) ExecuteSQLMigration(migrationsFolder string) error

func (*DB) Transaction

func (db *DB) Transaction(fn func(db *DB) error) error

Transaction executes all operations conducted with the supplied database in a single transaction. If the supplied function errors, the transaction is rolled back.

type L1BlockHeader

type L1BlockHeader struct {
	BlockHeader `gorm:"embedded"`
}

type L1BridgeDeposit

type L1BridgeDeposit struct {
	BridgeTransfer        `gorm:"embedded"`
	TransactionSourceHash common.Hash `gorm:"primaryKey;serializer:bytes"`
}

type L1BridgeDepositWithTransactionHashes

type L1BridgeDepositWithTransactionHashes struct {
	L1BridgeDeposit L1BridgeDeposit `gorm:"embedded"`

	L1BlockHash       common.Hash `gorm:"serializer:bytes"`
	L1TransactionHash common.Hash `gorm:"serializer:bytes"`
	L2TransactionHash common.Hash `gorm:"serializer:bytes"`
}

type L1BridgeDepositsResponse

type L1BridgeDepositsResponse struct {
	Deposits    []L1BridgeDepositWithTransactionHashes
	Cursor      string
	HasNextPage bool
}

type L1BridgeMessage

type L1BridgeMessage struct {
	BridgeMessage         `gorm:"embedded"`
	TransactionSourceHash common.Hash `gorm:"serializer:bytes"`
}

type L1ContractEvent

type L1ContractEvent struct {
	ContractEvent `gorm:"embedded"`
}

type L1TransactionDeposit

type L1TransactionDeposit struct {
	SourceHash           common.Hash `gorm:"serializer:bytes;primaryKey"`
	L2TransactionHash    common.Hash `gorm:"serializer:bytes"`
	InitiatedL1EventGUID uuid.UUID

	Tx       Transaction `gorm:"embedded"`
	GasLimit *big.Int    `gorm:"serializer:u256"`
}

type L2BlockHeader

type L2BlockHeader struct {
	BlockHeader `gorm:"embedded"`
}

type L2BridgeMessage

type L2BridgeMessage struct {
	BridgeMessage             `gorm:"embedded"`
	TransactionWithdrawalHash common.Hash `gorm:"serializer:bytes"`
}

type L2BridgeMessageVersionedMessageHash

type L2BridgeMessageVersionedMessageHash struct {
	MessageHash   common.Hash `gorm:"primaryKey;serializer:bytes"`
	V1MessageHash common.Hash `gorm:"serializer:bytes"`
}

type L2BridgeWithdrawal

type L2BridgeWithdrawal struct {
	BridgeTransfer            `gorm:"embedded"`
	TransactionWithdrawalHash common.Hash `gorm:"primaryKey;serializer:bytes"`
}

type L2BridgeWithdrawalWithTransactionHashes

type L2BridgeWithdrawalWithTransactionHashes struct {
	L2BridgeWithdrawal L2BridgeWithdrawal `gorm:"embedded"`
	L2TransactionHash  common.Hash        `gorm:"serializer:bytes"`
	L2BlockHash        common.Hash        `gorm:"serializer:bytes"`

	ProvenL1TransactionHash    common.Hash `gorm:"serializer:bytes"`
	FinalizedL1TransactionHash common.Hash `gorm:"serializer:bytes"`
}

type L2BridgeWithdrawalsResponse

type L2BridgeWithdrawalsResponse struct {
	Withdrawals []L2BridgeWithdrawalWithTransactionHashes
	Cursor      string
	HasNextPage bool
}

type L2ContractEvent

type L2ContractEvent struct {
	ContractEvent `gorm:"embedded"`
}

type L2TransactionWithdrawal

type L2TransactionWithdrawal struct {
	WithdrawalHash       common.Hash `gorm:"serializer:bytes;primaryKey"`
	Nonce                *big.Int    `gorm:"serializer:u256"`
	InitiatedL2EventGUID uuid.UUID

	ProvenL1EventGUID    *uuid.UUID
	FinalizedL1EventGUID *uuid.UUID
	Succeeded            *bool

	Tx       Transaction `gorm:"embedded"`
	GasLimit *big.Int    `gorm:"serializer:u256"`
}

type Logger

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

func (Logger) Error

func (l Logger) Error(ctx context.Context, msg string, data ...interface{})

func (Logger) Info

func (l Logger) Info(ctx context.Context, msg string, data ...interface{})

func (Logger) LogMode

func (l Logger) LogMode(lvl logger.LogLevel) logger.Interface

func (Logger) Trace

func (l Logger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (Logger) Warn

func (l Logger) Warn(ctx context.Context, msg string, data ...interface{})

type MockBlocksDB

type MockBlocksDB struct {
	MockBlocksView
}

func (*MockBlocksDB) DeleteReorgedState

func (m *MockBlocksDB) DeleteReorgedState(timestamp uint64) error

func (*MockBlocksDB) StoreL1BlockHeaders

func (m *MockBlocksDB) StoreL1BlockHeaders(headers []L1BlockHeader) error

func (*MockBlocksDB) StoreL2BlockHeaders

func (m *MockBlocksDB) StoreL2BlockHeaders(headers []L2BlockHeader) error

type MockBlocksView

type MockBlocksView struct {
	mock.Mock
}

func (*MockBlocksView) L1BlockHeader

func (m *MockBlocksView) L1BlockHeader(common.Hash) (*L1BlockHeader, error)

func (*MockBlocksView) L1BlockHeaderWithFilter

func (m *MockBlocksView) L1BlockHeaderWithFilter(BlockHeader) (*L1BlockHeader, error)

func (*MockBlocksView) L1BlockHeaderWithScope

func (m *MockBlocksView) L1BlockHeaderWithScope(func(*gorm.DB) *gorm.DB) (*L1BlockHeader, error)

func (*MockBlocksView) L1LatestBlockHeader

func (m *MockBlocksView) L1LatestBlockHeader() (*L1BlockHeader, error)

func (*MockBlocksView) L2BlockHeader

func (m *MockBlocksView) L2BlockHeader(common.Hash) (*L2BlockHeader, error)

func (*MockBlocksView) L2BlockHeaderWithFilter

func (m *MockBlocksView) L2BlockHeaderWithFilter(BlockHeader) (*L2BlockHeader, error)

func (*MockBlocksView) L2BlockHeaderWithScope

func (m *MockBlocksView) L2BlockHeaderWithScope(func(*gorm.DB) *gorm.DB) (*L2BlockHeader, error)

func (*MockBlocksView) L2LatestBlockHeader

func (m *MockBlocksView) L2LatestBlockHeader() (*L2BlockHeader, error)

type MockDB

type MockDB struct {
	MockBlocks *MockBlocksDB
	DB         *DB
}

MockDB is a mock database that can be used for testing

func NewMockDB

func NewMockDB() *MockDB

type RLPHeader

type RLPHeader types.Header

func (*RLPHeader) DecodeRLP

func (h *RLPHeader) DecodeRLP(s *rlp.Stream) error

func (*RLPHeader) EncodeRLP

func (h *RLPHeader) EncodeRLP(w io.Writer) error

func (*RLPHeader) Hash

func (h *RLPHeader) Hash() common.Hash

func (*RLPHeader) Header

func (h *RLPHeader) Header() *types.Header

type TokenPair

type TokenPair struct {
	LocalTokenAddress  common.Address `gorm:"serializer:bytes"`
	RemoteTokenAddress common.Address `gorm:"serializer:bytes"`
}

type Transaction

type Transaction struct {
	FromAddress common.Address `gorm:"serializer:bytes"`
	ToAddress   common.Address `gorm:"serializer:bytes"`
	Amount      *big.Int       `gorm:"serializer:u256"`
	Data        Bytes          `gorm:"serializer:bytes"`
	Timestamp   uint64
}

type WithdrawFilter

type WithdrawFilter uint8
const (
	All WithdrawFilter = iota // Same as "initialized"
	Proven
	Finalized
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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