diff --git a/blockchain/Cargo.toml b/blockchain/Cargo.toml index 6e8074bf9956..202dc9a4de86 100644 --- a/blockchain/Cargo.toml +++ b/blockchain/Cargo.toml @@ -9,5 +9,6 @@ edition = "2018" [dependencies] vm = {path = "../vm"} address = {path = "../vm/address"} +libp2p = { git = "https://github.com/SigP/rust-libp2p", rev = "cdd5251d29e21a01aa2ffed8cb577a37a0f9e2eb" } cid = "0.3.1" multihash = "0.8.0" \ No newline at end of file diff --git a/blockchain/src/chain_sync/block_msg.rs b/blockchain/src/chain_sync/block_msg.rs new file mode 100644 index 000000000000..ff8888b0b290 --- /dev/null +++ b/blockchain/src/chain_sync/block_msg.rs @@ -0,0 +1,39 @@ +use crate::blocks::TipSetKeys; +use libp2p::PeerId; +use std::fmt; + +/// BlockMsg is a container used to decode pubsub messages into prior to validation and propagation +/// see https://github.com/filecoin-project/go-filecoin/blob/master/internal/pkg/block/chain_info.go for reference +pub struct BlockMsg { + // the originator of the TipSetKey propagation wave + _source: PeerId, + // the peer that sent us the TipSetKey message + _sender: PeerId, + // proposed canonical tipset keys + _head: TipSetKeys, + // proposed chain height + _height: u64, +} + +impl BlockMsg { + /// new creates a BlockMsg container for peer id a head tipset key and chain height + fn _new(_source: PeerId, _sender: PeerId, _head: TipSetKeys, _height: u64) -> Self { + Self { + _source, + _sender, + _head, + _height, + } + } +} + +/// human-readable string representation of a block msg +impl fmt::Display for BlockMsg { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "{} {} {:?} {}", + self._source, self._sender, self._head, self._height + ) + } +} diff --git a/blockchain/src/chain_sync/block_proposer.rs b/blockchain/src/chain_sync/block_proposer.rs index 712bca98a922..545db3418e61 100644 --- a/blockchain/src/chain_sync/block_proposer.rs +++ b/blockchain/src/chain_sync/block_proposer.rs @@ -1,7 +1,8 @@ +use super::BlockMsg; use std::io; - -trait BlockProposer { - fn send_hello(&self) -> Result<(), io::Error>; - // fn send_own_block(&self) -> Result<(), io:Error>; - // fn send_gossip_block(&self) -> Result<(), io:Error>; +/// BlockProposer allows callers to propose new blocks for inclusion in the chain +pub trait BlockProposer { + fn send_hello(&self, bm: BlockMsg) -> Result<(), io::Error>; + fn send_own_block(&self, bm: BlockMsg) -> Result<(), io::Error>; + fn send_gossip_block(&self, bm: BlockMsg) -> Result<(), io::Error>; } diff --git a/blockchain/src/chain_sync/mod.rs b/blockchain/src/chain_sync/mod.rs index a6763136cfcd..9f9e0ffc1fba 100644 --- a/blockchain/src/chain_sync/mod.rs +++ b/blockchain/src/chain_sync/mod.rs @@ -1 +1,4 @@ +mod block_msg; mod block_proposer; + +pub use block_msg::*;