Skip to content

Commit 2003a72

Browse files
authored
Merge branch 'develop' into feat/naka-miner-heuristics
2 parents 90c2596 + 3bd42e0 commit 2003a72

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

stacks-signer/src/client/stacks_client.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
use std::collections::{HashMap, VecDeque};
17+
use std::fmt::Display;
18+
use std::time::{Duration, Instant};
1719

1820
use blockstack_lib::chainstate::nakamoto::NakamotoBlock;
1921
use blockstack_lib::chainstate::stacks::boot::{NakamotoSignerEntry, SIGNERS_NAME};
@@ -564,6 +566,29 @@ impl StacksClient {
564566
Ok(account_entry)
565567
}
566568

569+
/// Post a block to the stacks-node, retry forever on errors.
570+
///
571+
/// In tests, this panics if the retry takes longer than 30 seconds.
572+
pub fn post_block_until_ok<F: Display>(&self, log_fmt: &F, block: &NakamotoBlock) -> bool {
573+
let start_time = Instant::now();
574+
loop {
575+
match self.post_block(block) {
576+
Ok(block_push_result) => {
577+
debug!("{log_fmt}: Block pushed to stacks node: {block_push_result:?}");
578+
return block_push_result;
579+
}
580+
Err(e) => {
581+
if cfg!(test) && start_time.elapsed() > Duration::from_secs(30) {
582+
panic!(
583+
"{log_fmt}: Timed out in test while pushing block to stacks node: {e}"
584+
);
585+
}
586+
warn!("{log_fmt}: Failed to push block to stacks node: {e}. Retrying...");
587+
}
588+
};
589+
}
590+
}
591+
567592
/// Try to post a completed nakamoto block to our connected stacks-node
568593
/// Returns `true` if the block was accepted or `false` if the block
569594
/// was rejected.

stacks-signer/src/v0/signer.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -185,31 +185,13 @@ impl SignerTrait<SignerMessage> for Signer {
185185
);
186186
}
187187
SignerMessage::BlockPushed(b) => {
188-
let block_push_result = stacks_client.post_block(b);
189-
if let Err(ref e) = &block_push_result {
190-
warn!(
191-
"{self}: Failed to post block {} (id {}): {e:?}",
192-
&b.header.signer_signature_hash(),
193-
&b.block_id()
194-
);
195-
};
196188
// This will infinitely loop until the block is acknowledged by the node
197189
info!(
198190
"{self}: Got block pushed message";
199191
"block_id" => %b.block_id(),
200192
"signer_sighash" => %b.header.signer_signature_hash(),
201193
);
202-
loop {
203-
match stacks_client.post_block(b) {
204-
Ok(block_push_result) => {
205-
debug!("{self}: Block pushed to stacks node: {block_push_result:?}");
206-
break;
207-
}
208-
Err(e) => {
209-
warn!("{self}: Failed to push block to stacks node: {e}. Retrying...");
210-
}
211-
};
212-
}
194+
stacks_client.post_block_until_ok(self, &b);
213195
}
214196
SignerMessage::MockProposal(mock_proposal) => {
215197
let epoch = match stacks_client.get_node_epoch() {
@@ -908,15 +890,7 @@ impl Signer {
908890
"{self}: Broadcasting Stacks block {} to node",
909891
&block.block_id()
910892
);
911-
if let Err(e) = stacks_client.post_block(&block) {
912-
warn!(
913-
"{self}: Failed to post block {block_hash}: {e:?}";
914-
"stacks_block_id" => %block.block_id(),
915-
"parent_block_id" => %block.header.parent_block_id,
916-
"burnchain_consensus_hash" => %block.header.consensus_hash
917-
);
918-
return;
919-
}
893+
stacks_client.post_block_until_ok(self, &block);
920894

921895
if let Err(e) = self.signer_db.set_block_broadcasted(
922896
self.reward_cycle,

0 commit comments

Comments
 (0)