Introduce CommitOnly variant of Inputs (#3419)
* Introduce CommitOnly variant of Inputs. Introduce CommitWrapper so we can sort commit only inputs correctly. * rememebr to resort if converting * write inputs based on variant and protocol version * read and write protocol version specific inputs * store full blocks in local db in v3 convert to v2 when relaying to v2 peers * add debug version_str for inputs * no assumptions about spent index sort order * add additional version debug logs * fix ser/deser tests for proto v3 * cleanup coinbase maturity * rework pool to better handle v2 conversion robustly * cleanup txpool add_to_pool * fix nrd kernel test * move init conversion earlier * cleanup * cleanup based on PR feedback
This commit is contained in:
+2
-19
@@ -252,23 +252,6 @@ impl Peer {
|
||||
self.send(ban_reason_msg, msg::Type::BanReason).map(|_| ())
|
||||
}
|
||||
|
||||
/// Sends the provided block to the remote peer. The request may be dropped
|
||||
/// if the remote peer is known to already have the block.
|
||||
pub fn send_block(&self, b: &core::Block) -> Result<bool, Error> {
|
||||
if !self.tracking_adapter.has_recv(b.hash()) {
|
||||
trace!("Send block {} to {}", b.hash(), self.info.addr);
|
||||
self.send(b, msg::Type::Block)?;
|
||||
Ok(true)
|
||||
} else {
|
||||
debug!(
|
||||
"Suppress block send {} to {} (already seen)",
|
||||
b.hash(),
|
||||
self.info.addr,
|
||||
);
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_compact_block(&self, b: &core::CompactBlock) -> Result<bool, Error> {
|
||||
if !self.tracking_adapter.has_recv(b.hash()) {
|
||||
trace!("Send compact block {} to {}", b.hash(), self.info.addr);
|
||||
@@ -540,8 +523,8 @@ impl ChainAdapter for TrackingAdapter {
|
||||
self.adapter.locate_headers(locator)
|
||||
}
|
||||
|
||||
fn get_block(&self, h: Hash) -> Option<core::Block> {
|
||||
self.adapter.get_block(h)
|
||||
fn get_block(&self, h: Hash, peer_info: &PeerInfo) -> Option<core::Block> {
|
||||
self.adapter.get_block(h, peer_info)
|
||||
}
|
||||
|
||||
fn txhashset_read(&self, h: Hash) -> Option<TxHashSetRead> {
|
||||
|
||||
+2
-2
@@ -667,8 +667,8 @@ impl ChainAdapter for Peers {
|
||||
self.adapter.locate_headers(hs)
|
||||
}
|
||||
|
||||
fn get_block(&self, h: Hash) -> Option<core::Block> {
|
||||
self.adapter.get_block(h)
|
||||
fn get_block(&self, h: Hash, peer_info: &PeerInfo) -> Option<core::Block> {
|
||||
self.adapter.get_block(h, peer_info)
|
||||
}
|
||||
|
||||
fn txhashset_read(&self, h: Hash) -> Option<TxHashSetRead> {
|
||||
|
||||
+2
-3
@@ -15,7 +15,6 @@
|
||||
use crate::chain;
|
||||
use crate::conn::{Message, MessageHandler, Tracker};
|
||||
use crate::core::core::{self, hash::Hash, hash::Hashed, CompactBlock};
|
||||
|
||||
use crate::msg::{
|
||||
BanReason, GetPeerAddrs, Headers, Locator, Msg, PeerAddrs, Ping, Pong, TxHashSetArchive,
|
||||
TxHashSetRequest, Type,
|
||||
@@ -153,7 +152,7 @@ impl MessageHandler for Protocol {
|
||||
msg.header.msg_len,
|
||||
);
|
||||
|
||||
let bo = adapter.get_block(h);
|
||||
let bo = adapter.get_block(h, &self.peer_info);
|
||||
if let Some(b) = bo {
|
||||
return Ok(Some(Msg::new(Type::Block, b, self.peer_info.version)?));
|
||||
}
|
||||
@@ -177,7 +176,7 @@ impl MessageHandler for Protocol {
|
||||
|
||||
Type::GetCompactBlock => {
|
||||
let h: Hash = msg.body()?;
|
||||
if let Some(b) = adapter.get_block(h) {
|
||||
if let Some(b) = adapter.get_block(h, &self.peer_info) {
|
||||
let cb: CompactBlock = b.into();
|
||||
Ok(Some(Msg::new(
|
||||
Type::CompactBlock,
|
||||
|
||||
+1
-1
@@ -335,7 +335,7 @@ impl ChainAdapter for DummyAdapter {
|
||||
fn locate_headers(&self, _: &[Hash]) -> Result<Vec<core::BlockHeader>, chain::Error> {
|
||||
Ok(vec![])
|
||||
}
|
||||
fn get_block(&self, _: Hash) -> Option<core::Block> {
|
||||
fn get_block(&self, _: Hash, _: &PeerInfo) -> Option<core::Block> {
|
||||
None
|
||||
}
|
||||
fn txhashset_read(&self, _h: Hash) -> Option<TxHashSetRead> {
|
||||
|
||||
+2
-1
@@ -599,7 +599,8 @@ pub trait ChainAdapter: Sync + Send {
|
||||
fn locate_headers(&self, locator: &[Hash]) -> Result<Vec<core::BlockHeader>, chain::Error>;
|
||||
|
||||
/// Gets a full block by its hash.
|
||||
fn get_block(&self, h: Hash) -> Option<core::Block>;
|
||||
/// Converts block to v2 compatibility if necessary (based on peer protocol version).
|
||||
fn get_block(&self, h: Hash, peer_info: &PeerInfo) -> Option<core::Block>;
|
||||
|
||||
/// Provides a reading view into the current txhashset state as well as
|
||||
/// the required indexes for a consumer to rewind to a consistant state
|
||||
|
||||
Reference in New Issue
Block a user