Skip to content

Commit

Permalink
Track originaing peer for block gossip
Browse files Browse the repository at this point in the history
  • Loading branch information
danield9tqh committed Sep 5, 2023
1 parent e39f3b4 commit 8dcf6a3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
19 changes: 18 additions & 1 deletion ironfish/src/network/blockFetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,28 @@ export class BlockFetcher {
action: 'PROCESSING_COMPACT_BLOCK',
peer: peer.state.identity,
compactBlock,
sources: currentState ? currentState.sources : new Set<Identity>(),
sources: currentState ? currentState.sources : new Set<Identity>([peer.state.identity]),
})
return true
}

/**
* Return the first peer that notified us of this block
*/
firstSeenBy(hash: BlockHash): Identity | undefined {
const currentState = this.pending.get(hash)

if (!currentState || currentState.action === 'PROCESSING_FULL_BLOCK') {
return undefined
}

// According to docs, values are returned in insertion order
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set/values
for (const v of currentState.sources.values()) {
return v
}
}

requestBlockTransactions(
peer: Peer,
header: BlockHeader,
Expand Down
4 changes: 3 additions & 1 deletion ironfish/src/network/peerNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1198,13 +1198,15 @@ export class PeerNetwork {
return
}

const firstPeer = this.blockFetcher.firstSeenBy(block.header.hash)

// Mark that we've assembled a full block in the block fetcher
this.blockFetcher.receivedFullBlock(block)

this.broadcastBlock(block)

// log that we've validated the block enough to gossip it
this.telemetry.submitNewBlockSeen(block, new Date())
this.telemetry.submitNewBlockSeen(block, new Date(), firstPeer)

// verify the full block
const verified = await this.chain.verifier.verifyBlockAdd(block, prevHeader)
Expand Down
7 changes: 6 additions & 1 deletion ironfish/src/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export class Telemetry {
})
}

submitNewBlockSeen(block: Block, seenAt: Date): void {
submitNewBlockSeen(block: Block, seenAt: Date, peerId?: Identity): void {
this.submit({
measurement: 'block_propagation',
timestamp: seenAt,
Expand All @@ -419,6 +419,11 @@ export class Telemetry {
type: 'integer',
value: block.header.timestamp.valueOf(),
},
{
name: 'firstSeenBy',
type: 'string',
value: peerId || '',
},
{
name: 'sequence',
type: 'integer',
Expand Down

0 comments on commit 8dcf6a3

Please sign in to comment.