Skip to content

Commit

Permalink
- block signature edge case fix
Browse files Browse the repository at this point in the history
- minor improvements
- github actions fix
  • Loading branch information
IxiAngel committed Jan 19, 2025
1 parent 6037f19 commit 54dc50e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
19 changes: 9 additions & 10 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defaults:
jobs:
build:

runs-on: windows-latest
runs-on: ubuntu-latest

steps:
- name: Checkout Ixian-DLT
Expand All @@ -26,17 +26,16 @@ jobs:
path: Ixian-Core
ref: ${{ github.event.push.ref }}

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@2008f912f56e61277eefaac6d1888b750582aa16
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: 'true'
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '8.0.x'

- name: Restore dependencies
run: nuget restore DLTNode.sln
run: dotnet restore

- name: Building Ixian-DLT
run: msbuild DLTNode.sln
run: dotnet build

- name: Running Unit Tests
run: dotnet test UnitTests\bin\Debug\net6.0\unittests.dll --verbosity normal
#- name: Running Unit Tests
# run: dotnet test UnitTests\bin\Debug\net8.0\unittests.dll --verbosity normal
29 changes: 26 additions & 3 deletions IxianDLT/Block/BlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ public void onBlockReceived(Block b, RemoteEndpoint endpoint = null)

// remove signatures without PL entry but not if we're catching up with the network or if the chain is stuck
if (IxianHandler.getHighestKnownNetworkBlockHeight() < b.blockNum + 5
&& b.timestamp + 3600 > Clock.getNetworkTimestamp())
&& b.timestamp + CoreConfig.blockSignaturePlCheckTimeout > Clock.getNetworkTimestamp())
{
if (removeSignaturesWithoutPlEntry(b))
{
Expand Down Expand Up @@ -1829,7 +1829,7 @@ public bool verifyBlockSignatures(Block block, RemoteEndpoint endpoint)


if (highestNetworkBlockNum > last_block_num + 5
|| block.timestamp + 3600 < Clock.getNetworkTimestamp())
|| block.timestamp + CoreConfig.blockSignaturePlCheckTimeout < Clock.getNetworkTimestamp())
{
// catching up

Expand Down Expand Up @@ -1924,7 +1924,7 @@ public bool freezeSignatures(Block target_block)

List<BlockSignature> frozen_block_sigs = null;
if (highestNetworkBlockNum > target_block.blockNum + 10
|| target_block.timestamp + 3600 < Clock.getNetworkTimestamp())
|| target_block.timestamp + CoreConfig.blockSignaturePlCheckTimeout < Clock.getNetworkTimestamp())
{
// catching up
frozen_block_sigs = extractRequiredSignatures(target_block, required_consensus_count);
Expand Down Expand Up @@ -4131,5 +4131,28 @@ public ulong determineHighestNetworkBlockNum()
}
return netBh;
}

public void applyUpdatedSolutionSignature()
{
lock (localBlockLock)
{
var lastBlockHeight = IxianHandler.getLastBlockHeight();
if (lastBlockHeight < 5)
{
return;
}

for (uint i = 0; i < 5; i++)
{
Block b = Node.blockChain.getBlock(lastBlockHeight - i);
BlockSignature blockSig = b.applySignature(PresenceList.getPowSolution());
if (blockSig != null)
{
Node.inventoryCache.setProcessedFlag(InventoryItemTypes.blockSignature, InventoryItemSignature.getHash(blockSig.recipientPubKeyOrAddress.addressNoChecksum, b.blockChecksum), true);
SignatureProtocolMessages.broadcastBlockSignature(blockSig, b.blockNum, b.blockChecksum, null, null);
}
}
}
}
}
}
16 changes: 10 additions & 6 deletions IxianDLT/Miner/SignerPowMiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private void searchForBlock()

var submittedSolution = PresenceList.getPowSolution();
if (lastSignerPowSolution != null
&& Node.blockChain.getTimeSinceLastBlock() < 450
&& Node.blockChain.getTimeSinceLastBlock() < CoreConfig.blockSignaturePlCheckTimeout
&& lastSignerPowSolution.blockNum + calculationInterval + blockOffset > highestNetworkBlockHeight
&& (submittedSolution != null && solvingDifficulty <= submittedSolution.difficulty))
{
Expand Down Expand Up @@ -373,17 +373,15 @@ private void sendFoundSolution()
var solution = PresenceList.getPowSolution();
if (solution != null)
{
ulong lastBlockHeight = IxianHandler.getLastBlockHeight();

if (newSolution.difficulty <= solution.difficulty
&& solution.blockNum + ConsensusConfig.getPlPowBlocksValidity(IxianHandler.getLastBlockVersion()) > lastBlockHeight
&& solution.difficulty > solvingDifficulty)
&& solution.blockNum + ConsensusConfig.getPlPowBlocksValidity(IxianHandler.getLastBlockVersion()) - 1 > IxianHandler.getHighestKnownNetworkBlockHeight()
&& solution.difficulty > Node.blockChain.getMinSignerPowDifficulty(IxianHandler.getLastBlockHeight() + 1, Clock.getNetworkTimestamp()))
{
// If the new solution has a lower difficulty than the previously submitted solution and the previously submitted solution is still valid

// Check if we're mining for at least X minutes and that the blockchain isn't stuck
if (IxianHandler.getHighestKnownNetworkBlockHeight() - startedSolvingBlockHeight > ConsensusConfig.getPlPowMinCalculationBlockTime(IxianHandler.getLastBlockVersion())
&& Node.blockChain.getTimeSinceLastBlock() < 450) // TODO move 450 to CoreConfig
&& Node.blockChain.getTimeSinceLastBlock() < CoreConfig.blockSignaturePlCheckTimeout)
{
// Reset the blockReadyForMining, to stop mining on all threads
blockReadyForMining = false;
Expand All @@ -394,6 +392,12 @@ private void sendFoundSolution()
}

PresenceList.setPowSolution(newSolution);

if (Node.blockChain.getTimeSinceLastBlock() > CoreConfig.blockSignaturePlCheckTimeout)
{
Node.blockProcessor.applyUpdatedSolutionSignature();
}

Node.blockProcessor.acceptLocalNewBlock();
}
}
Expand Down

0 comments on commit 54dc50e

Please sign in to comment.