Skip to content

Commit c08b2b1

Browse files
committed
updated SignerPowMiner
1 parent 8cd7420 commit c08b2b1

File tree

6 files changed

+21
-39
lines changed

6 files changed

+21
-39
lines changed

IxianDLT/API/APIServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ public JsonResponse onStatus(Dictionary<string, object> parameters)
807807
networkArray.Add("Signer Bits", Crypto.hashToString(BitConverter.GetBytes(Node.blockChain.getRequiredSignerBits())));
808808
networkArray.Add("Signer Hashrate", Node.signerPowMiner.lastHashRate);
809809

810-
var tmpSolution = Node.signerPowMiner.lastSignerPowSolution;
810+
var tmpSolution = Node.signerPowMiner.GetSolutions(0).LastOrDefault();
811811
Dictionary<string, object> signerPowSolution = new Dictionary<string, object>();
812812
if (tmpSolution != null)
813813
{
@@ -819,7 +819,7 @@ public JsonResponse onStatus(Dictionary<string, object> parameters)
819819
}
820820
networkArray.Add("Signer Last PoW Solution", signerPowSolution);
821821

822-
tmpSolution = PresenceList.getPowSolution();
822+
tmpSolution = Node.signerPowMiner.GetBestSolution(0);
823823
signerPowSolution = new Dictionary<string, object>();
824824
if (tmpSolution != null)
825825
{

IxianDLT/Block/BlockProcessor.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,7 +2159,7 @@ public bool acceptLocalNewBlock()
21592159
{
21602160
if (Node.isMasterNode() && localNewBlock.blockNum > 7)
21612161
{
2162-
BlockSignature signature_data = localNewBlock.applySignature(PresenceList.getPowSolution()); // applySignature() will return signature_data, if signature was applied and null, if signature was already present from before
2162+
BlockSignature signature_data = localNewBlock.applySignature(Node.signerPowMiner.GetBestSolution(localNewBlock.blockNum)); // applySignature() will return signature_data, if signature was applied and null, if signature was already present from before
21632163
if (signature_data != null)
21642164
{
21652165
foreach (var sig in localNewBlock.signatures)
@@ -2172,6 +2172,7 @@ public bool acceptLocalNewBlock()
21722172
SignatureProtocolMessages.broadcastBlockSignature(sig, localNewBlock.blockNum, localNewBlock.blockChecksum, null, null);
21732173
}
21742174
BlockProtocolMessages.broadcastNewBlock(localNewBlock, null, null);
2175+
applyUpdatedSolutionSignature();
21752176
}
21762177
}
21772178
}
@@ -3200,7 +3201,7 @@ public void generateNewBlock(int block_version)
32003201

32013202
removeBlockBlacklist(localNewBlock);
32023203

