Remove more old Qora v1 compatibility code

This commit is contained in:
catbref 2020-04-27 15:17:22 +01:00
parent bd521baade
commit cd066cf357
4 changed files with 83 additions and 145 deletions

View File

@ -1107,14 +1107,8 @@ public class Block {
if (this.ourAtStates == this.getATStates()) // Note object reference compare
return ValidationResult.OK;
// For old v1 CIYAM ATs we blindly accept them
if (this.blockData.getVersion() < 4) {
this.ourAtStates = this.atStates;
this.ourAtFees = this.blockData.getATFees();
} else {
// Generate local AT states for comparison
this.executeATs();
}
// Check locally generated AT states against ones received from elsewhere

View File

@ -49,7 +49,6 @@ public class ArbitraryTransactionData extends TransactionData {
this.creatorPublicKey = this.senderPublicKey;
}
/** V3 */
public ArbitraryTransactionData(BaseTransactionData baseTransactionData,
int version, int service, byte[] data, DataType dataType, List<PaymentData> payments) {
super(TransactionType.ARBITRARY, baseTransactionData);
@ -62,12 +61,6 @@ public class ArbitraryTransactionData extends TransactionData {
this.payments = payments;
}
/** V1 */
public ArbitraryTransactionData(BaseTransactionData baseTransactionData,
int version, int service, byte[] data, DataType dataType) {
this(baseTransactionData, version, service, data, dataType, null);
}
// Getters/Setters
public byte[] getSenderPublicKey() {

View File

@ -54,8 +54,7 @@ public class BlockTransformer extends Transformer {
protected static final int ONLINE_ACCOUNTS_TIMESTAMP_LENGTH = LONG_LENGTH;
protected static final int ONLINE_ACCOUNTS_SIGNATURES_COUNT_LENGTH = INT_LENGTH;
protected static final int V2_AT_ENTRY_LENGTH = ADDRESS_LENGTH + MD5_LENGTH;
protected static final int V4_AT_ENTRY_LENGTH = ADDRESS_LENGTH + SHA256_LENGTH + BIG_DECIMAL_LENGTH;
protected static final int AT_ENTRY_LENGTH = ADDRESS_LENGTH + SHA256_LENGTH + BIG_DECIMAL_LENGTH;
/**
* Extract block data and transaction data from serialized bytes.
@ -86,8 +85,8 @@ public class BlockTransformer extends Transformer {
public static Triple<BlockData, List<TransactionData>, List<ATStateData>> fromByteBuffer(ByteBuffer byteBuffer) throws TransformationException {
int version = byteBuffer.getInt();
if (version >= 2 && byteBuffer.remaining() < BASE_LENGTH + AT_BYTES_LENGTH - VERSION_LENGTH)
throw new TransformationException("Byte data too short for V2+ Block");
if (byteBuffer.remaining() < BASE_LENGTH + AT_BYTES_LENGTH - VERSION_LENGTH)
throw new TransformationException("Byte data too short for Block");
if (byteBuffer.remaining() > BlockChain.getInstance().getMaxBlockSize())
throw new TransformationException("Byte data too long for Block");
@ -111,7 +110,6 @@ public class BlockTransformer extends Transformer {
BigDecimal atFees = BigDecimal.ZERO.setScale(8);
List<ATStateData> atStates = new ArrayList<>();
if (version >= 2) {
int atBytesLength = byteBuffer.getInt();
if (atBytesLength > BlockChain.getInstance().getMaxBlockSize())
@ -120,31 +118,9 @@ public class BlockTransformer extends Transformer {
ByteBuffer atByteBuffer = byteBuffer.slice();
atByteBuffer.limit(atBytesLength);
if (version < 4) {
// For versions < 4, read AT-address & MD5 pairs
if (atBytesLength % V2_AT_ENTRY_LENGTH != 0)
throw new TransformationException("AT byte data not a multiple of version 2+ entries");
while (atByteBuffer.hasRemaining()) {
byte[] atAddressBytes = new byte[ADDRESS_LENGTH];
atByteBuffer.get(atAddressBytes);
String atAddress = Base58.encode(atAddressBytes);
byte[] stateHash = new byte[MD5_LENGTH];
atByteBuffer.get(stateHash);
atStates.add(new ATStateData(atAddress, stateHash));
}
// Bump byteBuffer over AT states just read in slice
byteBuffer.position(byteBuffer.position() + atBytesLength);
// AT fees follow in versions < 4
atFees = Serialization.deserializeBigDecimal(byteBuffer);
} else {
// For block versions >= 4, read AT-address, SHA256 hash and fees
if (atBytesLength % V4_AT_ENTRY_LENGTH != 0)
throw new TransformationException("AT byte data not a multiple of version 4+ entries");
// Read AT-address, SHA256 hash and fees
if (atBytesLength % AT_ENTRY_LENGTH != 0)
throw new TransformationException("AT byte data not a multiple of AT entry length");
while (atByteBuffer.hasRemaining()) {
byte[] atAddressBytes = new byte[ADDRESS_LENGTH];
@ -160,14 +136,12 @@ public class BlockTransformer extends Transformer {
atStates.add(new ATStateData(atAddress, stateHash, fees));
}
}
// AT count to reflect the number of states we have
atCount = atStates.size();
// Add AT fees to totalFees
totalFees = totalFees.add(atFees);
}
int transactionCount = byteBuffer.getInt();
@ -201,7 +175,6 @@ public class BlockTransformer extends Transformer {
byte[] onlineAccountsSignatures = null;
Long onlineAccountsTimestamp = null;
if (version >= 4) {
onlineAccountsCount = byteBuffer.getInt();
int conciseSetLength = byteBuffer.getInt();
@ -234,7 +207,6 @@ public class BlockTransformer extends Transformer {
onlineAccountsSignatures = new byte[signaturesByteLength];
byteBuffer.get(onlineAccountsSignatures);
}
}
if (byteBuffer.hasRemaining())
throw new TransformationException("Excess byte data found after parsing Block");
@ -251,16 +223,13 @@ public class BlockTransformer extends Transformer {
BlockData blockData = block.getBlockData();
int blockLength = BASE_LENGTH;
if (blockData.getVersion() >= 4) {
blockLength += AT_BYTES_LENGTH + blockData.getATCount() * V4_AT_ENTRY_LENGTH;
blockLength += AT_BYTES_LENGTH + blockData.getATCount() * AT_ENTRY_LENGTH;
blockLength += ONLINE_ACCOUNTS_COUNT_LENGTH + ONLINE_ACCOUNTS_SIZE_LENGTH + blockData.getEncodedOnlineAccounts().length;
blockLength += ONLINE_ACCOUNTS_SIGNATURES_COUNT_LENGTH;
byte[] onlineAccountsSignatures = blockData.getOnlineAccountsSignatures();
if (onlineAccountsSignatures != null && onlineAccountsSignatures.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;
try {
// Short cut for no transactions
@ -290,8 +259,7 @@ public class BlockTransformer extends Transformer {
bytes.write(blockData.getTransactionsSignature());
bytes.write(blockData.getMinterSignature());
if (blockData.getVersion() >= 4) {
int atBytesLength = blockData.getATCount() * V4_AT_ENTRY_LENGTH;
int atBytesLength = blockData.getATCount() * AT_ENTRY_LENGTH;
bytes.write(Ints.toByteArray(atBytesLength));
for (ATStateData atStateData : block.getATStates()) {
@ -299,21 +267,6 @@ public class BlockTransformer extends Transformer {
bytes.write(atStateData.getStateHash());
Serialization.serializeBigDecimal(bytes, atStateData.getFees());
}
} else if (blockData.getVersion() >= 2) {
int atBytesLength = blockData.getATCount() * V2_AT_ENTRY_LENGTH;
bytes.write(Ints.toByteArray(atBytesLength));
for (ATStateData atStateData : block.getATStates()) {
bytes.write(Base58.decode(atStateData.getATAddress()));
bytes.write(atStateData.getStateHash());
}
if (blockData.getATFees() != null)
// NOTE: atFees serialized as long value, not as BigDecimal, for historic compatibility
bytes.write(Longs.toByteArray(blockData.getATFees().longValue()));
else
bytes.write(Longs.toByteArray(0));
}
// Transactions
bytes.write(Ints.toByteArray(blockData.getTransactionCount()));
@ -325,7 +278,6 @@ public class BlockTransformer extends Transformer {
}
// Online account info
if (blockData.getVersion() >= 4) {
byte[] encodedOnlineAccounts = blockData.getEncodedOnlineAccounts();
if (encodedOnlineAccounts != null) {
@ -352,7 +304,6 @@ public class BlockTransformer extends Transformer {
// Zero online accounts signatures (timestamp omitted also)
bytes.write(Ints.toByteArray(0));
}
}
return bytes.toByteArray();
} catch (IOException | DataException e) {

View File

@ -67,7 +67,7 @@ public class ArbitraryTransactionTransformer extends TransactionTransformer {
byte[] senderPublicKey = Serialization.deserializePublicKey(byteBuffer);
// V3+ allows payments but always return a list of payments, even if empty
// Always return a list of payments, even if empty
List<PaymentData> payments = new ArrayList<>();
if (version != 1) {
int paymentsCount = byteBuffer.getInt();