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

Show EL transactions on slot details page #40

Merged
merged 7 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions cmd/explorer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ func main() {
if err != nil {
logger.Fatalf("error starting beacon service: %v", err)
}
err = services.StartTxSignaturesService()
if err != nil {
logger.Fatalf("error starting tx signature service: %v", err)
}

if cfg.RateLimit.Enabled {
err = services.StartCallRateLimiter(cfg.RateLimit.ProxyCount, cfg.RateLimit.Rate, cfg.RateLimit.Burst)
Expand Down
170 changes: 170 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,3 +955,173 @@ func GetLatestBlobAssignment(commitment []byte) *dbtypes.BlobAssignment {
}
return &blobAssignment
}

func GetTxFunctionSignaturesByBytes(sigBytes []types.TxSignatureBytes) []*dbtypes.TxFunctionSignature {
fnSigs := []*dbtypes.TxFunctionSignature{}

var sql strings.Builder
fmt.Fprintf(&sql, `
SELECT
signature, bytes, name
FROM tx_function_signatures
WHERE bytes IN (`)
argIdx := 0
args := make([]any, len(sigBytes))
for i := range sigBytes {
if i > 0 {
fmt.Fprintf(&sql, ", ")
}
fmt.Fprintf(&sql, "$%v", argIdx+1)
args[argIdx] = sigBytes[i][:]
argIdx += 1
}
fmt.Fprintf(&sql, ")")

err := ReaderDb.Select(&fnSigs, sql.String(), args...)
if err != nil {
logger.Errorf("Error while fetching tx function signatures: %v", err)
return nil
}
return fnSigs
}

func InsertTxFunctionSignature(txFuncSig *dbtypes.TxFunctionSignature, tx *sqlx.Tx) error {
_, err := tx.Exec(EngineQuery(map[dbtypes.DBEngineType]string{
dbtypes.DBEnginePgsql: `
INSERT INTO tx_function_signatures (
signature, bytes, name
) VALUES ($1, $2, $3)
ON CONFLICT (signature) DO NOTHING`,
dbtypes.DBEngineSqlite: `
INSERT OR IGNORE INTO tx_function_signatures (
signature, bytes, name
) VALUES ($1, $2, $3)`,
}),
txFuncSig.Signature, txFuncSig.Bytes, txFuncSig.Name)
if err != nil {
return err
}
return nil
}

func GetUnknownFunctionSignatures(sigBytes []types.TxSignatureBytes) []*dbtypes.TxUnknownFunctionSignature {
unknwonFnSigs := []*dbtypes.TxUnknownFunctionSignature{}
if len(sigBytes) == 0 {
return unknwonFnSigs
}
var sql strings.Builder
fmt.Fprintf(&sql, `
SELECT
bytes, lastcheck
FROM tx_unknown_signatures
WHERE bytes in (`)
argIdx := 0
args := make([]any, len(sigBytes))
for i := range sigBytes {
if i > 0 {
fmt.Fprintf(&sql, ", ")
}
fmt.Fprintf(&sql, "$%v", argIdx+1)
args[argIdx] = sigBytes[i][:]
argIdx += 1
}
fmt.Fprintf(&sql, ")")
err := ReaderDb.Select(&unknwonFnSigs, sql.String(), args...)
if err != nil {
logger.Errorf("Error while fetching unknown function signatures: %v", err)
return nil
}
return unknwonFnSigs
}

func InsertUnknownFunctionSignatures(txUnknownSigs []*dbtypes.TxUnknownFunctionSignature, tx *sqlx.Tx) error {
var sql strings.Builder
fmt.Fprint(&sql, EngineQuery(map[dbtypes.DBEngineType]string{
dbtypes.DBEnginePgsql: `INSERT INTO tx_unknown_signatures (bytes, lastcheck) VALUES `,
dbtypes.DBEngineSqlite: `INSERT OR REPLACE INTO tx_unknown_signatures (bytes, lastcheck) VALUES `,
}))
argIdx := 0
args := make([]any, len(txUnknownSigs)*2)
for i := range txUnknownSigs {
if i > 0 {
fmt.Fprintf(&sql, ", ")
}
fmt.Fprintf(&sql, "($%v, $%v)", argIdx+1, argIdx+2)
args[argIdx] = txUnknownSigs[i].Bytes
args[argIdx+1] = txUnknownSigs[i].LastCheck
argIdx += 2
}
fmt.Fprint(&sql, EngineQuery(map[dbtypes.DBEngineType]string{
dbtypes.DBEnginePgsql: ` ON CONFLICT (bytes) DO UPDATE SET lastcheck = excluded.lastcheck`,
dbtypes.DBEngineSqlite: "",
}))
_, err := tx.Exec(sql.String(), args...)
if err != nil {
return err
}
return nil
}

func InsertPendingFunctionSignatures(txPendingSigs []*dbtypes.TxPendingFunctionSignature, tx *sqlx.Tx) error {
var sql strings.Builder
fmt.Fprint(&sql, EngineQuery(map[dbtypes.DBEngineType]string{
dbtypes.DBEnginePgsql: `INSERT INTO tx_pending_signatures (bytes, queuetime) VALUES `,
dbtypes.DBEngineSqlite: `INSERT OR IGNORE INTO tx_pending_signatures (bytes, queuetime) VALUES `,
}))
argIdx := 0
args := make([]any, len(txPendingSigs)*2)
for i := range txPendingSigs {
if i > 0 {
fmt.Fprintf(&sql, ", ")
}
fmt.Fprintf(&sql, "($%v, $%v)", argIdx+1, argIdx+2)
args[argIdx] = txPendingSigs[i].Bytes
args[argIdx+1] = txPendingSigs[i].QueueTime
argIdx += 2
}
fmt.Fprint(&sql, EngineQuery(map[dbtypes.DBEngineType]string{
dbtypes.DBEnginePgsql: ` ON CONFLICT (bytes) DO NOTHING`,
dbtypes.DBEngineSqlite: "",
}))
_, err := tx.Exec(sql.String(), args...)
if err != nil {
return err
}
return nil
}

func GetPendingFunctionSignatures(limit uint64) []*dbtypes.TxPendingFunctionSignature {
pendingFnSigs := []*dbtypes.TxPendingFunctionSignature{}
err := ReaderDb.Select(&pendingFnSigs, `
SELECT
bytes, queuetime
FROM tx_pending_signatures
ORDER BY queuetime ASC
LIMIT $1`, limit)
if err != nil {
logger.Errorf("Error while fetching unknown function signatures: %v", err)
return nil
}
return pendingFnSigs
}

func DeletePendingFunctionSignatures(sigBytes []types.TxSignatureBytes, tx *sqlx.Tx) error {
if len(sigBytes) == 0 {
return nil
}
var sql strings.Builder
fmt.Fprintf(&sql, `
DELETE FROM tx_pending_signatures
WHERE bytes in (`)
args := make([]any, len(sigBytes))
for i := range sigBytes {
if i > 0 {
fmt.Fprintf(&sql, ", ")
}
fmt.Fprintf(&sql, "$%v", i+1)
args[i] = sigBytes[i][:]
}
fmt.Fprintf(&sql, ")")
_, err := tx.Exec(sql.String(), args...)
return err
}
30 changes: 30 additions & 0 deletions db/schema/pgsql/20231113161726_tx-method-signatures.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- +goose Up
-- +goose StatementBegin

CREATE TABLE IF NOT EXISTS public."tx_function_signatures"
(
"bytes" bytea NOT NULL,
"signature" TEXT NOT NULL,
"name" TEXT NOT NULL,
PRIMARY KEY ("bytes")
);

CREATE TABLE IF NOT EXISTS public."tx_unknown_signatures"
(
"bytes" bytea NOT NULL,
"lastcheck" bigint NOT NULL,
PRIMARY KEY ("bytes")
);

CREATE TABLE IF NOT EXISTS public."tx_pending_signatures"
(
"bytes" bytea NOT NULL,
"queuetime" bigint NOT NULL,
PRIMARY KEY ("bytes")
);

-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
SELECT 'NOT SUPPORTED';
-- +goose StatementEnd
30 changes: 30 additions & 0 deletions db/schema/sqlite/20231113161726_tx-method-signatures.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-- +goose Up
-- +goose StatementBegin

CREATE TABLE IF NOT EXISTS "tx_function_signatures"
(
"bytes" BLOB NOT NULL,
"signature" TEXT NOT NULL,
"name" TEXT NOT NULL,
PRIMARY KEY ("bytes")
);

CREATE TABLE IF NOT EXISTS "tx_unknown_signatures"
(
"bytes" BLOB NOT NULL,
"lastcheck" bigint NOT NULL,
PRIMARY KEY ("bytes")
);

CREATE TABLE IF NOT EXISTS "tx_pending_signatures"
(
"bytes" BLOB NOT NULL,
"queuetime" bigint NOT NULL,
PRIMARY KEY ("bytes")
);

-- +goose StatementEnd
-- +goose Down
-- +goose StatementBegin
SELECT 'NOT SUPPORTED';
-- +goose StatementEnd
16 changes: 16 additions & 0 deletions dbtypes/dbtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,19 @@ type BlobAssignment struct {
Commitment []byte `db:"commitment"`
Slot uint64 `db:"slot"`
}

type TxFunctionSignature struct {
Signature string `db:"signature"`
Bytes []byte `db:"bytes"`
Name string `db:"name"`
}

type TxUnknownFunctionSignature struct {
Bytes []byte `db:"bytes"`
LastCheck uint64 `db:"lastcheck"`
}

type TxPendingFunctionSignature struct {
Bytes []byte `db:"bytes"`
QueueTime uint64 `db:"queuetime"`
}
Loading