@@ -913,9 +913,10 @@ def GetConfig32(self):
913913 #end if
914914
915915 self .local .add_log ("start GetConfig32 function" , "debug" )
916- config32 = dict ()
916+ config32 = Dict ()
917917 result = self .liteClient .Run ("getconfig 32" )
918918 config32 ["totalValidators" ] = int (parse (result , "total:" , ' ' ))
919+ config32 ["mainValidators" ] = int (parse (result , "main:" , ' ' ))
919920 config32 ["startWorkTime" ] = int (parse (result , "utime_since:" , ' ' ))
920921 config32 ["endWorkTime" ] = int (parse (result , "utime_until:" , ' ' ))
921922 lines = result .split ('\n ' )
@@ -928,7 +929,7 @@ def GetConfig32(self):
928929 validatorWeight = int (parse (line , "weight:" , ' ' ))
929930 except ValueError :
930931 validatorWeight = int (parse (line , "weight:" , ')' ))
931- buff = dict ()
932+ buff = Dict ()
932933 buff ["adnlAddr" ] = validatorAdnlAddr
933934 buff ["pubkey" ] = pubkey
934935 buff ["weight" ] = validatorWeight
@@ -949,9 +950,10 @@ def GetConfig34(self):
949950 #end if
950951
951952 self .local .add_log ("start GetConfig34 function" , "debug" )
952- config34 = dict ()
953+ config34 = Dict ()
953954 result = self .liteClient .Run ("getconfig 34" )
954955 config34 ["totalValidators" ] = int (parse (result , "total:" , ' ' ))
956+ config34 ["mainValidators" ] = int (parse (result , "main:" , ' ' ))
955957 config34 ["startWorkTime" ] = int (parse (result , "utime_since:" , ' ' ))
956958 config34 ["endWorkTime" ] = int (parse (result , "utime_until:" , ' ' ))
957959 config34 ["totalWeight" ] = int (parse (result , "total_weight:" , ' ' ))
@@ -965,7 +967,7 @@ def GetConfig34(self):
965967 validatorWeight = int (parse (line , "weight:" , ' ' ))
966968 except ValueError :
967969 validatorWeight = int (parse (line , "weight:" , ')' ))
968- buff = dict ()
970+ buff = Dict ()
969971 buff ["adnlAddr" ] = validatorAdnlAddr
970972 buff ["pubkey" ] = pubkey
971973 buff ["weight" ] = validatorWeight
@@ -2320,6 +2322,19 @@ def GetSaveComplaints(self):
23202322 return saveComplaints
23212323 #end define
23222324
2325+ def GetSaveVl (self ):
2326+ timestamp = get_timestamp ()
2327+ save_vl = self .local .db .get ("saveValidatorsLoad" )
2328+ if save_vl is None :
2329+ save_vl = dict ()
2330+ self .local .db ["saveValidatorsLoad" ] = save_vl
2331+ for key , item in list (save_vl .items ()):
2332+ diff_time = timestamp - int (key )
2333+ if diff_time > 172800 : # 48 hours
2334+ save_vl .pop (key )
2335+ return save_vl
2336+ #end define
2337+
23232338 def GetAdnlFromPubkey (self , inputPubkey ):
23242339 config32 = self .GetConfig32 ()
23252340 validators = config32 ["validators" ]
@@ -2467,12 +2482,17 @@ def get_valid_complaints(self, complaints: dict, election_id: int):
24672482 pseudohash = pubkey + str (election_id )
24682483 if pseudohash == complaint ['pseudohash' ]:
24692484 exists = True
2485+ vid = item ['id' ]
24702486 break
24712487
24722488 if not exists :
24732489 self .local .add_log (f"complaint { complaint ['hash_hex' ]} declined: complaint info was not found, probably it's wrong" , "info" )
24742490 continue
24752491
2492+ if vid >= config32 ['mainValidators' ]:
2493+ self .local .add_log (f"complaint { complaint ['hash_hex' ]} declined: complaint created for non masterchain validator" , "info" )
2494+ continue
2495+
24762496 # check complaint fine value
24772497 if complaint ['suggestedFine' ] != 101 : # https://github.com/ton-blockchain/ton/blob/5847897b3758bc9ea85af38e7be8fc867e4c133a/lite-client/lite-client.cpp#L3708
24782498 self .local .add_log (f"complaint { complaint ['hash_hex' ]} declined: complaint fine value is { complaint ['suggestedFine' ]} ton" , "info" )
@@ -2486,7 +2506,7 @@ def get_valid_complaints(self, complaints: dict, election_id: int):
24862506
24872507 def GetOnlineValidators (self ):
24882508 onlineValidators = list ()
2489- validators = self .GetValidatorsList ()
2509+ validators = self .GetValidatorsList (fast = True )
24902510 for validator in validators :
24912511 online = validator .get ("online" )
24922512 if online is True :
@@ -2503,7 +2523,6 @@ def GetValidatorsLoad(self, start, end, saveCompFiles=False) -> dict:
25032523 if buff :
25042524 return buff
25052525 #end if
2506-
25072526 text = "start GetValidatorsLoad function ({}, {})" .format (start , end )
25082527 self .local .add_log (text , "debug" )
25092528 if saveCompFiles is True :
@@ -2579,7 +2598,7 @@ def GetValidatorsLoad(self, start, end, saveCompFiles=False) -> dict:
25792598 return data
25802599 #end define
25812600
2582- def GetValidatorsList (self , past = False ):
2601+ def GetValidatorsList (self , past = False , fast = False ):
25832602 # Get buffer
25842603 bname = "validatorsList" + str (past )
25852604 buff = self .GetFunctionBuffer (bname , timeout = 60 )
@@ -2589,13 +2608,21 @@ def GetValidatorsList(self, past=False):
25892608
25902609 timestamp = get_timestamp ()
25912610 end = timestamp - 60
2592- start = end - 2000
25932611 config = self .GetConfig34 ()
2612+ if fast :
2613+ start = end - 1000
2614+ else :
2615+ start = config .get ("startWorkTime" )
25942616 if past :
25952617 config = self .GetConfig32 ()
25962618 start = config .get ("startWorkTime" )
25972619 end = config .get ("endWorkTime" ) - 60
2620+ save_vl = self .GetSaveVl ()
2621+ start_str = str (start )
2622+ if start_str in save_vl :
2623+ return save_vl [start_str ]
25982624 #end if
2625+
25992626 validatorsLoad = self .GetValidatorsLoad (start , end )
26002627 validators = config ["validators" ]
26012628 electionId = config .get ("startWorkTime" )
@@ -2608,12 +2635,22 @@ def GetValidatorsList(self, past=False):
26082635 validator ["wr" ] = validatorsLoad [vid ]["wr" ]
26092636 validator ["efficiency" ] = validatorsLoad [vid ]["efficiency" ]
26102637 validator ["online" ] = validatorsLoad [vid ]["online" ]
2638+ validator ["blocks_created" ] = validatorsLoad [vid ]["masterBlocksCreated" ] + validatorsLoad [vid ]["workBlocksCreated" ]
2639+ validator ["blocks_expected" ] = validatorsLoad [vid ]["masterBlocksExpected" ] + validatorsLoad [vid ]["workBlocksExpected" ]
2640+ validator ["is_masterchain" ] = False
2641+ if vid < config ["mainValidators" ]:
2642+ validator ["is_masterchain" ] = True
2643+ if not validator ["is_masterchain" ]:
2644+ validator ["efficiency" ] = round (validator ["wr" ] * 100 , 2 )
26112645 if saveElectionEntries and adnlAddr in saveElectionEntries :
26122646 validator ["walletAddr" ] = saveElectionEntries [adnlAddr ]["walletAddr" ]
26132647 #end for
26142648
26152649 # Set buffer
26162650 self .SetFunctionBuffer (bname , validators )
2651+ if past :
2652+ save_vl = self .GetSaveVl ()
2653+ save_vl [start ] = validators
26172654 return validators
26182655 #end define
26192656
@@ -2625,6 +2662,7 @@ def CheckValidators(self, start, end):
26252662 data = self .GetValidatorsLoad (start , end , saveCompFiles = True )
26262663 fullElectorAddr = self .GetFullElectorAddr ()
26272664 wallet = self .GetValidatorWallet (mode = "vote" )
2665+ config = self .GetConfig32 ()
26282666
26292667 # Check wallet and balance
26302668 if wallet is None :
@@ -2642,6 +2680,8 @@ def CheckValidators(self, start, end):
26422680 pseudohash = pubkey + str (electionId )
26432681 if pseudohash in valid_complaints :
26442682 continue
2683+ if item ['id' ] >= config ['mainValidators' ]: # do not create complaints for non-masterchain validators
2684+ continue
26452685 # Create complaint
26462686 fileName = self .remove_proofs_from_complaint (fileName )
26472687 fileName = self .PrepareComplaint (electionId , fileName )
@@ -3463,7 +3503,7 @@ def ImportCertificate(self, pubkey, fileName):
34633503
34643504 def GetValidatorsWalletsList (self ):
34653505 result = list ()
3466- vl = self .GetValidatorsList ()
3506+ vl = self .GetValidatorsList (fast = True )
34673507 for item in vl :
34683508 walletAddr = item ["walletAddr" ]
34693509 result .append (walletAddr )
0 commit comments