Skip to content

Commit d4a21e3

Browse files
committed
Merge remote-tracking branch 'core/develop' into feat/full-tx-replay
2 parents 772c942 + 172aaba commit d4a21e3

File tree

7 files changed

+387
-66
lines changed

7 files changed

+387
-66
lines changed

.github/workflows/lock-threads.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
id: lock_threads
3030
uses: stacks-network/actions/lock-threads@main
3131
with:
32-
github-token: ${{ secrets.GH_TOKEN }}
32+
github-token: ${{ secrets.GITHUB_TOKEN }}
3333
issue-inactive-days: 7
3434
pr-inactive-days: 7
3535
discussion-inactive-days: 7

libsigner/src/events.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ use stacks_common::types::chainstate::{
4646
BlockHeaderHash, BurnchainHeaderHash, ConsensusHash, SortitionId, StacksPublicKey,
4747
};
4848
use stacks_common::util::hash::{hex_bytes, Hash160, Sha512Trunc256Sum};
49-
use stacks_common::util::serde_serializers::{prefix_hex, prefix_opt_hex, prefix_string_0x};
49+
use stacks_common::util::serde_serializers::{
50+
prefix_hex, prefix_opt_hex, prefix_opt_hex, prefix_string_0x,
51+
};
5052
use stacks_common::util::HexError;
5153
use stacks_common::versions::STACKS_NODE_VERSION;
5254
use tiny_http::{

stacks-signer/src/client/mod.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use libstackerdb::Error as StackerDBError;
2828
pub use stackerdb::*;
2929
pub use stacks_client::*;
3030
use stacks_common::codec::Error as CodecError;
31-
use stacks_common::debug;
31+
use stacks_common::{debug, warn};
3232

3333
/// Backoff timer initial interval in milliseconds
3434
const BACKOFF_INITIAL_INTERVAL: u64 = 128;
@@ -103,7 +103,7 @@ pub enum ClientError {
103103
pub fn retry_with_exponential_backoff<F, E, T>(request_fn: F) -> Result<T, ClientError>
104104
where
105105
F: FnMut() -> Result<T, backoff::Error<E>>,
106-
E: std::fmt::Debug,
106+
E: std::fmt::Debug + Into<ClientError>,
107107
{
108108
let notify = |err, dur| {
109109
debug!(
@@ -117,7 +117,16 @@ where
117117
.with_max_elapsed_time(Some(Duration::from_secs(BACKOFF_MAX_ELAPSED)))
118118
.build();
119119

120-
backoff::retry_notify(backoff_timer, request_fn, notify).map_err(|_| ClientError::RetryTimeout)
120+
backoff::retry_notify(backoff_timer, request_fn, notify).map_err(|e| match e {
121+
backoff::Error::Permanent(err) => {
122+
warn!("Non-retry error during request: {err:?}");
123+
err.into()
124+
}
125+
backoff::Error::Transient { err, .. } => {
126+
warn!("Exceeded max retries during request: {err:?}");
127+
err.into()
128+
}
129+
})
121130
}
122131

123132
#[cfg(test)]

stacks-signer/src/client/stacks_client.rs

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
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};
1917

2018
use blockstack_lib::chainstate::nakamoto::NakamotoBlock;
2119
use blockstack_lib::chainstate::stacks::boot::{NakamotoSignerEntry, SIGNERS_NAME};
@@ -606,36 +604,6 @@ impl StacksClient {
606604
Ok(account_entry)
607605
}
608606

609-
/// Post a block to the stacks-node, retry forever on errors.
610-
///
611-
/// In tests, this panics if the retry takes longer than 30 seconds.
612-
pub fn post_block_until_ok<F: Display>(&self, log_fmt: &F, block: &NakamotoBlock) -> bool {
613-
debug!("StacksClient: Posting block to stacks node";
614-
"signer_signature_hash" => %block.header.signer_signature_hash(),
615-
"block_id" => %block.header.block_id(),
616-
"block_height" => %block.header.chain_length,
617-
);
618-
let start_time = Instant::now();
619-
loop {
620-
match self.post_block(block) {
621-
Ok(block_push_result) => {
622-
debug!("{log_fmt}: Block pushed to stacks node: {block_push_result:?}");
623-
return block_push_result;
624-
}
625-
Err(e) => {
626-
if cfg!(any(test, feature = "testing"))
627-
&& start_time.elapsed() > Duration::from_secs(30)
628-
{
629-
panic!(
630-
"{log_fmt}: Timed out in test while pushing block to stacks node: {e}"
631-
);
632-
}
633-
warn!("{log_fmt}: Failed to push block to stacks node: {e}. Retrying...");
634-
}
635-
};
636-
}
637-
}
638-
639607
/// Try to post a completed nakamoto block to our connected stacks-node
640608
/// Returns `true` if the block was accepted or `false` if the block
641609
/// was rejected.
@@ -648,22 +616,30 @@ impl StacksClient {
648616
let path = format!("{}{}?broadcast=1", self.http_origin, postblock_v3::PATH);
649617
let timer = crate::monitoring::actions::new_rpc_call_timer(&path, &self.http_origin);
650618
let send_request = || {
651-
self.stacks_node_client
619+
let response = self
620+
.stacks_node_client
652621
.post(&path)
653622
.header("Content-Type", "application/octet-stream")
654623
.header(AUTHORIZATION, self.auth_password.clone())
655624
.body(block.serialize_to_vec())
656625
.send()
657626
.map_err(|e| {
658627
debug!("Failed to submit block to the Stacks node: {e:?}");
659-
backoff::Error::transient(e)
660-
})
628+
backoff::Error::transient(ClientError::from(e))
629+
})?;
630+
if !response.status().is_success() {
631+
warn!(
632+
"Failed to post block to stacks-node, will retry until limit reached";
633+
"http_status" => %response.status(),
634+
);
635+
return Err(backoff::Error::transient(ClientError::RequestFailure(
636+
response.status(),
637+
)));
638+
}
639+
Ok(response)
661640
};
662641
let response = retry_with_exponential_backoff(send_request)?;
663642
timer.stop_and_record();
664-
if !response.status().is_success() {
665-
return Err(ClientError::RequestFailure(response.status()));
666-
}
667643
let post_block_resp = response.json::<StacksBlockAcceptedData>()?;
668644
Ok(post_block_resp.accepted)
669645
}

stacks-signer/src/v0/signer.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl Signer {
459459
if self.test_skip_block_broadcast(b) {
460460
return;
461461
}
462-
stacks_client.post_block_until_ok(self, b);
462+
self.handle_post_block(stacks_client, b);
463463
}
464464
SignerMessage::MockProposal(mock_proposal) => {
465465
let epoch = match stacks_client.get_node_epoch() {
@@ -1545,12 +1545,11 @@ impl Signer {
15451545
}
15461546

15471547
fn broadcast_signed_block(
1548-
&self,
1548+
&mut self,
15491549
stacks_client: &StacksClient,
15501550
mut block: NakamotoBlock,
15511551
addrs_to_sigs: &HashMap<StacksAddress, MessageSignature>,
15521552
) {
1553-
let block_hash = block.header.signer_signature_hash();
15541553
// collect signatures for the block
15551554
let signatures: Vec<_> = self
15561555
.signer_addresses
@@ -1565,17 +1564,25 @@ impl Signer {
15651564
if self.test_skip_block_broadcast(&block) {
15661565
return;
15671566
}
1568-
debug!(
1569-
"{self}: Broadcasting Stacks block {} to node",
1570-
&block.block_id()
1571-
);
1572-
stacks_client.post_block_until_ok(self, &block);
1567+
self.handle_post_block(stacks_client, &block);
1568+
}
15731569

1574-
if let Err(e) = self
1575-
.signer_db
1576-
.set_block_broadcasted(&block_hash, get_epoch_time_secs())
1577-
{
1578-
warn!("{self}: Failed to set block broadcasted for {block_hash}: {e:?}");
1570+
/// Attempt to post a block to the stacks-node and handle the result
1571+
pub fn handle_post_block(&mut self, stacks_client: &StacksClient, block: &NakamotoBlock) {
1572+
let block_hash = block.header.signer_signature_hash();
1573+
match stacks_client.post_block(block) {
1574+
Ok(accepted) => {
1575+
debug!("{self}: Block {block_hash} accepted by stacks node: {accepted}");
1576+
if let Err(e) = self
1577+
.signer_db
1578+
.set_block_broadcasted(&block_hash, get_epoch_time_secs())
1579+
{
1580+
warn!("{self}: Failed to set block broadcasted for {block_hash}: {e:?}");
1581+
}
1582+
}
1583+
Err(e) => {
1584+
warn!("{self}: Failed to broadcast block {block_hash} to the node: {e}")
1585+
}
15791586
}
15801587
}
15811588

0 commit comments

Comments
 (0)