Trait grin_p2p::types::ChainAdapter
source · pub trait ChainAdapter: Sync + Send {
Show 26 methods
// Required methods
fn total_difficulty(&self) -> Result<Difficulty, Error>;
fn total_height(&self) -> Result<u64, Error>;
fn transaction_received(
&self,
tx: Transaction,
stem: bool
) -> Result<bool, Error>;
fn get_transaction(&self, kernel_hash: Hash) -> Option<Transaction>;
fn tx_kernel_received(
&self,
kernel_hash: Hash,
peer_info: &PeerInfo
) -> Result<bool, Error>;
fn block_received(
&self,
b: Block,
peer_info: &PeerInfo,
opts: Options
) -> Result<bool, Error>;
fn compact_block_received(
&self,
cb: CompactBlock,
peer_info: &PeerInfo
) -> Result<bool, Error>;
fn header_received(
&self,
bh: BlockHeader,
peer_info: &PeerInfo
) -> Result<bool, Error>;
fn headers_received(
&self,
bh: &[BlockHeader],
peer_info: &PeerInfo
) -> Result<bool, Error>;
fn locate_headers(
&self,
locator: &[Hash]
) -> Result<Vec<BlockHeader>, Error>;
fn get_block(&self, h: Hash, peer_info: &PeerInfo) -> Option<Block>;
fn txhashset_read(&self, h: Hash) -> Option<TxHashSetRead>;
fn txhashset_archive_header(&self) -> Result<BlockHeader, Error>;
fn txhashset_receive_ready(&self) -> bool;
fn txhashset_download_update(
&self,
start_time: DateTime<Utc>,
downloaded_size: u64,
total_size: u64
) -> bool;
fn txhashset_write(
&self,
h: Hash,
txhashset_data: File,
peer_peer_info: &PeerInfo
) -> Result<bool, Error>;
fn get_tmp_dir(&self) -> PathBuf;
fn get_tmpfile_pathname(&self, tmpfile_name: String) -> PathBuf;
fn get_kernel_segment(
&self,
hash: Hash,
id: SegmentIdentifier
) -> Result<Segment<TxKernel>, Error>;
fn get_bitmap_segment(
&self,
hash: Hash,
id: SegmentIdentifier
) -> Result<(Segment<BitmapChunk>, Hash), Error>;
fn get_output_segment(
&self,
hash: Hash,
id: SegmentIdentifier
) -> Result<(Segment<OutputIdentifier>, Hash), Error>;
fn get_rangeproof_segment(
&self,
hash: Hash,
id: SegmentIdentifier
) -> Result<Segment<RangeProof>, Error>;
fn receive_bitmap_segment(
&self,
block_hash: Hash,
output_root: Hash,
segment: Segment<BitmapChunk>
) -> Result<bool, Error>;
fn receive_output_segment(
&self,
block_hash: Hash,
bitmap_root: Hash,
segment: Segment<OutputIdentifier>
) -> Result<bool, Error>;
fn receive_rangeproof_segment(
&self,
block_hash: Hash,
segment: Segment<RangeProof>
) -> Result<bool, Error>;
fn receive_kernel_segment(
&self,
block_hash: Hash,
segment: Segment<TxKernel>
) -> Result<bool, Error>;
}
Expand description
Bridge between the networking layer and the rest of the system. Handles the forwarding or querying of blocks and transactions from the network among other things.
Required Methods§
sourcefn total_difficulty(&self) -> Result<Difficulty, Error>
fn total_difficulty(&self) -> Result<Difficulty, Error>
Current total difficulty on our chain
sourcefn total_height(&self) -> Result<u64, Error>
fn total_height(&self) -> Result<u64, Error>
Current total height
sourcefn transaction_received(
&self,
tx: Transaction,
stem: bool
) -> Result<bool, Error>
fn transaction_received( &self, tx: Transaction, stem: bool ) -> Result<bool, Error>
A valid transaction has been received from one of our peers
fn get_transaction(&self, kernel_hash: Hash) -> Option<Transaction>
fn tx_kernel_received( &self, kernel_hash: Hash, peer_info: &PeerInfo ) -> Result<bool, Error>
sourcefn block_received(
&self,
b: Block,
peer_info: &PeerInfo,
opts: Options
) -> Result<bool, Error>
fn block_received( &self, b: Block, peer_info: &PeerInfo, opts: Options ) -> Result<bool, Error>
A block has been received from one of our peers. Returns true if the block could be handled properly and is not deemed defective by the chain. Returning false means the block will never be valid and may result in the peer being banned.
fn compact_block_received( &self, cb: CompactBlock, peer_info: &PeerInfo ) -> Result<bool, Error>
fn header_received( &self, bh: BlockHeader, peer_info: &PeerInfo ) -> Result<bool, Error>
sourcefn headers_received(
&self,
bh: &[BlockHeader],
peer_info: &PeerInfo
) -> Result<bool, Error>
fn headers_received( &self, bh: &[BlockHeader], peer_info: &PeerInfo ) -> Result<bool, Error>
A set of block header has been received, typically in response to a block header request.
sourcefn locate_headers(&self, locator: &[Hash]) -> Result<Vec<BlockHeader>, Error>
fn locate_headers(&self, locator: &[Hash]) -> Result<Vec<BlockHeader>, Error>
Finds a list of block headers based on the provided locator. Tries to identify the common chain and gets the headers that follow it immediately.
sourcefn get_block(&self, h: Hash, peer_info: &PeerInfo) -> Option<Block>
fn get_block(&self, h: Hash, peer_info: &PeerInfo) -> Option<Block>
Gets a full block by its hash. Converts block to v2 compatibility if necessary (based on peer protocol version).
sourcefn txhashset_read(&self, h: Hash) -> Option<TxHashSetRead>
fn txhashset_read(&self, h: Hash) -> Option<TxHashSetRead>
Provides a reading view into the current txhashset state as well as the required indexes for a consumer to rewind to a consistant state at the provided block hash.
sourcefn txhashset_archive_header(&self) -> Result<BlockHeader, Error>
fn txhashset_archive_header(&self) -> Result<BlockHeader, Error>
Header of the txhashset archive currently being served to peers.
sourcefn txhashset_receive_ready(&self) -> bool
fn txhashset_receive_ready(&self) -> bool
Whether the node is ready to accept a new txhashset. If this isn’t the case, the archive is provided without being requested and likely an attack attempt. This should be checked before downloading the whole state data.
sourcefn txhashset_download_update(
&self,
start_time: DateTime<Utc>,
downloaded_size: u64,
total_size: u64
) -> bool
fn txhashset_download_update( &self, start_time: DateTime<Utc>, downloaded_size: u64, total_size: u64 ) -> bool
Update txhashset downloading progress
sourcefn txhashset_write(
&self,
h: Hash,
txhashset_data: File,
peer_peer_info: &PeerInfo
) -> Result<bool, Error>
fn txhashset_write( &self, h: Hash, txhashset_data: File, peer_peer_info: &PeerInfo ) -> Result<bool, Error>
Writes a reading view on a txhashset state that’s been provided to us. If we’re willing to accept that new state, the data stream will be read as a zip file, unzipped and the resulting state files should be rewound to the provided indexes.
sourcefn get_tmp_dir(&self) -> PathBuf
fn get_tmp_dir(&self) -> PathBuf
Get the Grin specific tmp dir
sourcefn get_tmpfile_pathname(&self, tmpfile_name: String) -> PathBuf
fn get_tmpfile_pathname(&self, tmpfile_name: String) -> PathBuf
Get a tmp file path in above specific tmp dir (create tmp dir if not exist) Delete file if tmp file already exists