Improve Block.getBytesForMinterSignature()

This commit is contained in:
catbref 2020-12-14 15:05:31 +00:00
parent 625dbfbbd7
commit bd51806a0d
2 changed files with 11 additions and 28 deletions

View File

@ -357,12 +357,8 @@ public class Block {
System.arraycopy(onlineAccountData.getSignature(), 0, onlineAccountsSignatures, i * Transformer.SIGNATURE_LENGTH, Transformer.SIGNATURE_LENGTH); System.arraycopy(onlineAccountData.getSignature(), 0, onlineAccountsSignatures, i * Transformer.SIGNATURE_LENGTH, Transformer.SIGNATURE_LENGTH);
} }
byte[] minterSignature; byte[] minterSignature = minter.sign(BlockTransformer.getBytesForMinterSignature(parentBlockData.getMinterSignature(),
try { minter.getPublicKey(), encodedOnlineAccounts));
minterSignature = minter.sign(BlockTransformer.getBytesForMinterSignature(parentBlockData.getMinterSignature(), minter, encodedOnlineAccounts));
} catch (TransformationException e) {
throw new DataException("Unable to calculate next block minter signature", e);
}
// Qortal: minter is always a reward-share, so find actual minter and get their effective minting level // Qortal: minter is always a reward-share, so find actual minter and get their effective minting level
int minterLevel = Account.getRewardShareEffectiveMintingLevel(repository, minter.getPublicKey()); int minterLevel = Account.getRewardShareEffectiveMintingLevel(repository, minter.getPublicKey());
@ -428,12 +424,8 @@ public class Block {
int version = this.blockData.getVersion(); int version = this.blockData.getVersion();
byte[] reference = this.blockData.getReference(); byte[] reference = this.blockData.getReference();
byte[] minterSignature; byte[] minterSignature = minter.sign(BlockTransformer.getBytesForMinterSignature(parentBlockData.getMinterSignature(),
try { minter.getPublicKey(), this.blockData.getEncodedOnlineAccounts()));
minterSignature = minter.sign(BlockTransformer.getBytesForMinterSignature(parentBlockData.getMinterSignature(), minter, this.blockData.getEncodedOnlineAccounts()));
} catch (TransformationException e) {
throw new DataException("Unable to calculate next block's minter signature", e);
}
// Qortal: minter is always a reward-share, so find actual minter and get their effective minting level // Qortal: minter is always a reward-share, so find actual minter and get their effective minting level
int minterLevel = Account.getRewardShareEffectiveMintingLevel(repository, minter.getPublicKey()); int minterLevel = Account.getRewardShareEffectiveMintingLevel(repository, minter.getPublicKey());

View File

@ -7,7 +7,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import org.qortal.account.PublicKeyAccount;
import org.qortal.block.Block; import org.qortal.block.Block;
import org.qortal.block.BlockChain; import org.qortal.block.BlockChain;
import org.qortal.data.at.ATStateData; import org.qortal.data.at.ATStateData;
@ -23,7 +22,6 @@ import org.qortal.utils.Base58;
import org.qortal.utils.Serialization; import org.qortal.utils.Serialization;
import org.qortal.utils.Triple; import org.qortal.utils.Triple;
import com.google.common.primitives.Bytes;
import com.google.common.primitives.Ints; import com.google.common.primitives.Ints;
import com.google.common.primitives.Longs; import com.google.common.primitives.Longs;
@ -334,27 +332,20 @@ public class BlockTransformer extends Transformer {
public static byte[] getBytesForMinterSignature(BlockData blockData) throws TransformationException { public static byte[] getBytesForMinterSignature(BlockData blockData) throws TransformationException {
byte[] minterSignature = getMinterSignatureFromReference(blockData.getReference()); byte[] minterSignature = getMinterSignatureFromReference(blockData.getReference());
PublicKeyAccount minter = new PublicKeyAccount(null, blockData.getMinterPublicKey());
return getBytesForMinterSignature(minterSignature, minter, blockData.getEncodedOnlineAccounts()); return getBytesForMinterSignature(minterSignature, blockData.getMinterPublicKey(), blockData.getEncodedOnlineAccounts());
} }
public static byte[] getBytesForMinterSignature(byte[] minterSignature, PublicKeyAccount minter, byte[] encodedOnlineAccounts) public static byte[] getBytesForMinterSignature(byte[] minterSignature, byte[] minterPublicKey, byte[] encodedOnlineAccounts) {
throws TransformationException { byte[] bytes = new byte[MINTER_SIGNATURE_LENGTH + MINTER_PUBLIC_KEY_LENGTH + encodedOnlineAccounts.length];
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream(MINTER_SIGNATURE_LENGTH + MINTER_PUBLIC_KEY_LENGTH + encodedOnlineAccounts.length);
bytes.write(minterSignature); System.arraycopy(minterSignature, 0, bytes, 0, MINTER_SIGNATURE_LENGTH);
// We're padding here just in case the minter is the genesis account whose public key is only 8 bytes long. System.arraycopy(minterPublicKey, 0, bytes, MINTER_SIGNATURE_LENGTH, MINTER_PUBLIC_KEY_LENGTH);
bytes.write(Bytes.ensureCapacity(minter.getPublicKey(), MINTER_PUBLIC_KEY_LENGTH, 0));
bytes.write(encodedOnlineAccounts); System.arraycopy(encodedOnlineAccounts, 0, bytes, MINTER_SIGNATURE_LENGTH + MINTER_PUBLIC_KEY_LENGTH, encodedOnlineAccounts.length);
return bytes.toByteArray(); return bytes;
} catch (IOException e) {
throw new TransformationException(e);
}
} }
public static byte[] getBytesForTransactionsSignature(Block block) throws TransformationException { public static byte[] getBytesForTransactionsSignature(Block block) throws TransformationException {