Skip to content

Commit

Permalink
feat: #48 Added onParsingError call back to listen to any block parsi…
Browse files Browse the repository at this point in the history
…ng error
  • Loading branch information
satran004 committed Feb 26, 2024
1 parent 63e7f99 commit 06e0983
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,17 @@ private void onReceiveBlocks(MsgBlock message) {
} catch (Exception e) {
errorBlks++;
log.error("Error in parsing", e);
Array headerArray = (Array) ((Array)array.getDataItems().get(1)).getDataItems().get(0);
BlockHeader blockHeader = BlockHeaderSerializer.INSTANCE.getBlockHeaderFromHeaderArray(headerArray);
log.error("BlockHeader >> Block No: " + blockHeader.getHeaderBody().getBlockNumber() +", Slot: " + blockHeader.getHeaderBody().getSlot());

//Catch exception to avoid exception propagation
try {
Array headerArray = (Array) ((Array) array.getDataItems().get(1)).getDataItems().get(0);
BlockHeader blockHeader = BlockHeaderSerializer.INSTANCE.getBlockHeaderFromHeaderArray(headerArray);
log.error("BlockHeader >> Block No: " + blockHeader.getHeaderBody().getBlockNumber() + ", Slot: " + blockHeader.getHeaderBody().getSlot());
} catch (Exception e1) {
log.error("Error in parsing block header", e1);
}

getAgentListeners().stream().forEach(blockfetchAgentListener -> blockfetchAgentListener.onParsingError(e));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ default void byronEbBlockFound(ByronEbBlock byronEbBlock) {

}

default void onParsingError(Exception e) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ default void intersactFound(Tip tip, Point point) {}
default void intersactNotFound(Tip tip) {}

default void onDisconnect() {}

default void onParsingError(Exception e) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,9 @@ public void noBlockFound(Point from, Point to) {
public void onDisconnect() {
blockChainDataListener.onDisconnect();
}

@Override
public void onParsingError(Exception e) {
blockChainDataListener.onParsingError(e);
}
}

0 comments on commit 06e0983

Please sign in to comment.