Skip to content

Commit

Permalink
[Changed]The frozen amount must be at least 40,000 BOA.
Browse files Browse the repository at this point in the history
according to the Yellow White Paper
renamed Amount.FreezeAmount to Amount.MinFrrzeAmount
  • Loading branch information
Hyeonyeob Kim authored and AndrejMitrovic committed Dec 16, 2019
1 parent 3169cca commit 6bbd491
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions source/agora/common/Amount.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public struct Amount
public static immutable Amount MaxUnitSupply =
Amount(UnitPerCoin.value * MaxCoinSupply, true);
/// Exact amount that needs to be staked to make a freezing transaction
public static immutable Amount FreezeAmount =
public static immutable Amount MinFreezeAmount =
Amount(UnitPerCoin.value * 40_000, true);

/// Helper type for `toString`
Expand Down Expand Up @@ -260,8 +260,8 @@ pure @safe nothrow @nogc unittest
assert(Amount(100_500_000).integral() == 10);
assert(Amount(100_500_000).decimal() == 500_000);

assert(Amount.FreezeAmount.decimal() == 0);
assert(Amount.FreezeAmount.integral() == 40_000);
assert(Amount.MinFreezeAmount.decimal() == 0);
assert(Amount.MinFreezeAmount.integral() == 40_000);
}

unittest
Expand Down
28 changes: 14 additions & 14 deletions source/agora/consensus/Validation.d
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public string isInvalidReason (const Transaction tx, UTXOFinder findUTXO,
return "Transaction: Can only freeze a Payment transaction";
}

if (sum_unspent != Amount.FreezeAmount)
return "Transaction: Only available when the amount is 40,000";
if (sum_unspent.integral() < Amount.MinFreezeAmount.integral())
return "Transaction: available when the amount is at least 40,000 BOA";
}
else if (tx.type == TxType.Payment)
{
Expand Down Expand Up @@ -358,7 +358,7 @@ unittest
{
storage.clear;
// Create the previous transaction with type `TxType.Payment`
previousTx = newCoinbaseTX(key_pairs[0].address, Amount.FreezeAmount);
previousTx = newCoinbaseTX(key_pairs[0].address, Amount.MinFreezeAmount);
previousHash = hashFull(previousTx);
foreach (idx, output; previousTx.outputs)
{
Expand All @@ -375,7 +375,7 @@ unittest
secondTx = Transaction(
TxType.Freeze,
[Input(previousHash, 0)],
[Output(Amount.FreezeAmount, key_pairs[1].address)]
[Output(Amount.MinFreezeAmount, key_pairs[1].address)]
);
secondTx.inputs[0].signature = key_pairs[0].secret.sign(hashFull(secondTx)[]);

Expand All @@ -388,7 +388,7 @@ unittest
{
storage.clear;
// Create the previous transaction with type `TxType.Payment`
previousTx = newCoinbaseTX(key_pairs[0].address, Amount.FreezeAmount);
previousTx = newCoinbaseTX(key_pairs[0].address, Amount.MinFreezeAmount);
previousHash = hashFull(previousTx);
foreach (idx, output; previousTx.outputs)
{
Expand All @@ -405,7 +405,7 @@ unittest
secondTx = Transaction(
TxType.Freeze,
[Input(previousHash, 0)],
[Output(Amount.FreezeAmount, key_pairs[1].address)]
[Output(Amount.MinFreezeAmount, key_pairs[1].address)]
);
secondTx.inputs[0].signature = key_pairs[0].secret.sign(hashFull(secondTx)[]);

Expand Down Expand Up @@ -444,7 +444,7 @@ unittest
}

// When the privious transaction with too many amount at freezings.
// Second transaction is invalid.
// Second transaction is valid.
{
// Create the previous transaction with type `TxType.Payment`
previousTx = newCoinbaseTX(key_pairs[0].address, Amount(500_000_000_000L));
Expand All @@ -468,8 +468,8 @@ unittest
);
secondTx.inputs[0].signature = key_pairs[0].secret.sign(hashFull(secondTx)[]);

// Second Transaction is invalid.
assert(!secondTx.isValid(findUTXO, 0));
// Second Transaction is valid.
assert(secondTx.isValid(findUTXO, 0));
}
}

Expand Down Expand Up @@ -523,7 +523,7 @@ unittest
// Expected Status : melted
{
block_height = 0;
previousTx = newCoinbaseTX(key_pairs[0].address, Amount.FreezeAmount);
previousTx = newCoinbaseTX(key_pairs[0].address, Amount.MinFreezeAmount);

// Save to UTXOSet
previousHash = hashFull(previousTx);
Expand All @@ -549,7 +549,7 @@ unittest
secondTx = Transaction(
TxType.Freeze,
[Input(previousHash, 0)],
[Output(Amount.FreezeAmount, key_pairs[1].address)]
[Output(Amount.MinFreezeAmount, key_pairs[1].address)]
);
secondTx.inputs[0].signature = key_pairs[0].secret.sign(hashFull(secondTx)[]);

Expand Down Expand Up @@ -580,7 +580,7 @@ unittest
thirdTx = Transaction(
TxType.Payment,
[Input(secondHash, 0)],
[Output(Amount.FreezeAmount, key_pairs[2].address)]
[Output(Amount.MinFreezeAmount, key_pairs[2].address)]
);
thirdTx.inputs[0].signature = key_pairs[1].secret.sign(hashFull(thirdTx)[]);

Expand Down Expand Up @@ -611,7 +611,7 @@ unittest
fourthTx = Transaction(
TxType.Payment,
[Input(thirdHash, 0)],
[Output(Amount.FreezeAmount, key_pairs[3].address)]
[Output(Amount.MinFreezeAmount, key_pairs[3].address)]
);
fourthTx.inputs[0].signature = key_pairs[2].secret.sign(hashFull(fourthTx)[]);

Expand All @@ -629,7 +629,7 @@ unittest
fifthTx = Transaction(
TxType.Payment,
[Input(thirdHash, 0)],
[Output(Amount.FreezeAmount, key_pairs[3].address)]
[Output(Amount.MinFreezeAmount, key_pairs[3].address)]
);
fifthTx.inputs[0].signature = key_pairs[2].secret.sign(hashFull(fourthTx)[]);

Expand Down
4 changes: 2 additions & 2 deletions source/agora/node/Ledger.d
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ private Transaction[] makeTransactionForFreezing (
Transaction[] transactions;

// always use the same amount, for simplicity
const Amount AmountPerTx = Amount.FreezeAmount;
const Amount AmountPerTx = Amount.MinFreezeAmount;

foreach (idx; 0 .. TxCount)
{
Expand Down Expand Up @@ -754,7 +754,7 @@ unittest
version (unittest)
private Transaction[] splitGenesisTransaction (
KeyPair[] in_key,
KeyPair[] out_key, Amount amount = Amount.FreezeAmount)
KeyPair[] out_key, Amount amount = Amount.MinFreezeAmount)
{
Transaction[] txes;
foreach (idx; 0 .. Block.TxsInBlock)
Expand Down

0 comments on commit 6bbd491

Please sign in to comment.