update submit/rollback pattern
All checks were successful
Unit and integration tests / Run unit tests (pull_request) Successful in 15m4s
Unit and integration tests / Run integration tests (pull_request) Successful in 41m5s

This commit is contained in:
Roy Crihfield 2023-10-01 01:11:30 +08:00
parent 6497eba1c4
commit 9efcd2713e
4 changed files with 20 additions and 16 deletions

6
go.mod
View File

@ -284,11 +284,11 @@ require (
) )
replace ( replace (
github.com/cerc-io/eth-ipfs-state-validator/v5 => git.vdb.to/cerc-io/eth-ipfs-state-validator/v5 v5.1.0-alpha github.com/cerc-io/eth-ipfs-state-validator/v5 => git.vdb.to/cerc-io/eth-ipfs-state-validator/v5 v5.1.1-alpha
github.com/cerc-io/eth-iterator-utils => git.vdb.to/cerc-io/eth-iterator-utils v0.1.2 github.com/cerc-io/eth-iterator-utils => git.vdb.to/cerc-io/eth-iterator-utils v0.1.2
github.com/cerc-io/eth-testing => git.vdb.to/cerc-io/eth-testing v0.3.1 github.com/cerc-io/eth-testing => git.vdb.to/cerc-io/eth-testing v0.3.1
github.com/cerc-io/ipld-eth-server/v5 => git.vdb.to/cerc-io/ipld-eth-server/v5 v5.1.1-alpha github.com/cerc-io/ipld-eth-server/v5 => git.vdb.to/cerc-io/ipld-eth-server/v5 v5.1.2-alpha
github.com/cerc-io/ipld-eth-statedb => git.vdb.to/cerc-io/ipld-eth-statedb v0.0.6-alpha github.com/cerc-io/ipld-eth-statedb => git.vdb.to/cerc-io/ipld-eth-statedb v0.0.7-alpha
github.com/cerc-io/plugeth-statediff => git.vdb.to/cerc-io/plugeth-statediff v0.1.4 github.com/cerc-io/plugeth-statediff => git.vdb.to/cerc-io/plugeth-statediff v0.1.4
github.com/ethereum/go-ethereum => git.vdb.to/cerc-io/plugeth v0.0.0-20230808125822-691dc334fab1 github.com/ethereum/go-ethereum => git.vdb.to/cerc-io/plugeth v0.0.0-20230808125822-691dc334fab1
github.com/openrelayxyz/plugeth-utils => git.vdb.to/cerc-io/plugeth-utils v0.0.0-20230706160122-cd41de354c46 github.com/openrelayxyz/plugeth-utils => git.vdb.to/cerc-io/plugeth-utils v0.0.0-20230706160122-cd41de354c46

13
go.sum
View File

@ -45,15 +45,15 @@ dmitri.shuralyov.com/html/belt v0.0.0-20180602232347-f7d459c86be0/go.mod h1:JLBr
dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4= dmitri.shuralyov.com/service/change v0.0.0-20181023043359-a85b471d5412/go.mod h1:a1inKt/atXimZ4Mv927x+r7UpyzRUf4emIoiiSC2TN4=
dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU= dmitri.shuralyov.com/state v0.0.0-20180228185332-28bcc343414c/go.mod h1:0PRwlb0D6DFvNNtx+9ybjezNCa8XF0xaYcETyp6rHWU=
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg= git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
git.vdb.to/cerc-io/eth-ipfs-state-validator/v5 v5.1.0-alpha h1:jHCtUi2CYJE0CLPHiwBBpHWDSfN1hGMJq8NOiBUHDaQ= git.vdb.to/cerc-io/eth-ipfs-state-validator/v5 v5.1.1-alpha h1:tophBXLyhMKmQILsxjfUTwQW+TGHtEJNajVULJJLhe0=
git.vdb.to/cerc-io/eth-ipfs-state-validator/v5 v5.1.0-alpha/go.mod h1:zljw2omf9IEyCT2WmR/gzVKQbsQ1XzPE22noSDQ2l34= git.vdb.to/cerc-io/eth-ipfs-state-validator/v5 v5.1.1-alpha/go.mod h1:e/9QV7BeaAvR+E6G3fab5+OxKGOEwCmJzs8WReuqKZM=
git.vdb.to/cerc-io/eth-iterator-utils v0.1.2 h1:PdMR5B9wrQSYuYpFhN+9Kc8AEZ0pTt5eKCmu8oCtFcY= git.vdb.to/cerc-io/eth-iterator-utils v0.1.2 h1:PdMR5B9wrQSYuYpFhN+9Kc8AEZ0pTt5eKCmu8oCtFcY=
git.vdb.to/cerc-io/eth-iterator-utils v0.1.2/go.mod h1:OvXbdWbZ5viBXC/Ui1EkhsSmGB+AUX+TjGa3UDAfjfg= git.vdb.to/cerc-io/eth-iterator-utils v0.1.2/go.mod h1:OvXbdWbZ5viBXC/Ui1EkhsSmGB+AUX+TjGa3UDAfjfg=
git.vdb.to/cerc-io/eth-testing v0.3.1 h1:sPnlMev6oEgTjsW7GtUkSsjKNG/+X6P9q0izSejLGpM= git.vdb.to/cerc-io/eth-testing v0.3.1 h1:sPnlMev6oEgTjsW7GtUkSsjKNG/+X6P9q0izSejLGpM=
git.vdb.to/cerc-io/ipld-eth-server/v5 v5.1.1-alpha h1:2P0iHcH2Bnq6Rs8GZCH9w1gc76as2YaiXb3WRX6+yuM= git.vdb.to/cerc-io/ipld-eth-server/v5 v5.1.2-alpha h1:kQ1dIFhso2VaJpJ3cVapTvTYmk64pE3XnUnr4eHdJdU=
git.vdb.to/cerc-io/ipld-eth-server/v5 v5.1.1-alpha/go.mod h1:DlhOVss3Iji8fcqkzDzpVYHgnm9+yz7SKkKYInLEgco= git.vdb.to/cerc-io/ipld-eth-server/v5 v5.1.2-alpha/go.mod h1:oWqgcY4QPLT70/hSCI/VRxBadCxlpi2k/tMfA8cIDd8=
git.vdb.to/cerc-io/ipld-eth-statedb v0.0.6-alpha h1:0YnoohjuK7w2JhIqLDDyVUNnu1RjyeDqqyhm6MojD74= git.vdb.to/cerc-io/ipld-eth-statedb v0.0.7-alpha h1:jtE+I+xlX9Q+vrkrgef9+w2JC7kuiUdrD//KVWtti5s=
git.vdb.to/cerc-io/ipld-eth-statedb v0.0.6-alpha/go.mod h1:cCQCfIUX5vTZBHeAfLa8wLUeLKO8kygDPm7Afc+MMI8= git.vdb.to/cerc-io/ipld-eth-statedb v0.0.7-alpha/go.mod h1:hUTzvyEEdaM0qVrfbtobZEURZoOpaN6wJ5s3YQgAHo8=
git.vdb.to/cerc-io/plugeth v0.0.0-20230808125822-691dc334fab1 h1:KLjxHwp9Zp7xhECccmJS00RiL+VwTuUGLU7qeIctg8g= git.vdb.to/cerc-io/plugeth v0.0.0-20230808125822-691dc334fab1 h1:KLjxHwp9Zp7xhECccmJS00RiL+VwTuUGLU7qeIctg8g=
git.vdb.to/cerc-io/plugeth v0.0.0-20230808125822-691dc334fab1/go.mod h1:cYXZu70+6xmDgIgrTD81GPasv16piiAFJnKyAbwVPMU= git.vdb.to/cerc-io/plugeth v0.0.0-20230808125822-691dc334fab1/go.mod h1:cYXZu70+6xmDgIgrTD81GPasv16piiAFJnKyAbwVPMU=
git.vdb.to/cerc-io/plugeth-statediff v0.1.4 h1:swDJDAk1/yu6MOHAvxeyZz+MS1H9FCmSWGQRswFxFEw= git.vdb.to/cerc-io/plugeth-statediff v0.1.4 h1:swDJDAk1/yu6MOHAvxeyZz+MS1H9FCmSWGQRswFxFEw=
@ -120,7 +120,6 @@ github.com/btcsuite/btcd v0.0.0-20190605094302-a0d1e3e36d50/go.mod h1:3J08xEfcug
github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI= github.com/btcsuite/btcd v0.0.0-20190824003749-130ea5bddde3/go.mod h1:3J08xEfcugPacsc34/LKRU2yO7YmuT8yt28J8k2+rrI=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.21.0-beta/go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94= github.com/btcsuite/btcd v0.21.0-beta/go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94=
github.com/btcsuite/btcd v0.22.0-beta h1:LTDpDKUM5EeOFBPM8IXpinEcmZ6FWfNZbE3lfrfdnWo=
github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U=
github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04=
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 h1:KdUfX2zKommPRa+PD0sWZUyXe9w277ABlgELO7H04IM= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.2 h1:KdUfX2zKommPRa+PD0sWZUyXe9w277ABlgELO7H04IM=

View File

@ -24,7 +24,7 @@ func TestStateDiffIndexer(ctx context.Context, chainConfig *params.ChainConfig,
ClientName: "geth", ClientName: "geth",
ChainID: chainConfig.ChainID.Uint64(), ChainID: chainConfig.ChainID.Uint64(),
} }
_, indexer, err := indexer.NewStateDiffIndexer(ctx, chainConfig, testInfo, TestDBConfig) _, indexer, err := indexer.NewStateDiffIndexer(ctx, chainConfig, testInfo, TestDBConfig, true)
return indexer, err return indexer, err
} }
@ -72,6 +72,7 @@ func IndexChain(indexer interfaces.StateDiffIndexer, params IndexChainParams) er
if err != nil { if err != nil {
return fmt.Errorf("failed to index block (block %d): %w", block.Number(), err) return fmt.Errorf("failed to index block (block %d): %w", block.Number(), err)
} }
defer tx.RollbackOnFailure(err)
if !params.SkipStateNodes { if !params.SkipStateNodes {
for _, node := range diff.Nodes { for _, node := range diff.Nodes {
@ -91,7 +92,7 @@ func IndexChain(indexer interfaces.StateDiffIndexer, params IndexChainParams) er
} }
} }
} }
if err = tx.Submit(err); err != nil { if err = tx.Submit(); err != nil {
return fmt.Errorf("failed to commit diff: %w", err) return fmt.Errorf("failed to commit diff: %w", err)
} }
} }

