Replace magic numbers for header sizes with constants

This commit is contained in:
Ross Nicoll
2015-10-18 11:15:46 +01:00
committed by Andreas Schildbach
parent a4c9ad6894
commit 4375f66d20
3 changed files with 6 additions and 6 deletions

View File

@@ -108,7 +108,7 @@ public class Block extends Message {
time = System.currentTimeMillis() / 1000;
prevBlockHash = Sha256Hash.ZERO_HASH;
length = 80;
length = HEADER_SIZE;
}
/**

View File

@@ -70,7 +70,7 @@ public class HeadersMessage extends Message {
cursor = saveCursor;
// Each header has 80 bytes and one more byte for transactions number which is 00.
length = 81 * (int)numHeaders;
length = (Block.HEADER_SIZE + 1) * (int)numHeaders;
}
long numHeaders = readVarInt();
@@ -83,11 +83,11 @@ public class HeadersMessage extends Message {
for (int i = 0; i < numHeaders; ++i) {
// Read 80 bytes of the header and one more byte for the transaction list, which is always a 00 because the
// transaction list is empty.
byte[] blockHeader = readBytes(81);
if (blockHeader[80] != 0)
byte[] blockHeader = readBytes(Block.HEADER_SIZE + 1);
if (blockHeader[Block.HEADER_SIZE] != 0)
throw new ProtocolException("Block header does not end with a null byte");
Block newBlockHeader = this.params.getSerializer(true)
.makeBlock(blockHeader, 81);
.makeBlock(blockHeader, Block.HEADER_SIZE + 1);
blockHeaders.add(newBlockHeader);
}

View File

@@ -1647,7 +1647,7 @@ public class PeerGroup implements TransactionBroadcaster {
@Override
public synchronized void onBlocksDownloaded(Peer peer, Block block, @Nullable FilteredBlock filteredBlock, int blocksLeft) {
blocksInLastSecond++;
bytesInLastSecond += 80; // For the header.
bytesInLastSecond += Block.HEADER_SIZE;
List<Transaction> blockTransactions = block.getTransactions();
// This whole area of the type hierarchy is a mess.
int txCount = (blockTransactions != null ? countAndMeasureSize(blockTransactions) : 0) +