forked from Qortal/qortal
Correction to commit #eb876e1
Block serialization is in fact affected by the online accounts serialization, as we have to calculate the expected length ahead of time.
This commit is contained in:
parent
9a1941fac4
commit
5857929508
@ -977,11 +977,7 @@ public class Block {
|
|||||||
return ValidationResult.ONLINE_ACCOUNT_SIGNATURES_MISSING;
|
return ValidationResult.ONLINE_ACCOUNT_SIGNATURES_MISSING;
|
||||||
|
|
||||||
// Verify the online account signatures length
|
// Verify the online account signatures length
|
||||||
int expectedLength;
|
int expectedLength = Block.getExpectedOnlineAccountsSignaturesLength(onlineRewardShares.size(), this.blockData.getTimestamp());
|
||||||
if (this.blockData.getTimestamp() >= BlockChain.getInstance().getOnlineAccountsMemoryPoWTimestamp())
|
|
||||||
expectedLength = onlineRewardShares.size() * (Transformer.SIGNATURE_LENGTH + Transformer.REDUCED_SIGNATURE_LENGTH + Transformer.INT_LENGTH + (OnlineAccountsManager.MAX_NONCE_COUNT * Transformer.INT_LENGTH));
|
|
||||||
else
|
|
||||||
expectedLength = onlineRewardShares.size() * Transformer.SIGNATURE_LENGTH;
|
|
||||||
|
|
||||||
if (this.blockData.getOnlineAccountsSignatures().length != expectedLength)
|
if (this.blockData.getOnlineAccountsSignatures().length != expectedLength)
|
||||||
return ValidationResult.ONLINE_ACCOUNT_SIGNATURES_MALFORMED;
|
return ValidationResult.ONLINE_ACCOUNT_SIGNATURES_MALFORMED;
|
||||||
@ -2064,6 +2060,29 @@ public class Block {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expected length of serialized online accounts
|
||||||
|
* @param onlineRewardSharesCount the number of reward shares in the serialized data
|
||||||
|
* @param timestamp the block's timestamp, used for versioning / serialization differences
|
||||||
|
* @return the number of bytes to expect
|
||||||
|
*/
|
||||||
|
public static int getExpectedOnlineAccountsSignaturesLength(int onlineRewardSharesCount, long timestamp) {
|
||||||
|
int expectedLength;
|
||||||
|
|
||||||
|
if (timestamp >= BlockChain.getInstance().getOnlineAccountsMemoryPoWTimestamp()) {
|
||||||
|
// byte array contains signatures, reduced signatures, and nonces
|
||||||
|
expectedLength = onlineRewardSharesCount *
|
||||||
|
(Transformer.SIGNATURE_LENGTH + Transformer.REDUCED_SIGNATURE_LENGTH + Transformer.INT_LENGTH +
|
||||||
|
(OnlineAccountsManager.MAX_NONCE_COUNT * Transformer.INT_LENGTH));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// byte array contains signatures only
|
||||||
|
expectedLength = onlineRewardSharesCount * Transformer.SIGNATURE_LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
return expectedLength;
|
||||||
|
}
|
||||||
|
|
||||||
private void logDebugInfo() {
|
private void logDebugInfo() {
|
||||||
try {
|
try {
|
||||||
// Avoid calculations if possible. We have to check against INFO here, since Level.isMoreSpecificThan() confusingly uses <= rather than just <
|
// Avoid calculations if possible. We have to check against INFO here, since Level.isMoreSpecificThan() confusingly uses <= rather than just <
|
||||||
|
@ -217,7 +217,7 @@ public class BlockTransformer extends Transformer {
|
|||||||
// Online accounts timestamp is only present if there are also signatures
|
// Online accounts timestamp is only present if there are also signatures
|
||||||
onlineAccountsTimestamp = byteBuffer.getLong();
|
onlineAccountsTimestamp = byteBuffer.getLong();
|
||||||
|
|
||||||
final int signaturesByteLength = onlineAccountsSignaturesCount * Transformer.SIGNATURE_LENGTH;
|
final int signaturesByteLength = Block.getExpectedOnlineAccountsSignaturesLength(onlineAccountsSignaturesCount, timestamp);
|
||||||
if (signaturesByteLength > BlockChain.getInstance().getMaxBlockSize())
|
if (signaturesByteLength > BlockChain.getInstance().getMaxBlockSize())
|
||||||
throw new TransformationException("Byte data too long for online accounts signatures");
|
throw new TransformationException("Byte data too long for online accounts signatures");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user