Skip to content

Commit

Permalink
nit: resolve PR comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Kavaldzhiev <[email protected]>
  • Loading branch information
IvanKavaldzhiev committed Dec 20, 2024
1 parent f95e7d3 commit 70cc987
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,11 @@ public void handleConsensusRound(
final ConsensusEvent event = eventIterator.next();
captureTimestamp(event);
event.consensusTransactionIterator().forEachRemaining(transaction -> {
final var transactionWithSystemBytes = handleTransaction(transaction);
if (transactionWithSystemBytes != null) {
stateSignatureTransaction.accept(new ScopedSystemTransaction(
event.getCreatorId(), event.getSoftwareVersion(), transactionWithSystemBytes));
if (areTransactionBytesSystemOnes(transaction)) {
stateSignatureTransaction.accept(
new ScopedSystemTransaction(event.getCreatorId(), event.getSoftwareVersion(), transaction));
} else {
handleTransaction(transaction);
}
});
if (!eventIterator.hasNext()) {
Expand Down Expand Up @@ -308,27 +309,21 @@ private void captureTimestamp(final ConsensusEvent event) {
* Apply a transaction to the state.
*
* @param transaction the transaction to apply
* @return {@link ConsensusTransaction} only if it represents system transaction wrapped in Bytes
*/
private ConsensusTransaction handleTransaction(final ConsensusTransaction transaction) {
private void handleTransaction(final ConsensusTransaction transaction) {
if (transaction.isSystem()) {
return null;
}

if (areTransactionBytesSystemOnes(transaction)) {
return transaction;
return;
}

final int delta =
ByteUtils.byteArrayToInt(transaction.getApplicationTransaction().toByteArray(), 0);
runningSum += delta;
setChild(RUNNING_SUM_INDEX, new StringLeaf(Long.toString(runningSum)));

return null;
}

/**
* Checks if the transaction bytes are system ones. The test creates application transactions with max length of 4. System transactions will be always bigger than that.
* Checks if the transaction bytes are system ones. The test creates application transactions with max length of 4.
* System transactions will be always bigger than that.
*
* @param transaction the consensus transaction to check
* @return true if the transaction bytes are system ones, false otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ void handleConsensusRoundWithDeprecatedSystemTransaction() {
// Given
givenRoundAndEvent();

when(consensusTransaction.getApplicationTransaction()).thenReturn(Bytes.EMPTY);
when(consensusTransaction.isSystem()).thenReturn(true);

// When
Expand Down

0 comments on commit 70cc987

Please sign in to comment.