@@ -214,65 +214,6 @@ def interact_with_storage_contract(dest, nonce):
214
214
215
215
return nonce
216
216
217
- def processUrllibRequest (endpoint , payload = {}, silentErrors = False , exitOnError = False , exitMsg = None , returnType = ReturnType .json ):
218
- cmd = f"{ endpoint } "
219
- req = urllib .request .Request (cmd , method = "POST" )
220
- req .add_header ('Content-Type' , 'application/json' )
221
- req .add_header ('Accept' , 'application/json' )
222
- data = payload
223
- data = json .dumps (data )
224
- data = data .encode ()
225
- if Utils .Debug : Utils .Print ("cmd: %s" % (cmd ))
226
- rtn = None
227
- start = time .perf_counter ()
228
- try :
229
- response = urllib .request .urlopen (req , data = data )
230
- if returnType == ReturnType .json :
231
- rtn = {}
232
- rtn ["code" ] = response .getcode ()
233
- rtn ["payload" ] = json .load (response )
234
- elif returnType == ReturnType .raw :
235
- rtn = response .read ()
236
- else :
237
- unhandledEnumType (returnType )
238
-
239
- if Utils .Debug :
240
- end = time .perf_counter ()
241
- Utils .Print ("cmd Duration: %.3f sec" % (end - start ))
242
- printReturn = json .dumps (rtn ) if returnType == ReturnType .json else rtn
243
- Utils .Print ("cmd returned: %s" % (printReturn [:1024 ]))
244
- except urllib .error .HTTPError as ex :
245
- if not silentErrors :
246
- end = time .perf_counter ()
247
- msg = ex .msg
248
- errorMsg = "Exception during \" %s\" . %s. cmd Duration=%.3f sec." % (cmd , msg , end - start )
249
- if exitOnError :
250
- Utils .cmdError (errorMsg )
251
- Utils .errorExit (errorMsg )
252
- else :
253
- Utils .Print ("ERROR: %s" % (errorMsg ))
254
- if returnType == ReturnType .json :
255
- rtn = json .load (ex )
256
- elif returnType == ReturnType .raw :
257
- rtn = ex .read ()
258
- else :
259
- unhandledEnumType (returnType )
260
- else :
261
- return None
262
- except :
263
- Utils .Print ("Unknown exception occurred during processUrllibRequest" )
264
- raise
265
-
266
- if exitMsg is not None :
267
- exitMsg = ": " + exitMsg
268
- else :
269
- exitMsg = ""
270
- if exitOnError and rtn is None :
271
- Utils .cmdError ("could not \" %s\" - %s" % (cmd ,exitMsg ))
272
- Utils .errorExit ("Failed to \" %s\" " % (cmd ))
273
-
274
- return rtn
275
-
276
217
def getGasPrice ():
277
218
return 15000000000
278
219
@@ -320,10 +261,11 @@ def makeReservedEvmAddress(account):
320
261
321
262
specificExtraNodeosArgs [2 ]= "--plugin eosio::test_control_api_plugin"
322
263
323
- extraNodeosArgs = "--contracts-console --resource-monitor-not-shutdown-on-threshold-exceeded"
264
+ extraNodeosArgs = "--contracts-console --production-pause-vote-timeout-ms 0 -- resource-monitor-not-shutdown-on-threshold-exceeded"
324
265
325
266
Print ("Stand up cluster" )
326
- if cluster .launch (prodCount = 2 , pnodes = 2 , topo = "bridge" , totalNodes = 3 , extraNodeosArgs = extraNodeosArgs , totalProducers = 3 , specificExtraNodeosArgs = specificExtraNodeosArgs ,delay = 5 ) is False :
267
+ # node 0 (defproducera, defproducerb), node 1 (defproducerc, ...)
268
+ if cluster .launch (prodCount = 2 , pnodes = 2 , topo = "bridge" , totalNodes = 3 , extraNodeosArgs = extraNodeosArgs , totalProducers = 4 , specificExtraNodeosArgs = specificExtraNodeosArgs ,delay = 5 ,activateIF = True ,biosFinalizer = False ) is False :
327
269
errorExit ("Failed to stand up eos cluster." )
328
270
329
271
Print ("Wait for Cluster stabilization" )
@@ -352,10 +294,10 @@ def makeReservedEvmAddress(account):
352
294
prodNodes .append (node )
353
295
producers .extend (node .producers )
354
296
355
- node = prodNodes [0 ] # producers: defproducera, defproducerb
356
- node1 = prodNodes [1 ] # producers: defproducerc
357
297
# node2 is the nonProdnode (the bridge node)
358
- prodNode = prodNodes [0 ]
298
+ prodNode = prodNodes [shipNodeNum ] # the node the push transactions
299
+ node = prodNode
300
+ node1 = prodNodes [1 - shipNodeNum ]
359
301
360
302
# *** Identify a block where production is stable ***
361
303
#verify nodes are in sync and advancing
@@ -496,16 +438,8 @@ def makeReservedEvmAddress(account):
496
438
trans = prodNode .pushMessage (evmAcc .name , "pushtx" , json .dumps (actData ), '-p {0}' .format (minerAcc .name ))
497
439
prodNode .waitForTransBlockIfNeeded (trans [1 ], True )
498
440
499
- #
500
- # Test some failure cases
501
- #
502
-
503
- # incorrect nonce
504
- Utils .Print ("Send balance again, should fail with wrong nonce" )
505
- retValue = prodNode .pushMessage (evmAcc .name , "pushtx" , json .dumps (actData ), '-p {0}' .format (minerAcc .name ), silentErrors = True )
506
- assert not retValue [0 ], f"push trx should have failed: { retValue } "
507
-
508
441
# correct nonce
442
+ time .sleep (1.0 )
509
443
nonce += 1
510
444
gasP = getGasPrice ()
511
445
signed_trx = w3 .eth .account .sign_transaction (dict (
@@ -524,30 +458,6 @@ def makeReservedEvmAddress(account):
524
458
time .sleep (1.0 )
525
459
assert retValue [0 ], f"push trx should have succeeded: { retValue } "
526
460
527
- # incorrect chainid
528
- nonce += 1
529
- evmChainId = 8888
530
- gasP = getGasPrice ()
531
- signed_trx = w3 .eth .account .sign_transaction (dict (
532
- nonce = nonce ,
533
- gas = 100000 , #100k Gas
534
- gasPrice = gasP ,
535
- to = Web3 .to_checksum_address (toAdd ),
536
- value = amount ,
537
- data = b'' ,
538
- chainId = evmChainId
539
- ), evmSendKey )
540
-
541
- actData = {"miner" :minerAcc .name , "rlptx" :Web3 .to_hex (get_raw_transaction (signed_trx ))[2 :]}
542
- Utils .Print ("Send balance again, with invalid chainid" )
543
- retValue = prodNode .pushMessage (evmAcc .name , "pushtx" , json .dumps (actData ), '-p {0}' .format (minerAcc .name ), silentErrors = True )
544
- time .sleep (1.0 )
545
- assert not retValue [0 ], f"push trx should have failed: { retValue } "
546
-
547
- # correct values for continuing
548
- nonce -= 1
549
- evmChainId = 15555
550
-
551
461
Utils .Print ("Simple Solidity contract" )
552
462
# pragma solidity >=0.7.0 <0.9.0;
553
463
# contract Storage {
@@ -758,7 +668,7 @@ def makeReservedEvmAddress(account):
758
668
# Verify header.nonce == 1 (evmversion=1)
759
669
evm_block = w3 .eth .get_block ('latest' )
760
670
Utils .Print ("before fork, the latest evm block is:" + str (evm_block ))
761
- assert (evm_block ["nonce" ].hex () == "0000000000000001" )
671
+ assert (evm_block ["nonce" ].hex () == "0000000000000001" or evm_block [ "nonce" ]. hex () == "0x0000000000000001" )
762
672
assert ("consensusParameter" in evm_block )
763
673
assert (evm_block ["consensusParameter" ]["gasFeeParameters" ]["gasCodedeposit" ] == 477 )
764
674
assert (evm_block ["consensusParameter" ]["gasFeeParameters" ]["gasNewaccount" ] == 165519 )
@@ -823,8 +733,9 @@ def makeReservedEvmAddress(account):
823
733
Utils .errorExit ("failed to catch a block produced by defproducerb" )
824
734
825
735
blockProducer1 = node1 .getBlockProducerByNum (blockNum )
826
- Utils .Print ("block number %d is producer by %s in node0" % (blockNum , blockProducer ))
827
- Utils .Print ("block number %d is producer by %s in node1" % (blockNum , blockProducer1 ))
736
+ lib = info ["last_irreversible_block_num" ]
737
+ Utils .Print ("before kill, block number %d is producer by %s in node0, LIB %d" % (blockNum , blockProducer , lib ))
738
+ Utils .Print ("before kill, block number %d is producer by %s in node1, LIB %d" % (blockNum , blockProducer1 , lib ))
828
739
829
740
# ===== start to make a fork, killing the "bridge" node ====
830
741
Print ("Sending command to kill \" bridge\" node to separate the 2 producer groups." )
@@ -900,12 +811,11 @@ def makeReservedEvmAddress(account):
900
811
prodNode .waitForTransBlockIfNeeded (trans [1 ], True );
901
812
time .sleep (2 )
902
813
903
- Utils .Print ("Transfer funds to trigger gas parameter in minor fork" )
904
814
# EVM -> EVM
905
815
# 0x9E126C57330FA71556628e0aabd6B6B6783d99fA private key: 0xba8c9ff38e4179748925335a9891b969214b37dc3723a1754b8b849d3eea9ac0
906
816
toAdd = 0x4ce0ca184bc155a5df5dae2f4643cba60eb1a9ed
907
817
evmSendKey = "ba8c9ff38e4179748925335a9891b969214b37dc3723a1754b8b849d3eea9ac0"
908
- Print ("Transfer EVM->EVM funds 1Gwei from account %s to %s" % (evmAcc .name , toAdd ))
818
+ Print ("In minor fork, transfer EVM->EVM funds 1Gwei from account %s to %s to trigger gas parameter change " % (evmAcc .name , toAdd ))
909
819
nonce = 1
910
820
gasP = getGasPrice ()
911
821
signed_trx = w3 .eth .account .sign_transaction (dict (
@@ -924,7 +834,7 @@ def makeReservedEvmAddress(account):
924
834
time .sleep (1.0 )
925
835
prodNode .waitForTransBlockIfNeeded (trans [1 ], True )
926
836
row4 = prodNode .getTableRow (evmAcc .name , evmAcc .name , "account" , 4 )
927
- Utils .Print ("\t account row4 in node0: " , row4 )
837
+ Utils .Print ("In minor fork account row4 in node0: " , row4 )
928
838
929
839
assert (row4 ["eth_address" ] == "9e126c57330fa71556628e0aabd6b6b6783d99fa" )
930
840
assert (row4 ["balance" ] == "0000000000000000000000000000000000000000000000024c8ff6c362545600" )
@@ -934,15 +844,15 @@ def makeReservedEvmAddress(account):
934
844
time .sleep (1.0 )
935
845
node1 .waitForTransBlockIfNeeded (trans [1 ], True )
936
846
row4_node1 = node1 .getTableRow (evmAcc .name , evmAcc .name , "account" , 4 )
937
- Utils .Print ("\t account row4 in node1: " , row4_node1 )
847
+ Utils .Print ("In minor fork, account row4 in node1: " , row4_node1 )
938
848
assert (row4_node1 ["eth_address" ] == "9e126c57330fa71556628e0aabd6b6b6783d99fa" )
939
849
assert (row4_node1 ["balance" ] == "0000000000000000000000000000000000000000000000024c91bd38333b1600" )
940
850
assert (row4 ["balance" ] != row4_node1 ["balance" ])
941
851
942
852
# verify eos-evm-node get the new gas parameter from the minor fork
943
853
evm_block = w3 .eth .get_block ('latest' )
944
854
Utils .Print ("in minor fork, the latest evm block is:" + str (evm_block ))
945
- assert (evm_block ["nonce" ].hex () == "0000000000000001" )
855
+ assert (evm_block ["nonce" ].hex () == "0000000000000001" or evm_block [ "nonce" ]. hex () == "0x0000000000000001" )
946
856
assert ("consensusParameter" in evm_block )
947
857
948
858
assert (evm_block ["consensusParameter" ]["gasFeeParameters" ]["gasCodedeposit" ] == 573 )
@@ -992,6 +902,10 @@ def makeReservedEvmAddress(account):
992
902
# if node1.verifyAlive():
993
903
# Utils.errorExit("Expected the node 1 to have shutdown.")
994
904
905
+ blockNum0 = prodNodes [0 ].getBlockNum ()
906
+ blockNum1 = prodNodes [1 ].getBlockNum ()
907
+ WaitUntilBlockNum = max (blockNum0 , blockNum1 ) + 20
908
+ Print ("Before relaunching the bridge node: prod[0] head_block_num %d, prod[1] head_block_num %d" % (blockNum0 , blockNum1 ))
995
909
Print ("Relaunching the non-producing bridge node to connect the node 0 (defproducera, defproducerb)" )
996
910
if not nonProdNode .relaunch (chainArg = " --hard-replay " ):
997
911
errorExit ("Failure - (non-production) node %d should have restarted" % (nonProdNode .nodeNum ))
@@ -1001,7 +915,7 @@ def makeReservedEvmAddress(account):
1001
915
# if not node1.relaunch(chainArg=" --enable-stale-production "):
1002
916
# errorExit("Failure - (non-production) node 1 should have restarted")
1003
917
1004
- Print ("Waiting to allow forks to resolve" )
918
+ Print ("Waiting to allow forks to resolve from block %d" % ( killBlockNum ) )
1005
919
time .sleep (3 )
1006
920
1007
921
for prodNode in prodNodes :
@@ -1024,9 +938,11 @@ def makeReservedEvmAddress(account):
1024
938
if match :
1025
939
if checkHead :
1026
940
forkResolved = True
1027
- Print ("Great! fork resolved!!!" )
941
+ Print ("Great! fork resolved!!! killBlockNum %d, current head_number %d, producer %s" % ( killBlockNum , checkMatchBlock , blockProducer0 ) )
1028
942
break
1029
943
else :
944
+ Print ("Block %d has producer %s in both nodes, continue to check head" % (checkMatchBlock , blockProducer0 ))
945
+ assert (blockProducer0 == "defproducerc" or blockProducer0 == "defproducerd" ), "node0 must switch fork at %d" % (killBlockNum )
1030
946
checkHead = True
1031
947
continue
1032
948
Print ("Fork has not resolved yet, wait a little more. Block %s has producer %s for node_00 and %s for node_01. Original divergence was at block %s. Wait time remaining: %d" % (checkMatchBlock , blockProducer0 , blockProducer1 , killBlockNum , remainingChecks ))
@@ -1036,6 +952,12 @@ def makeReservedEvmAddress(account):
1036
952
assert forkResolved , "fork was not resolved in a reasonable time. node_00 lib {} head {}, node_01 lib {} head {}" .format (\
1037
953
prodNodes [0 ].getIrreversibleBlockNum (), prodNodes [0 ].getHeadBlockNum (), \
1038
954
prodNodes [1 ].getIrreversibleBlockNum (), prodNodes [1 ].getHeadBlockNum ())
955
+
956
+ # wait until the current chain is longer than any minor fork happened in the past
957
+ # ensure the EVM oracle to switch to longer fork
958
+ blockNum0 = prodNodes [0 ].getBlockNum ()
959
+ WaitUntilBlockNum = max (WaitUntilBlockNum , killBlockNum + 30 )
960
+ prodNodes [0 ].waitForBlock (WaitUntilBlockNum )
1039
961
1040
962
row4 = prodNode .getTableRow (evmAcc .name , evmAcc .name , "account" , 4 )
1041
963
Utils .Print ("\t account row4 in node0: " , row4 )
@@ -1046,7 +968,7 @@ def makeReservedEvmAddress(account):
1046
968
1047
969
evm_block = w3 .eth .get_block ('latest' )
1048
970
Utils .Print ("after fork resolved, the latest evm block is:" + str (evm_block ))
1049
- assert (evm_block ["nonce" ].hex () == "0000000000000001" )
971
+ assert (evm_block ["nonce" ].hex () == "0000000000000001" or evm_block [ "nonce" ]. hex () == "0x0000000000000001" )
1050
972
assert ("consensusParameter" in evm_block )
1051
973
1052
974
assert (evm_block ["consensusParameter" ]["gasFeeParameters" ]["gasCodedeposit" ] == 477 )
0 commit comments