announceBlock method
Announce a block hash to specified peers Returns list of peers that successfully received the announcement
Implementation
@override
Future<List<PeerI>> announceBlock(Hash blockHash, List<PeerI> targetPeers) async {
if (_isShutdown) {
return [];
}
// Check cooldown to prevent spam
if (_isInCooldown(blockHash)) {
logger.fine('Block announcement in cooldown: $blockHash');
return [];
}
final successful = <PeerI>[];
List<Peer> peersToUse;
if (targetPeers.isNotEmpty) {
// Use specified peers (filtered for our peers)
peersToUse = targetPeers
.whereType<Peer>()
.where((p) => _peers.containsValue(p) && p.isHealthy)
.toList();
} else {
// Announce blocks to all healthy peers (more important than transactions)
peersToUse = getHealthyPeers();
}
logger.fine('Announcing block $blockHash to ${peersToUse.length} peers');
for (final peer in peersToUse) {
try {
await peer.announceBlock(blockHash);
successful.add(peer);
} catch (e) {
logger.warning('Failed to announce block to ${peer}: $e');
}
}
if (successful.isNotEmpty) {
_recordAnnouncement(blockHash);
}
return successful;
}