Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

L2DB.CheckNonces updates all txs, but should filter by state = pending #396

Closed
ed255 opened this issue Dec 21, 2020 · 0 comments · Fixed by #402
Closed

L2DB.CheckNonces updates all txs, but should filter by state = pending #396

ed255 opened this issue Dec 21, 2020 · 0 comments · Fixed by #402
Assignees
Labels
bug Something isn't working
Projects

Comments

@ed255
Copy link
Contributor

ed255 commented Dec 21, 2020

var checkNoncesQuery = fmt.Sprintf(`
		UPDATE tx_pool SET
			state = '%s',
			batch_num = %%d
		FROM (VALUES
			(NULL::::BIGINT, NULL::::BIGINT),
			(:idx, :nonce)
		) as updated_acc (idx, nonce)
		WHERE tx_pool.from_idx = updated_acc.idx AND tx_pool.nonce <= updated_acc.nonce;
	`, common.PoolL2TxStateInvalid)

// CheckNonces 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 *L2DB) CheckNonces(updatedAccounts []common.IdxNonce, batchNum common.BatchNum) (err error) {
	if len(updatedAccounts) == 0 {
		return nil
	}
	// Fill the batch_num in the query with Sprintf because we are using a
	// named query which works with slices, and doens't handle an extra
	// individual argument.
	query := fmt.Sprintf(checkNoncesQuery, batchNum)
	if _, err := sqlx.NamedExec(l2db.db, query, updatedAccounts); err != nil {
		return tracerr.Wrap(err)
	}
	return nil
}
@ed255 ed255 self-assigned this Dec 21, 2020
@ed255 ed255 added the bug Something isn't working label Dec 21, 2020
@ed255 ed255 added this to To do in v0 via automation Dec 21, 2020
@ed255 ed255 added this to the v0-implementation milestone Dec 21, 2020
ed255 added a commit that referenced this issue Dec 21, 2020
- Test all the purger functions
- Fix nonces set by til (previously til started with nonce 1 for pool l2txs,
  but the correct implementation is to start with nonce 0)
- Rename L2DB.CheckNonces to L2DB.invalidateOldNoncesQuery
- Rename L2DB.checkNoncesQuery to L2DB.InvalidateOldNonces

Related #392 (Fix checkNoncesQuery)
Resolve #396
ed255 added a commit that referenced this issue Dec 22, 2020
- Test all the purger functions
- Fix nonces set by til (previously til started with nonce 1 for pool l2txs,
  but the correct implementation is to start with nonce 0)
- Rename L2DB.CheckNonces to L2DB.invalidateOldNoncesQuery
- Rename L2DB.checkNoncesQuery to L2DB.InvalidateOldNonces

Related #392 (Fix checkNoncesQuery)
Resolve #396
ed255 added a commit that referenced this issue Dec 22, 2020
- Test all the purger functions
- Fix nonces set by til (previously til started with nonce 1 for pool l2txs,
  but the correct implementation is to start with nonce 0)
- Rename L2DB.CheckNonces to L2DB.invalidateOldNoncesQuery
- Rename L2DB.checkNoncesQuery to L2DB.InvalidateOldNonces

Related #392 (Fix checkNoncesQuery)
Resolve #396
v0 automation moved this from To do to Done Dec 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
No open projects
v0
  
Done
Development

Successfully merging a pull request may close this issue.

1 participant