Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion rskj-core/src/main/java/org/ethereum/core/BlockFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
return decodeHeader(RLP.decodeList(encoded), compressed, true);
}

private BlockHeader decodeHeader(RLPList rlpHeader, boolean compressed, boolean sealed) {

Check failure on line 120 in rskj-core/src/main/java/org/ethereum/core/BlockFactory.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

The Cyclomatic Complexity of this method "decodeHeader" is 15 which is greater than 10 authorized.

See more on https://sonarcloud.io/project/issues?id=rskj&issues=AZsIg5y9hHvxs6JXP2MA&open=AZsIg5y9hHvxs6JXP2MA&pullRequest=3411

Check failure on line 120 in rskj-core/src/main/java/org/ethereum/core/BlockFactory.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=rskj&issues=AZsIg5y9hHvxs6JXP2L_&open=AZsIg5y9hHvxs6JXP2L_&pullRequest=3411
byte[] parentHash = rlpHeader.get(0).getRLPData();
byte[] unclesHash = rlpHeader.get(1).getRLPData();
byte[] coinBaseBytes = rlpHeader.get(2).getRLPData();
Expand Down Expand Up @@ -185,7 +185,8 @@
short[] txExecutionSublistsEdges = null;
byte[] baseEvent = null;

if (!activationConfig.isActive(ConsensusRule.RSKIP351, blockNumber) || !compressed) {
// Compressed headers don't have the txExecutionSublistsEdges and baseEvent fields
if (!isCompressed(blockNumber, compressed)) {
if (rlpHeader.size() > r && activationConfig.isActive(ConsensusRule.RSKIP144, blockNumber)) {
txExecutionSublistsEdges = ByteUtil.rlpToShorts(rlpHeader.get(r++).getRLPRawData());
}
Expand Down Expand Up @@ -216,6 +217,17 @@
useRskip92Encoding, includeForkDetectionData);
}

private boolean isCompressed(long blockNumber, boolean compressedFlag) {
// RSKIP-351 is what introduced the possibility of compressed headers
// before that, all headers were uncompressed
if (!activationConfig.isActive(ConsensusRule.RSKIP351, blockNumber)) {
return false;
}

// After RSKIP-351, we can trust the compressed flag
return compressedFlag;
}

private BlockHeader createBlockHeader(boolean compressed, boolean sealed, byte[] parentHash, byte[] unclesHash,
byte[] coinBaseBytes, RskAddress coinbase, byte[] stateRoot, byte[] txTrieRoot, byte[] receiptTrieRoot, byte[] extensionData,
byte[] difficultyBytes, BlockDifficulty difficulty, byte[] glBytes, long blockNumber, long gasUsed, long timestamp, byte[] extraData,
Expand Down