base

package
v0.0.139 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package base contains the base sql implementation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ChainIDFieldName gets the chain id field name.
	ChainIDFieldName string
	// DestinationFieldName is the field name of the destination.
	DestinationFieldName string
	// NonceFieldName is the field name of the tx hash.
	NonceFieldName string
	// AttestationNonceFieldName is the field name of the attestation nonce.
	AttestationNonceFieldName string
	// RootFieldName is the name of the block number field.
	RootFieldName string
	// BlockNumberFieldName is the name of the block number field.
	BlockNumberFieldName string
	// DestinationBlockNumberFieldName is the index field name.
	DestinationBlockNumberFieldName string
	// DestinationTimestampFieldName is the destination timestamp field name.
	DestinationTimestampFieldName string
	// ExecutedFieldName is the executed field name.
	ExecutedFieldName string
	// MinimumTimeSetFieldName is the minimum time set field name.
	MinimumTimeSetFieldName string
	// MinimumTimeFieldName is the minimum time field name.
	MinimumTimeFieldName string
	// SnapshotRootFieldName is the snapshot root field name.
	SnapshotRootFieldName string
)
View Source
var PageSize = 50_000

PageSize is the amount of entries per page of logs.

Functions

func AttestationToDBAttestation added in v0.0.63

func AttestationToDBAttestation(attestation Attestation) types.DBAttestation

AttestationToDBAttestation converts an Attestation to a DBAttestation.

func GetAllModels

func GetAllModels() (allModels []interface{})

GetAllModels gets all models to migrate see: https://medium.com/@SaifAbid/slice-interfaces-8c78f8b6345d for an explanation of why we can't do this at initialization time

func MessageToDBMessage

func MessageToDBMessage(message Message) types.DBMessage

MessageToDBMessage converts a Message to a DBMessage.

func StateToDBState added in v0.0.130

func StateToDBState(state State) types.DBState

StateToDBState converts a State to a DBState.

Types

type Attestation added in v0.0.63

type Attestation struct {
	// Destination is the destination of the attestation.
	Destination uint32 `gorm:"column:destination;primaryKey"`
	// SnapshotRoot is the snapshot root.
	SnapshotRoot string `gorm:"column:snapshot_root;primaryKey"`
	// Height is the height of the snapshot Merkle tree.
	Height uint8 `gorm:"column:height"`
	// AttestationNonce is the nonce of the attestation.
	AttestationNonce uint32 `gorm:"column:attestation_nonce;primaryKey"`
	// SummitBlockNumber is the block number when the attestation was created in Summit.
	SummitBlockNumber uint64 `gorm:"column:summit_block_number"`
	// SummitTimestamp is the timestamp of the block when the attestation was created in Summit.
	SummitTimestamp uint64 `gorm:"column:summit_timestamp"`
	// DestinationBlockNumber is the block number that the attestation was submitted on the destination.
	DestinationBlockNumber uint64 `gorm:"column:destination_block_number"`
	// DestinationTimestamp is the timestamp of the block that the attestation was submitted on the destination.
	DestinationTimestamp uint64 `gorm:"column:destination_timestamp"`
}

Attestation is the information about an attestation parsed by the Executor.

func DBAttestationToAttestation added in v0.0.63

func DBAttestationToAttestation(dbAttestation types.DBAttestation) Attestation

DBAttestationToAttestation converts a DBAttestation to an Attestation.

type Message

type Message struct {
	// ChainID is the chain id.
	ChainID uint32 `gorm:"column:chain_id;primaryKey"`
	// Destination is the destination.
	Destination uint32 `gorm:"column:destination;primaryKey"`
	// Nonce is the nonce.
	Nonce uint32 `gorm:"column:nonce;primaryKey"`
	// Message is the message.
	Message []byte `gorm:"column:message"`
	// BlockNumber is the block number.
	BlockNumber uint64 `gorm:"column:block_number"`
	// Executed is if the message has been executed.
	Executed bool `gorm:"column:executed"`
	// MinimumTimeSet is if the MinimumTime field has been set from an Attestation.
	MinimumTimeSet bool `gorm:"column:minimum_time_set"`
	// MinimumTime is the minimum time that the message can be executed.
	MinimumTime uint64 `gorm:"column:minimum_time"`
}

Message is the information about a message parsed by the Executor.

func AgentsTypesMessageToMessage

func AgentsTypesMessageToMessage(message agentsTypes.Message, blockNumber uint64, minimumTimeSet bool, minimumTime uint64) (Message, error)

AgentsTypesMessageToMessage converts an agentsTypes.Message to a Message.

func DBMessageToMessage

func DBMessageToMessage(dbMessage types.DBMessage) Message

DBMessageToMessage converts a DBMessage to a Message.

type State added in v0.0.130

type State struct {
	// SnapshotRoot is the snapshot root.
	SnapshotRoot string `gorm:"column:snapshot_root;primaryKey"`
	// Root is the origin Merkle tree's root.
	Root string `gorm:"column:root;primaryKey"`
	// ChainID is the origin chain id.
	ChainID uint32 `gorm:"column:chain_id;primaryKey"`
	// Nonce is the origin Merkle tree's nonce.
	Nonce uint32 `gorm:"column:nonce;primaryKey"`
	// OriginBlockNumber is the block number that the state was taken from on the origin.
	OriginBlockNumber uint64 `gorm:"column:origin_block_number"`
	// OriginTimestamp is the timestamp of the block that the state was taken from on the origin.
	OriginTimestamp uint64 `gorm:"column:origin_timestamp"`
	// Proof is the Snapshot Merkle Tree proof for the state.
	Proof json.RawMessage `gorm:"column:proof"`
	// TreeHeight is the height of the Snapshot Merkle Tree that the state belongs to.
	TreeHeight uint32 `gorm:"column:tree_height"`
	// StateIndex is the index of the state in the Snapshot.
	StateIndex uint32 `gorm:"column:state_index"`
}

State is the information about a state, received from the `Summit` and parsed by the Executor.

func AgentsTypesStateToState added in v0.0.130

func AgentsTypesStateToState(state agentsTypes.State, snapshotRoot [32]byte, proof [][]byte, treeHeight, stateIndex uint32) (State, error)

AgentsTypesStateToState converts an agentsTypes.State to a State.

func DBStateToState added in v0.0.130

func DBStateToState(dbState types.DBState) State

DBStateToState converts a DBState to a State.

type Store

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

Store is the sqlite store. It extends the base store for sqlite specific queries.

func NewStore

func NewStore(db *gorm.DB) *Store

NewStore creates a new store.

func (Store) DB

func (s Store) DB() *gorm.DB

DB gets the database.

func (Store) ExecuteMessage added in v0.0.86

func (s Store) ExecuteMessage(ctx context.Context, messageMask types.DBMessage) error

ExecuteMessage marks a message as executed in the database. TODO: Make batch update.

func (Store) GetAttestation added in v0.0.63

func (s Store) GetAttestation(ctx context.Context, attestationMask types.DBAttestation) (*agentsTypes.Attestation, error)

GetAttestation gets an attestation that has fields matching the attestation mask.

func (Store) GetAttestationBlockNumber added in v0.0.63

func (s Store) GetAttestationBlockNumber(ctx context.Context, attestationMask types.DBAttestation) (*uint64, error)

GetAttestationBlockNumber gets the block number of an attestation.

func (Store) GetAttestationTimestamp added in v0.0.130

func (s Store) GetAttestationTimestamp(ctx context.Context, attestationMask types.DBAttestation) (*uint64, error)

GetAttestationTimestamp gets the timestamp of an attestation.

func (Store) GetBlockNumber added in v0.0.63

func (s Store) GetBlockNumber(ctx context.Context, messageMask types.DBMessage) (uint64, error)

GetBlockNumber gets the block number of a message from the database.

func (Store) GetEarliestSnapshotFromAttestation added in v0.0.130

func (s Store) GetEarliestSnapshotFromAttestation(ctx context.Context, attestationMask types.DBAttestation, snapshotRoots []string) (*[32]byte, error)

GetEarliestSnapshotFromAttestation takes a list of snapshot roots, checks which one has the lowest block number, and returns that snapshot root back.

func (Store) GetEarliestStateInRange added in v0.0.134

func (s Store) GetEarliestStateInRange(ctx context.Context, chainID, destination, startNonce, endNonce uint32, tablePrefix string) (*agentsTypes.State, error)

GetEarliestStateInRange gets the earliest state with the same snapshot root as an attestation within a nonce range. 1. Get all states that are within a nonce range. 2. Get the state with the earliest attestation associated to it.

func (Store) GetExecutableMessages added in v0.0.86

func (s Store) GetExecutableMessages(ctx context.Context, messageMask types.DBMessage, currentTime uint64, page int) ([]agentsTypes.Message, error)

GetExecutableMessages gets executable messages from the database.

func (Store) GetLastBlockNumber

func (s Store) GetLastBlockNumber(ctx context.Context, chainID uint32) (uint64, error)

GetLastBlockNumber gets the last block number that had a message in the database.

func (Store) GetMessage

func (s Store) GetMessage(ctx context.Context, messageMask types.DBMessage) (*agentsTypes.Message, error)

GetMessage gets a message from the database.

func (Store) GetMessageMinimumTime added in v0.0.86

func (s Store) GetMessageMinimumTime(ctx context.Context, messageMask types.DBMessage) (*uint64, error)

GetMessageMinimumTime gets the minimum time for a message to be executed.

func (Store) GetMessages

func (s Store) GetMessages(ctx context.Context, messageMask types.DBMessage, page int) ([]agentsTypes.Message, error)

GetMessages gets messages from the database, paginated and ordered in ascending order by nonce.

func (Store) GetPotentialSnapshotRoots added in v0.0.130

func (s Store) GetPotentialSnapshotRoots(ctx context.Context, chainID uint32, nonce uint32) ([]string, error)

GetPotentialSnapshotRoots gets all snapshot roots that are greater than or equal to a specified nonce and matches a specified chain ID.

func (Store) GetSnapshotRootsInNonceRange added in v0.0.130

func (s Store) GetSnapshotRootsInNonceRange(ctx context.Context, chainID uint32, startNonce uint32, endNonce uint32) ([]string, error)

GetSnapshotRootsInNonceRange gets all snapshot roots for all states in a specified nonce range.

func (Store) GetState added in v0.0.130

func (s Store) GetState(ctx context.Context, stateMask types.DBState) (*agentsTypes.State, error)

GetState gets a state from the database.

func (Store) GetStateMetadata added in v0.0.130

func (s Store) GetStateMetadata(ctx context.Context, stateMask types.DBState) (snapshotRoot *[32]byte, proof *json.RawMessage, treeHeight *uint32, stateIndex *uint32, err error)

GetStateMetadata gets the snapshot root, proof, and tree height of a state from the database.

func (Store) GetTimestampForMessage added in v0.0.134

func (s Store) GetTimestampForMessage(ctx context.Context, chainID, destination, nonce uint32, tablePrefix string) (*uint64, error)

GetTimestampForMessage gets the timestamp for a message. This is done in multiple logical steps: 1. Get all potential snapshot roots for the message (all snapshot roots that are associated to states with the same chain ID and a nonce greater than or equal to the message nonce). 2. Get the minimum destination block number for all attestations that are associated to the potential snapshot roots. 3. Return the timestamp of the attestation with the minimum destination block number.

func (Store) GetUnsetMinimumTimeMessages added in v0.0.86

func (s Store) GetUnsetMinimumTimeMessages(ctx context.Context, messageMask types.DBMessage, page int) ([]agentsTypes.Message, error)

GetUnsetMinimumTimeMessages gets messages from the database that have not had their minimum time set.

func (Store) SetMinimumTime added in v0.0.86

func (s Store) SetMinimumTime(ctx context.Context, messageMask types.DBMessage, minimumTime uint64) error

SetMinimumTime sets the minimum time of a message.

func (Store) StoreAttestation added in v0.0.63

func (s Store) StoreAttestation(ctx context.Context, attestation agentsTypes.Attestation, destination uint32, destinationBlockNumber, destinationTimestamp uint64) error

StoreAttestation stores an attestation.

func (Store) StoreMessage

func (s Store) StoreMessage(ctx context.Context, message agentsTypes.Message, blockNumber uint64, minimumTimeSet bool, minimumTime uint64) error

StoreMessage stores a message in the database.

func (Store) StoreState added in v0.0.130

func (s Store) StoreState(ctx context.Context, state agentsTypes.State, snapshotRoot [32]byte, proof [][]byte, treeHeight, stateIndex uint32) error

StoreState stores a state.

func (Store) StoreStates added in v0.0.130

func (s Store) StoreStates(ctx context.Context, states []agentsTypes.State, snapshotRoot [32]byte, proofs [][][]byte, treeHeight uint32) error

StoreStates stores multiple states with the same snapshot root.

Jump to

Keyboard shortcuts

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