visit
git clone //github.com/yolannel/CTKBlockchain
pip install -U -r requirements.txt
Often described as 'spreadsheets in the sky' - these present a really unique way to use Chaos Toolkit. The goal of this experiment is to check that a chain exists and can be called after a simple transaction. No rollbacks should be supported since a blockchain should be immutable. To test this here's our first experiment:
{
"version": "1.0.0",
"title": "Can we make a new transaction?",
"description": "The system should respond to a transaction request.",
"tags": ["tx"],
...
"steady-state-hypothesis": {
"title": "Chain exists",
"probes": [
{
"type": "probe",
"name": "chain-exists",
"tolerance": 200,
"provider": {
"type": "http",
"timeout": 5,
"url": "//127.0.0.1:5000/chain"
}
}
]
},
Probes can help you to check the system state, but actions introduce new information or a change to the system being tested. For example, checking that the chain exists is a probe but creating a new transaction is an action.The next step is to include the specific arguments called for by our blockchain.py file, defined below:
"method": [
{
"type": "action",
"name": "make-new-transaction",
"provider": {
"type": "http",
"timeout": 1,
"url": "//127.0.0.1:5000/transactions/new",
"method": "POST",
"headers": {
"Content-Type": "application/json"
},
"arguments": {
"sender": "me",
"recipient": "new-other-address",
"amount": 20
}
}
},
{
"type": "probe",
"name": "check-chain",
"provider": {
"type": "http",
"url": "//127.0.0.1:5000/mine"
}
},
{
"type": "action",
"name": "mine-block",
"provider": {
"type": "http",
"timeout": 3,
"url": "//127.0.0.1:5000/mine"
}
},
{
"type": "probe",
"name": "check-chain",
"provider": {
"type": "http",
"url": "//127.0.0.1:5000/mine"
}
}
],
Finally, we reach the rollbacks! When designing an experiment, you should be aware of the capabilities of your system and also what it should be able to do.
For example, I could include code in my blockchain.py file that allows a user to delete a transaction which hasn’t been mined yet; however, this would violate the operation of a blockchain because blockchains derive trust from immutability.
A software production rollback is simply the returning of a codebase to an earlier, more stable version. If you are curious about the execution workflow that would typically result in a rollback, you can understand those conditions from the . Then the snippet that usually handles rollbacks is simply:
"rollbacks": [
]}
$ python blockchain.py
$ chaos run testTransaction.json
Centralized, decentralized and distributed network models by Paul Baran (1964), part of a RAND Institute study to create a robust and nonlinear military communication network .
{
"type": "action",
"name": "simulate activity",
"provider": {
"type": "python",
"module": "os",
"func": "system",
"arguments": {
"command": "python -c \"import activity; activity.run(100)\""
}
}
}
$ python blockchain.py --port 5000
$ python blockchain.py --port 5001
$ chaos run testConsensus.json
1. The Chaos Toolkit tests what states are actually possible for your system, so that is context specific - walking through this tutorial, you have seen how the experiments should be tailored to how the system should work (in this case, no rollback options).
2. On an even more abstracted level, the CTK is an automation tool - note how the consensus test essentially automates a lot of usage and then checks. This actually makes it incredibly powerful even if you aren’t specifically running a chaos experiment because there is a set process that you create which is replicable. Think of experiments as blueprints for what you want to try!
Diving into blockchain with experimentation is a great way to flex your mind around immutability and stable states. If you have any questions or would like some insights into similar topics, find us at Reliably on Hackernoon.
This Chaos Engineering with Blockchain tutorial was developed by . The blockchain tutorial linked in the beginning was developed by Daniel van Flymen.