3203-
BlockSignature signature_data = localNewBlock.applySignature(PresenceList.getPowSolution());
3204+
BlockSignature signature_data = localNewBlock.applySignature(Node.signerPowMiner.GetBestSolution(localNewBlock.blockNum));
32043205
if (signature_data != null)
32053206
{
32063207
InventoryCache.Instance.setProcessedFlag(InventoryItemTypes.blockSignature, InventoryItemSignature.getHash(signature_data.recipientPubKeyOrAddress.addressNoChecksum, localNewBlock.blockChecksum));
@@ -4070,7 +4071,7 @@ public void applyUpdatedSolutionSignature()
40704071
for (uint i = 0; i < 5; i++)
40714072
{
40724073
Block b = Node.blockChain.getBlock(lastBlockHeight - i);
4073-
BlockSignature blockSig = b.applySignature(PresenceList.getPowSolution());
4074+
BlockSignature blockSig = b.applySignature(Node.signerPowMiner.GetBestSolution(b.blockNum));
40744075
if (blockSig != null)
40754076
{
40764077
InventoryCache.Instance.setProcessedFlag(InventoryItemTypes.blockSignature, InventoryItemSignature.getHash(blockSig.recipientPubKeyOrAddress.addressNoChecksum, b.blockChecksum));

IxianDLT/Block/BlockSync.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ private void stopSyncStartBlockProcessing()
11301130

11311131
Node.blockProcessor.firstBlockAfterSync = true;
11321132
Node.blockProcessor.resumeOperation();
1133-
Node.signerPowMiner.start(Config.cpuThreads > 2 ? (int)Config.cpuThreads / 2 : 1);
1133+
Node.signerPowMiner.Start(Config.cpuThreads > 2 ? (int)Config.cpuThreads / 2 : 1);
11341134

11351135
lock (pendingBlocks)
11361136
{

IxianDLT/Meta/Node.cs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,11 @@ public void start(bool verboseConsoleOutput)
377377

378378
UpdateVerify.start();
379379

380+
signerPowMiner = new SignerPowMiner();
381+
//signerPowMiner.test();
382+
380383
// Generate presence list
381-
PresenceList.init(IxianHandler.publicIP, Config.serverPort, node_type, CoreConfig.serverKeepAliveInterval);
384+
PresenceList.init(IxianHandler.publicIP, Config.serverPort, node_type, CoreConfig.serverKeepAliveInterval, signerPowMiner);
382385

383386
activityStorage = new ActivityStorage(Config.activityFolderPath, 32 << 20, 0);
384387
activityStorage.prepareStorage(true);
@@ -416,9 +419,7 @@ public void start(bool verboseConsoleOutput)
416419
}
417420

418421
miner = new Miner();
419-
signerPowMiner = new SignerPowMiner();
420422
//Node.blockProcessor.resumeOperation();
421-
//signerPowMiner.test();
422423

423424
// Start the network queue
424425
NetworkQueue.start();
@@ -449,7 +450,7 @@ public void start(bool verboseConsoleOutput)
449450
PresenceList.myPresenceType = 'M';
450451
IxianHandler.enableNetworkServer = true;
451452
blockProcessor.resumeOperation();
452-
signerPowMiner.start(Config.cpuThreads > 2 ? (int)Config.cpuThreads / 2 : 1);
453+
signerPowMiner.Start(Config.cpuThreads > 2 ? (int)Config.cpuThreads / 2 : 1);
453454
serverStarted = true;
454455
if (!isMasterNode())
455456
{
@@ -668,7 +669,7 @@ static public void stop()
668669

669670
if(signerPowMiner != null)
670671
{
671-
signerPowMiner.stop();
672+
signerPowMiner.Stop();
672673
signerPowMiner = null;
673674
}
674675

@@ -762,10 +763,10 @@ static public bool checkMasternodeBalance()
762763
public static void doPostSyncOperations()
763764
{
764765
if (postSyncOperationsDone
765-
|| Node.blockSync == null
766-
|| Node.blockSync.synchronizing
767-
|| !Node.blockProcessor.operating
768-
|| NetworkClientManager.getConnectedClients().Count() == 0)
766+
|| blockSync == null
767+
|| blockSync.synchronizing
768+
|| !blockProcessor.operating
769+
|| (NetworkClientManager.getConnectedClients().Count() == 0 && NetworkServer.getConnectedClients().Count() == 0))
769770
{
770771
return;
771772
}
@@ -775,7 +776,9 @@ public static void doPostSyncOperations()
775776
return;
776777
}
777778

778-
if (signerPowMiner.lastSignerPowSolution == null)
779+
signerPowMiner.pause = false;
780+
781+
if (signerPowMiner.GetBestSolution(0) == null)
779782
{
780783
return;
781784
}
@@ -793,7 +796,7 @@ public static void doPostSyncOperations()
793796
if (blockNum + 5 >= IxianHandler.getHighestKnownNetworkBlockHeight())
794797
{
795798
Block b = blockChain.getBlock(blockNum);
796-
BlockSignature blockSig = b.applySignature(PresenceList.getPowSolution());
799+
BlockSignature blockSig = b.applySignature(signerPowMiner.GetBestSolution(b.blockNum));
797800
if (blockSig != null)
798801
{
799802
InventoryCache.Instance.setProcessedFlag(InventoryItemTypes.blockSignature, InventoryItemSignature.getHash(blockSig.recipientPubKeyOrAddress.addressNoChecksum, b.blockChecksum));
@@ -1275,18 +1278,6 @@ public override long getTimeSinceLastBlock()
12751278
return blockChain.getTimeSinceLastBlock();
12761279
}
12771280

1278-
public override void onSignerSolutionFound()
1279-
{
1280-
if (Clock.getNetworkTimestamp() - blockChain.getLastBlock().timestamp > CoreConfig.blockSignaturePlCheckTimeout)
1281-
{
1282-
blockProcessor.applyUpdatedSolutionSignature();
1283-
}
1284-
1285-
blockProcessor.acceptLocalNewBlock();
1286-
1287-
PresenceList.forceSendKeepAlive = true;
1288-
}
1289-
12901281
private ulong estimateDBBlockCacheSize(ulong totalRAM)
12911282
{
12921283
const ulong MB = 1024 * 1024;

IxianDLT/Tests/BenchmarkNode.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,5 @@ public override byte[] getBlockHash(ulong blockNum)
211211
{
212212
throw new NotImplementedException();
213213
}
214-
215-
public override void onSignerSolutionFound()
216-
{
217-
throw new NotImplementedException();
218-
}
219214
}
220215
}

UnitTests/DummyIxianNode.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,5 @@ public override void shutdown()
9595
{
9696
throw new NotImplementedException();
9797
}
98-
99-
public override void onSignerSolutionFound()
100-
{
101-
throw new NotImplementedException();
102-
}
10398
}
10499
}

0 commit comments

Comments
 (0)