Skip to content

Commit

Permalink
Rework timer message to be driven by catchup
Browse files Browse the repository at this point in the history
The previous implementation was frequently showing the network discovery message,
which didn't make much sense to users and developers alike.
This downgrade that message to Trace level, and instead try to intelligently
print the current state of the Ledger compared to the expected state.
  • Loading branch information
Geod24 committed Feb 20, 2022
1 parent 0781022 commit 424bc25
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion source/agora/network/Manager.d
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ public class NetworkManager
this.required_peers.put(peer.key);
}

log.info(
log.trace(
"Doing periodic network discovery: {} required peers requested, {} missing, known {}",
required_peer_utxos.length, this.required_peers.length, last_known_validator_utxos.length);

Expand Down
29 changes: 23 additions & 6 deletions source/agora/node/FullNode.d
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,14 @@ public class FullNode : API
this.startTaskTimer(TimersIdx.BlockCatchup, this.config.node.block_catchup_interval);
}

if (this.network.peers.empty()) // no clients yet (discovery)
if (this.network.peers.empty())
{
// TODO: Iff the node is the single validator for the network,
// this should not be printed, or at least not be `warn`.
this.log.warn("Could not perform catchup yet because we have no peer");
return;
}

const nextHeight = Height(this.ledger.height() + 1);
log.dbg("catchupTask: getBlocksFrom height {}", nextHeight);
try
{
this.network.getMissingBlockSigs(this.ledger, &this.acceptHeader);
Expand All @@ -558,9 +561,23 @@ public class FullNode : API
{
log.error("Error sending updated block headers:{}", e);
}
this.network.getBlocksFrom(
nextHeight,
&this.addBlocks);

const Height expected = this.ledger.expectedHeight(this.clock.utcTime());
if (expected < this.ledger.height)
this.log.warn("Our current Ledger state is ahead of the expected height (current: {}, expected: {}",
this.ledger.height, expected);
else if (expected > this.ledger.height)
{
const size_t missing = expected - this.ledger.height;
this.log.info("Ledger out of sync, missing {} blocks (current height: {}, delay: {})",
missing, this.ledger.height, this.ledger.params.BlockInterval * missing);

this.network.getBlocksFrom(
this.ledger.height + 1,
&this.addBlocks);
}
// Otherwise we don't print a message, as the Ledger is up to date.

this.network.getUnknownTXs(this.ledger);
}

Expand Down

0 comments on commit 424bc25

Please sign in to comment.