Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: block broadcast when block comes from forger #2430

Merged
merged 4 commits into from
Apr 16, 2019

Conversation

air1one
Copy link
Contributor

@air1one air1one commented Apr 16, 2019

Proposed changes

When block is received from forger, always broadcast to all peers.

Also refactored the block broadcast general logic, to use "peer quotas" based on block pings, instead of using randomization to select peers to broadcast to.

Types of changes

  • Refactoring (improve a current implementation without adding a new feature or fixing a bug)

Checklist

  • I have read the CONTRIBUTING documentation
  • Lint and unit tests pass locally with my changes

@@ -63,8 +63,9 @@ export async function postBlock({ req }): Promise<void> {
const blockchain: Blockchain.IBlockchain = app.resolvePlugin<Blockchain.IBlockchain>("blockchain");

const block: Interfaces.IBlockData = req.data.block;
const fromForger = isWhitelisted(app.resolveOptions("p2p").remoteAccess, req.headers.remoteAddress);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const fromForger = isWhitelisted(app.resolveOptions("p2p").remoteAccess, req.headers.remoteAddress);
const fromForger: boolean = isWhitelisted(app.resolveOptions("p2p").remoteAccess, req.headers.remoteAddress);

@@ -310,9 +310,9 @@ export class NetworkMonitor implements P2P.INetworkMonitor {
// wait a bit before broadcasting if a bit early
const diff = blockPing.last - blockPing.first;
const maxHop = 4;
let proba = (maxHop - blockPing.count) / maxHop;
let broadcastQuota = (maxHop - blockPing.count) / maxHop;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let broadcastQuota = (maxHop - blockPing.count) / maxHop;
let broadcastQuota: number = (maxHop - blockPing.count) / maxHop;

@codecov-io
Copy link

Codecov Report

Merging #2430 into 2.4 will increase coverage by <.01%.
The diff coverage is 91.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##              2.4    #2430      +/-   ##
==========================================
+ Coverage   67.91%   67.92%   +<.01%     
==========================================
  Files         385      385              
  Lines        8438     8443       +5     
  Branches      430      392      -38     
==========================================
+ Hits         5731     5735       +4     
- Misses       2659     2660       +1     
  Partials       48       48
Impacted Files Coverage Δ
packages/core-blockchain/src/blockchain.ts 54.07% <100%> (+0.69%) ⬆️
packages/core-p2p/src/network-monitor.ts 64.49% <100%> (ø) ⬆️
...ckages/core-p2p/src/socket-server/versions/peer.ts 80% <100%> (+0.37%) ⬆️
packages/core-blockchain/src/state-storage.ts 95.65% <50%> (-1.37%) ⬇️
packages/core-logger-winston/src/formatter.ts 41.66% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d012ce8...427f0fb. Read the comment docs.

@faustbrian faustbrian merged commit 92adfad into 2.4 Apr 16, 2019
@ghost ghost deleted the refactor/block-broadcast branch April 16, 2019 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants