This repository was archived by the owner on Aug 2, 2022. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathnodeos_multiple_version_protocol_feature_test.py
More file actions
executable file
·229 lines (197 loc) · 11.8 KB
/
Copy pathnodeos_multiple_version_protocol_feature_test.py
File metadata and controls
executable file
·229 lines (197 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env python3
from testUtils import Utils
from Cluster import Cluster, PFSetupPolicy
from TestHelper import TestHelper
from WalletMgr import WalletMgr
from Node import Node
import signal
import json
import time
import os
from os.path import join, exists
from datetime import datetime
###############################################################
# nodeos_multiple_version_protocol_feature_test
#
# Test for verifying that older versions of nodeos can work with newer versions of nodeos.
#
###############################################################
# Parse command line arguments
args = TestHelper.parse_args({"-v","--clean-run","--dump-error-details","--leave-running",
"--keep-logs", "--alternate-version-labels-file"})
Utils.Debug=args.v
killAll=args.clean_run
dumpErrorDetails=args.dump_error_details
dontKill=args.leave_running
killEosInstances=not dontKill
killWallet=not dontKill
keepLogs=args.keep_logs
alternateVersionLabelsFile=args.alternate_version_labels_file
walletMgr=WalletMgr(True)
cluster=Cluster(walletd=True)
cluster.setWalletMgr(walletMgr)
def restartNode(node: Node, chainArg=None, addSwapFlags=None, nodeosPath=None):
if not node.killed:
node.kill(signal.SIGTERM)
isRelaunchSuccess = node.relaunch(chainArg, addSwapFlags=addSwapFlags,
timeout=5, cachePopen=True, nodeosPath=nodeosPath)
assert isRelaunchSuccess, "Fail to relaunch"
def waitForOneRound():
time.sleep(24) # We have 4 producers for this test
def setValidityOfActTimeSubjRestriction(node, codename, valid, chainArg=None, nodeosPath=None):
invalidActTimeSubjRestriction = {
"earliest_allowed_activation_time": "2030-01-01T00:00:00.000",
}
validActTimeSubjRestriction = {
"earliest_allowed_activation_time": "1970-01-01T00:00:00.000",
}
actTimeSubjRestriction = validActTimeSubjRestriction if valid else invalidActTimeSubjRestriction
node.modifyBuiltinPFSubjRestrictions(codename, actTimeSubjRestriction)
restartNode(node, chainArg=chainArg, nodeosPath=nodeosPath)
def waitUntilBlockBecomeIrr(node, blockNum, timeout=60):
def hasBlockBecomeIrr():
return node.getIrreversibleBlockNum() >= blockNum
return Utils.waitForTruth(hasBlockBecomeIrr, timeout)
# List to contain the test result message
testSuccessful = False
try:
TestHelper.printSystemInfo("BEGIN")
cluster.killall(allInstances=killAll)
cluster.cleanup()
# Create a cluster of 4 nodes, each node has 1 producer. The first 3 nodes use the latest vesion,
# While the 4th node use the version that doesn't support protocol feature activation (i.e. 1.7.0)
associatedNodeLabels = {
"3": "alt_ver"
}
Utils.Print("Alternate Version Labels File is {}".format(alternateVersionLabelsFile))
assert exists(alternateVersionLabelsFile), "Alternate version labels file does not exist"
# version 1.7 did not provide a default value for "--last-block-time-offset-us" so this is needed to
# avoid dropping late blocks
assert cluster.launch(pnodes=4, totalNodes=4, prodCount=1, totalProducers=4,
extraNodeosArgs=" --plugin eosio::producer_api_plugin --plugin eosio::trace_api_plugin --trace-no-abis",
useBiosBootFile=False,
specificExtraNodeosArgs={
0:"--http-max-response-time-ms 990000",
1:"--http-max-response-time-ms 990000",
2:"--http-max-response-time-ms 990000",
3:"--last-block-time-offset-us -200000 --plugin eosio::history_api_plugin"},
onlySetProds=True,
pfSetupPolicy=PFSetupPolicy.NONE,
alternateVersionLabelsFile=alternateVersionLabelsFile,
associatedNodeLabels=associatedNodeLabels), "Unable to launch cluster"
newNodeIds = [0, 1, 2]
oldNodeId = 3
newNodes = list(map(lambda id: cluster.getNode(id), newNodeIds))
oldNode = cluster.getNode(oldNodeId)
allNodes = [*newNodes, oldNode]
def pauseBlockProductions():
for node in allNodes:
if not node.killed: node.processCurlCmd("producer", "pause", "")
def resumeBlockProductions():
for node in allNodes:
if not node.killed: node.processCurlCmd("producer", "resume", "")
def areNodesInSync(nodes:[Node], pauseAll=True, resumeAll=True):
# Pause all block production to ensure the head is not moving
if pauseAll:
pauseBlockProductions()
time.sleep(2) # Wait for some time to ensure all blocks are propagated
# Get current head block number and IDs for each producer
headBlockNums = []
headBlockIds = []
for node in nodes:
hb = node.getInfo()
headBlockNums.append(hb["head_block_num"])
headBlockIds.append(hb["head_block_id"])
Utils.Print("node {}, head block id: {}, num: {}".format(node.nodeId, hb["head_block_id"], hb["head_block_num"]))
assert len(set(headBlockNums)) == len(set(headBlockIds)), "Different block IDs have the same block numbers, thus nodes are not in sync"
# Check if each node has head blocks from other producers
inSync = True
if len(set(headBlockNums)) != 1:
def nodeHasBlocks(node, blockIds, blockNums):
for blkId, blkNum in zip(blockIds, blockNums):
assert node.waitForBlock(blkNum, timeout=3) != None, "Expected to find block {}, but only reached {}".format(blkNum, node.getInfo()["head_block_num"])
if node.getBlock(blkId) is None:
Utils.Print("node {} does not have block Id: {} (num: {})".format(node.nodeId, blkId, blkNum))
return False
return True
for node in nodes:
if not nodeHasBlocks(node, headBlockIds, headBlockNums):
inSync = False
break
if resumeAll:
resumeBlockProductions()
return inSync
Utils.Print("+++ Nodes are in sync before preactivation +++")
# Before everything starts, all nodes (new version and old version) should be in sync
assert areNodesInSync(allNodes), "Nodes are not in sync before preactivation"
# First, we are going to test the case where:
# - 1st node has valid earliest_allowed_activation_time
# - While 2nd and 3rd node have invalid earliest_allowed_activation_time
# Producer in the 1st node is going to activate PREACTIVATE_FEATURE during his turn
# Immediately, in the next block PREACTIVATE_FEATURE should be active in 1st node, but not on 2nd and 3rd
# Therefore, 1st node will be out of sync with 2nd, 3rd, and 4th node
# After a round has passed though, 1st node will realize he's in minority fork and then join the other nodes
# Hence, the PREACTIVATE_FEATURE that was previously activated will be dropped and all of the nodes should be in sync
Utils.Print("+++ 1st Node should contain PREACTIVATE FEATURE +++")
setValidityOfActTimeSubjRestriction(newNodes[1], "PREACTIVATE_FEATURE", False)
setValidityOfActTimeSubjRestriction(newNodes[2], "PREACTIVATE_FEATURE", False)
# emulating =< 1.7.0 version that haven't had PREACTIVATE_FEATURE
setValidityOfActTimeSubjRestriction(oldNode, "PREACTIVATE_FEATURE", False)
for i in range(3):
Utils.Print("1st node tries activatePreactivateFeature time(s): {}".format(i+1))
# 1st node waits for the start of the production turn each time it tries activatePreactivateFeature()
beginningOfProdTurnHead = newNodes[0].waitUntilBeginningOfProdTurn("defproducera")
newNodes[0].activatePreactivateFeature()
if newNodes[0].containsPreactivateFeature():
break
diff = newNodes[0].getInfo()["head_block_num"] - beginningOfProdTurnHead
assert diff >= 12, "1st node should contain PREACTIVATE FEATURE since we set it during its production window"
assert newNodes[0].containsPreactivateFeature(), "1st node should contain PREACTIVATE FEATURE"
assert not (newNodes[1].containsPreactivateFeature() or newNodes[2].containsPreactivateFeature()), \
"2nd and 3rd node should not contain PREACTIVATE FEATURE"
Utils.Print("+++ 2nd, 3rd and 4th node should be in sync, and 1st node should be out of sync +++")
assert areNodesInSync([newNodes[1], newNodes[2], oldNode], pauseAll=True, resumeAll=False), "2nd, 3rd and 4th node should be in sync"
assert not areNodesInSync(allNodes, pauseAll=False, resumeAll=True), "+++ 1st node should be out of sync with the rest nodes +++"
waitForOneRound()
assert not newNodes[0].containsPreactivateFeature(), "PREACTIVATE_FEATURE should be dropped"
assert areNodesInSync(allNodes), "All nodes should be in sync"
# Then we set the earliest_allowed_activation_time of 2nd node and 3rd node with valid value
# Once the 1st node activate PREACTIVATE_FEATURE, all of them should have PREACTIVATE_FEATURE activated in the next block
# They will be in sync and their LIB will advance since they control > 2/3 of the producers
# Also the LIB should be able to advance past the block that contains PREACTIVATE_FEATURE
# However, the 4th node will be out of sync with them, and its LIB will stuck
setValidityOfActTimeSubjRestriction(newNodes[1], "PREACTIVATE_FEATURE", True)
setValidityOfActTimeSubjRestriction(newNodes[2], "PREACTIVATE_FEATURE", True)
newNodes[0].waitUntilBeginningOfProdTurn("defproducera")
libBeforePreactivation = newNodes[0].getIrreversibleBlockNum()
newNodes[0].activatePreactivateFeature()
assert areNodesInSync(newNodes, pauseAll=True, resumeAll=False), "New nodes should be in sync"
assert not areNodesInSync(allNodes, pauseAll=False, resumeAll=True), "Nodes should not be in sync after preactivation"
for node in newNodes: assert node.containsPreactivateFeature(), "New node should contain PREACTIVATE_FEATURE"
activatedBlockNum = newNodes[0].getHeadBlockNum() # The PREACTIVATE_FEATURE should have been activated before or at this block num
assert waitUntilBlockBecomeIrr(newNodes[0], activatedBlockNum), \
"1st node LIB should be able to advance past the block that contains PREACTIVATE_FEATURE"
assert newNodes[1].getIrreversibleBlockNum() >= activatedBlockNum and \
newNodes[2].getIrreversibleBlockNum() >= activatedBlockNum, \
"2nd and 3rd node LIB should also be able to advance past the block that contains PREACTIVATE_FEATURE"
assert oldNode.getIrreversibleBlockNum() <= libBeforePreactivation, \
"4th node LIB should be stuck on LIB before PREACTIVATE_FEATURE is activated"
# Kill and restart old node with newest version
# When we restart the 4th node with the version of nodeos that supports protocol feature,
# all nodes should be in sync, and the 4th node will also contain PREACTIVATE_FEATURE
oldNode.kill(signal.SIGTERM)
# we need this step to enable node pass through the protocol feature block
# we disabled it earlier to emulate behavior of old 1.7.0 node that haven't had PREACTIVATE_FEATURE at all.
setValidityOfActTimeSubjRestriction(oldNode,
"PREACTIVATE_FEATURE",
True,
chainArg="--replay-blockchain",
nodeosPath="programs/nodeos/nodeos")
time.sleep(2) # Give some time to replay
assert areNodesInSync(allNodes), "All nodes should be in sync"
assert oldNode.containsPreactivateFeature(), "4th node should contain PREACTIVATE_FEATURE"
testSuccessful = True
finally:
TestHelper.shutdown(cluster, walletMgr, testSuccessful, killEosInstances, killWallet, keepLogs, killAll, dumpErrorDetails)
exitCode = 0 if testSuccessful else 1
exit(exitCode)