-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Report Peers that give bad Block Info #1331
Changes from 12 commits
0be8bf6
a8a388b
bb4ec70
36ee8f8
c27b261
9448c0f
fcc862c
6aafc43
ea711ab
08b01a4
d988f61
45d0b53
c71c876
fc4aa10
07a1804
6ab71d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ use fuel_core_services::stream::BoxStream; | |
use fuel_core_sync::ports::{ | ||
BlockImporterPort, | ||
ConsensusPort, | ||
PeerReportReason, | ||
PeerToPeerPort, | ||
}; | ||
use fuel_core_types::{ | ||
|
@@ -21,6 +22,10 @@ use fuel_core_types::{ | |
fuel_tx::Transaction, | ||
fuel_types::BlockHeight, | ||
services::p2p::{ | ||
peer_reputation::{ | ||
AppScore, | ||
PeerReport, | ||
}, | ||
PeerId, | ||
SourcePeer, | ||
}, | ||
|
@@ -46,25 +51,17 @@ impl PeerToPeerPort for P2PAdapter { | |
async fn get_sealed_block_headers( | ||
&self, | ||
block_range_height: Range<u32>, | ||
) -> anyhow::Result<Option<Vec<SourcePeer<SealedBlockHeader>>>> { | ||
) -> anyhow::Result<SourcePeer<Option<Vec<SealedBlockHeader>>>> { | ||
if let Some(service) = &self.service { | ||
Ok(service | ||
.get_sealed_block_headers(block_range_height) | ||
.await? | ||
.and_then(|(peer_id, headers)| { | ||
let peer_id: PeerId = peer_id.into(); | ||
headers.map(|headers| { | ||
headers | ||
.into_iter() | ||
.map(|header| SourcePeer { | ||
peer_id: peer_id.clone(), | ||
data: header, | ||
}) | ||
.collect() | ||
}) | ||
})) | ||
let (peer_id, headers) = | ||
service.get_sealed_block_headers(block_range_height).await?; | ||
let sourced_headers = SourcePeer { | ||
peer_id: peer_id.into(), | ||
data: headers, | ||
}; | ||
Ok(sourced_headers) | ||
} else { | ||
Ok(None) | ||
Err(anyhow::anyhow!("No P2P service available")) | ||
} | ||
} | ||
|
||
|
@@ -81,7 +78,45 @@ impl PeerToPeerPort for P2PAdapter { | |
.get_transactions_from_peer(peer_id.into(), block) | ||
.await | ||
} else { | ||
Ok(None) | ||
Err(anyhow::anyhow!("No P2P service available")) | ||
} | ||
} | ||
|
||
async fn report_peer( | ||
&self, | ||
peer: PeerId, | ||
report: PeerReportReason, | ||
) -> anyhow::Result<()> { | ||
if let Some(service) = &self.service { | ||
let service_name = "Sync"; | ||
let new_peer_report_reason: NewPeerReportReason = report.into(); | ||
service.report_peer(peer, new_peer_report_reason, service_name)?; | ||
Ok(()) | ||
} else { | ||
Err(anyhow::anyhow!("No P2P service available")) | ||
} | ||
} | ||
} | ||
|
||
struct NewPeerReportReason(PeerReportReason); | ||
|
||
impl From<PeerReportReason> for NewPeerReportReason { | ||
fn from(reason: PeerReportReason) -> Self { | ||
Self(reason) | ||
} | ||
} | ||
|
||
impl PeerReport for NewPeerReportReason { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are arbitrary values. We should do a spike or something to determine good values. Should we move these to a config? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a config struct or constants file containing all the reputation values seems useful. They could still be hardcoded for now, but it would let us manage all the reputation behaviors from a single place that's easy to find. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay. I added a config to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
fn get_score_from_report(&self) -> AppScore { | ||
match self.0 { | ||
// Good | ||
PeerReportReason::SuccessfulBlockImport => 5., | ||
// Bad | ||
PeerReportReason::BadBlockHeader => -100., | ||
PeerReportReason::MissingTransactions => -100., | ||
PeerReportReason::InvalidTransactions => -100., | ||
PeerReportReason::MissingBlockHeaders => -100., | ||
PeerReportReason::InvalidBlock => -100., | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this removed from the breaking section?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were two
Breaking
sections.