forked from Qortal/qortal
Rename timestampSignatures to onlineAccountsSignatures
This commit is contained in:
parent
504cfc6a74
commit
aa81c86cf1
@ -253,11 +253,11 @@ public class Block {
|
||||
byte[] encodedOnlineAccounts = BlockTransformer.encodeOnlineAccounts(onlineAccountsSet);
|
||||
|
||||
// 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) {
|
||||
Integer accountIndex = accountIndexes.get(i);
|
||||
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;
|
||||
@ -282,7 +282,7 @@ public class Block {
|
||||
|
||||
// This instance used for AT processing
|
||||
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
|
||||
this.executeATs();
|
||||
@ -294,7 +294,7 @@ public class Block {
|
||||
|
||||
// Rebuild blockData using post-AT-execute data
|
||||
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();
|
||||
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,
|
||||
generator.getPublicKey(), generatorSignature, atCount, atFees, encodedOnlineAccounts, onlineAccountsTimestamp, timestampSignatures);
|
||||
generator.getPublicKey(), generatorSignature, atCount, atFees, encodedOnlineAccounts, onlineAccountsTimestamp, onlineAccountsSignatures);
|
||||
|
||||
// Resign to update transactions signature
|
||||
newBlock.sign();
|
||||
@ -869,6 +869,10 @@ public class Block {
|
||||
}
|
||||
|
||||
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
|
||||
ConciseSet accountIndexes = BlockTransformer.decodeOnlineAccounts(this.blockData.getEncodedOnlineAccounts());
|
||||
|
||||
@ -889,19 +893,19 @@ public class Block {
|
||||
// Possibly check signatures if block is recent
|
||||
long signatureRequirementThreshold = NTP.getTime() - BlockChain.getInstance().getOnlineAccountSignaturesMinLifetime();
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
// 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());
|
||||
|
||||
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());
|
||||
byte[] signature = timestampSignatures.get(i);
|
||||
byte[] signature = onlineAccountsSignatures.get(i);
|
||||
|
||||
if (!account.verify(signature, message))
|
||||
return ValidationResult.ONLINE_ACCOUNT_SIGNATURE_INCORRECT;
|
||||
|
@ -34,7 +34,7 @@ public class BlockData implements Serializable {
|
||||
private BigDecimal atFees;
|
||||
private byte[] encodedOnlineAccounts;
|
||||
private Long onlineAccountsTimestamp;
|
||||
private byte[] timestampSignatures;
|
||||
private byte[] onlineAccountsSignatures;
|
||||
|
||||
// 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,
|
||||
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.reference = reference;
|
||||
this.transactionCount = transactionCount;
|
||||
@ -59,7 +59,7 @@ public class BlockData implements Serializable {
|
||||
this.atFees = atFees;
|
||||
this.encodedOnlineAccounts = encodedOnlineAccounts;
|
||||
this.onlineAccountsTimestamp = onlineAccountsTimestamp;
|
||||
this.timestampSignatures = timestampSignatures;
|
||||
this.onlineAccountsSignatures = onlineAccountsSignatures;
|
||||
|
||||
if (this.generatorSignature != null && this.transactionsSignature != null)
|
||||
this.signature = Bytes.concat(this.generatorSignature, this.transactionsSignature);
|
||||
@ -175,8 +175,8 @@ public class BlockData implements Serializable {
|
||||
this.onlineAccountsTimestamp = onlineAccountsTimestamp;
|
||||
}
|
||||
|
||||
public byte[] getTimestampSignatures() {
|
||||
return this.timestampSignatures;
|
||||
public byte[] getOnlineAccountsSignatures() {
|
||||
return this.onlineAccountsSignatures;
|
||||
}
|
||||
|
||||
// JAXB special
|
||||
|
@ -50,10 +50,10 @@ public class HSQLDBBlockRepository implements BlockRepository {
|
||||
BigDecimal atFees = resultSet.getBigDecimal(12);
|
||||
byte[] encodedOnlineAccounts = resultSet.getBytes(13);
|
||||
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,
|
||||
generatorPublicKey, generatorSignature, atCount, atFees, encodedOnlineAccounts, onlineAccountsTimestamp, timestampSignatures);
|
||||
generatorPublicKey, generatorSignature, atCount, atFees, encodedOnlineAccounts, onlineAccountsTimestamp, onlineAccountsSignatures);
|
||||
} catch (SQLException 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("online_accounts", blockData.getEncodedOnlineAccounts())
|
||||
.bind("online_accounts_timestamp", toOffsetDateTime(blockData.getOnlineAccountsTimestamp()))
|
||||
.bind("online_accounts_signatures", blockData.getTimestampSignatures());
|
||||
.bind("online_accounts_signatures", blockData.getOnlineAccountsSignatures());
|
||||
|
||||
try {
|
||||
saveHelper.execute(this.repository);
|
||||
|
@ -195,7 +195,7 @@ public class BlockTransformer extends Transformer {
|
||||
|
||||
// Online accounts info?
|
||||
byte[] onlineAccounts = null;
|
||||
byte[] timestampSignatures = null;
|
||||
byte[] onlineAccountsSignatures = null;
|
||||
Long onlineAccountsTimestamp = null;
|
||||
|
||||
if (version >= 4) {
|
||||
@ -211,14 +211,14 @@ public class BlockTransformer extends Transformer {
|
||||
byteBuffer.get(onlineAccounts);
|
||||
|
||||
// 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
|
||||
onlineAccountsTimestamp = byteBuffer.getLong();
|
||||
|
||||
timestampSignatures = new byte[timestampSignaturesCount * Transformer.SIGNATURE_LENGTH];
|
||||
byteBuffer.get(timestampSignatures);
|
||||
onlineAccountsSignatures = new byte[onlineAccountsSignaturesCount * Transformer.SIGNATURE_LENGTH];
|
||||
byteBuffer.get(onlineAccountsSignatures);
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,7 +228,7 @@ public class BlockTransformer extends Transformer {
|
||||
// We don't have a height!
|
||||
Integer height = null;
|
||||
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);
|
||||
}
|
||||
@ -241,8 +241,8 @@ public class BlockTransformer extends Transformer {
|
||||
blockLength += AT_BYTES_LENGTH + blockData.getATCount() * V4_AT_ENTRY_LENGTH;
|
||||
blockLength += ONLINE_ACCOUNTS_SIZE_LENGTH + blockData.getEncodedOnlineAccounts().length;
|
||||
blockLength += ONLINE_ACCOUNTS_SIGNATURES_COUNT_LENGTH;
|
||||
if (blockData.getTimestampSignatures().length > 0)
|
||||
blockLength += ONLINE_ACCOUNTS_TIMESTAMP_LENGTH + blockData.getTimestampSignatures().length;
|
||||
if (blockData.getOnlineAccountsSignatures().length > 0)
|
||||
blockLength += ONLINE_ACCOUNTS_TIMESTAMP_LENGTH + blockData.getOnlineAccountsSignatures().length;
|
||||
} else if (blockData.getVersion() >= 2)
|
||||
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));
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
bytes.write(Longs.toByteArray(blockData.getOnlineAccountsTimestamp()));
|
||||
|
||||
bytes.write(timestampSignatures);
|
||||
bytes.write(onlineAccountsSignatures);
|
||||
}
|
||||
} else {
|
||||
bytes.write(Ints.toByteArray(0));
|
||||
|
Loading…
x
Reference in New Issue
Block a user