@@ -870,9 +870,10 @@ def GetConfig32(self):
870870 #end if
871871
872872 self .local .add_log ("start GetConfig32 function" , "debug" )
873- config32 = dict ()
873+ config32 = Dict ()
874874 result = self .liteClient .Run ("getconfig 32" )
875875 config32 ["totalValidators" ] = int (parse (result , "total:" , ' ' ))
876+ config32 ["mainValidators" ] = int (parse (result , "main:" , ' ' ))
876877 config32 ["startWorkTime" ] = int (parse (result , "utime_since:" , ' ' ))
877878 config32 ["endWorkTime" ] = int (parse (result , "utime_until:" , ' ' ))
878879 lines = result .split ('\n ' )
@@ -885,7 +886,7 @@ def GetConfig32(self):
885886 validatorWeight = int (parse (line , "weight:" , ' ' ))
886887 except ValueError :
887888 validatorWeight = int (parse (line , "weight:" , ')' ))
888- buff = dict ()
889+ buff = Dict ()
889890 buff ["adnlAddr" ] = validatorAdnlAddr
890891 buff ["pubkey" ] = pubkey
891892 buff ["weight" ] = validatorWeight
@@ -906,9 +907,10 @@ def GetConfig34(self):
906907 #end if
907908
908909 self .local .add_log ("start GetConfig34 function" , "debug" )
909- config34 = dict ()
910+ config34 = Dict ()
910911 result = self .liteClient .Run ("getconfig 34" )
911912 config34 ["totalValidators" ] = int (parse (result , "total:" , ' ' ))
913+ config34 ["mainValidators" ] = int (parse (result , "main:" , ' ' ))
912914 config34 ["startWorkTime" ] = int (parse (result , "utime_since:" , ' ' ))
913915 config34 ["endWorkTime" ] = int (parse (result , "utime_until:" , ' ' ))
914916 config34 ["totalWeight" ] = int (parse (result , "total_weight:" , ' ' ))
@@ -922,7 +924,7 @@ def GetConfig34(self):
922924 validatorWeight = int (parse (line , "weight:" , ' ' ))
923925 except ValueError :
924926 validatorWeight = int (parse (line , "weight:" , ')' ))
925- buff = dict ()
927+ buff = Dict ()
926928 buff ["adnlAddr" ] = validatorAdnlAddr
927929 buff ["pubkey" ] = pubkey
928930 buff ["weight" ] = validatorWeight
@@ -2152,6 +2154,19 @@ def GetSaveComplaints(self):
21522154 return saveComplaints
21532155 #end define
21542156
2157+ def GetSaveVl (self ):
2158+ timestamp = get_timestamp ()
2159+ save_vl = self .local .db .get ("saveValidatorsLoad" )
2160+ if save_vl is None :
2161+ save_vl = dict ()
2162+ self .local .db ["saveValidatorsLoad" ] = save_vl
2163+ for key , item in list (save_vl .items ()):
2164+ diff_time = timestamp - int (key )
2165+ if diff_time > 172800 : # 48 hours
2166+ save_vl .pop (key )
2167+ return save_vl
2168+ #end define
2169+
21552170 def GetAdnlFromPubkey (self , inputPubkey ):
21562171 config32 = self .GetConfig32 ()
21572172 validators = config32 ["validators" ]
@@ -2299,12 +2314,17 @@ def get_valid_complaints(self, complaints: dict, election_id: int):
22992314 pseudohash = pubkey + str (election_id )
23002315 if pseudohash == complaint ['pseudohash' ]:
23012316 exists = True
2317+ vid = item ['id' ]
23022318 break
23032319
23042320 if not exists :
23052321 self .local .add_log (f"complaint { complaint ['hash_hex' ]} declined: complaint info was not found, probably it's wrong" , "info" )
23062322 continue
23072323
2324+ if vid >= config32 ['mainValidators' ]:
2325+ self .local .add_log (f"complaint { complaint ['hash_hex' ]} declined: complaint created for non masterchain validator" , "info" )
2326+ continue
2327+
23082328 # check complaint fine value
23092329 if complaint ['suggestedFine' ] != 101 : # https://github.com/ton-blockchain/ton/blob/5847897b3758bc9ea85af38e7be8fc867e4c133a/lite-client/lite-client.cpp#L3708
23102330 self .local .add_log (f"complaint { complaint ['hash_hex' ]} declined: complaint fine value is { complaint ['suggestedFine' ]} ton" , "info" )
@@ -2318,7 +2338,7 @@ def get_valid_complaints(self, complaints: dict, election_id: int):
23182338
23192339 def GetOnlineValidators (self ):
23202340 onlineValidators = list ()
2321- validators = self .GetValidatorsList ()
2341+ validators = self .GetValidatorsList (fast = True )
23222342 for validator in validators :
23232343 online = validator .get ("online" )
23242344 if online is True :
@@ -2335,7 +2355,6 @@ def GetValidatorsLoad(self, start, end, saveCompFiles=False) -> dict:
23352355 if buff :
23362356 return buff
23372357 #end if
2338-
23392358 text = "start GetValidatorsLoad function ({}, {})" .format (start , end )
23402359 self .local .add_log (text , "debug" )
23412360 if saveCompFiles is True :
@@ -2411,7 +2430,7 @@ def GetValidatorsLoad(self, start, end, saveCompFiles=False) -> dict:
24112430 return data
24122431 #end define
24132432
2414- def GetValidatorsList (self , past = False ):
2433+ def GetValidatorsList (self , past = False , fast = False ):
24152434 # Get buffer
24162435 bname = "validatorsList" + str (past )
24172436 buff = self .GetFunctionBuffer (bname , timeout = 60 )
@@ -2421,13 +2440,21 @@ def GetValidatorsList(self, past=False):
24212440
24222441 timestamp = get_timestamp ()
24232442 end = timestamp - 60
2424- start = end - 2000
24252443 config = self .GetConfig34 ()
2444+ if fast :
2445+ start = end - 1000
2446+ else :
2447+ start = config .get ("startWorkTime" )
24262448 if past :
24272449 config = self .GetConfig32 ()
24282450 start = config .get ("startWorkTime" )
24292451 end = config .get ("endWorkTime" ) - 60
2452+ save_vl = self .GetSaveVl ()
2453+ start_str = str (start )
2454+ if start_str in save_vl :
2455+ return save_vl [start_str ]
24302456 #end if
2457+
24312458 validatorsLoad = self .GetValidatorsLoad (start , end )
24322459 validators = config ["validators" ]
24332460 electionId = config .get ("startWorkTime" )
@@ -2440,12 +2467,22 @@ def GetValidatorsList(self, past=False):
24402467 validator ["wr" ] = validatorsLoad [vid ]["wr" ]
24412468 validator ["efficiency" ] = validatorsLoad [vid ]["efficiency" ]
24422469 validator ["online" ] = validatorsLoad [vid ]["online" ]
2470+ validator ["blocks_created" ] = validatorsLoad [vid ]["masterBlocksCreated" ] + validatorsLoad [vid ]["workBlocksCreated" ]
2471+ validator ["blocks_expected" ] = validatorsLoad [vid ]["masterBlocksExpected" ] + validatorsLoad [vid ]["workBlocksExpected" ]
2472+ validator ["is_masterchain" ] = False
2473+ if vid < config ["mainValidators" ]:
2474+ validator ["is_masterchain" ] = True
2475+ if not validator ["is_masterchain" ]:
2476+ validator ["efficiency" ] = round (validator ["wr" ] * 100 , 2 )
24432477 if saveElectionEntries and adnlAddr in saveElectionEntries :
24442478 validator ["walletAddr" ] = saveElectionEntries [adnlAddr ]["walletAddr" ]
24452479 #end for
24462480
24472481 # Set buffer
24482482 self .SetFunctionBuffer (bname , validators )
2483+ if past :
2484+ save_vl = self .GetSaveVl ()
2485+ save_vl [str (start )] = validators
24492486 return validators
24502487 #end define
24512488
@@ -2457,6 +2494,7 @@ def CheckValidators(self, start, end):
24572494 data = self .GetValidatorsLoad (start , end , saveCompFiles = True )
24582495 fullElectorAddr = self .GetFullElectorAddr ()
24592496 wallet = self .GetValidatorWallet (mode = "vote" )
2497+ config = self .GetConfig32 ()
24602498
24612499 # Check wallet and balance
24622500 if wallet is None :
@@ -2474,6 +2512,8 @@ def CheckValidators(self, start, end):
24742512 pseudohash = pubkey + str (electionId )
24752513 if pseudohash in valid_complaints :
24762514 continue
2515+ if item ['id' ] >= config ['mainValidators' ]: # do not create complaints for non-masterchain validators
2516+ continue
24772517 # Create complaint
24782518 fileName = self .remove_proofs_from_complaint (fileName )
24792519 fileName = self .PrepareComplaint (electionId , fileName )
@@ -3188,7 +3228,7 @@ def ImportCertificate(self, pubkey, fileName):
31883228
31893229 def GetValidatorsWalletsList (self ):
31903230 result = list ()
3191- vl = self .GetValidatorsList ()
3231+ vl = self .GetValidatorsList (fast = True )
31923232 for item in vl :
31933233 walletAddr = item ["walletAddr" ]
31943234 result .append (walletAddr )
0 commit comments