Rename timestampSignatures to onlineAccountsSignatures

This commit is contained in:
catbref 2019-09-16 11:11:42 +01:00
parent 504cfc6a74
commit aa81c86cf1
4 changed files with 36 additions and 32 deletions

View File

@ -253,11 +253,11 @@ public class Block {
byte[] encodedOnlineAccounts = BlockTransformer.encodeOnlineAccounts(onlineAccountsSet); byte[] encodedOnlineAccounts = BlockTransformer.encodeOnlineAccounts(onlineAccountsSet);
// Concatenate online account timestamp signatures (in correct order) // Concatenate online account timestamp signatures (in correct order)
byte[] timestampSignatures = new byte[accountIndexes.size() * Transformer.SIGNATURE_LENGTH]; byte[] onlineAccountsSignatures = new byte[accountIndexes.size() * Transformer.SIGNATURE_LENGTH];
for (int i = 0; i < accountIndexes.size(); ++i) { for (int i = 0; i < accountIndexes.size(); ++i) {
Integer accountIndex = accountIndexes.get(i); Integer accountIndex = accountIndexes.get(i);
OnlineAccount onlineAccount = indexedOnlineAccounts.get(accountIndex); OnlineAccount onlineAccount = indexedOnlineAccounts.get(accountIndex);
System.arraycopy(onlineAccount.getSignature(), 0, timestampSignatures, i * Transformer.SIGNATURE_LENGTH, Transformer.SIGNATURE_LENGTH); System.arraycopy(onlineAccount.getSignature(), 0, onlineAccountsSignatures, i * Transformer.SIGNATURE_LENGTH, Transformer.SIGNATURE_LENGTH);
} }
byte[] generatorSignature; byte[] generatorSignature;
@ -282,7 +282,7 @@ public class Block {
// This instance used for AT processing // This instance used for AT processing
this.blockData = new BlockData(version, reference, transactionCount, totalFees, transactionsSignature, height, timestamp, generatingBalance, this.blockData = new BlockData(version, reference, transactionCount, totalFees, transactionsSignature, height, timestamp, generatingBalance,
generator.getPublicKey(), generatorSignature, atCount, atFees, encodedOnlineAccounts, onlineAccountsTimestamp, timestampSignatures); generator.getPublicKey(), generatorSignature, atCount, atFees, encodedOnlineAccounts, onlineAccountsTimestamp, onlineAccountsSignatures);
// Requires this.blockData and this.transactions, sets this.ourAtStates and this.ourAtFees // Requires this.blockData and this.transactions, sets this.ourAtStates and this.ourAtFees
this.executeATs(); this.executeATs();
@ -294,7 +294,7 @@ public class Block {
// Rebuild blockData using post-AT-execute data // Rebuild blockData using post-AT-execute data
this.blockData = new BlockData(version, reference, transactionCount, totalFees, transactionsSignature, height, timestamp, generatingBalance, this.blockData = new BlockData(version, reference, transactionCount, totalFees, transactionsSignature, height, timestamp, generatingBalance,
generator.getPublicKey(), generatorSignature, atCount, atFees, encodedOnlineAccounts, onlineAccountsTimestamp, timestampSignatures); generator.getPublicKey(), generatorSignature, atCount, atFees, encodedOnlineAccounts, onlineAccountsTimestamp, onlineAccountsSignatures);
} }
/** /**
@ -344,10 +344,10 @@ public class Block {
byte[] encodedOnlineAccounts = this.blockData.getEncodedOnlineAccounts(); byte[] encodedOnlineAccounts = this.blockData.getEncodedOnlineAccounts();
Long onlineAccountsTimestamp = this.blockData.getOnlineAccountsTimestamp(); Long onlineAccountsTimestamp = this.blockData.getOnlineAccountsTimestamp();
byte[] timestampSignatures = this.blockData.getTimestampSignatures(); byte[] onlineAccountsSignatures = this.blockData.getOnlineAccountsSignatures();
newBlock.blockData = new BlockData(version, reference, transactionCount, totalFees, transactionsSignature, height, timestamp, generatingBalance, newBlock.blockData = new BlockData(version, reference, transactionCount, totalFees, transactionsSignature, height, timestamp, generatingBalance,
generator.getPublicKey(), generatorSignature, atCount, atFees, encodedOnlineAccounts, onlineAccountsTimestamp, timestampSignatures); generator.getPublicKey(), generatorSignature, atCount, atFees, encodedOnlineAccounts, onlineAccountsTimestamp, onlineAccountsSignatures);
// Resign to update transactions signature // Resign to update transactions signature
newBlock.sign(); newBlock.sign();
@ -869,6 +869,10 @@ public class Block {
} }
public ValidationResult areOnlineAccountsValid() throws DataException { public ValidationResult areOnlineAccountsValid() throws DataException {
// Doesn't apply for Genesis block!
if (this.blockData.getHeight() != null && this.blockData.getHeight() == 1)
return ValidationResult.OK;
// Expand block's online accounts indexes into actual accounts // Expand block's online accounts indexes into actual accounts
ConciseSet accountIndexes = BlockTransformer.decodeOnlineAccounts(this.blockData.getEncodedOnlineAccounts()); ConciseSet accountIndexes = BlockTransformer.decodeOnlineAccounts(this.blockData.getEncodedOnlineAccounts());
@ -889,19 +893,19 @@ public class Block {
// Possibly check signatures if block is recent // Possibly check signatures if block is recent
long signatureRequirementThreshold = NTP.getTime() - BlockChain.getInstance().getOnlineAccountSignaturesMinLifetime(); long signatureRequirementThreshold = NTP.getTime() - BlockChain.getInstance().getOnlineAccountSignaturesMinLifetime();
if (this.blockData.getTimestamp() >= signatureRequirementThreshold) { if (this.blockData.getTimestamp() >= signatureRequirementThreshold) {
if (this.blockData.getTimestampSignatures() == null || this.blockData.getTimestampSignatures().length == 0) if (this.blockData.getOnlineAccountsSignatures() == null || this.blockData.getOnlineAccountsSignatures().length == 0)
return ValidationResult.ONLINE_ACCOUNT_SIGNATURES_MISSING; return ValidationResult.ONLINE_ACCOUNT_SIGNATURES_MISSING;
if (this.blockData.getTimestampSignatures().length != expandedAccounts.size() * Transformer.SIGNATURE_LENGTH) if (this.blockData.getOnlineAccountsSignatures().length != expandedAccounts.size() * Transformer.SIGNATURE_LENGTH)
return ValidationResult.ONLINE_ACCOUNT_SIGNATURES_MALFORMED; return ValidationResult.ONLINE_ACCOUNT_SIGNATURES_MALFORMED;
// Check signatures // Check signatures
List<byte[]> timestampSignatures = BlockTransformer.decodeTimestampSignatures(this.blockData.getTimestampSignatures()); List<byte[]> onlineAccountsSignatures = BlockTransformer.decodeTimestampSignatures(this.blockData.getOnlineAccountsSignatures());
byte[] message = Longs.toByteArray(this.blockData.getOnlineAccountsTimestamp()); byte[] message = Longs.toByteArray(this.blockData.getOnlineAccountsTimestamp());
for (int i = 0; i < timestampSignatures.size(); ++i) { for (int i = 0; i < onlineAccountsSignatures.size(); ++i) {
PublicKeyAccount account = new PublicKeyAccount(null, expandedAccounts.get(i).getProxyPublicKey()); PublicKeyAccount account = new PublicKeyAccount(null, expandedAccounts.get(i).getProxyPublicKey());
byte[] signature = timestampSignatures.get(i); byte[] signature = onlineAccountsSignatures.get(i);
if (!account.verify(signature, message)) if (!account.verify(signature, message))
return ValidationResult.ONLINE_ACCOUNT_SIGNATURE_INCORRECT; return ValidationResult.ONLINE_ACCOUNT_SIGNATURE_INCORRECT;

View File

@ -34,7 +34,7 @@ public class BlockData implements Serializable {
private BigDecimal atFees; private BigDecimal atFees;
private byte[] encodedOnlineAccounts; private byte[] encodedOnlineAccounts;
private Long onlineAccountsTimestamp; private Long onlineAccountsTimestamp;
private byte[] timestampSignatures; private byte[] onlineAccountsSignatures;
// Constructors // Constructors
@ -44,7 +44,7 @@ public class BlockData implements Serializable {
public BlockData(int version, byte[] reference, int transactionCount, BigDecimal totalFees, byte[] transactionsSignature, Integer height, long timestamp, public BlockData(int version, byte[] reference, int transactionCount, BigDecimal totalFees, byte[] transactionsSignature, Integer height, long timestamp,
BigDecimal generatingBalance, byte[] generatorPublicKey, byte[] generatorSignature, int atCount, BigDecimal atFees, BigDecimal generatingBalance, byte[] generatorPublicKey, byte[] generatorSignature, int atCount, BigDecimal atFees,
byte[] encodedOnlineAccounts, Long onlineAccountsTimestamp, byte[] timestampSignatures) { byte[] encodedOnlineAccounts, Long onlineAccountsTimestamp, byte[] onlineAccountsSignatures) {
this.version = version; this.version = version;
this.reference = reference; this.reference = reference;
this.transactionCount = transactionCount; this.transactionCount = transactionCount;
@ -59,7 +59,7 @@ public class BlockData implements Serializable {
this.atFees = atFees; this.atFees = atFees;
this.encodedOnlineAccounts = encodedOnlineAccounts; this.encodedOnlineAccounts = encodedOnlineAccounts;
this.onlineAccountsTimestamp = onlineAccountsTimestamp; this.onlineAccountsTimestamp = onlineAccountsTimestamp;
this.timestampSignatures = timestampSignatures; this.onlineAccountsSignatures = onlineAccountsSignatures;
if (this.generatorSignature != null && this.transactionsSignature != null) if (this.generatorSignature != null && this.transactionsSignature != null)
this.signature = Bytes.concat(this.generatorSignature, this.transactionsSignature); this.signature = Bytes.concat(this.generatorSignature, this.transactionsSignature);
@ -175,8 +175,8 @@ public class BlockData implements Serializable {
this.onlineAccountsTimestamp = onlineAccountsTimestamp; this.onlineAccountsTimestamp = onlineAccountsTimestamp;
} }
public byte[] getTimestampSignatures() { public byte[] getOnlineAccountsSignatures() {
return this.timestampSignatures; return this.onlineAccountsSignatures;
} }
// JAXB special // JAXB special

View File

@ -50,10 +50,10 @@ public class HSQLDBBlockRepository implements BlockRepository {
BigDecimal atFees = resultSet.getBigDecimal(12); BigDecimal atFees = resultSet.getBigDecimal(12);
byte[] encodedOnlineAccounts = resultSet.getBytes(13); byte[] encodedOnlineAccounts = resultSet.getBytes(13);
Long onlineAccountsTimestamp = getZonedTimestampMilli(resultSet, 14); Long onlineAccountsTimestamp = getZonedTimestampMilli(resultSet, 14);
byte[] timestampSignatures = resultSet.getBytes(15); byte[] onlineAccountsSignatures = resultSet.getBytes(15);
return new BlockData(version, reference, transactionCount, totalFees, transactionsSignature, height, timestamp, generatingBalance, return new BlockData(version, reference, transactionCount, totalFees, transactionsSignature, height, timestamp, generatingBalance,
generatorPublicKey, generatorSignature, atCount, atFees, encodedOnlineAccounts, onlineAccountsTimestamp, timestampSignatures); generatorPublicKey, generatorSignature, atCount, atFees, encodedOnlineAccounts, onlineAccountsTimestamp, onlineAccountsSignatures);
} catch (SQLException e) { } catch (SQLException e) {
throw new DataException("Error extracting data from result set", e); throw new DataException("Error extracting data from result set", e);
} }
@ -323,7 +323,7 @@ public class HSQLDBBlockRepository implements BlockRepository {
.bind("AT_count", blockData.getATCount()).bind("AT_fees", blockData.getATFees()) .bind("AT_count", blockData.getATCount()).bind("AT_fees", blockData.getATFees())
.bind("online_accounts", blockData.getEncodedOnlineAccounts()) .bind("online_accounts", blockData.getEncodedOnlineAccounts())
.bind("online_accounts_timestamp", toOffsetDateTime(blockData.getOnlineAccountsTimestamp())) .bind("online_accounts_timestamp", toOffsetDateTime(blockData.getOnlineAccountsTimestamp()))
.bind("online_accounts_signatures", blockData.getTimestampSignatures()); .bind("online_accounts_signatures", blockData.getOnlineAccountsSignatures());
try { try {
saveHelper.execute(this.repository); saveHelper.execute(this.repository);

View File

@ -195,7 +195,7 @@ public class BlockTransformer extends Transformer {
// Online accounts info? // Online accounts info?
byte[] onlineAccounts = null; byte[] onlineAccounts = null;
byte[] timestampSignatures = null; byte[] onlineAccountsSignatures = null;
Long onlineAccountsTimestamp = null; Long onlineAccountsTimestamp = null;
if (version >= 4) { if (version >= 4) {
@ -211,14 +211,14 @@ public class BlockTransformer extends Transformer {
byteBuffer.get(onlineAccounts); byteBuffer.get(onlineAccounts);
// Note: number of signatures, not byte length // Note: number of signatures, not byte length
int timestampSignaturesCount = byteBuffer.getInt(); int onlineAccountsSignaturesCount = byteBuffer.getInt();
if (timestampSignaturesCount > 0) { if (onlineAccountsSignaturesCount > 0) {
// 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();
timestampSignatures = new byte[timestampSignaturesCount * Transformer.SIGNATURE_LENGTH]; onlineAccountsSignatures = new byte[onlineAccountsSignaturesCount * Transformer.SIGNATURE_LENGTH];
byteBuffer.get(timestampSignatures); byteBuffer.get(onlineAccountsSignatures);
} }
} }
@ -228,7 +228,7 @@ public class BlockTransformer extends Transformer {
// We don't have a height! // We don't have a height!
Integer height = null; Integer height = null;
BlockData blockData = new BlockData(version, reference, transactionCount, totalFees, transactionsSignature, height, timestamp, generatingBalance, BlockData blockData = new BlockData(version, reference, transactionCount, totalFees, transactionsSignature, height, timestamp, generatingBalance,
generatorPublicKey, generatorSignature, atCount, atFees, onlineAccounts, onlineAccountsTimestamp, timestampSignatures); generatorPublicKey, generatorSignature, atCount, atFees, onlineAccounts, onlineAccountsTimestamp, onlineAccountsSignatures);
return new Triple<BlockData, List<TransactionData>, List<ATStateData>>(blockData, transactions, atStates); return new Triple<BlockData, List<TransactionData>, List<ATStateData>>(blockData, transactions, atStates);
} }
@ -241,8 +241,8 @@ public class BlockTransformer extends Transformer {
blockLength += AT_BYTES_LENGTH + blockData.getATCount() * V4_AT_ENTRY_LENGTH; blockLength += AT_BYTES_LENGTH + blockData.getATCount() * V4_AT_ENTRY_LENGTH;
blockLength += ONLINE_ACCOUNTS_SIZE_LENGTH + blockData.getEncodedOnlineAccounts().length; blockLength += ONLINE_ACCOUNTS_SIZE_LENGTH + blockData.getEncodedOnlineAccounts().length;
blockLength += ONLINE_ACCOUNTS_SIGNATURES_COUNT_LENGTH; blockLength += ONLINE_ACCOUNTS_SIGNATURES_COUNT_LENGTH;
if (blockData.getTimestampSignatures().length > 0) if (blockData.getOnlineAccountsSignatures().length > 0)
blockLength += ONLINE_ACCOUNTS_TIMESTAMP_LENGTH + blockData.getTimestampSignatures().length; blockLength += ONLINE_ACCOUNTS_TIMESTAMP_LENGTH + blockData.getOnlineAccountsSignatures().length;
} else if (blockData.getVersion() >= 2) } else if (blockData.getVersion() >= 2)
blockLength += AT_FEES_LENGTH + AT_BYTES_LENGTH + blockData.getATCount() * V2_AT_ENTRY_LENGTH; blockLength += AT_FEES_LENGTH + AT_BYTES_LENGTH + blockData.getATCount() * V2_AT_ENTRY_LENGTH;
@ -321,17 +321,17 @@ public class BlockTransformer extends Transformer {
bytes.write(Ints.toByteArray(0)); bytes.write(Ints.toByteArray(0));
} }
byte[] timestampSignatures = blockData.getTimestampSignatures(); byte[] onlineAccountsSignatures = blockData.getOnlineAccountsSignatures();
if (timestampSignatures != null) { if (onlineAccountsSignatures != null) {
// Note: we write the number of signatures, not the number of bytes // Note: we write the number of signatures, not the number of bytes
bytes.write(Ints.toByteArray(timestampSignatures.length / Transformer.SIGNATURE_LENGTH)); bytes.write(Ints.toByteArray(onlineAccountsSignatures.length / Transformer.SIGNATURE_LENGTH));
if (timestampSignatures.length > 0) { if (onlineAccountsSignatures.length > 0) {
// Only write online accounts timestamp if we have signatures // Only write online accounts timestamp if we have signatures
bytes.write(Longs.toByteArray(blockData.getOnlineAccountsTimestamp())); bytes.write(Longs.toByteArray(blockData.getOnlineAccountsTimestamp()));
bytes.write(timestampSignatures); bytes.write(onlineAccountsSignatures);
} }
} else { } else {
bytes.write(Ints.toByteArray(0)); bytes.write(Ints.toByteArray(0));