@@ -190,44 +190,45 @@ public void selectPendingTransactions(
190190
191191 private void checkAndSendLivenessBundle (
192192 BlockTransactionSelectionService bts , long pendingBlockNumber ) {
193+ if (livenessService .isEmpty ()) {
194+ return ;
195+ }
196+ final var livenessService = this .livenessService .get ();
193197 final long headBlockTimestamp = blockchainService .getChainHeadHeader ().getTimestamp ();
194198
195199 Optional <TransactionBundle > livenessBundle =
196- livenessService .isPresent ()
197- ? livenessService
198- .get ()
199- .checkBlockTimestampAndBuildBundle (
200- Instant .now ().getEpochSecond (), headBlockTimestamp , pendingBlockNumber )
201- : Optional .empty ();
202-
203- if (livenessBundle .isPresent ()) {
204- log .trace ("Starting evaluation of liveness bundle {}" , livenessBundle .get ());
205- var badBundleRes =
206- livenessBundle .get ().pendingTransactions ().stream ()
207- .map (bts ::evaluatePendingTransaction )
208- .filter (evalRes -> !evalRes .selected ())
209- .findFirst ();
210-
211- if (badBundleRes .isPresent ()) {
212- final var notSelectedReason = badBundleRes .get ();
213-
214- if (isSelectionInterrupted (notSelectedReason )) {
215- isSelectionInterrupted .set (true );
216- log .debug (
217- "Bundle selection interrupted while processing liveness bundle {}, reason {}" ,
218- livenessBundle .get (),
219- notSelectedReason );
220- } else {
221- log .debug (
222- "Failed liveness bundle {}, reason {}" , livenessBundle .get (), notSelectedReason );
223- }
224- livenessService .get ().updateUptimeMetrics (false , headBlockTimestamp );
225- rollback (bts );
200+ livenessService .checkBlockTimestampAndBuildBundle (
201+ Instant .now ().getEpochSecond (), headBlockTimestamp , pendingBlockNumber );
202+
203+ if (livenessBundle .isEmpty ()) {
204+ return ;
205+ }
206+
207+ log .trace ("Starting evaluation of liveness bundle {}" , livenessBundle .get ());
208+ var badBundleRes =
209+ livenessBundle .get ().pendingTransactions ().stream ()
210+ .map (bts ::evaluatePendingTransaction )
211+ .filter (evalRes -> !evalRes .selected ())
212+ .findFirst ();
213+
214+ if (badBundleRes .isPresent ()) {
215+ final var notSelectedReason = badBundleRes .get ();
216+
217+ if (isSelectionInterrupted (notSelectedReason )) {
218+ isSelectionInterrupted .set (true );
219+ log .debug (
220+ "Bundle selection interrupted while processing liveness bundle {}, reason {}" ,
221+ livenessBundle .get (),
222+ notSelectedReason );
226223 } else {
227- log .debug ("Selected liveness bundle {}" , livenessBundle .get ());
228- livenessService .get ().updateUptimeMetrics (true , headBlockTimestamp );
229- commit (bts );
224+ log .debug ("Failed liveness bundle {}, reason {}" , livenessBundle .get (), notSelectedReason );
230225 }
226+ livenessService .updateUptimeMetrics (false , headBlockTimestamp );
227+ rollback (bts );
228+ } else {
229+ log .debug ("Selected liveness bundle {}" , livenessBundle .get ());
230+ livenessService .updateUptimeMetrics (true , headBlockTimestamp );
231+ commit (bts );
231232 }
232233 }
233234
0 commit comments