Documentation ¶
Overview ¶
Package base contains the base sql implementation
Index ¶
- Variables
- func AttestationToDBAttestation(attestation Attestation) db.DBAttestation
- func GetAllModels() (allModels []interface{})
- func MessageToDBMessage(message Message) db.DBMessage
- func StateToDBState(state State) db.DBState
- type Attestation
- type Message
- type State
- type Store
- func (s Store) DB() *gorm.DB
- func (s Store) ExecuteMessage(ctx context.Context, messageMask db.DBMessage) error
- func (s Store) GetAttestation(ctx context.Context, attestationMask db.DBAttestation) (*agentsTypes.Attestation, error)
- func (s Store) GetAttestationBlockNumber(ctx context.Context, attestationMask db.DBAttestation) (*uint64, error)
- func (s Store) GetAttestationTimestamp(ctx context.Context, attestationMask db.DBAttestation) (*uint64, error)
- func (s Store) GetBlockNumber(ctx context.Context, messageMask db.DBMessage) (uint64, error)
- func (s Store) GetEarliestSnapshotFromAttestation(ctx context.Context, attestationMask db.DBAttestation, snapshotRoots []string) (*[32]byte, error)
- func (s Store) GetEarliestStateInRange(ctx context.Context, chainID, destination, startNonce, endNonce uint32) (*agentsTypes.State, error)
- func (s Store) GetExecutableMessages(ctx context.Context, messageMask db.DBMessage, currentTime uint64, page int) ([]agentsTypes.Message, error)
- func (s Store) GetLastBlockNumber(ctx context.Context, chainID uint32, contractType types.ContractType) (uint64, error)
- func (s Store) GetMessage(ctx context.Context, messageMask db.DBMessage) (*agentsTypes.Message, error)
- func (s Store) GetMessageMinimumTime(ctx context.Context, messageMask db.DBMessage) (*uint64, error)
- func (s Store) GetMessages(ctx context.Context, messageMask db.DBMessage, page int) ([]agentsTypes.Message, error)
- func (s Store) GetPotentialSnapshotRoots(ctx context.Context, chainID uint32, nonce uint32) ([]string, error)
- func (s Store) GetSnapshotRootsInNonceRange(ctx context.Context, chainID uint32, startNonce uint32, endNonce uint32) ([]string, error)
- func (s Store) GetState(ctx context.Context, stateMask db.DBState) (*agentsTypes.State, error)
- func (s Store) GetStateMetadata(ctx context.Context, stateMask db.DBState) (snapshotRoot *[32]byte, proof *json.RawMessage, stateIndex *uint32, err error)
- func (s Store) GetTimestampForMessage(ctx context.Context, chainID, destination, nonce uint32) (*uint64, error)
- func (s Store) GetUnsetMinimumTimeMessages(ctx context.Context, messageMask db.DBMessage, page int) ([]agentsTypes.Message, error)
- func (s Store) SetMinimumTime(ctx context.Context, messageMask db.DBMessage, minimumTime uint64) error
- func (s Store) StoreAttestation(ctx context.Context, attestation agentsTypes.Attestation, destination uint32, ...) error
- func (s Store) StoreMessage(ctx context.Context, message agentsTypes.Message, blockNumber uint64, ...) error
- func (s Store) StoreState(ctx context.Context, state agentsTypes.State, snapshotRoot [32]byte, ...) error
- func (s Store) StoreStates(ctx context.Context, states []agentsTypes.State, snapshotRoot [32]byte, ...) error
Constants ¶
This section is empty.
Variables ¶
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 )
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) db.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 ¶
MessageToDBMessage converts a Message to a DBMessage.
func StateToDBState ¶ added in v0.0.130
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"` // DataHash is the agent root and SnapGasHash combined into a single hash. DataHash string `gorm:"column:data_hash"` // 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. This is an event derived from the destination contract.
func DBAttestationToAttestation ¶ added in v0.0.63
func DBAttestationToAttestation(dbAttestation db.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;index:idx_chain_dest_nonce"` // Destination is the destination. Destination uint32 `gorm:"column:destination;primaryKey;index:idx_chain_dest_nonce"` // Nonce is the nonce. Nonce uint32 `gorm:"column:nonce;primaryKey;index:idx_chain_dest_nonce"` // 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. This is an event derived from the origin contract.
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 ¶
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"` // StateIndex is the index of the state in the Snapshot. StateIndex uint32 `gorm:"column:state_index"` // BlockNumber is the block number the state update was received on Summit. BlockNumber uint64 `gorm:"column:block_number"` // GDGasPrice is the gas price from the gas data. GDGasPrice uint16 `gorm:"column:gd_gas_price"` // GDDataPrice is the data price from the gas data. GDDataPrice uint16 `gorm:"column:gd_data_price"` // GDExecBuffer is the exec buffer from the gas data. GDExecBuffer uint16 `gorm:"column:gd_exec_buffer"` // GDAmortAttCost is the amortAttCost from the gas data. GDAmortAttCost uint16 `gorm:"column:gd_amort_att_cost"` // GDEtherPrice is the etherPrice from the gas data. GDEtherPrice uint16 `gorm:"column:gd_ether_price"` // GDMarkup is the markup from the gas data. GDMarkup uint16 `gorm:"column:gd_markup"` }
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, stateIndex uint32, blockNumber uint64) (State, error)
AgentsTypesStateToState converts an agentsTypes.State to a State.
func DBStateToState ¶ added in v0.0.130
DBStateToState converts a DBState to a State. nolint:cyclop
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 (Store) ExecuteMessage ¶ added in v0.0.86
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 db.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 db.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 db.DBAttestation) (*uint64, error)
GetAttestationTimestamp gets the timestamp of an attestation.
func (Store) GetBlockNumber ¶ added in v0.0.63
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 db.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) (*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 db.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, contractType types.ContractType) (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 db.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 db.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 db.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) GetStateMetadata ¶ added in v0.0.130
func (s Store) GetStateMetadata(ctx context.Context, stateMask db.DBState) (snapshotRoot *[32]byte, proof *json.RawMessage, 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) (*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 db.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 db.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.