diff --git a/statediff/indexer/database/dump/indexer.go b/statediff/indexer/database/dump/indexer.go index ccbe28c66c91..357a78ece0ab 100644 --- a/statediff/indexer/database/dump/indexer.go +++ b/statediff/indexer/database/dump/indexer.go @@ -315,10 +315,7 @@ func (sdi *StateDiffIndexer) processReceiptsAndTxs(tx *BatchTx, args processArgs Data: trx.Data(), CID: txNode.Cid().String(), MhKey: shared.MultihashKeyFromCID(txNode.Cid()), - } - txType := trx.Type() - if txType != types.LegacyTxType { - txModel.Type = &txType + Type: trx.Type(), } if _, err := fmt.Fprintf(sdi.dump, "%+v\r\n", txModel); err != nil { return err diff --git a/statediff/indexer/database/sql/indexer.go b/statediff/indexer/database/sql/indexer.go index b9cfd0733557..fad68bf96e11 100644 --- a/statediff/indexer/database/sql/indexer.go +++ b/statediff/indexer/database/sql/indexer.go @@ -366,10 +366,7 @@ func (sdi *StateDiffIndexer) processReceiptsAndTxs(tx *BatchTx, args processArgs Data: trx.Data(), CID: txNode.Cid().String(), MhKey: shared.MultihashKeyFromCID(txNode.Cid()), - } - txType := trx.Type() - if txType != types.LegacyTxType { - txModel.Type = &txType + Type: trx.Type(), } txID, err := sdi.dbWriter.upsertTransactionCID(tx.dbtx, txModel, args.headerID) if err != nil { diff --git a/statediff/indexer/database/sql/interfaces.go b/statediff/indexer/database/sql/interfaces.go index 755c4e156ff5..3ed1a11e7a6b 100644 --- a/statediff/indexer/database/sql/interfaces.go +++ b/statediff/indexer/database/sql/interfaces.go @@ -67,7 +67,6 @@ type Tx interface { // ScannableRow interface to accommodate different concrete row types type ScannableRow interface { Scan(dest ...interface{}) error - StructScan(dest interface{}) error } // Result interface to accommodate different concrete result types diff --git a/statediff/indexer/database/sql/pgx_indexer_legacy_test.go b/statediff/indexer/database/sql/pgx_indexer_legacy_test.go index f97f3e2573c3..d08336e63e02 100644 --- a/statediff/indexer/database/sql/pgx_indexer_legacy_test.go +++ b/statediff/indexer/database/sql/pgx_indexer_legacy_test.go @@ -20,6 +20,7 @@ import ( "context" "testing" + "github.com/jmoiron/sqlx" "github.com/multiformats/go-multihash" "github.com/stretchr/testify/require" @@ -76,7 +77,7 @@ func TestPGXIndexerLegacy(t *testing.T) { } header := new(res) - err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).StructScan(header) + err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header) require.NoError(t, err) test_helpers.ExpectEqual(t, header.CID, legacyHeaderCID.String()) diff --git a/statediff/indexer/database/sql/pgx_indexer_test.go b/statediff/indexer/database/sql/pgx_indexer_test.go index 730257b21c40..f63efe712952 100644 --- a/statediff/indexer/database/sql/pgx_indexer_test.go +++ b/statediff/indexer/database/sql/pgx_indexer_test.go @@ -26,6 +26,7 @@ import ( "github.com/ipfs/go-cid" blockstore "github.com/ipfs/go-ipfs-blockstore" dshelp "github.com/ipfs/go-ipfs-ds-help" + "github.com/jmoiron/sqlx" "github.com/multiformats/go-multihash" "github.com/stretchr/testify/require" @@ -164,7 +165,7 @@ func TestPGXIndexer(t *testing.T) { BaseFee *int64 `db:"base_fee"` } header := new(res) - err = db.QueryRow(context.Background(), pgStr, mocks.BlockNumber.Uint64()).StructScan(header) + err = db.QueryRow(context.Background(), pgStr, mocks.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header) if err != nil { t.Fatal(err) } @@ -216,12 +217,12 @@ func TestPGXIndexer(t *testing.T) { if err != nil { t.Fatal(err) } + txTypePgStr := `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1` switch c { case trx1CID.String(): test_helpers.ExpectEqual(t, data, tx1) var txType *uint8 - pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1` - err = db.Get(context.Background(), &txType, pgStr, c) + err = db.Get(context.Background(), &txType, txTypePgStr, c) if err != nil { t.Fatal(err) } @@ -231,8 +232,7 @@ func TestPGXIndexer(t *testing.T) { case trx2CID.String(): test_helpers.ExpectEqual(t, data, tx2) var txType *uint8 - pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1` - err = db.Get(context.Background(), &txType, pgStr, c) + err = db.Get(context.Background(), &txType, txTypePgStr, c) if err != nil { t.Fatal(err) } @@ -242,8 +242,7 @@ func TestPGXIndexer(t *testing.T) { case trx3CID.String(): test_helpers.ExpectEqual(t, data, tx3) var txType *uint8 - pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1` - err = db.Get(context.Background(), &txType, pgStr, c) + err = db.Get(context.Background(), &txType, txTypePgStr, c) if err != nil { t.Fatal(err) } @@ -253,8 +252,7 @@ func TestPGXIndexer(t *testing.T) { case trx4CID.String(): test_helpers.ExpectEqual(t, data, tx4) var txType *uint8 - pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1` - err = db.Get(context.Background(), &txType, pgStr, c) + err = db.Get(context.Background(), &txType, txTypePgStr, c) if err != nil { t.Fatal(err) } @@ -284,8 +282,7 @@ func TestPGXIndexer(t *testing.T) { case trx5CID.String(): test_helpers.ExpectEqual(t, data, tx5) var txType *uint8 - pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1` - err = db.Get(context.Background(), &txType, pgStr, c) + err = db.Get(context.Background(), &txType, txTypePgStr, c) if err != nil { t.Fatal(err) } @@ -398,6 +395,7 @@ func TestPGXIndexer(t *testing.T) { t.Fatal(err) } + postStatePgStr := `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1` switch c { case rct1CID.String(): test_helpers.ExpectEqual(t, data, rct1) @@ -411,8 +409,7 @@ func TestPGXIndexer(t *testing.T) { case rct2CID.String(): test_helpers.ExpectEqual(t, data, rct2) var postState string - pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1` - err = db.Get(context.Background(), &postState, pgStr, c) + err = db.Get(context.Background(), &postState, postStatePgStr, c) if err != nil { t.Fatal(err) } @@ -420,8 +417,7 @@ func TestPGXIndexer(t *testing.T) { case rct3CID.String(): test_helpers.ExpectEqual(t, data, rct3) var postState string - pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1` - err = db.Get(context.Background(), &postState, pgStr, c) + err = db.Get(context.Background(), &postState, postStatePgStr, c) if err != nil { t.Fatal(err) } @@ -429,8 +425,7 @@ func TestPGXIndexer(t *testing.T) { case rct4CID.String(): test_helpers.ExpectEqual(t, data, rct4) var postState string - pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1` - err = db.Get(context.Background(), &postState, pgStr, c) + err = db.Get(context.Background(), &postState, postStatePgStr, c) if err != nil { t.Fatal(err) } @@ -438,8 +433,7 @@ func TestPGXIndexer(t *testing.T) { case rct5CID.String(): test_helpers.ExpectEqual(t, data, rct5) var postState string - pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1` - err = db.Get(context.Background(), &postState, pgStr, c) + err = db.Get(context.Background(), &postState, postStatePgStr, c) if err != nil { t.Fatal(err) } diff --git a/statediff/indexer/database/sql/postgres/config.go b/statediff/indexer/database/sql/postgres/config.go index aff7ac7739cc..a7c7cc9b4492 100644 --- a/statediff/indexer/database/sql/postgres/config.go +++ b/statediff/indexer/database/sql/postgres/config.go @@ -24,7 +24,7 @@ import ( "github.com/ethereum/go-ethereum/statediff/indexer/shared" ) -// DriverType to explicity type the kind of sql driver we are using +// DriverType to explicitly type the kind of sql driver we are using type DriverType string const ( diff --git a/statediff/indexer/database/sql/postgres/pgx.go b/statediff/indexer/database/sql/postgres/pgx.go index 838c78911669..9f670140048e 100644 --- a/statediff/indexer/database/sql/postgres/pgx.go +++ b/statediff/indexer/database/sql/postgres/pgx.go @@ -105,8 +105,7 @@ func (pgx *PGXDriver) createNode() error { // QueryRow satisfies sql.Database func (pgx *PGXDriver) QueryRow(ctx context.Context, sql string, args ...interface{}) sql.ScannableRow { - rows, _ := pgx.pool.Query(ctx, sql, args...) - return rowsWrapper{rows: rows} + return pgx.pool.QueryRow(ctx, sql, args...) } // Exec satisfies sql.Database @@ -160,20 +159,6 @@ func (pgx *PGXDriver) Context() context.Context { return pgx.ctx } -type rowsWrapper struct { - rows pgx.Rows -} - -// Scan satisfies sql.ScannableRow -func (r rowsWrapper) Scan(dest ...interface{}) error { - return (pgx.Row)(r.rows).Scan(dest...) -} - -// StructScan satisfies sql.ScannableRow -func (r rowsWrapper) StructScan(dest interface{}) error { - return pgxscan.ScanRow(dest, r.rows) -} - type resultWrapper struct { ct pgconn.CommandTag } @@ -234,8 +219,7 @@ type pgxTxWrapper struct { // QueryRow satisfies sql.Tx func (t pgxTxWrapper) QueryRow(ctx context.Context, sql string, args ...interface{}) sql.ScannableRow { - rows, _ := t.tx.Query(ctx, sql, args...) - return rowsWrapper{rows: rows} + return t.tx.QueryRow(ctx, sql, args...) } // Exec satisfies sql.Tx diff --git a/statediff/indexer/database/sql/sqlx_indexer_legacy_test.go b/statediff/indexer/database/sql/sqlx_indexer_legacy_test.go index 840a1ccae70d..2ce5f494f7af 100644 --- a/statediff/indexer/database/sql/sqlx_indexer_legacy_test.go +++ b/statediff/indexer/database/sql/sqlx_indexer_legacy_test.go @@ -20,15 +20,15 @@ import ( "context" "testing" - "github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres" - "github.com/ethereum/go-ethereum/statediff/indexer/interfaces" - "github.com/ipfs/go-cid" + "github.com/jmoiron/sqlx" "github.com/multiformats/go-multihash" "github.com/stretchr/testify/require" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/statediff/indexer/database/sql" + "github.com/ethereum/go-ethereum/statediff/indexer/database/sql/postgres" + "github.com/ethereum/go-ethereum/statediff/indexer/interfaces" "github.com/ethereum/go-ethereum/statediff/indexer/ipld" "github.com/ethereum/go-ethereum/statediff/indexer/mocks" "github.com/ethereum/go-ethereum/statediff/indexer/test_helpers" @@ -85,7 +85,7 @@ func TestSQLXIndexerLegacy(t *testing.T) { BaseFee *int64 `db:"base_fee"` } header := new(res) - err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).StructScan(header) + err = db.QueryRow(context.Background(), pgStr, legacyData.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header) require.NoError(t, err) test_helpers.ExpectEqual(t, header.CID, legacyHeaderCID.String()) diff --git a/statediff/indexer/database/sql/sqlx_indexer_test.go b/statediff/indexer/database/sql/sqlx_indexer_test.go index 815d3691551f..0fa4e8c1a3f9 100644 --- a/statediff/indexer/database/sql/sqlx_indexer_test.go +++ b/statediff/indexer/database/sql/sqlx_indexer_test.go @@ -26,6 +26,7 @@ import ( "github.com/ipfs/go-cid" blockstore "github.com/ipfs/go-ipfs-blockstore" dshelp "github.com/ipfs/go-ipfs-ds-help" + "github.com/jmoiron/sqlx" "github.com/multiformats/go-multihash" "github.com/stretchr/testify/require" @@ -190,7 +191,7 @@ func TestSQLXIndexer(t *testing.T) { BaseFee *int64 `db:"base_fee"` } header := new(res) - err = db.QueryRow(context.Background(), pgStr, mocks.BlockNumber.Uint64()).StructScan(header) + err = db.QueryRow(context.Background(), pgStr, mocks.BlockNumber.Uint64()).(*sqlx.Row).StructScan(header) if err != nil { t.Fatal(err) } @@ -242,50 +243,47 @@ func TestSQLXIndexer(t *testing.T) { if err != nil { t.Fatal(err) } + txTypePgStr := `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1` switch c { case trx1CID.String(): test_helpers.ExpectEqual(t, data, tx1) - var txType *uint8 - pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1` - err = db.Get(context.Background(), &txType, pgStr, c) + var txType uint8 + err = db.Get(context.Background(), &txType, txTypePgStr, c) if err != nil { t.Fatal(err) } - if txType != nil { - t.Fatalf("expected nil tx_type, got %d", *txType) + if txType != 0 { + t.Fatalf("expected LegacyTxType (0), got %d", txType) } case trx2CID.String(): test_helpers.ExpectEqual(t, data, tx2) - var txType *uint8 - pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1` - err = db.Get(context.Background(), &txType, pgStr, c) + var txType uint8 + err = db.Get(context.Background(), &txType, txTypePgStr, c) if err != nil { t.Fatal(err) } - if txType != nil { - t.Fatalf("expected nil tx_type, got %d", *txType) + if txType != 0 { + t.Fatalf("expected LegacyTxType (0), got %d", txType) } case trx3CID.String(): test_helpers.ExpectEqual(t, data, tx3) - var txType *uint8 - pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1` - err = db.Get(context.Background(), &txType, pgStr, c) + var txType uint8 + err = db.Get(context.Background(), &txType, txTypePgStr, c) if err != nil { t.Fatal(err) } - if txType != nil { - t.Fatalf("expected nil tx_type, got %d", *txType) + if txType != 0 { + t.Fatalf("expected LegacyTxType (0), got %d", txType) } case trx4CID.String(): test_helpers.ExpectEqual(t, data, tx4) - var txType *uint8 - pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1` - err = db.Get(context.Background(), &txType, pgStr, c) + var txType uint8 + err = db.Get(context.Background(), &txType, txTypePgStr, c) if err != nil { t.Fatal(err) } - if *txType != types.AccessListTxType { - t.Fatalf("expected AccessListTxType (1), got %d", *txType) + if txType != types.AccessListTxType { + t.Fatalf("expected AccessListTxType (1), got %d", txType) } accessListElementModels := make([]models.AccessListElementModel, 0) pgStr = `SELECT access_list_element.* FROM eth.access_list_element INNER JOIN eth.transaction_cids ON (tx_id = transaction_cids.id) WHERE cid = $1 ORDER BY access_list_element.index ASC` @@ -310,8 +308,7 @@ func TestSQLXIndexer(t *testing.T) { case trx5CID.String(): test_helpers.ExpectEqual(t, data, tx5) var txType *uint8 - pgStr = `SELECT tx_type FROM eth.transaction_cids WHERE cid = $1` - err = db.Get(context.Background(), &txType, pgStr, c) + err = db.Get(context.Background(), &txType, txTypePgStr, c) if err != nil { t.Fatal(err) } @@ -423,7 +420,7 @@ func TestSQLXIndexer(t *testing.T) { if err != nil { t.Fatal(err) } - + postStatePgStr := `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1` switch c { case rct1CID.String(): test_helpers.ExpectEqual(t, data, rct1) @@ -437,8 +434,7 @@ func TestSQLXIndexer(t *testing.T) { case rct2CID.String(): test_helpers.ExpectEqual(t, data, rct2) var postState string - pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1` - err = db.Get(context.Background(), &postState, pgStr, c) + err = db.Get(context.Background(), &postState, postStatePgStr, c) if err != nil { t.Fatal(err) } @@ -446,8 +442,7 @@ func TestSQLXIndexer(t *testing.T) { case rct3CID.String(): test_helpers.ExpectEqual(t, data, rct3) var postState string - pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1` - err = db.Get(context.Background(), &postState, pgStr, c) + err = db.Get(context.Background(), &postState, postStatePgStr, c) if err != nil { t.Fatal(err) } @@ -455,8 +450,7 @@ func TestSQLXIndexer(t *testing.T) { case rct4CID.String(): test_helpers.ExpectEqual(t, data, rct4) var postState string - pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1` - err = db.Get(context.Background(), &postState, pgStr, c) + err = db.Get(context.Background(), &postState, postStatePgStr, c) if err != nil { t.Fatal(err) } @@ -464,8 +458,7 @@ func TestSQLXIndexer(t *testing.T) { case rct5CID.String(): test_helpers.ExpectEqual(t, data, rct5) var postState string - pgStr = `SELECT post_state FROM eth.receipt_cids WHERE leaf_cid = $1` - err = db.Get(context.Background(), &postState, pgStr, c) + err = db.Get(context.Background(), &postState, postStatePgStr, c) if err != nil { t.Fatal(err) } diff --git a/statediff/indexer/models/models.go b/statediff/indexer/models/models.go index 72efe23836ba..5e849193efa9 100644 --- a/statediff/indexer/models/models.go +++ b/statediff/indexer/models/models.go @@ -67,7 +67,7 @@ type TxModel struct { Dst string `db:"dst"` Src string `db:"src"` Data []byte `db:"tx_data"` - Type *uint8 `db:"tx_type"` + Type uint8 `db:"tx_type"` } // AccessListElementModel is the db model for eth.access_list_entry diff --git a/statediff/indexer/shared/db_kind.go b/statediff/indexer/shared/db_kind.go index 78aae9f7f033..6b88164e1ee9 100644 --- a/statediff/indexer/shared/db_kind.go +++ b/statediff/indexer/shared/db_kind.go @@ -27,7 +27,7 @@ type DBType string const ( POSTGRES DBType = "Postgres" DUMP DBType = "Dump" - UNKOWN DBType = "Unknown" + UNKNOWN DBType = "Unknown" ) // ResolveDBType resolves a DBType from a provided string @@ -38,6 +38,6 @@ func ResolveDBType(str string) (DBType, error) { case "dump", "d": return DUMP, nil default: - return UNKOWN, fmt.Errorf("unrecognized db type string: %s", str) + return UNKNOWN, fmt.Errorf("unrecognized db type string: %s", str) } }