Skip to content

Commit 320e8f0

Browse files
committed
Merge branch 'develop' into feat/propagate-vm-error
2 parents c89cf7f + a7646f9 commit 320e8f0

File tree

7 files changed

+71
-104
lines changed

7 files changed

+71
-104
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ and this project adheres to the versioning scheme outlined in the [README.md](RE
1111

1212
- Include a reason string in the transaction receipt when a transaction is rolled back due to a post-condition. This should help users in understanding what went wrong.
1313

14+
### Changed
15+
16+
- Reduce the default `block_rejection_timeout_steps` configuration so that miners will retry faster when blocks fail to reach 70% approved or 30% rejected.
17+
1418
## [3.1.0.0.8]
1519

1620
### Added

libsigner/src/tests/mod.rs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,6 @@ fn test_simple_signer() {
142142
chunks.push(chunk_event);
143143
}
144144

145-
chunks.sort_by(|ev1, ev2| {
146-
ev1.modified_slots[0]
147-
.slot_id
148-
.partial_cmp(&ev2.modified_slots[0].slot_id)
149-
.unwrap()
150-
});
151-
152145
let thread_chunks = chunks.clone();
153146

154147
// simulate a node that's trying to push data
@@ -186,41 +179,45 @@ fn test_simple_signer() {
186179

187180
let sent_events: Vec<SignerEvent<SignerMessage>> = chunks
188181
.iter()
189-
.map(|chunk| {
190-
let msg = chunk.modified_slots[0].data.clone();
191-
let pubkey = chunk.modified_slots[0]
192-
.recover_pk()
193-
.expect("Faield to recover public key of slot");
194-
let signer_message = read_next::<SignerMessage, _>(&mut &msg[..]).unwrap();
182+
.map(|event| {
183+
let messages: Vec<(StacksPublicKey, SignerMessage)> = event
184+
.modified_slots
185+
.iter()
186+
.filter_map(|chunk| {
187+
Some((
188+
chunk.recover_pk().ok()?,
189+
read_next::<SignerMessage, _>(&mut &chunk.data[..]).ok()?,
190+
))
191+
})
192+
.collect();
195193
SignerEvent::SignerMessages {
196194
signer_set: 0,
197-
messages: vec![(pubkey, signer_message)],
195+
messages,
198196
received_time: SystemTime::now(),
199197
}
200198
})
201199
.collect();
202200

203-
for (sent_event, accepted_event) in sent_events.iter().zip(accepted_events.iter()) {
201+
for event in sent_events {
204202
let SignerEvent::SignerMessages {
205-
signer_set,
206-
messages,
207-
received_time,
208-
} = sent_event
203+
signer_set: sent_signer_set,
204+
messages: sent_messages,
205+
..
206+
} = event
209207
else {
210-
panic!("BUG: should not have sent anything but a signer message");
208+
panic!("We expect ONLY signer messages");
211209
};
212-
let SignerEvent::SignerMessages {
213-
signer_set: accepted_signer_set,
214-
messages: accepted_messages,
215-
received_time: accepted_time,
216-
} = accepted_event
217-
else {
218-
panic!("BUG: should not have accepted anything but a signer message");
219-
};
220-
221-
assert_eq!(signer_set, accepted_signer_set);
222-
assert_eq!(messages, accepted_messages);
223-
assert_ne!(received_time, accepted_time);
210+
assert!(accepted_events.iter().any(|e| {
211+
let SignerEvent::SignerMessages {
212+
signer_set: accepted_signer_set,
213+
messages: accepted_messages,
214+
..
215+
} = e
216+
else {
217+
panic!("We expect ONLY signer messages");
218+
};
219+
*accepted_signer_set == sent_signer_set && *accepted_messages == sent_messages
220+
}))
224221
}
225222
mock_stacks_node.join().unwrap();
226223
}

stacks-signer/src/client/stacks_client.rs

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ use std::time::{Duration, Instant};
2020
use blockstack_lib::chainstate::nakamoto::NakamotoBlock;
2121
use blockstack_lib::chainstate::stacks::boot::{NakamotoSignerEntry, SIGNERS_NAME};
2222
use blockstack_lib::chainstate::stacks::db::StacksBlockHeaderTypes;
23-
use blockstack_lib::chainstate::stacks::{
24-
StacksTransaction, StacksTransactionSigner, TransactionAnchorMode, TransactionAuth,
25-
TransactionContractCall, TransactionPayload, TransactionPostConditionMode,
26-
TransactionSpendingCondition, TransactionVersion,
27-
};
23+
use blockstack_lib::chainstate::stacks::TransactionVersion;
2824
use blockstack_lib::net::api::callreadonly::CallReadOnlyResponse;
2925
use blockstack_lib::net::api::get_tenures_fork_info::{
3026
TenureForkingInfo, RPC_TENURE_FORKING_INFO_PATH,
@@ -61,8 +57,6 @@ use crate::runloop::RewardCycleInfo;
6157
pub struct StacksClient {
6258
/// The stacks address of the signer
6359
stacks_address: StacksAddress,
64-
/// The private key used in all stacks node communications
65-
stacks_private_key: StacksPrivateKey,
6660
/// The stacks node HTTP base endpoint
6761
http_origin: String,
6862
/// The types of transactions
@@ -94,7 +88,6 @@ pub struct CurrentAndLastSortition {
9488
impl From<&GlobalConfig> for StacksClient {
9589
fn from(config: &GlobalConfig) -> Self {
9690
Self {
97-
stacks_private_key: config.stacks_private_key,
9891
stacks_address: config.stacks_address,
9992
http_origin: format!("http://{}", config.node_host),
10093
tx_version: config.network.to_transaction_version(),
@@ -123,7 +116,6 @@ impl StacksClient {
123116
};
124117
let stacks_address = StacksAddress::p2pkh(mainnet, &pubkey);
125118
Self {
126-
stacks_private_key,
127119
stacks_address,
128120
http_origin: format!("http://{}", node_host),
129121
tx_version,
@@ -756,60 +748,6 @@ impl StacksClient {
756748
fn tenure_tip_path(&self, consensus_hash: &ConsensusHash) -> String {
757749
format!("{}/v3/tenures/tip/{}", self.http_origin, consensus_hash)
758750
}
759-
760-
/// Helper function to create a stacks transaction for a modifying contract call
761-
#[allow(clippy::too_many_arguments)]
762-
pub fn build_unsigned_contract_call_transaction(
763-
contract_addr: &StacksAddress,
764-
contract_name: ContractName,
765-
function_name: ClarityName,
766-
function_args: &[ClarityValue],
767-
stacks_private_key: &StacksPrivateKey,
768-
tx_version: TransactionVersion,
769-
chain_id: u32,
770-
nonce: u64,
771-
) -> Result<StacksTransaction, ClientError> {
772-
let tx_payload = TransactionPayload::ContractCall(TransactionContractCall {
773-
address: *contract_addr,
774-
contract_name,
775-
function_name,
776-
function_args: function_args.to_vec(),
777-
});
778-
let public_key = StacksPublicKey::from_private(stacks_private_key);
779-
let tx_auth = TransactionAuth::Standard(
780-
TransactionSpendingCondition::new_singlesig_p2pkh(public_key).ok_or(
781-
ClientError::TransactionGenerationFailure(format!(
782-
"Failed to create spending condition from public key: {}",
783-
public_key.to_hex()
784-
)),
785-
)?,
786-
);
787-
788-
let mut unsigned_tx = StacksTransaction::new(tx_version, tx_auth, tx_payload);
789-
unsigned_tx.set_origin_nonce(nonce);
790-
791-
unsigned_tx.anchor_mode = TransactionAnchorMode::Any;
792-
unsigned_tx.post_condition_mode = TransactionPostConditionMode::Allow;
793-
unsigned_tx.chain_id = chain_id;
794-
Ok(unsigned_tx)
795-
}
796-
797-
/// Sign an unsigned transaction
798-
pub fn sign_transaction(
799-
&self,
800-
unsigned_tx: StacksTransaction,
801-
) -> Result<StacksTransaction, ClientError> {
802-
let mut tx_signer = StacksTransactionSigner::new(&unsigned_tx);
803-
tx_signer
804-
.sign_origin(&self.stacks_private_key)
805-
.map_err(|e| ClientError::TransactionGenerationFailure(e.to_string()))?;
806-
807-
tx_signer
808-
.get_tx()
809-
.ok_or(ClientError::TransactionGenerationFailure(
810-
"Failed to generate transaction from a transaction signer".to_string(),
811-
))
812-
}
813751
}
814752

815753
#[cfg(test)]

stacks-signer/src/runloop.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,15 @@ impl<Signer: SignerTrait<T>, T: StacksMessageCodec + Clone + Send + Debug> RunLo
466466
// We are either the current or a future reward cycle, so we are not stale.
467467
continue;
468468
}
469-
if let ConfiguredSigner::RegisteredSigner(signer) = signer {
470-
if !signer.has_unprocessed_blocks() {
471-
debug!("{signer}: Signer's tenure has completed.");
469+
match signer {
470+
ConfiguredSigner::RegisteredSigner(signer) => {
471+
if !signer.has_unprocessed_blocks() {
472+
debug!("{signer}: Signer's tenure has completed.");
473+
to_delete.push(*idx);
474+
}
475+
}
476+
ConfiguredSigner::NotRegistered { .. } => {
477+
debug!("{signer}: Unregistered signer's tenure has completed.");
472478
to_delete.push(*idx);
473479
}
474480
}

stackslib/src/config/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,9 +2244,9 @@ impl Default for MinerConfig {
22442244

22452245
block_rejection_timeout_steps: {
22462246
let mut rejections_timeouts_default_map = HashMap::<u32, Duration>::new();
2247-
rejections_timeouts_default_map.insert(0, Duration::from_secs(600));
2248-
rejections_timeouts_default_map.insert(10, Duration::from_secs(300));
2249-
rejections_timeouts_default_map.insert(20, Duration::from_secs(150));
2247+
rejections_timeouts_default_map.insert(0, Duration::from_secs(180));
2248+
rejections_timeouts_default_map.insert(10, Duration::from_secs(90));
2249+
rejections_timeouts_default_map.insert(20, Duration::from_secs(45));
22502250
rejections_timeouts_default_map.insert(30, Duration::from_secs(0));
22512251
rejections_timeouts_default_map
22522252
},
@@ -2835,6 +2835,7 @@ impl MinerConfigFile {
28352835
})
28362836
}
28372837
}
2838+
28382839
#[derive(Clone, Deserialize, Default, Debug)]
28392840
#[serde(deny_unknown_fields)]
28402841
pub struct AtlasConfigFile {

testnet/stacks-node/src/nakamoto_node/miner.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,16 @@ impl BlockMinerThread {
704704
)?
705705
.ok_or_else(|| NakamotoNodeError::UnexpectedChainState)?;
706706

707-
if processed {
707+
// Once the block has been processed and the miner is no longer
708+
// blocked, we can continue mining.
709+
if processed
710+
&& !(*self
711+
.globals
712+
.get_miner_status()
713+
.lock()
714+
.expect("FATAL: mutex poisoned"))
715+
.is_blocked()
716+
{
708717
break;
709718
}
710719

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12115,8 +12115,20 @@ fn repeated_rejection() {
1211512115
let send_amt = 100;
1211612116
let send_fee = 180;
1211712117
let recipient = PrincipalData::from(StacksAddress::burn_address(false));
12118-
let mut signer_test: SignerTest<SpawnedSigner> =
12119-
SignerTest::new(num_signers, vec![(sender_addr, (send_amt + send_fee) * 3)]);
12118+
let mut signer_test: SignerTest<SpawnedSigner> = SignerTest::new_with_config_modifications(
12119+
num_signers,
12120+
vec![(sender_addr, (send_amt + send_fee) * 3)],
12121+
|_| {},
12122+
|config| {
12123+
config.miner.block_rejection_timeout_steps.clear();
12124+
config
12125+
.miner
12126+
.block_rejection_timeout_steps
12127+
.insert(0, Duration::from_secs(120));
12128+
},
12129+
None,
12130+
None,
12131+
);
1212012132
let http_origin = format!("http://{}", &signer_test.running_nodes.conf.node.rpc_bind);
1212112133
signer_test.boot_to_epoch_3();
1212212134

0 commit comments

Comments
 (0)