Skip to content

Commit

Permalink
- enforced minimum capacity
Browse files Browse the repository at this point in the history
- other improvements
  • Loading branch information
IxiAngel committed Mar 15, 2024
1 parent 5054c55 commit cd15d59
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 129 deletions.
2 changes: 1 addition & 1 deletion IxianDLT/Block/BlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2471,7 +2471,7 @@ public bool applyAcceptedBlock(Block b, bool generating_new = false)
else if (b.version >= BlockVer.v11)
{
IxiNumber nameRewardAmount = calculateNameReward(b.blockNum);
if (!Node.regNameState.decreaseRewardPool(nameRewardAmount))
if (nameRewardAmount > 0 && !Node.regNameState.decreaseRewardPool(nameRewardAmount))
{
Logging.error("Error while decreasing reward pool.");
return false;
Expand Down
4 changes: 2 additions & 2 deletions IxianDLT/Block/BlockSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ private void rollForward()
byte[] wsChecksum = Node.walletState.calculateWalletStateChecksum();
if (wsChecksum == null || !wsChecksum.SequenceEqual(b.walletStateChecksum))
{
Logging.error("After applying block #{0}, walletStateChecksum is incorrect!. Block's WS: {1}, actual WS: {2}", b.blockNum, Crypto.hashToString(b.walletStateChecksum), Crypto.hashToString(wsChecksum));
Logging.error("After applying block #{0}, walletStateChecksum is incorrect. Block's WS: {1}, actual WS: {2}", b.blockNum, Crypto.hashToString(b.walletStateChecksum), Crypto.hashToString(wsChecksum));
Node.walletState.revertTransaction(b.blockNum);
Node.regNameState.revertTransaction(b.blockNum);
Node.blockChain.revertBlockTransactions(b);
Expand All @@ -875,7 +875,7 @@ private void rollForward()
byte[] rnChecksum = Node.regNameState.calculateRegNameStateChecksum(b.blockNum);
if (rnChecksum == null || !rnChecksum.SequenceEqual(b.regNameStateChecksum))
{
Logging.error("After applying block #{0}, regNameStateChecksum is incorrect!. Block's RN: {1}, actual RN: {2}", b.blockNum, Crypto.hashToString(b.regNameStateChecksum), Crypto.hashToString(rnChecksum));
Logging.error("After applying block #{0}, regNameStateChecksum is incorrect. Block's RN: {1}, actual RN: {2}", b.blockNum, Crypto.hashToString(b.regNameStateChecksum), Crypto.hashToString(rnChecksum));
Node.walletState.revertTransaction(b.blockNum);
Node.regNameState.revertTransaction(b.blockNum);
Node.blockChain.revertBlockTransactions(b);
Expand Down
5 changes: 5 additions & 0 deletions IxianDLT/Meta/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,11 @@ public override byte[] calculateRegNameChecksumForRecovery(byte[] name, Address
{
return regNameState.calculateRegNameChecksumForRecovery(name, recoveryHash, sequence, nextPkHash);
}

public override RegisteredNameRecord getRegName(byte[] name, bool useAbsoluteId = true)
{
return regNameState.getName(name, useAbsoluteId);
}
}

class dataPoint
Expand Down
2 changes: 1 addition & 1 deletion IxianDLT/RegNames/RegNameEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public IEnumerable<RegisteredNameRecord> getAffectedRegNames()
Dictionary<byte[], bool> addresses = new Dictionary<byte[], bool>(new ByteArrayComparer());
foreach (var entry in entries)
{
if (addresses.ContainsKey(entry.targetWallet))
if (entry.targetWallet == null || addresses.ContainsKey(entry.targetWallet))
{
continue;
}
Expand Down
27 changes: 25 additions & 2 deletions IxianDLT/RegNames/RegisteredNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ private bool updateCapacityInternal(byte[] id, uint newCapacity, Address nextPkH
{
lock (stateLock)
{
if (newCapacity < ConsensusConfig.rnMinCapacity)
{
Logging.error("Invalid capacity change requested for registered name {0}.", Crypto.hashToString(id));
return false;
}

RegisteredNameRecord rnr = getName(id);
if (rnr == null)
{
Expand Down Expand Up @@ -357,6 +363,12 @@ private bool revertCapacityInternal(byte[] id, uint newCapacity, Address nextPkH
return false;
}

if (rnr.sequence < 1)
{
Logging.error("Sequence is invalid while reverting capacity for name {0}.", Crypto.hashToString(id));
return false;
}

rnr.setCapacity(newCapacity, rnr.sequence - 1, nextPkHash, sigPubKey, sig);
var rnrChecksum = rnr.calculateChecksum();

Expand Down Expand Up @@ -493,6 +505,11 @@ private bool setNameRecordsInternal(byte[] id, List<RegisteredNameDataRecord> re
ulong nextSequence;
if (reverting)
{
if (rnr.sequence < 1)
{
Logging.error("Sequence is invalid while reverting capacity for name {0}.", Crypto.hashToString(id));
return false;
}
nextSequence = rnr.sequence - 1;
} else
{
Expand Down Expand Up @@ -562,6 +579,12 @@ private bool revertRecoverNameInternal(byte[] id, Address newRecoveryHash, Addre
return false;
}

if (rnr.sequence < 1)
{
Logging.error("Sequence is invalid while reverting recovery for name {0}.", Crypto.hashToString(id));
return false;
}

rnr.setRecoveryHash(newRecoveryHash, rnr.sequence - 1, nextPkHash, sigPubKey, sig);
byte[] rnrChecksum = rnr.calculateChecksum();

Expand Down Expand Up @@ -1065,7 +1088,7 @@ private bool verifyRegisterTransaction(Transaction tx)
}
}

if (rnReg.capacity < 1)
if (rnReg.capacity < ConsensusConfig.rnMinCapacity)
{
Logging.error("RN Transaction {0} tried to register name {1} with invalid capacity.", tx.getTxIdString(), Crypto.hashToString(rnReg.name));
return false;
Expand Down Expand Up @@ -1181,7 +1204,7 @@ private bool verifyChangeCapacityTransaction(Transaction tx)
return false;
}

if (rnCap.newCapacity < 1)
if (rnCap.newCapacity < ConsensusConfig.rnMinCapacity)
{
Logging.error("RN Transaction {0} tried to change capacity for name {1} with invalid capacity.", tx.getTxIdString(), Crypto.hashToString(rnCap.name));
return false;
Expand Down
5 changes: 5 additions & 0 deletions IxianDLT/Tests/BenchmarkNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,10 @@ public override byte[] calculateRegNameChecksumForRecovery(byte[] name, Address
{
throw new NotImplementedException();
}

public override RegisteredNameRecord getRegName(byte[] name, bool useAbsoluteId)
{
throw new NotImplementedException();
}
}
}
14 changes: 7 additions & 7 deletions TestingScripts/Start-Testnet.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ Write-Host "Working directory: $($wd)"
Write-Host "Loading required assemblies..."
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$srcDir = "..\IxianDLT\bin\$($ClientBinary)"
$srcDir = "..\IxianDLT\bin\$($ClientBinary)\net6.0"
$dstPaths = New-Object System.Collections.ArrayList

$ClientAddresses = @{}
Expand Down Expand Up @@ -450,7 +450,7 @@ if($ClearState.IsPresent) {
$wasError = $true
break
}
if($ns.'Block Height' -lt 5) {
if($ns.'Block Height' -lt 2) {
Write-Host -ForegroundColor Green -NoNewline "`r-> Block Height: $($ns.'Block Height')"
} else {
Write-Host -ForegroundColor Green "-> Block Height reached, proceeding."
Expand Down Expand Up @@ -504,11 +504,11 @@ if($ClearState.IsPresent) {
}
if($wasError -eq $false) {
# wait for all pending transactions to clear
$pendTxCleared = WaitConfirm-PendingTX -Clients $DLTProcesses -TXList $pendingTx -Blocks 5
if($pendTxCleared -eq $false) {
Write-Host -ForegroundColor Magenta "Pending transctions did not clear within 5 blocks, aborting."
$wasError = $true
}
#$pendTxCleared = WaitConfirm-PendingTX -Clients $DLTProcesses -TXList $pendingTx -Blocks 5
#if($pendTxCleared -eq $false) {
# Write-Host -ForegroundColor Magenta "Pending transctions did not clear within 5 blocks, aborting."
# $wasError = $true
#}
}

if($wasError) {
Expand Down
19 changes: 18 additions & 1 deletion UnitTests/DummyIxianNode.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
using IXICore;
// Copyright (C) 2017-2024 Ixian OU
// This file is part of Ixian DLT - www.github.com/ProjectIxian/Ixian-DLT
//
// Ixian DLT is free software: you can redistribute it and/or modify
// it under the terms of the MIT License as published
// by the Open Source Initiative.
//
// Ixian DLT is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// MIT License for more details.

using IXICore;
using IXICore.Meta;
using IXICore.Network;
using IXICore.RegNames;
Expand Down Expand Up @@ -54,6 +66,11 @@ public override IxiNumber getMinSignerPowDifficulty(ulong blockNum)
throw new NotImplementedException();
}

public override RegisteredNameRecord getRegName(byte[] name, bool useAbsoluteId)
{
throw new NotImplementedException();
}

public override Wallet getWallet(Address id)
{
throw new NotImplementedException();
Expand Down

0 comments on commit cd15d59

Please sign in to comment.