Documentation ¶
Overview ¶
Package l2db is responsible for storing and retrieving the data received by the coordinator through the api. Note that this data will be different for each coordinator in the network, as this represents the L2 information.
The data managed by this package is fundamentally PoolL2Tx and AccountCreationAuth. All this data come from the API sent by clients and is used by the txselector to decide which transactions are selected to forge a batch.
Some of the database tooling used in this package such as meddler and migration tools is explained in the db package.
This package is spitted in different files following these ideas: - l2db.go: constructor and functions used by packages other than the api. - apiqueries.go: functions used by the API, the queries implemented in this functions use a semaphore to restrict the maximum concurrent connections to the database. - views.go: structs used to retrieve/store data from/to the database. When possible, the common structs are used, however most of the time there is no 1:1 relation between the struct fields and the tables of the schema, especially when joining tables. In some cases, some of the structs defined in this file also include custom Marshallers to easily match the expected api formats.
Index ¶
- type AccountCreationAuthAPI
- type GetPoolTxsAPIRequest
- type L2DB
- func (l2db *L2DB) AddAccountCreationAuth(auth *common.AccountCreationAuth) error
- func (l2db *L2DB) AddAccountCreationAuthAPI(auth *common.AccountCreationAuth) error
- func (l2db *L2DB) AddAtomicTxsAPI(txs []common.PoolL2Tx) error
- func (l2db *L2DB) AddManyAccountCreationAuth(auths []common.AccountCreationAuth) error
- func (l2db *L2DB) AddTxAPI(tx *common.PoolL2Tx) error
- func (l2db *L2DB) AddTxTest(tx *common.PoolL2Tx) error
- func (l2db *L2DB) DB() *sqlx.DB
- func (l2db *L2DB) DoneForging(txIDs []common.TxID, batchNum common.BatchNum) error
- func (l2db *L2DB) GetAccountCreationAuth(addr ethCommon.Address) (*common.AccountCreationAuth, error)
- func (l2db *L2DB) GetAccountCreationAuthAPI(addr ethCommon.Address) (*AccountCreationAuthAPI, error)
- func (l2db *L2DB) GetPendingTxs() ([]common.PoolL2Tx, error)
- func (l2db *L2DB) GetPendingUniqueFromIdxs() ([]common.Idx, error)
- func (l2db *L2DB) GetPoolTxsAPI(request GetPoolTxsAPIRequest) ([]apitypes.TxL2, uint64, error)
- func (l2db *L2DB) GetPoolTxsByAtomicGroupIDAPI(atomicGroupID common.AtomicGroupID) ([]apitypes.TxL2, error)
- func (l2db *L2DB) GetTx(txID common.TxID) (*common.PoolL2Tx, error)
- func (l2db *L2DB) GetTxAPI(txID common.TxID) (apitypes.TxL2, error)
- func (l2db *L2DB) InvalidateOldNonces(updatedAccounts []common.IdxNonce, batchNum common.BatchNum) (err error)
- func (l2db *L2DB) InvalidateTxs(txIDs []common.TxID, batchNum common.BatchNum) error
- func (l2db *L2DB) MinFeeUSD() float64
- func (l2db *L2DB) Purge(currentBatchNum common.BatchNum) (err error)
- func (l2db *L2DB) PurgeByExternalDelete() error
- func (l2db *L2DB) Reorg(lastValidBatch common.BatchNum) error
- func (l2db *L2DB) StartForging(txIDs []common.TxID, batchNum common.BatchNum) error
- func (l2db *L2DB) UpdateTxAPI(tx *common.PoolL2Tx) error
- func (l2db *L2DB) UpdateTxByIdxAndNonceAPI(idx common.Idx, nonce nonce.Nonce, tx *common.PoolL2Tx) error
- func (l2db *L2DB) UpdateTxsInfo(txs []common.PoolL2Tx, batchNum common.BatchNum) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountCreationAuthAPI ¶
type AccountCreationAuthAPI struct { EthAddr apitypes.HezEthAddr `json:"hezEthereumAddress" meddler:"eth_addr" ` BJJ apitypes.HezBJJ `json:"bjj" meddler:"bjj" ` Signature apitypes.EthSignature `json:"signature" meddler:"signature" ` Timestamp time.Time `json:"timestamp" meddler:"timestamp,utctime"` }
AccountCreationAuthAPI represents an account creation auth in the expected format by the API
type GetPoolTxsAPIRequest ¶ added in v1.2.0
type GetPoolTxsAPIRequest struct { EthAddr *ethCommon.Address FromEthAddr *ethCommon.Address ToEthAddr *ethCommon.Address Bjj *babyjub.PublicKeyComp FromBjj *babyjub.PublicKeyComp ToBjj *babyjub.PublicKeyComp TxType *common.TxType TokenID *common.TokenID Idx *common.Idx FromIdx *common.Idx ToIdx *common.Idx State *common.PoolL2TxState FromItem *uint Limit *uint Order string }
GetPoolTxsAPIRequest is an API request struct for getting txs from the pool
type L2DB ¶
type L2DB struct {
// contains filtered or unexported fields
}
L2DB stores L2 txs and authorization registers received by the coordinator and keeps them until they are no longer relevant due to them being forged or invalid after a safety period
func NewL2DB ¶
func NewL2DB( dbRead, dbWrite *sqlx.DB, safetyPeriod common.BatchNum, maxTxs uint32, minFeeUSD float64, maxFeeUSD float64, TTL time.Duration, apiConnCon *db.APIConnectionController, ) *L2DB
NewL2DB creates a L2DB. To create it, it's needed db connection, safety period expressed in batches, maxTxs that the DB should have and TTL (time to live) for pending txs.
func (*L2DB) AddAccountCreationAuth ¶
func (l2db *L2DB) AddAccountCreationAuth(auth *common.AccountCreationAuth) error
AddAccountCreationAuth inserts an account creation authorization into the DB
func (*L2DB) AddAccountCreationAuthAPI ¶
func (l2db *L2DB) AddAccountCreationAuthAPI(auth *common.AccountCreationAuth) error
AddAccountCreationAuthAPI inserts an account creation authorization into the DB
func (*L2DB) AddAtomicTxsAPI ¶ added in v1.6.0
AddAtomicTxsAPI inserts transactions into the pool if minFeeUSD <= total fee in USD <= maxFeeUSD. It's assumed that the given txs conform a single atomic group and AtomicGroupID will be set for all the txs awith value last AtomigGroupID in the DB +1
func (*L2DB) AddManyAccountCreationAuth ¶
func (l2db *L2DB) AddManyAccountCreationAuth(auths []common.AccountCreationAuth) error
AddManyAccountCreationAuth inserts a batch of accounts creation authorization if not exist into the DB
func (*L2DB) AddTxTest ¶
AddTxTest inserts a tx into the L2DB, without security checks. This is useful for test purposes,
func (*L2DB) DB ¶
DB returns a pointer to the L2DB.db. This method should be used only for internal testing purposes.
func (*L2DB) DoneForging ¶
DoneForging updates the state of the transactions that have been forged so the state of the txs referenced by txIDs will be changed from Forging -> Forged
func (*L2DB) GetAccountCreationAuth ¶
func (l2db *L2DB) GetAccountCreationAuth(addr ethCommon.Address) (*common.AccountCreationAuth, error)
GetAccountCreationAuth returns an account creation authorization from the DB
func (*L2DB) GetAccountCreationAuthAPI ¶
func (l2db *L2DB) GetAccountCreationAuthAPI(addr ethCommon.Address) (*AccountCreationAuthAPI, error)
GetAccountCreationAuthAPI returns an account creation authorization from the DB
func (*L2DB) GetPendingTxs ¶
GetPendingTxs return all the pending txs of the L2DB, that have a non NULL AbsoluteFee
func (*L2DB) GetPendingUniqueFromIdxs ¶
GetPendingUniqueFromIdxs returns from all the pending transactions, the set of unique FromIdx
func (*L2DB) GetPoolTxsAPI ¶ added in v1.2.0
GetPoolTxsAPI return Txs from the pool
func (*L2DB) GetPoolTxsByAtomicGroupIDAPI ¶ added in v1.6.0
func (l2db *L2DB) GetPoolTxsByAtomicGroupIDAPI(atomicGroupID common.AtomicGroupID) ([]apitypes.TxL2, error)
GetPoolTxsByAtomicGroupIDAPI return Txs from the pool that belong to the given atomicGroupID
func (*L2DB) InvalidateOldNonces ¶
func (l2db *L2DB) InvalidateOldNonces(updatedAccounts []common.IdxNonce, batchNum common.BatchNum) (err error)
InvalidateOldNonces invalidate txs with nonces that are smaller or equal than their respective accounts nonces. The state of the affected txs will be changed from Pending to Invalid
func (*L2DB) InvalidateTxs ¶
InvalidateTxs updates the state of the transactions that are invalid. The state of the txs referenced by txIDs will be changed from * -> Invalid
func (*L2DB) MinFeeUSD ¶
MinFeeUSD returns the minimum fee in USD that is required to accept txs into the pool
func (*L2DB) Purge ¶
Purge deletes transactions that have been forged or marked as invalid for longer than the safety period it also deletes pending txs that have been in the L2DB for longer than the ttl if maxTxs has been exceeded
func (*L2DB) PurgeByExternalDelete ¶
PurgeByExternalDelete deletes all pending transactions marked with true in the `external_delete` column. An external process can set this column to true to instruct the coordinator to delete the tx when possible.
func (*L2DB) Reorg ¶
Reorg updates the state of txs that were updated in a batch that has been discarted due to a blockchain reorg. The state of the affected txs can change form Forged -> Pending or from Invalid -> Pending
func (*L2DB) StartForging ¶
StartForging updates the state of the transactions that will begin the forging process. The state of the txs referenced by txIDs will be changed from Pending -> Forging
func (*L2DB) UpdateTxAPI ¶ added in v1.7.0
UpdateTxAPI Update PoolL2Tx regular transactions in the pool.