Merge branch 'blocksig' into master

This commit is contained in:
catbref 2021-02-27 18:20:13 +00:00
commit 414399b2a0
11 changed files with 47 additions and 26 deletions

View File

@ -357,7 +357,7 @@ 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 = minter.sign(BlockTransformer.getBytesForMinterSignature(parentBlockData.getMinterSignature(), byte[] minterSignature = minter.sign(BlockTransformer.getBytesForMinterSignature(parentBlockData,
minter.getPublicKey(), encodedOnlineAccounts)); minter.getPublicKey(), encodedOnlineAccounts));
// 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
@ -424,7 +424,7 @@ 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 = minter.sign(BlockTransformer.getBytesForMinterSignature(parentBlockData.getMinterSignature(), byte[] minterSignature = minter.sign(BlockTransformer.getBytesForMinterSignature(parentBlockData,
minter.getPublicKey(), this.blockData.getEncodedOnlineAccounts())); minter.getPublicKey(), this.blockData.getEncodedOnlineAccounts()));
// 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
@ -738,11 +738,7 @@ public class Block {
if (!(this.minter instanceof PrivateKeyAccount)) if (!(this.minter instanceof PrivateKeyAccount))
throw new IllegalStateException("Block's minter is not a PrivateKeyAccount - can't sign!"); throw new IllegalStateException("Block's minter is not a PrivateKeyAccount - can't sign!");
try { this.blockData.setMinterSignature(((PrivateKeyAccount) this.minter).sign(BlockTransformer.getBytesForMinterSignature(this.blockData)));
this.blockData.setMinterSignature(((PrivateKeyAccount) this.minter).sign(BlockTransformer.getBytesForMinterSignature(this.blockData)));
} catch (TransformationException e) {
throw new RuntimeException("Unable to calculate block's minter signature", e);
}
} }
/** /**

View File

@ -70,7 +70,8 @@ public class BlockChain {
private GenesisBlock.GenesisInfo genesisInfo; private GenesisBlock.GenesisInfo genesisInfo;
public enum FeatureTrigger { public enum FeatureTrigger {
atFindNextTransactionFix; atFindNextTransactionFix,
newBlockSigHeight;
} }
/** Map of which blockchain features are enabled when (height/timestamp) */ /** Map of which blockchain features are enabled when (height/timestamp) */
@ -376,6 +377,10 @@ public class BlockChain {
return this.featureTriggers.get(FeatureTrigger.atFindNextTransactionFix.name()).intValue(); return this.featureTriggers.get(FeatureTrigger.atFindNextTransactionFix.name()).intValue();
} }
public int getNewBlockSigHeight() {
return this.featureTriggers.get(FeatureTrigger.newBlockSigHeight.name()).intValue();
}
// More complex getters for aspects that change by height or timestamp // More complex getters for aspects that change by height or timestamp
public long getRewardAtHeight(int ourHeight) { public long getRewardAtHeight(int ourHeight) {

View File

@ -326,24 +326,36 @@ public class BlockTransformer extends Transformer {
} }
} }
public static byte[] getMinterSignatureFromReference(byte[] blockReference) { private static byte[] getReferenceBytesForMinterSignature(int blockHeight, byte[] reference) {
return Arrays.copyOf(blockReference, MINTER_SIGNATURE_LENGTH); int newBlockSigTriggerHeight = BlockChain.getInstance().getNewBlockSigHeight();
return blockHeight >= newBlockSigTriggerHeight
// 'new' block sig uses all of previous block's signature
? reference
// 'old' block sig only uses first 64 bytes of previous block's signature
: Arrays.copyOf(reference, MINTER_SIGNATURE_LENGTH);
} }
public static byte[] getBytesForMinterSignature(BlockData blockData) throws TransformationException { public static byte[] getBytesForMinterSignature(BlockData blockData) {
byte[] minterSignature = getMinterSignatureFromReference(blockData.getReference()); byte[] referenceBytes = getReferenceBytesForMinterSignature(blockData.getHeight(), blockData.getReference());
return getBytesForMinterSignature(minterSignature, blockData.getMinterPublicKey(), blockData.getEncodedOnlineAccounts()); return getBytesForMinterSignature(referenceBytes, blockData.getMinterPublicKey(), blockData.getEncodedOnlineAccounts());
} }
public static byte[] getBytesForMinterSignature(byte[] minterSignature, byte[] minterPublicKey, byte[] encodedOnlineAccounts) { public static byte[] getBytesForMinterSignature(BlockData parentBlockData, byte[] minterPublicKey, byte[] encodedOnlineAccounts) {
byte[] bytes = new byte[MINTER_SIGNATURE_LENGTH + MINTER_PUBLIC_KEY_LENGTH + encodedOnlineAccounts.length]; byte[] referenceBytes = getReferenceBytesForMinterSignature(parentBlockData.getHeight() + 1, parentBlockData.getSignature());
System.arraycopy(minterSignature, 0, bytes, 0, MINTER_SIGNATURE_LENGTH); return getBytesForMinterSignature(referenceBytes, minterPublicKey, encodedOnlineAccounts);
}
System.arraycopy(minterPublicKey, 0, bytes, MINTER_SIGNATURE_LENGTH, MINTER_PUBLIC_KEY_LENGTH); private static byte[] getBytesForMinterSignature(byte[] referenceBytes, byte[] minterPublicKey, byte[] encodedOnlineAccounts) {
byte[] bytes = new byte[referenceBytes.length + MINTER_PUBLIC_KEY_LENGTH + encodedOnlineAccounts.length];
System.arraycopy(encodedOnlineAccounts, 0, bytes, MINTER_SIGNATURE_LENGTH + MINTER_PUBLIC_KEY_LENGTH, encodedOnlineAccounts.length); System.arraycopy(referenceBytes, 0, bytes, 0, referenceBytes.length);
System.arraycopy(minterPublicKey, 0, bytes, referenceBytes.length, MINTER_PUBLIC_KEY_LENGTH);
System.arraycopy(encodedOnlineAccounts, 0, bytes, referenceBytes.length + MINTER_PUBLIC_KEY_LENGTH, encodedOnlineAccounts.length);
return bytes; return bytes;
} }

