Skip to content

Commit

Permalink
Compare potential signature count in catchup
Browse files Browse the repository at this point in the history
During catchup if we fetch a header we should check if it has more
signatures after adding ones we have in memory.
  • Loading branch information
hewison-chris committed Feb 22, 2022
1 parent d855de7 commit fd41c2f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
10 changes: 6 additions & 4 deletions source/agora/network/Manager.d
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,8 @@ public class NetworkManager
***************************************************************************/

public void getMissingBlockSigs (Ledger ledger,
scope void delegate (BlockHeader) @safe acceptHeader) @safe nothrow
scope ulong delegate(BlockHeader) @safe extra_sigs,
scope void delegate(BlockHeader) @safe acceptHeader) @safe nothrow
{
import std.algorithm;
import std.conv;
Expand Down Expand Up @@ -939,9 +940,10 @@ public class NetworkManager
{
foreach (header; peer.getBlockHeaders(missing_heights))
{
auto sig_signed_validators = iota(enrolled_validators[header.height]).filter!(i =>
header.validators[i] || header.preimages[i] is Hash.init).count();
if (sig_signed_validators > signed_validators[header.height])
auto potential_sig_count = iota(enrolled_validators[header.height]).filter!(i =>
header.validators[i] || header.preimages[i] is Hash.init).count()
+ extra_sigs(header);
if (potential_sig_count > signed_validators[header.height])
{
try
{
Expand Down
23 changes: 22 additions & 1 deletion source/agora/node/FullNode.d
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public class FullNode : API

try
{
this.network.getMissingBlockSigs(this.ledger, &this.acceptHeader);
this.network.getMissingBlockSigs(this.ledger, &this.extra_sigs, &this.acceptHeader);
}
catch (Exception e)
{
Expand All @@ -582,6 +582,27 @@ public class FullNode : API
this.network.getUnknownTXs(this.ledger);
}

/***************************************************************************
Count extra signatures that could be added to the provided header.
For Validators this is overridden as it stores signatures and could add
them to the header if missing.
Params:
header = the block header fetched from another node
Returns:
The number of signatures that could be added to the given header,
FullNode does not store signatures so will return 0
***************************************************************************/

protected ulong extra_sigs (BlockHeader header) @safe
{
return 0;
}

/***************************************************************************
Push the header to upstream servers.
Expand Down
19 changes: 19 additions & 0 deletions source/agora/node/Validator.d
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,25 @@ public class Validator : FullNode, API
super.acceptHeader(header);
}

/***************************************************************************
Count extra signatures that could be added to the provided header.
Params:
header = the block header fetched from another node
Returns:
The number of signatures that could be added to the given header
***************************************************************************/

protected override ulong extra_sigs (BlockHeader header) @safe
{
const currentCount = header.validators.setCount;
this.nominator.updateMultiSignature(header);
return header.validators.setCount - currentCount;
}

/***************************************************************************
Receive an SCP envelope.
Expand Down

0 comments on commit fd41c2f

Please sign in to comment.