@@ -72,7 +72,7 @@ public void onEvent(AbstractBlockEvent blockEvent, long l, boolean b) throws Int
7272 Map <Receipt .ReceiptBlock , List <Receipt >> zone_1 = inner_receipts .get (keyset .toArray ()[0 ]);
7373 ServiceSubmit (zone_1 );
7474 } catch (Exception e ) {
75- // e.printStackTrace();
75+ e .printStackTrace ();
7676 } finally {
7777 latch .countDown ();
7878 }
@@ -120,52 +120,71 @@ public void ServiceSubmit(Map<Receipt.ReceiptBlock, List<Receipt>> zone) {
120120
121121 //find validator position in structure map
122122 Integer my_pos = blockIndex .getPublicKeyIndex (CachedZoneIndex .getInstance ().getZoneIndex (), CachedBLSKeyPair .getInstance ().getPublicKey ());
123- // get first zone index from inner receipts and search in foor loop in which zone index of structure map belongs
124- Integer receiptZoneIndex = inner_receipts .keySet ().stream ().findFirst ().get ();
125- String IP = "" ;
126- for (Integer BlockZoneIndex : committeeBlock .getStructureMap ().keySet ()) {
127- if (BlockZoneIndex == receiptZoneIndex ) {
128-
129- //Fill in the list with auto increment positions of Linkdhasamp ip where zone index belong
130- List <Integer > searchable_list = IntStream
131- .range (0 , 0 + committeeBlock .getStructureMap ().get (BlockZoneIndex ).size ())
132- .boxed ().collect (Collectors .toList ());
133-
134- // Find the closest value of ip in order to get this ip from linkdnHashmap
135- //and look for value
136- int target = searchable_list .stream ()
137- .min (Comparator .comparingInt (i -> Math .abs (i - my_pos )))
138- .orElseThrow (() -> new NoSuchElementException ("No value present" ));
139- IP = blockIndex .getIpValue (BlockZoneIndex , blockIndex .getPublicKeyByIndex (BlockZoneIndex , target ));
140- break ;
123+ boolean bError = false ;
124+ Integer receiptZoneIndex =0 ;
125+ List <TransactionBlock > current =null ;
126+ do {
127+ try {
128+ // get first zone index from inner receipts and search in foor loop in which zone index of structure map belongs
129+ receiptZoneIndex = inner_receipts .keySet ().stream ().findFirst ().get ();
130+ String IP = "" ;
131+ for (Integer BlockZoneIndex : committeeBlock .getStructureMap ().keySet ()) {
132+ if (BlockZoneIndex == receiptZoneIndex ) {
133+
134+ //Fill in the list with auto increment positions of Linkdhasamp ip where zone index belong
135+ List <Integer > searchable_list = IntStream
136+ .range (0 , 0 + committeeBlock .getStructureMap ().get (BlockZoneIndex ).size ())
137+ .boxed ().collect (Collectors .toList ());
138+
139+ // Find the closest value of ip in order to get this ip from linkdnHashmap
140+ //and look for value
141+ Integer finalMy_pos = my_pos ;
142+ int target = searchable_list .stream ()
143+ .min (Comparator .comparingInt (i -> Math .abs (i - finalMy_pos )))
144+ .orElseThrow (() -> new NoSuchElementException ("No value present" ));
145+ IP = blockIndex .getIpValue (BlockZoneIndex , blockIndex .getPublicKeyByIndex (BlockZoneIndex , target ));
146+ break ;
147+ }
148+ }
149+ if (IP .equals ("" )) {
150+ LOG .info ("Cross zone Verification failed not valid IP" );
151+ transactionBlock .setStatustype (StatusType .ABORT );
152+ return ;
153+ }
154+ ArrayList <String > to_search = new ArrayList <>();
155+ for (Receipt .ReceiptBlock receiptBlock : zone .keySet ()) {
156+ to_search .add (String .valueOf (receiptBlock .getHeight ()));
157+ }
158+ RpcAdrestusClient <TransactionBlock > client = new RpcAdrestusClient <TransactionBlock >(new TransactionBlock (), IP , ZoneDatabaseFactory .getDatabaseRPCPort (blockIndex .getZone (IP )),400 , CachedEventLoop .getInstance ().getEventloop ());
159+ client .connect ();
160+
161+ current = client .getBlock (to_search );
162+ bError = false ;
163+ } catch (IllegalArgumentException e ) {
164+ bError =true ;
165+ if (my_pos ==committeeBlock .getStructureMap ().get (receiptZoneIndex ).size ()-1 ){
166+ my_pos =0 ;
167+ }
168+ else {
169+ my_pos =my_pos +1 ;
170+ }
141171 }
142- }
143- if (IP .equals ("" )) {
144- LOG .info ("Cross zone Verification failed not valid IP" );
145- transactionBlock .setStatustype (StatusType .ABORT );
146- return ;
147- }
148- ArrayList <String > to_search = new ArrayList <>();
149- for (Receipt .ReceiptBlock receiptBlock : zone .keySet ()) {
150- to_search .add (String .valueOf (receiptBlock .getHeight ()));
151- }
152- RpcAdrestusClient <TransactionBlock > client = new RpcAdrestusClient <TransactionBlock >(new TransactionBlock (), IP , ZoneDatabaseFactory .getDatabaseRPCPort (blockIndex .getZone (IP )), CachedEventLoop .getInstance ().getEventloop ());
153- client .connect ();
154- List <TransactionBlock > current = client .getBlock (to_search );
172+ } while (bError );
155173 int position = -1 ;
156174 for (Map .Entry <Receipt .ReceiptBlock , List <Receipt >> entry : zone .entrySet ()) {
157175 position ++;
158176 int finalPosition = position ;
177+ List <TransactionBlock > finalCurrent = current ;
159178 entry .getValue ().stream ().forEach (receipt -> {
160- int index = Collections .binarySearch (current .get (finalPosition ).getTransactionList (), receipt .getTransaction ());
179+ int index = Collections .binarySearch (finalCurrent .get (finalPosition ).getTransactionList (), receipt .getTransaction ());
161180 if (index < 0 ) {
162181 LOG .info ("Cannot find transaction in Transaction Block" );
163182 transactionBlock .setStatustype (StatusType .ABORT );
164183 return ;
165184 }
166- Transaction transaction = current .get (finalPosition ).getTransactionList ().get (index );
167- boolean check = PreConditionsChecks (receipt , entry .getKey (), current .get (finalPosition ), transaction , index );
168- boolean cross_check = CrossZoneConditionsChecks (current .get (finalPosition ), entry .getKey ());
185+ Transaction transaction = finalCurrent .get (finalPosition ).getTransactionList ().get (index );
186+ boolean check = PreConditionsChecks (receipt , entry .getKey (), finalCurrent .get (finalPosition ), transaction , index );
187+ boolean cross_check = CrossZoneConditionsChecks (finalCurrent .get (finalPosition ), entry .getKey ());
169188 if (!check || !cross_check )
170189 atomicInteger .decrementAndGet ();
171190 });
0 commit comments