Skip to content

Commit 21fc76d

Browse files
committed
feat: allow forced block broadcast
1 parent b41846b commit 21fc76d

File tree

1 file changed

+47
-4
lines changed

1 file changed

+47
-4
lines changed

stackslib/src/net/relay.rs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,11 +790,44 @@ impl Relayer {
790790
}
791791
Ok(res)
792792
}
793+
794+
/// Wrapper around inner_process_new_nakamoto_block
795+
pub fn process_new_nakamoto_block(
796+
burnchain: &Burnchain,
797+
sortdb: &SortitionDB,
798+
sort_handle: &mut SortitionHandleConn,
799+
chainstate: &mut StacksChainState,
800+
stacks_tip: &StacksBlockId,
801+
block: &NakamotoBlock,
802+
coord_comms: Option<&CoordinatorChannels>,
803+
obtained_method: NakamotoBlockObtainMethod,
804+
) -> Result<bool, chainstate_error> {
805+
Self::process_new_nakamoto_block_ext(
806+
burnchain,
807+
sortdb,
808+
sort_handle,
809+
chainstate,
810+
stacks_tip,
811+
block,
812+
coord_comms,
813+
obtained_method,
814+
false
815+
)
816+
}
793817

794818
/// Insert a staging Nakamoto block that got relayed to us somehow -- e.g. uploaded via http,
795819
/// downloaded by us, or pushed via p2p.
796-
/// Return Ok(true) if we stored it, Ok(false) if we didn't
797-
pub fn process_new_nakamoto_block(
820+
/// Return Ok(true) if we should broadcast the block. If force_broadcast is true, then this
821+
/// function will return Ok(true) even if we already have the block.
822+
/// Return Ok(false) if we should not broadcast it (e.g. we already have it, it was invalid,
823+
/// etc.)
824+
/// Return Err(..) in the following cases, beyond DB errors:
825+
/// * If the block is from a tenure we don't recognize
826+
/// * If we're not in the Nakamoto epoch
827+
/// * If the reward cycle info could not be determined
828+
/// * If there was an unrecognized signer
829+
/// * If the coordinator is closed, and `coord_comms` is Some(..)
830+
pub fn process_new_nakamoto_block_ext(
798831
burnchain: &Burnchain,
799832
sortdb: &SortitionDB,
800833
sort_handle: &mut SortitionHandleConn,
@@ -803,6 +836,7 @@ impl Relayer {
803836
block: &NakamotoBlock,
804837
coord_comms: Option<&CoordinatorChannels>,
805838
obtained_method: NakamotoBlockObtainMethod,
839+
force_broadcast: bool
806840
) -> Result<bool, chainstate_error> {
807841
debug!(
808842
"Handle incoming Nakamoto block {}/{} obtained via {}",
@@ -825,8 +859,16 @@ impl Relayer {
825859
e
826860
})?
827861
{
828-
debug!("Already have Nakamoto block {}", &block.header.block_id());
829-
return Ok(false);
862+
if force_broadcast {
863+
// it's possible that the signer sent this block to us, in which case, we should
864+
// broadcast it
865+
debug!("Already have Nakamoto block {}, but broadcasting anyway", &block.header.block_id());
866+
return Ok(true);
867+
}
868+
else {
869+
debug!("Already have Nakamoto block {}", &block.header.block_id());
870+
return Ok(false);
871+
}
830872
}
831873

832874
let block_sn =
@@ -2541,6 +2583,7 @@ impl Relayer {
25412583
accepted_blocks: Vec<AcceptedNakamotoBlocks>,
25422584
force_send: bool,
25432585
) {
2586+
// TODO: we don't relay HTTP-uploaded blocks :(
25442587
debug!(
25452588
"{:?}: relay {} sets of Nakamoto blocks",
25462589
_local_peer,

0 commit comments

Comments
 (0)