View File

@ -48,7 +48,8 @@
"minutesPerBlock": 1 "minutesPerBlock": 1
}, },
"featureTriggers": { "featureTriggers": {
"atFindNextTransactionFix": 275000 "atFindNextTransactionFix": 275000,
"newBlockSigHeight": 999999
}, },
"genesisInfo": { "genesisInfo": {
"version": 4, "version": 4,

View File

@ -45,7 +45,8 @@
"qortalTimestamp": 0, "qortalTimestamp": 0,
"newAssetPricingTimestamp": 0, "newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0, "groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0 "atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
}, },
"genesisInfo": { "genesisInfo": {
"version": 4, "version": 4,

View File

@ -45,7 +45,8 @@
"qortalTimestamp": 0, "qortalTimestamp": 0,
"newAssetPricingTimestamp": 0, "newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0, "groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0 "atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
}, },
"genesisInfo": { "genesisInfo": {
"version": 4, "version": 4,

View File

@ -45,7 +45,8 @@
"qortalTimestamp": 0, "qortalTimestamp": 0,
"newAssetPricingTimestamp": 0, "newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0, "groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0 "atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
}, },
"genesisInfo": { "genesisInfo": {
"version": 4, "version": 4,

View File

@ -45,7 +45,8 @@
"qortalTimestamp": 0, "qortalTimestamp": 0,
"newAssetPricingTimestamp": 0, "newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0, "groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0 "atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
}, },
"genesisInfo": { "genesisInfo": {
"version": 4, "version": 4,

View File

@ -45,7 +45,8 @@
"qortalTimestamp": 0, "qortalTimestamp": 0,
"newAssetPricingTimestamp": 0, "newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0, "groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0 "atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
}, },
"genesisInfo": { "genesisInfo": {
"version": 4, "version": 4,

View File

@ -45,7 +45,8 @@
"qortalTimestamp": 0, "qortalTimestamp": 0,
"newAssetPricingTimestamp": 0, "newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0, "groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0 "atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
}, },
"genesisInfo": { "genesisInfo": {
"version": 4, "version": 4,

View File

@ -45,7 +45,8 @@
"qortalTimestamp": 0, "qortalTimestamp": 0,
"newAssetPricingTimestamp": 0, "newAssetPricingTimestamp": 0,
"groupApprovalTimestamp": 0, "groupApprovalTimestamp": 0,
"atFindNextTransactionFix": 0 "atFindNextTransactionFix": 0,
"newBlockSigHeight": 999999
}, },
"genesisInfo": { "genesisInfo": {
"version": 4, "version": 4,