Allow zero fee transactions if the fee is zero in blockchain.json

Until now it wasn't possible to set up a chain with zero transaction fees due to a hardcoded zero check in Payment.isValid(), and a divide by zero error in Transaction.hasMinimumFeePerByte()
This commit is contained in:
CalDescent 2021-07-04 09:31:51 +01:00
parent 4b1de108d1
commit 49eddc9da5
2 changed files with 7 additions and 2 deletions

View File

@ -40,8 +40,9 @@ public class Payment {
public ValidationResult isValid(byte[] senderPublicKey, List<PaymentData> payments, long fee, boolean isZeroAmountValid) throws DataException { public ValidationResult isValid(byte[] senderPublicKey, List<PaymentData> payments, long fee, boolean isZeroAmountValid) throws DataException {
AssetRepository assetRepository = this.repository.getAssetRepository(); AssetRepository assetRepository = this.repository.getAssetRepository();
// Check fee is positive // Check fee is positive or zero
if (fee <= 0) // We have already checked that the fee is correct in the Transaction superclass
if (fee < 0)
return ValidationResult.NEGATIVE_FEE; return ValidationResult.NEGATIVE_FEE;
// Total up payment amounts by assetId // Total up payment amounts by assetId

View File

@ -348,6 +348,10 @@ public abstract class Transaction {
long unitFee = BlockChain.getInstance().getUnitFee(); long unitFee = BlockChain.getInstance().getUnitFee();
int maxBytePerUnitFee = BlockChain.getInstance().getMaxBytesPerUnitFee(); int maxBytePerUnitFee = BlockChain.getInstance().getMaxBytesPerUnitFee();
// If the unit fee is zero, any fee is enough to cover the byte-length of the transaction
if (unitFee == 0) {
return true;
}
return this.feePerByte() >= maxBytePerUnitFee / unitFee; return this.feePerByte() >= maxBytePerUnitFee / unitFee;
} }