Skip to content

Commit

Permalink
- improved block generation interval
Browse files Browse the repository at this point in the history
- improved block signature propagation
  • Loading branch information
IxiAngel committed Nov 9, 2020
1 parent 41d0ad1 commit 54b643f
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions IxianDLT/Block/BlockProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ public void onUpdate()
}
else
{
if (timeSinceLastBlock.TotalSeconds >= blockGenerationInterval)
Block last_block = Node.blockChain.getLastBlock();
if (last_block == null || Clock.getNetworkTimestamp() - last_block.timestamp >= blockGenerationInterval)
{
if (last_block_num < 8 || Node.isElectedToGenerateNextBlock(getElectedNodeOffset()))
{
Expand Down Expand Up @@ -271,16 +272,21 @@ public void onUpdate()
// returns offset depending on time since last block and block generation interval. This function will return -1 if more than 10 block generation intervals have passed
public int getElectedNodeOffset()
{
TimeSpan timeSinceLastBlock = DateTime.UtcNow - lastBlockStartTime;
if(timeSinceLastBlock.TotalSeconds < 0)
Block b = Node.blockChain.getLastBlock();
if(b == null)
{
return -1;
}
if(timeSinceLastBlock.TotalSeconds > blockGenerationInterval * 10) // edge case, if network is stuck for more than 10 blocks always return -1 as the node offset.
long timeSinceLastBlock = Clock.getNetworkTimestamp() - b.timestamp;
if(timeSinceLastBlock < 0)
{
return 0;
}
if(timeSinceLastBlock > blockGenerationInterval * 10) // edge case, if network is stuck for more than 10 blocks always return -1 as the node offset.
{
return -1;
}
return (int)(timeSinceLastBlock.TotalSeconds / (blockGenerationInterval*3));
return (int)(timeSinceLastBlock / (blockGenerationInterval*3));
}

public List<byte[][]> getSignaturesWithoutPlEntry(Block b)
Expand Down Expand Up @@ -1306,8 +1312,8 @@ private void onBlockReceived_currentBlock(Block b, RemoteEndpoint endpoint)
foreach (var sig in added_signatures)
{
Node.inventoryCache.setProcessedFlag(InventoryItemTypes.blockSignature, InventoryItemSignature.getHash(sig[1], b.blockChecksum), true);
SignatureProtocolMessages.broadcastBlockSignature(sig[0], sig[1], b.blockNum, b.blockChecksum, endpoint, null);
}
SignatureProtocolMessages.broadcastBlockSignatures(b.blockNum, b.blockChecksum, added_signatures, endpoint);
}
}else if(localNewBlock.signatures.Count != b.signatures.Count)
{
Expand Down

0 comments on commit 54b643f

Please sign in to comment.