View File

@ -51,14 +51,17 @@ func setupStateValidator(t *testing.T) *sqlx.DB {
t.Fatal(err) t.Fatal(err)
} }
{ // Insert some non-canonical data into the database so that we test our ability to discern canonicity // Insert some non-canonical data into the database so that we test our ability to discern canonicity
// Use a func here for defer
func() {
tx, err := indexer.PushBlock(server_mocks.MockBlock, server_mocks.MockReceipts, tx, err := indexer.PushBlock(server_mocks.MockBlock, server_mocks.MockReceipts,
server_mocks.MockBlock.Difficulty()) server_mocks.MockBlock.Difficulty())
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer tx.RollbackOnFailure(err)
err = tx.Submit(err) err = tx.Submit()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -69,6 +72,7 @@ func setupStateValidator(t *testing.T) *sqlx.DB {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer tx.RollbackOnFailure(err)
ipld := sdtypes.IPLD{ ipld := sdtypes.IPLD{
CID: ipld.Keccak256ToCid(ipld.RawBinary, server_mocks.CodeHash.Bytes()).String(), CID: ipld.Keccak256ToCid(ipld.RawBinary, server_mocks.CodeHash.Bytes()).String(),
@ -79,11 +83,11 @@ func setupStateValidator(t *testing.T) *sqlx.DB {
t.Fatal(err) t.Fatal(err)
} }
err = tx.Submit(err) err = tx.Submit()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
} }()
if err := helpers.IndexChain(indexer, helpers.IndexChainParams{ if err := helpers.IndexChain(indexer, helpers.IndexChainParams{
StateCache: chain.StateCache(), StateCache: chain.StateCache(),