Skip to content

Commit

Permalink
Revert "Merge pull request #1342 from 0chain/629-use-concurrency-safe…
Browse files Browse the repository at this point in the history
…guards-on-crt-chain-field"

This reverts commit b7a2de1, reversing
changes made to 3676668.
  • Loading branch information
Kishan-Dhakan committed Jun 10, 2022
1 parent e889bfa commit 46e167b
Show file tree
Hide file tree
Showing 146 changed files with 4,965 additions and 2,999 deletions.
17 changes: 0 additions & 17 deletions .github/workflows/build-&-publish-docker-image.yml
Expand Up @@ -41,11 +41,6 @@ jobs:
- uses: actions/checkout@v2

- name: Setup go 1.18
uses: actions/setup-go@v2
with:
go-version: '1.18' # The Go version to download (if necessary) and use.

- name: Build base images
run: |
docker build -f docker.local/build.base/Dockerfile.build_base . -t $ZCHAIN_BUILDBASE
Expand All @@ -59,11 +54,8 @@ jobs:

- name: Build & Push
run: |
make install-mockery
make build-mocks
sed 's,%COPY%,COPY --from=miner_build $APP_DIR,g' "$DOCKERFILE_MINER.template" > "$DOCKERFILE_MINER"
docker build --build-arg GIT_COMMIT=$GITHUB_SHA -t miner:latest -f "$DOCKERFILE_MINER" .
docker tag miner:latest ${MINER_REGISTRY}:$TAG
docker push ${MINER_REGISTRY}:$TAG
Expand Down Expand Up @@ -99,12 +91,6 @@ jobs:
- uses: actions/checkout@v1

- name: Setup go 1.18
uses: actions/setup-go@v2
with:
go-version: '1.18' # The Go version to download (if necessary) and use.


- name: Build base images
run: |
docker build -f docker.local/build.base/Dockerfile.build_base . -t $ZCHAIN_BUILDBASE
Expand All @@ -118,9 +104,6 @@ jobs:

- name: Build & Push
run: |
make install-mockery
make build-mocks
docker build --build-arg GIT_COMMIT=$GITHUB_SHA -t sharder:latest -f docker.local/build.sharder/Dockerfile .
docker tag sharder:latest ${SHARDER_REGISTRY}:$TAG
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/unit-test.yml
Expand Up @@ -18,12 +18,12 @@ jobs:
- name: Check msgp changes
run: ./docker.local/bin/check.msgp.sh

- name: Build Base
run: ./docker.local/bin/build.base.sh

- name: Check swagger generation
run: docker.local/bin/test.swagger.sh

- name: Build Base
run: ./docker.local/bin/build.base.sh

- name: Run unit tests
run: ./docker.local/bin/unit_test_build.sh

Expand All @@ -45,11 +45,11 @@ jobs:
- name: Check msgp changes
run: ./docker.local/bin/check.msgp.sh

- name: Build Base
run: ./docker.local/bin/build.base.sh

- name: Check swagger generation
run: docker.local/bin/test.swagger.sh

- name: Build Base
run: ./docker.local/bin/build.base.sh

- name: Run Linter
run: ./docker.local/bin/linter.sh
25 changes: 0 additions & 25 deletions Makefile
Expand Up @@ -4,28 +4,15 @@
# For usage on Windows see [Chocolatey CLI Documentation](https://docs.chocolatey.org/en-us/choco/setup)
# Then execute `choco install make` command in shell, now you will be able to use `make` on Windows.


ifeq ($(OS),Windows_NT)
detected_OS := Windows
detected_ARCH := x86_64
else
detected_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
detected_ARCH := $(shell sh -c 'uname -m 2>/dev/null || echo Unknown')
endif


make_path := $(abspath $(lastword $(MAKEFILE_LIST)))
root_path := $(patsubst %/, %, $(dir $(make_path)))
GOPATH := $(shell go env GOPATH)

.PHONY: pre-push go-mod check-commit
pre-push: go-mod check-commit

.PHONY: check-commit go-get run-test
check-commit: go-get run-test

.PHONY: install-mockery mockery

go-mod:
@echo "Prepare Go mod files..."
@cd $(root_path)/code/go/0chain.net && go mod tidy -v
Expand All @@ -42,18 +29,6 @@ run-test:
@cd $(root_path)/code/go/0chain.net && go test -tags bn256 -cover ./...
@echo "Tests completed."

