Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow pool to be blocked #1899

Merged
merged 9 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions db/migrations/pool/0006.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- +migrate Up
CREATE TABLE pool.blocked
(
addr varchar NOT NULL PRIMARY KEY
);

-- +migrate Down
DROP TABLE pool.blocked;
3 changes: 3 additions & 0 deletions pool/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ var (
// ErrInvalidSender is returned if the transaction contains an invalid signature.
ErrInvalidSender = errors.New("invalid sender")

// ErrInvalidSender is returned if the transaction is sent by a blocked account.
ErrBlockedSender = errors.New("blocked sender")

// ErrNonceTooLow is returned if the nonce of a transaction is lower than the
// one present in the local chain.
ErrNonceTooLow = errors.New("nonce too low")
Expand Down
1 change: 1 addition & 0 deletions pool/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type storage interface {
GetTxZkCountersByHash(ctx context.Context, hash common.Hash) (*state.ZKCounters, error)
DeleteTransactionByHash(ctx context.Context, hash common.Hash) error
MarkWIPTxsAsPending(ctx context.Context) error
IsAddressBlocked(ctx context.Context, address common.Address) (bool, error)
}

type stateInterface interface {
Expand Down
16 changes: 16 additions & 0 deletions pool/pgpoolstorage/pgpoolstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,19 @@ func (p *PostgresPoolStorage) UpdateTxWIPStatus(ctx context.Context, hash common
}
return nil
}

// IsAddressBlocked check if an address is added to the blocked table
func (p *PostgresPoolStorage) IsAddressBlocked(ctx context.Context, address common.Address) (bool, error) {
tclemos marked this conversation as resolved.
Show resolved Hide resolved
sql := `SELECT addr FROM pool.blocked WHERE addr = $1`
var addr string
err := p.db.QueryRow(ctx, sql, address.String()).Scan(&addr)
if err != nil {
if errors.Is(err, pgx.ErrNoRows) {
return false, nil
} else {
return false, err
}
}

return true, nil
}
8 changes: 8 additions & 0 deletions pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ func (p *Pool) validateTx(ctx context.Context, tx types.Transaction) error {
return ErrInvalidSender
}

// check if sender is blocked
blocked, err := p.storage.IsAddressBlocked(ctx, from)
if err != nil {
return err
} else if blocked {
return ErrBlockedSender
}

lastL2BlockNumber, err := p.state.GetLastL2BlockNumber(ctx, nil)
if err != nil {
return err
Expand Down
Loading