Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit 322a0ef

Browse files
Add batch_before, batch_after and block_end events
Add support for the batch_before, batch_after and block_end injector events. Add support for negative values in the "XatY" and "local" rules in the setting "sawtooth.validator.block_validation_rules". Implement missing abstract methods in the Batch Injector Factory in the python implementation and add injector class examples for after_batch, before_batch and block_end injection events. Move injectors into a dedicated folder. Create integration tests for the after_batch, before_batch and block_end events. This will change the "block_validation_rules" to only be applied at the end of the block in order to avoid conflicts and multiple validations of previously approved batches. Co-authored-by: AntonioBranco <antonio.branco@voidsoftware.com> Signed-off-by: Micael Ferreira <micael.ferreira@voidsoftware.com>
1 parent 1ef2890 commit 322a0ef

File tree

16 files changed

+1154
-95
lines changed

16 files changed

+1154
-95
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
/docs/source/sdks/
6464

6565
/integration/**/__pycache__/
66+
/integration/.tmp
6667

6768
/rest_api/build/
6869
/rest_api/sawtooth_rest_api/protobuf/

bin/run_tests

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ MODULE_LIST="
2323
settings
2424
identity
2525
block_info
26+
batch_injectors
2627
ipv6
2728
battleship
2829
validator
@@ -133,6 +134,9 @@ main() {
133134
block_info)
134135
test_block_info
135136
;;
137+
batch_injectors)
138+
test_batch_injection_events
139+
;;
136140
battleship)
137141
test_battleship
138142
;;
@@ -190,12 +194,17 @@ test_ipv6() {
190194
}
191195

192196
test_block_info() {
193-
run_docker_test test_block_info_injector
194-
copy_coverage .coverage.block_info_injector
197+
run_docker_test test_block_info_injector
198+
copy_coverage .coverage.block_info_injector
199+
}
200+
201+
test_batch_injection_events() {
202+
run_docker_test test_batch_injection_events
203+
copy_coverage .coverage.test_batch_injection_events
195204
}
196205

197206
test_battleship() {
198-
run_docker_test ./families/battleship/tests/test_tp_battleship.yaml
207+
run_docker_test ./families/battleship/tests/test_tp_battleship.yaml
199208
}
200209

