Skip to content

Commit 8f3a573

Browse files
authored
Merge pull request #202 from vulcanize/v1.10.15-statediff-3.0.2
V1.10.15 statediff 3.0.2
2 parents f78f9be + db96f3d commit 8f3a573

File tree

11 files changed

+46
-22
lines changed

11 files changed

+46
-22
lines changed

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
VersionMajor = 1 // Major version component of the current release
2525
VersionMinor = 10 // Minor version component of the current release
2626
VersionPatch = 15 // Patch version component of the current release
27-
VersionMeta = "statediff-3.0.1" // Version metadata to append to the version string
27+
VersionMeta = "statediff-3.0.2" // Version metadata to append to the version string
2828
)
2929

3030
// Version holds the textual version string.

statediff/indexer/database/sql/indexer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ import (
2525
"math/big"
2626
"time"
2727

28-
ipld2 "github.com/ethereum/go-ethereum/statediff/indexer/ipld"
29-
3028
"github.com/ipfs/go-cid"
3129
node "github.com/ipfs/go-ipld-format"
3230
"github.com/multiformats/go-multihash"
@@ -39,6 +37,7 @@ import (
3937
"github.com/ethereum/go-ethereum/params"
4038
"github.com/ethereum/go-ethereum/rlp"
4139
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
40+
ipld2 "github.com/ethereum/go-ethereum/statediff/indexer/ipld"
4241
"github.com/ethereum/go-ethereum/statediff/indexer/models"
4342
"github.com/ethereum/go-ethereum/statediff/indexer/shared"
4443
sdtypes "github.com/ethereum/go-ethereum/statediff/types"
@@ -155,9 +154,11 @@ func (sdi *StateDiffIndexer) PushBlock(block *types.Block, receipts types.Receip
155154
close(self.iplds)
156155
}()
157156
if p := recover(); p != nil {
157+
log.Info("panic detected before tx submission, rolling back the tx", "panic", p)
158158
rollback(sdi.ctx, tx)
159159
panic(p)
160160
} else if err != nil {
161+
log.Info("error detected before tx submission, rolling back the tx", "error", err)
161162
rollback(sdi.ctx, tx)
162163
} else {
163164
tDiff := time.Since(t)

statediff/indexer/database/sql/indexer_shared_test.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import (
66
"os"
77
"testing"
88

9-
"github.com/ethereum/go-ethereum/rlp"
10-
119
"github.com/ipfs/go-cid"
1210
"github.com/multiformats/go-multihash"
11+
"github.com/stretchr/testify/require"
1312

1413
"github.com/ethereum/go-ethereum/core/types"
14+
"github.com/ethereum/go-ethereum/rlp"
1515
"github.com/ethereum/go-ethereum/statediff/indexer/database/sql"
1616
"github.com/ethereum/go-ethereum/statediff/indexer/interfaces"
1717
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
@@ -141,3 +141,15 @@ func expectTrue(t *testing.T, value bool) {
141141
t.Fatalf("Assertion failed")
142142
}
143143
}
144+
145+
func checkTxClosure(t *testing.T, idle, inUse, open int64) {
146+
require.Equal(t, idle, db.Stats().Idle())
147+
require.Equal(t, inUse, db.Stats().InUse())
148+
require.Equal(t, open, db.Stats().Open())
149+
}
150+
151+
func tearDown(t *testing.T) {
152+
sql.TearDownDB(t, db)
153+
err := ind.Close()
154+
require.NoError(t, err)
155+
}

statediff/indexer/database/sql/mainnet_tests/indexer_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ func setup(t *testing.T, testBlock *types.Block, testReceipts types.Receipts) {
103103
}
104104

105105
func tearDown(t *testing.T) {
106+
require.Equal(t, int64(0), db.Stats().Idle())
107+
require.Equal(t, int64(0), db.Stats().InUse())
108+
require.Equal(t, int64(0), db.Stats().Open())
106109
sql.TearDownDB(t, db)
107110
err = ind.Close()
108111
require.NoError(t, err)

statediff/indexer/database/sql/pgx_indexer_legacy_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ func setupLegacyPGX(t *testing.T) {
5959
test_helpers.ExpectEqual(t, tx.(*sql.BatchTx).BlockNumber, legacyData.BlockNumber.Uint64())
6060
}
6161

62-
func TestPGXIndexerLegacy(t *testing.T) {
62+
func TestLegacyPGXIndexer(t *testing.T) {
6363
t.Run("Publish and index header IPLDs", func(t *testing.T) {
6464
setupLegacyPGX(t)
6565
defer tearDown(t)
66+
defer checkTxClosure(t, 1, 0, 1)
6667
pgStr := `SELECT cid, cast(td AS TEXT), cast(reward AS TEXT), block_hash, coinbase
6768
FROM eth.header_cids
6869
WHERE block_number = $1`

statediff/indexer/database/sql/pgx_indexer_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func TestPGXIndexer(t *testing.T) {
6969
t.Run("Publish and index header IPLDs in a single tx", func(t *testing.T) {
7070
setupPGX(t)
7171
defer tearDown(t)
72+
defer checkTxClosure(t, 1, 0, 1)
7273
pgStr := `SELECT cid, cast(td AS TEXT), cast(reward AS TEXT), block_hash, coinbase
7374
FROM eth.header_cids
7475
WHERE block_number = $1`
@@ -111,6 +112,7 @@ func TestPGXIndexer(t *testing.T) {
111112
t.Run("Publish and index transaction IPLDs in a single tx", func(t *testing.T) {
112113
setupPGX(t)
113114
defer tearDown(t)
115+
defer checkTxClosure(t, 1, 0, 1)
114116
// check that txs were properly indexed and published
115117
trxs := make([]string, 0)
116118
pgStr := `SELECT transaction_cids.cid FROM eth.transaction_cids INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.block_hash)
@@ -237,6 +239,7 @@ func TestPGXIndexer(t *testing.T) {
237239
t.Run("Publish and index log IPLDs for multiple receipt of a specific block", func(t *testing.T) {
238240
setupPGX(t)
239241
defer tearDown(t)
242+
defer checkTxClosure(t, 1, 0, 1)
240243

241244
rcts := make([]string, 0)
242245
rctsPgStr := `SELECT receipt_cids.leaf_cid FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids
@@ -294,6 +297,7 @@ func TestPGXIndexer(t *testing.T) {
294297
t.Run("Publish and index receipt IPLDs in a single tx", func(t *testing.T) {
295298
setupPGX(t)
296299
defer tearDown(t)
300+
defer checkTxClosure(t, 1, 0, 1)
297301

298302
// check receipts were properly indexed and published
299303
rcts := make([]string, 0)
@@ -395,6 +399,7 @@ func TestPGXIndexer(t *testing.T) {
395399
t.Run("Publish and index state IPLDs in a single tx", func(t *testing.T) {
396400
setupPGX(t)
397401
defer tearDown(t)
402+
defer checkTxClosure(t, 1, 0, 1)
398403
// check that state nodes were properly indexed and published
399404
stateNodes := make([]models.StateNodeModel, 0)
400405
pgStr := `SELECT state_cids.cid, state_cids.state_leaf_key, state_cids.node_type, state_cids.state_path, state_cids.header_id
@@ -484,6 +489,7 @@ func TestPGXIndexer(t *testing.T) {
484489
t.Run("Publish and index storage IPLDs in a single tx", func(t *testing.T) {
485490
setupPGX(t)
486491
defer tearDown(t)
492+
defer checkTxClosure(t, 1, 0, 1)
487493
// check that storage nodes were properly indexed
488494
storageNodes := make([]models.StorageNodeWithStateKeyModel, 0)
489495
pgStr := `SELECT storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path

statediff/indexer/database/sql/postgres/sqlx.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,10 @@ func NewSQLXDriver(ctx context.Context, config Config, node node.Info) (*SQLXDri
4545
if config.MaxConns > 0 {
4646
db.SetMaxOpenConns(config.MaxConns)
4747
}
48-
if config.MaxIdle > 0 {
49-
db.SetMaxIdleConns(config.MaxIdle)
50-
}
5148
if config.MaxConnLifetime > 0 {
52-
lifetime := config.MaxConnLifetime
53-
db.SetConnMaxLifetime(lifetime)
49+
db.SetConnMaxLifetime(config.MaxConnLifetime)
5450
}
51+
db.SetMaxIdleConns(config.MaxIdle)
5552
driver := &SQLXDriver{ctx: ctx, db: db, nodeInfo: node}
5653
if err := driver.createNode(); err != nil {
5754
return &SQLXDriver{}, ErrUnableToSetNode(err)

statediff/indexer/database/sql/postgres/test_helpers.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import (
2525

2626
// SetupSQLXDB is used to setup a sqlx db for tests
2727
func SetupSQLXDB() (sql.Database, error) {
28-
driver, err := NewSQLXDriver(context.Background(), DefaultConfig, node.Info{})
28+
conf := DefaultConfig
29+
conf.MaxIdle = 0
30+
driver, err := NewSQLXDriver(context.Background(), conf, node.Info{})
2931
if err != nil {
3032
return nil, err
3133
}

statediff/indexer/database/sql/sqlx_indexer_legacy_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,11 @@ func setupLegacySQLX(t *testing.T) {
6969
test_helpers.ExpectEqual(t, tx.(*sql.BatchTx).BlockNumber, legacyData.BlockNumber.Uint64())
7070
}
7171

72-
func TestSQLXIndexerLegacy(t *testing.T) {
72+
func TestLegacySQLXIndexer(t *testing.T) {
7373
t.Run("Publish and index header IPLDs", func(t *testing.T) {
7474
setupLegacySQLX(t)
7575
defer tearDown(t)
76+
defer checkTxClosure(t, 0, 0, 0)
7677
pgStr := `SELECT cid, td, reward, block_hash, coinbase
7778
FROM eth.header_cids
7879
WHERE block_number = $1`

statediff/indexer/database/sql/sqlx_indexer_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,11 @@ func setupSQLX(t *testing.T) {
6666
test_helpers.ExpectEqual(t, tx.(*sql.BatchTx).BlockNumber, mocks.BlockNumber.Uint64())
6767
}
6868

69-
func tearDown(t *testing.T) {
70-
sql.TearDownDB(t, db)
71-
if err := ind.Close(); err != nil {
72-
t.Fatal(err)
73-
}
74-
}
75-
7669
func TestSQLXIndexer(t *testing.T) {
7770
t.Run("Publish and index header IPLDs in a single tx", func(t *testing.T) {
7871
setupSQLX(t)
7972
defer tearDown(t)
73+
defer checkTxClosure(t, 0, 0, 0)
8074
pgStr := `SELECT cid, td, reward, block_hash, coinbase
8175
FROM eth.header_cids
8276
WHERE block_number = $1`
@@ -114,6 +108,7 @@ func TestSQLXIndexer(t *testing.T) {
114108
t.Run("Publish and index transaction IPLDs in a single tx", func(t *testing.T) {
115109
setupSQLX(t)
116110
defer tearDown(t)
111+
defer checkTxClosure(t, 0, 0, 0)
117112
// check that txs were properly indexed and published
118113
trxs := make([]string, 0)
119114
pgStr := `SELECT transaction_cids.cid FROM eth.transaction_cids INNER JOIN eth.header_cids ON (transaction_cids.header_id = header_cids.block_hash)
@@ -240,6 +235,7 @@ func TestSQLXIndexer(t *testing.T) {
240235
t.Run("Publish and index log IPLDs for multiple receipt of a specific block", func(t *testing.T) {
241236
setupSQLX(t)
242237
defer tearDown(t)
238+
defer checkTxClosure(t, 0, 0, 0)
243239

244240
rcts := make([]string, 0)
245241
rctsPgStr := `SELECT receipt_cids.leaf_cid FROM eth.receipt_cids, eth.transaction_cids, eth.header_cids
@@ -295,6 +291,7 @@ func TestSQLXIndexer(t *testing.T) {
295291
t.Run("Publish and index receipt IPLDs in a single tx", func(t *testing.T) {
296292
setupSQLX(t)
297293
defer tearDown(t)
294+
defer checkTxClosure(t, 0, 0, 0)
298295

299296
// check receipts were properly indexed and published
300297
rcts := make([]string, 0)
@@ -395,6 +392,7 @@ func TestSQLXIndexer(t *testing.T) {
395392
t.Run("Publish and index state IPLDs in a single tx", func(t *testing.T) {
396393
setupSQLX(t)
397394
defer tearDown(t)
395+
defer checkTxClosure(t, 0, 0, 0)
398396
// check that state nodes were properly indexed and published
399397
stateNodes := make([]models.StateNodeModel, 0)
400398
pgStr := `SELECT state_cids.cid, state_cids.state_leaf_key, state_cids.node_type, state_cids.state_path, state_cids.header_id
@@ -484,6 +482,7 @@ func TestSQLXIndexer(t *testing.T) {
484482
t.Run("Publish and index storage IPLDs in a single tx", func(t *testing.T) {
485483
setupSQLX(t)
486484
defer tearDown(t)
485+
defer checkTxClosure(t, 0, 0, 0)
487486
// check that storage nodes were properly indexed
488487
storageNodes := make([]models.StorageNodeWithStateKeyModel, 0)
489488
pgStr := `SELECT storage_cids.cid, state_cids.state_leaf_key, storage_cids.storage_leaf_key, storage_cids.node_type, storage_cids.storage_path

0 commit comments

Comments
 (0)