From 161febc47ad6da63a913137fe7cffa9bb66b3291 Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Wed, 4 Oct 2023 07:44:43 +0000 Subject: [PATCH] Fix concurrency and tests (#4) 1. Synchronizes pushes to indexer - The Tx object is not threadsafe. 2. Fixes the chain config for the CI test fixtures, which were not accurate for the data, and causing processing errors Reviewed-on: https://git.vdb.to/cerc-io/eth-statediff-service/pulls/4 --- .gitea/workflows/tests.yml | 20 +++++++++++--------- pkg/service.go | 11 +++++++++-- scripts/compare-statediffs.sh | 3 ++- test/ci-chain.json | 7 ++++++- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/.gitea/workflows/tests.yml b/.gitea/workflows/tests.yml index 8f1f1e9..db3f398 100644 --- a/.gitea/workflows/tests.yml +++ b/.gitea/workflows/tests.yml @@ -48,18 +48,18 @@ jobs: - name: Run basic integration test env: DATABASE_TYPE: postgres - LEVELDB_PATH: ./fixtures/chaindata/_data/small - LEVELDB_ANCIENT: ./fixtures/chaindata/_data/small/ancient + LEVELDB_PATH: ./fixtures/chaindata/_data/small2 + LEVELDB_ANCIENT: ./fixtures/chaindata/_data/small2/ancient LOG_FILE: ./server-log - ETH_GENESIS_BLOCK: "0x37cbb63c7150a7b60f2878433963ed8ba7e5f82fb2683ec7a945c974e1cf4e05" - timeout-minutes: 30 + ETH_GENESIS_BLOCK: "0x8a3c7cddacbd1ab4ec1b03805fa2a287f3a75e43d87f4f987fcc399f5c042614" + timeout-minutes: 20 run: | ./eth-statediff-service --config ./test/ci-config.toml serve & sleep 10 - ./scripts/request-range.sh 0 32 || (E=$?; cat $LOG_FILE; exit $E) + ./scripts/request-range.sh 0 10 || (E=$?; cat $LOG_FILE; exit $E) - until grep "Finished processing block 32" $LOG_FILE + until grep "Finished processing block 10" $LOG_FILE do sleep 1; done count_results() { @@ -68,9 +68,11 @@ jobs: psql -tA cerc_testing -U vdbm -c "$query" } set -x - [[ "$(count_results eth.header_cids)" = 33 ]] - [[ "$(count_results eth.state_cids)" = 21 ]] - [[ "$(count_results eth.storage_cids)" = 18 ]] + [[ "$(count_results eth.header_cids)" = 11 ]] + [[ "$(count_results eth.state_cids)" = 287 ]] + [[ "$(count_results eth.storage_cids)" = 31 ]] + [[ "$(count_results eth.transaction_cids)" = 144 ]] + [[ "$(count_results eth.receipt_cids)" = 144 ]] compliance-test: name: Run compliance tests diff --git a/pkg/service.go b/pkg/service.go index 6785079..1ba687b 100644 --- a/pkg/service.go +++ b/pkg/service.go @@ -405,10 +405,17 @@ func (sds *Service) writeStateDiff(block *types.Block, parentRoot common.Hash, p return err } // defer handling of commit/rollback for any return case + defer tx.RollbackOnFailure(err) + + var nodeMtx, ipldMtx sync.Mutex output := func(node sdtypes.StateLeafNode) error { + nodeMtx.Lock() + defer nodeMtx.Unlock() return sds.indexer.PushStateNode(tx, node, block.Hash().String()) } - codeOutput := func(c sdtypes.IPLD) error { + ipldOutput := func(c sdtypes.IPLD) error { + ipldMtx.Lock() + defer ipldMtx.Unlock() return sds.indexer.PushIPLD(tx, c) } prom.SetTimeMetric(prom.T_BLOCK_PROCESSING, time.Now().Sub(t)) @@ -418,7 +425,7 @@ func (sds *Service) writeStateDiff(block *types.Block, parentRoot common.Hash, p OldStateRoot: parentRoot, BlockNumber: block.Number(), BlockHash: block.Hash(), - }, params, output, codeOutput) + }, params, output, ipldOutput) prom.SetTimeMetric(prom.T_STATE_PROCESSING, time.Now().Sub(t)) t = time.Now() err = tx.Submit() diff --git a/scripts/compare-statediffs.sh b/scripts/compare-statediffs.sh index 9442862..d0b6687 100755 --- a/scripts/compare-statediffs.sh +++ b/scripts/compare-statediffs.sh @@ -48,7 +48,6 @@ export DATABASE_PASSWORD="password" export ETH_NODE_ID=test-node export ETH_CLIENT_NAME=test-client export ETH_NETWORK_ID=test-network -export ETH_CHAIN_ID=4242 export SERVICE_HTTP_PATH='127.0.0.1:8545' export LOG_LEVEL=debug @@ -65,6 +64,7 @@ clear_table() { } tables=( + eth.header_cids eth.log_cids eth.receipt_cids eth.state_cids @@ -86,6 +86,7 @@ run_service() { service_binary=$1 service_output_dir=$2 + mkdir -p $service_output_dir $service_binary serve & until grep "HTTP endpoint opened" $LOG_FILE diff --git a/test/ci-chain.json b/test/ci-chain.json index d2ee2f5..44d2cd2 100644 --- a/test/ci-chain.json +++ b/test/ci-chain.json @@ -1,5 +1,5 @@ { - "chainId": 41337, + "chainId": 1212, "homesteadBlock": 0, "eip150Block": 0, "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", @@ -9,6 +9,11 @@ "constantinopleBlock": 0, "petersburgBlock": 0, "istanbulBlock": 0, + "berlinBlock": 0, + "londonBlock": 0, + "mergeForkBlock": 0, + "terminalTotalDifficulty": 0, + "mergeNetsplitBlock": 0, "clique": { "period": 5, "epoch": 30000