201210
test_validator() {
Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# Copyright 2017 Intel Corporation
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
# ------------------------------------------------------------------------------
15+
16+
version: '2.1'
17+
18+
services:
19+
settings-tp:
20+
build:
21+
context: ../../..
22+
dockerfile: ./families/settings/Dockerfile
23+
args:
24+
- http_proxy
25+
- https_proxy
26+
- no_proxy
27+
image: sawtooth-settings-tp$INSTALL_TYPE:$ISOLATION_ID
28+
volumes:
29+
- $SAWTOOTH_CORE:/project/sawtooth-core
30+
expose:
31+
- 4004
32+
depends_on:
33+
- validator
34+
command: settings-tp -vv -C tcp://validator:4004
35+
stop_signal: SIGKILL
36+
37+
intkey-tp-python:
38+
image: hyperledger/sawtooth-intkey-tp-python:nightly
39+
expose:
40+
- 4004
41+
depends_on:
42+
- validator
43+
command: intkey-tp-python -vv -C tcp://validator:4004
44+
stop_signal: SIGKILL
45+
46+
block-info-tp:
47+
build:
48+
context: ../../..
49+
dockerfile: ./families/block_info/Dockerfile
50+
args:
51+
- http_proxy
52+
- https_proxy
53+
- no_proxy
54+
image: sawtooth-block-info-tp$INSTALL_TYPE:$ISOLATION_ID
55+
volumes:
56+
- $SAWTOOTH_CORE:/project/sawtooth-core
57+
expose:
58+
- 4004
59+
depends_on:
60+
- validator
61+
command: block-info-tp -vv -C tcp://validator:4004
62+
stop_signal: SIGKILL
63+
64+
validator:
65+
build:
66+
context: ../../..
67+
dockerfile: ./validator/Dockerfile
68+
args:
69+
- http_proxy
70+
- https_proxy
71+
- no_proxy
72+
image: sawtooth-validator$INSTALL_TYPE:$ISOLATION_ID
73+
volumes:
74+
- $SAWTOOTH_CORE:/project/sawtooth-core
75+
expose:
76+
- 4004
77+
- 8800
78+
# start the validator with an empty genesis batch
79+
command: "bash -c \"\
80+
sawadm keygen --force && \
81+
sawset genesis \
82+
-k /etc/sawtooth/keys/validator.priv \
83+
-o config-genesis.batch && \
84+
sawset proposal create \
85+
-k /etc/sawtooth/keys/validator.priv \
86+
sawtooth.consensus.algorithm.name=Devmode \
87+
sawtooth.consensus.algorithm.version=0.1 \
88+
sawtooth.settings.vote.authorized_keys=\
89+
\\\"$$(cat /etc/sawtooth/keys/validator.pub),\
90+
03e3aed7546a2a1921b7a694cd589e2cbff1893cd80e0b667c434059fcf2b9a465\\\"
91+
-o config.batch && \
92+
sawadm genesis \
93+
config-genesis.batch config.batch && \
94+
sawtooth-validator --endpoint tcp://validator:8800 -v \
95+
--bind component:tcp://eth0:4004 \
96+
--bind network:tcp://eth0:8800 \
97+
--bind consensus:tcp://eth0:5005 \
98+
\""
99+
stop_signal: SIGKILL
100+
101+
devmode:
102+
image: hyperledger/sawtooth-devmode-engine-rust:nightly
103+
command: devmode-engine-rust --connect tcp://validator:5005 -v
104+
stop_signal: SIGKILL
105+
106+
rest-api:
107+
build:
108+
context: ../../..
109+
dockerfile: ./rest_api/Dockerfile
110+
args:
111+
- http_proxy
112+
- https_proxy
113+
- no_proxy
114+
image: sawtooth-rest-api$INSTALL_TYPE:$ISOLATION_ID
115+
volumes:
116+
- $SAWTOOTH_CORE:/project/sawtooth-core
117+
expose:
118+
- 4004
119+
- 8008
120+
depends_on:
121+
- validator
122+
command: sawtooth-rest-api -v --connect tcp://validator:4004 --bind rest-api:8008
123+
stop_signal: SIGKILL
124+
125+
test-batch-injection-events:
126+
build:
127+
context: ../../..
128+
dockerfile: integration/sawtooth_integration/docker/integration-tests.dockerfile
129+
args:
130+
- http_proxy
131+
- https_proxy
132+
- no_proxy
133+
image: integration-tests:$ISOLATION_ID
134+
volumes:
135+
- $SAWTOOTH_CORE:/project/sawtooth-core
136+
expose:
137+
- 8008
138+
depends_on:
139+
- validator
140+
- rest-api
141+
command: |
142+
bash -c "
143+
mkdir -p /etc/sawtooth/keys && \
144+
touch /etc/sawtooth/keys/key.priv && \
145+
touch /etc/sawtooth/keys/key.pub && \
146+
echo \"a3ff296f454ddc43221046c9edc1c455ffef0cbb0ebef93fc7ad491646f13a4f\" > /etc/sawtooth/keys/key.priv && \
147+
echo \"03e3aed7546a2a1921b7a694cd589e2cbff1893cd80e0b667c434059fcf2b9a465\" > /etc/sawtooth/keys/key.pub && \
148+
sleep 5 && \
149+
echo Initialize intkey 'inject' key
150+
intkey set inject 0 \
151+
--keyfile /etc/sawtooth/keys/key.priv \
152+
--url http://rest-api:8008 && \
153+
echo ''
154+
echo ''
155+
echo Change batch_injectors settings to before_batch_injector
156+
sawset proposal create \
157+
-k /etc/sawtooth/keys/key.priv \
158+
sawtooth.validator.batch_injectors=before_batch \
159+
--url http://rest-api:8008 && \
160+
sleep 3 && \
161+
nose2-3 \
162+
-c /project/sawtooth-core/integration/sawtooth_integration/nose2.cfg \
163+
-v \
164+
-s /project/sawtooth-core/integration/sawtooth_integration/tests \
165+
test_batch_injection_events.TestBatchInjectionEvents.test_before_batch_injection
166+
echo ''
167+
echo ''
168+
echo Change batch_injectors settings to after_batch_injector
169+
sawset proposal create \
170+
-k /etc/sawtooth/keys/key.priv \
171+
sawtooth.validator.batch_injectors=after_batch \
172+
--url http://rest-api:8008 && \
173+
sleep 3 && \
174+
nose2-3 \
175+
-c /project/sawtooth-core/integration/sawtooth_integration/nose2.cfg \
176+
-v \
177+
-s /project/sawtooth-core/integration/sawtooth_integration/tests \
178+
test_batch_injection_events.TestBatchInjectionEvents.test_after_batch_injection
179+
echo ''
180+
echo ''
181+
echo Change batch_injectors settings to block_end_injector
182+
sawset proposal create \
183+
-k /etc/sawtooth/keys/key.priv \
184+
sawtooth.validator.batch_injectors=block_end \
185+
'sawtooth.validator.block_validation_rules=NofX:1,block_info;XatY:block_info,-1;local:-1' \
186+
--url http://rest-api:8008 && \
187+
sleep 3 && \
188+
nose2-3 \
189+
-c /project/sawtooth-core/integration/sawtooth_integration/nose2.cfg \
190+
-v \
191+
-s /project/sawtooth-core/integration/sawtooth_integration/tests \
192+
test_batch_injection_events.TestBatchInjectionEvents.test_block_end_injection
193+
"
194+
stop_signal: SIGKILL
195+
environment:
196+
PYTHONPATH: "/project/sawtooth-core/validator:\
197+
/project/sawtooth-core/integration"

0 commit comments

Comments
 (0)