install-mockery:
@([ -d ./tmp/mockery ] || mkdir -p ./tmp/mockery) \
&& echo "[+]download mockery" \
&& ([ -f ./tmp/mockery/mockery.tar.gz ] || curl -L -o ./tmp/mockery/mockery.tar.gz https://github.com/vektra/mockery/releases/download/v2.12.2/mockery_2.12.2_$(detected_OS)_$(detected_ARCH).tar.gz) \
&& echo "[+]install mockery" \
&& tar zxvfC ./tmp/mockery/mockery.tar.gz ./tmp/mockery \
&& cp ./tmp/mockery/mockery $(GOPATH)/bin/ \
&& rm -rf ./tmp

build-mocks:
./generate_mocks.sh

install-msgp:
@echo "Install msgp..."
./docker.local/bin/install.msgp.sh
Expand Down
71 changes: 64 additions & 7 deletions README.md
Expand Up @@ -25,7 +25,6 @@
- [Cleanup](#cleanup)
- [Minio Setup](#minio)
- [Integration tests](#integration-tests)
- [Benchmarks](#benchmarks)
- [Run 0chain on ec2 / vm / bare metal](https://github.com/0chain/0chain/blob/master/docker.aws/README.md)
- [Run 0chain on ec2 / vm / bare metal over https](https://github.com/0chain/0chain/blob/master/https/README.md)
- [Swagger documentation](#swagger-documentation)
Expand Down Expand Up @@ -61,7 +60,7 @@ Setup a network called testnet0 for each of these node containers to talk to eac
**_Note: The config file should be providing the IP address of the nodes as per the IP addresses in this network._**

```
./docker.local/bin/setup.network.sh
./docker.local/bin/setup_network.sh
```

## Building the Nodes
Expand Down Expand Up @@ -438,6 +437,69 @@ ok 0chain.net/chaincore/block 0.128s coverage: 98.9% of statements

The above output shows 98.9% of code statements was covered with tests.

Here is a sample output for all the unit test cases:

```
? 0chain.net/chaincore [no test files]
ok 0chain.net/chaincore/block 0.128s coverage: 98.9% of statements
? 0chain.net/chaincore/block/magicBlock [no test files]
ok 0chain.net/chaincore/chain 0.254s coverage: 6.0% of statements
? 0chain.net/chaincore/chain/state [no test files]
ok 0chain.net/chaincore/client 0.328s coverage: 30.8% of statements
? 0chain.net/chaincore/config [no test files]
? 0chain.net/chaincore/diagnostics [no test files]
ok 0chain.net/chaincore/httpclientutil 2.048s coverage: 91.7% of statements
ok 0chain.net/chaincore/node 0.011s coverage: 8.9% of statements
ok 0chain.net/chaincore/round 0.048s coverage: 97.1% of statements
ok 0chain.net/chaincore/smartcontract 0.032s coverage: 9.1% of statements
ok 0chain.net/chaincore/smartcontractinterface 0.032s coverage: 97.3%
? 0chain.net/chaincore/state [no test files]
ok 0chain.net/chaincore/threshold/bls 9.912s coverage: 1.1% of statem
ok 0chain.net/chaincore/tokenpool 10.034s coverage: 100.0% of statements
ok 0chain.net/chaincore/transaction 0.029s coverage: 0.4% of statements [no tests to run]
ok 0chain.net/chaincore/wallet 6.600s coverage: 40.0% of statements
? 0chain.net/conductor [no test files]
? 0chain.net/conductor/conductor [no test files]
? 0chain.net/conductor/conductrpc [no test files]
? 0chain.net/conductor/config [no test files]
? 0chain.net/conductor/sdkproxy [no test files]
? 0chain.net/conductor/utils [no test files]
? 0chain.net/core [no test files]
? 0chain.net/core/build [no test files]
ok 0chain.net/core/cache 0.004s coverage: 100.0% of statements
ok 0chain.net/core/common 0.238s coverage: 87.4% of statements
ok 0chain.net/core/datastore 0.033s coverage: 92.0% of statements
ok 0chain.net/core/ememorystore 1.018s coverage: 91.7% of statements
ok 0chain.net/core/encryption 1.290s coverage: 95.3% of statements
? 0chain.net/core/encryption/keys [no test files]
ok 0chain.net/core/logging 0.069s coverage: 96.5% of statements
ok 0chain.net/core/memorystore 0.281s coverage: 93.8% of statements
? 0chain.net/core/metric [no test files]
ok 0chain.net/core/persistencestore 0.036s coverage: 73.5% of statements
ok 0chain.net/core/util 22.237s coverage: 76.5% of statements
ok 0chain.net/miner 0.303s coverage: 8.0% of statements
? 0chain.net/miner/miner [no test files]
? 0chain.net/miner/mocks [no test files]
? 0chain.net/mocks [no test files]
? 0chain.net/mocks/core/datastore [no test files]
? 0chain.net/mocks/core/encryption [no test files]
ok 0chain.net/sharder 0.168s coverage: 20.8% of statements
ok 0chain.net/sharder/blockdb 0.004s coverage: 79.3% of statements
ok 0chain.net/sharder/blockstore 0.045s coverage: 79.7% of statements
? 0chain.net/sharder/sharder [no test files]
? 0chain.net/smartcontract [no test files]
? 0chain.net/smartcontract/faucetsc [no test files]
ok 0chain.net/smartcontract/interestpoolsc 0.030s coverage: 45.0% of statements
ok 0chain.net/smartcontract/minersc 0.104s coverage: 30.9% of statements
? 0chain.net/smartcontract/multisigsc [no test files]
? 0chain.net/smartcontract/multisigsc/test [no test files]
? 0chain.net/smartcontract/setupsc [no test files]
ok 0chain.net/smartcontract/storagesc 1.877s coverage: 58.8% of statements
ok 0chain.net/smartcontract/vestingsc 0.034s coverage: 81.8% of statements
ok 0chain.net/smartcontract/zrc20sc 0.030s coverage: 23.3% of statements
```

## Creating The Magic Block

First build the magic block image.
Expand Down Expand Up @@ -550,12 +612,7 @@ Integration testing combines individual 0chain modules and test them as a group.

For integration testing, A conductor which is a RPC(Remote Procedure Call) server is implemented to control behaviour of nodes .To know more about the conductor refer to the [conductor documentation](https://github.com/0chain/0chain/blob/master/code/go/0chain.net/conductor/README.md)

## Benchmarks
Benchmark 0chain smart-contract endpoints.

Runs testing.Benchmark on each 0chain endpoint. The blockchain database used in these tests is constructed from the parameters in the benchmark.yaml. file. Smartcontracts do not (or should not) access tha chain so a populated MPT database is enough to give a realistic benchmark.

More info in [read.me](code/go/0chain.net/smartcontract/benchmark/main/readme.md)

### Architecture
A conductor requires the nodes to be built in a certain order to control them during the tests. A config file is defined in [conductor.config.yaml](https://github.com/0chain/0chain/blob/master/docker.local/config/conductor.config.yaml) which contains important details such as details of all nodes used and custom commands used in integration testing.
Expand Down
15 changes: 8 additions & 7 deletions code/go/0chain.net/chaincore/block/block_eventdb.go
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"

"0chain.net/core/util"
"0chain.net/smartcontract/dbs/event"
)

Expand All @@ -17,10 +16,10 @@ func blockToBlockEvent(block *Block) *event.Block {
MinerID: block.MinerID,
RoundRandomSeed: block.RoundRandomSeed,
MerkleTreeRoot: block.GetMerkleTree().GetRoot(),
StateHash: util.ToHex(block.ClientStateHash),
StateHash: string(block.ClientStateHash),
ReceiptMerkleTreeRoot: block.GetReceiptsMerkleTree().GetRoot(),
NumTxns: len(block.Txns),
MagicBlockHash: block.LatestFinalizedMagicBlockHash,
MagicBlockHash: block.MagicBlock.Hash,
PrevHash: block.PrevHash,
Signature: block.Signature,
ChainId: block.ChainID,
Expand All @@ -30,18 +29,20 @@ func blockToBlockEvent(block *Block) *event.Block {
}
}

func CreateBlockEvent(block *Block) (error, event.Event) {
func emitBlockEvent(block *Block) error {
data, err := json.Marshal(blockToBlockEvent(block))
if err != nil {
return fmt.Errorf("error marshalling block: %v", err), event.Event{}
return fmt.Errorf("error marshalling block: %v", err)
}

return nil, event.Event{
block.Events = append(block.Events, event.Event{
BlockNumber: block.Round,
TxHash: "",
Type: int(event.TypeStats),
Tag: int(event.TagAddBlock),
Index: block.Hash,
Data: string(data),
}
})

return nil
}
5 changes: 5 additions & 0 deletions code/go/0chain.net/chaincore/block/entity.go
Expand Up @@ -1069,6 +1069,11 @@ func (b *Block) ComputeStateLocal(ctx context.Context, c Chainer) error {
}
}

err := emitBlockEvent(b.PrevBlock)
if err != nil {
logging.Logger.Error("emit block event error", zap.Error(err))
}

if !bytes.Equal(b.ClientStateHash, bState.GetRoot()) {
b.SetStateStatus(StateFailed)
logging.Logger.Error("compute state local - state hash mismatch",
Expand Down

0 comments on commit 46e167b

Please sign in to comment.