Skip to content

Commit ee944d7

Browse files
authored
Merge branch 'develop' into fix/clippy-ci-stacks-lib-redundant-closure
2 parents 8fb9924 + 95139fb commit ee944d7

File tree

16 files changed

+1112
-242
lines changed

16 files changed

+1112
-242
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ jobs:
136136
- tests::signer::v0::block_proposal_max_age_rejections
137137
- tests::signer::v0::global_acceptance_depends_on_block_announcement
138138
- tests::signer::v0::no_reorg_due_to_successive_block_validation_ok
139+
- tests::signer::v0::incoming_signers_ignore_block_proposals
140+
- tests::signer::v0::outgoing_signers_ignore_block_proposals
141+
- tests::signer::v0::injected_signatures_are_ignored_across_boundaries
139142
- tests::nakamoto_integrations::burn_ops_integration_test
140143
- tests::nakamoto_integrations::check_block_heights
141144
- tests::nakamoto_integrations::clarity_burn_state

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,38 @@ jobs:
164164
- check-release
165165
uses: ./.github/workflows/stacks-core-tests.yml
166166

167+
## Checks to run on built binaries
168+
##
169+
## Runs when:
170+
## - it is a release run
171+
## or:
172+
## - it is not a release run
173+
## and any of:
174+
## - this workflow is called manually
175+
## - PR is opened
176+
## - PR added to merge queue
177+
## - commit to either (development, next, master) branch
178+
stacks-core-build-tests:
179+
if: |
180+
needs.check-release.outputs.is_release == 'true' || (
181+
github.event_name == 'workflow_dispatch' ||
182+
github.event_name == 'pull_request' ||
183+
github.event_name == 'merge_group' ||
184+
(
185+
contains('
186+
refs/heads/master
187+
refs/heads/develop
188+
refs/heads/next
189+
', github.event.pull_request.head.ref) &&
190+
github.event_name == 'push'
191+
)
192+
)
193+
name: Stacks Core Build Tests
194+
needs:
195+
- rustfmt
196+
- check-release
197+
uses: ./.github/workflows/core-build-tests.yml
198+
167199
bitcoin-tests:
168200
if: |
169201
needs.check-release.outputs.is_release == 'true' || (
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Core build tests
2+
3+
# Only run when:
4+
# - PRs are (re)opened against develop branch
5+
on:
6+
workflow_call:
7+
8+
jobs:
9+
check-consts:
10+
name: Check the constants from stacks-inspect
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout the latest code
14+
id: git_checkout
15+
uses: actions/checkout@v3
16+
- name: Define Rust Toolchain
17+
id: define_rust_toolchain
18+
run: echo "RUST_TOOLCHAIN=$(cat ./rust-toolchain)" >> $GITHUB_ENV
19+
- name: Setup Rust Toolchain
20+
id: setup_rust_toolchain
21+
uses: actions-rust-lang/setup-rust-toolchain@v1
22+
with:
23+
toolchain: ${{ env.RUST_TOOLCHAIN }}
24+
- name: Build the binaries
25+
id: build
26+
run: |
27+
cargo build
28+
- name: Dump constants JSON
29+
id: consts-dump
30+
run: cargo run --bin stacks-inspect -- dump-consts | tee out.json
31+
- name: Set expected constants JSON
32+
id: expects-json
33+
run: diff out.json ./sample/expected_consts.json

pox-locking/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ mutants = "0.0.3"
2828

2929
[features]
3030
slog_json = ["stacks_common/slog_json", "clarity/slog_json"]
31+
testing = []

sample/expected_consts.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"chain_id_mainnet": 1,
3+
"chain_id_testnet": 2147483648,
4+
"microstacks_per_stacks": 1000000,
5+
"miner_reward_maturity": 100,
6+
"network_id_mainnet": 385875968,
7+
"network_id_testnet": 4278190080,
8+
"peer_version_mainnet_major": 402653184,
9+
"peer_version_testnet_major": 4207599104,
10+
"signer_slots_per_user": 13,
11+
"stacks_epoch_max": 9223372036854775807
12+
}

stacks-common/src/util/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use std::time::{SystemTime, UNIX_EPOCH};
3636
use std::{error, fmt, thread, time};
3737

3838
/// Given a relative path inside the Cargo workspace, return the absolute path
39-
#[cfg(any(test, feature = "testing"))]
4039
pub fn cargo_workspace<P>(relative_path: P) -> PathBuf
4140
where
4241
P: AsRef<Path>,

stacks-signer/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ serde_stacker = "0.1"
3636
slog = { version = "2.5.2", features = [ "max_level_trace" ] }
3737
slog-json = { version = "2.3.0", optional = true }
3838
slog-term = "2.6.0"
39-
stacks-common = { path = "../stacks-common", features = ["testing"] }
39+
stacks-common = { path = "../stacks-common" }
4040
stackslib = { path = "../stackslib" }
4141
thiserror = { workspace = true }
4242
tiny_http = { version = "0.12", optional = true }
@@ -49,6 +49,7 @@ rusqlite = { workspace = true, features = ["functions"] }
4949

5050
[dev-dependencies]
5151
clarity = { path = "../clarity", features = ["testing"] }
52+
stacks-common = { path = "../stacks-common", features = ["testing"] }
5253
num-traits = "0.2.18"
5354

5455
[dependencies.serde_json]

stacks-signer/src/chainstate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ impl SortitionsView {
539539
///
540540
/// The rationale here is that the signer DB can be out-of-sync with the node. For example,
541541
/// the signer may have been added to an already-running node.
542-
fn check_tenure_change_confirms_parent(
542+
pub fn check_tenure_change_confirms_parent(
543543
tenure_change: &TenureChangePayload,
544544
block: &NakamotoBlock,
545545
signer_db: &mut SignerDb,

stacks-signer/src/runloop.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ use stacks_common::{debug, error, info, warn};
2626
use crate::chainstate::SortitionsView;
2727
use crate::client::{retry_with_exponential_backoff, ClientError, StacksClient};
2828
use crate::config::{GlobalConfig, SignerConfig};
29+
#[cfg(any(test, feature = "testing"))]
30+
use crate::v0::tests::TEST_SKIP_SIGNER_CLEANUP;
2931
use crate::Signer as SignerTrait;
3032

3133
#[derive(thiserror::Error, Debug)]
@@ -46,6 +48,8 @@ pub struct StateInfo {
4648
pub runloop_state: State,
4749
/// the current reward cycle info
4850
pub reward_cycle_info: Option<RewardCycleInfo>,
51+
/// The current running signers reward cycles
52+
pub running_signers: Vec<u64>,
4953
}
5054

5155
/// The signer result that can be sent across threads
@@ -421,6 +425,11 @@ impl<Signer: SignerTrait<T>, T: StacksMessageCodec + Clone + Send + Debug> RunLo
421425
}
422426

423427
fn cleanup_stale_signers(&mut self, current_reward_cycle: u64) {
428+
#[cfg(any(test, feature = "testing"))]
429+
if TEST_SKIP_SIGNER_CLEANUP.get() {
430+
warn!("Skipping signer cleanup due to testing directive.");
431+
return;
432+
}
424433
let mut to_delete = Vec::new();
425434
for (idx, signer) in &mut self.stacks_signers {
426435
let reward_cycle = signer.reward_cycle();
@@ -467,6 +476,11 @@ impl<Signer: SignerTrait<T>, T: StacksMessageCodec + Clone + Send + Debug>
467476
if let Err(e) = res.send(vec![StateInfo {
468477
runloop_state: self.state,
469478
reward_cycle_info: self.current_reward_cycle_info,
479+
running_signers: self
480+
.stacks_signers
481+
.values()
482+
.map(|s| s.reward_cycle())
483+
.collect(),
470484
}
471485
.into()])
472486
{

stacks-signer/src/signerdb.rs

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -733,18 +733,6 @@ impl SignerDb {
733733
try_deserialize(result)
734734
}
735735

736-
/// Return the last accepted block the signer (highest stacks height). It will tie break a match based on which was more recently signed.
737-
pub fn get_signer_last_accepted_block(&self) -> Result<Option<BlockInfo>, DBError> {
738-
let query = "SELECT block_info FROM blocks WHERE state IN (?1, ?2) ORDER BY stacks_height DESC, signed_group DESC, signed_self DESC LIMIT 1";
739-
let args = params![
740-
&BlockState::GloballyAccepted.to_string(),
741-
&BlockState::LocallyAccepted.to_string()
742-
];
743-
let result: Option<String> = query_row(&self.db, query, args)?;
744-
745-
try_deserialize(result)
746-
}
747-
748736
/// Return the last accepted block in a tenure (identified by its consensus hash).
749737
pub fn get_last_accepted_block(
750738
&self,
@@ -972,22 +960,6 @@ impl SignerDb {
972960
Ok(Some(broadcasted))
973961
}
974962

975-
/// Get the current state of a given block in the database
976-
pub fn get_block_state(
977-
&self,
978-
block_sighash: &Sha512Trunc256Sum,
979-
) -> Result<Option<BlockState>, DBError> {
980-
let qry = "SELECT state FROM blocks WHERE signer_signature_hash = ?1 LIMIT 1";
981-
let args = params![block_sighash];
982-
let state_opt: Option<String> = query_row(&self.db, qry, args)?;
983-
let Some(state) = state_opt else {
984-
return Ok(None);
985-
};
986-
Ok(Some(
987-
BlockState::try_from(state.as_str()).map_err(|_| DBError::Corruption)?,
988-
))
989-
}
990-
991963
/// Return the start time (epoch time in seconds) and the processing time in milliseconds of the tenure (idenfitied by consensus_hash).
992964
fn get_tenure_times(&self, tenure: &ConsensusHash) -> Result<(u64, u64), DBError> {
993965
let query = "SELECT tenure_change, proposed_time, validation_time_ms FROM blocks WHERE consensus_hash = ?1 AND state = ?2 ORDER BY stacks_height DESC";
@@ -1145,13 +1117,6 @@ mod tests {
11451117
.expect("Unable to get block from db");
11461118

11471119
assert_eq!(BlockInfo::from(block_proposal_2.clone()), block_info);
1148-
// test getting the block state
1149-
let block_state = db
1150-
.get_block_state(&block_proposal_1.block.header.signer_signature_hash())
1151-
.unwrap()
1152-
.expect("Unable to get block state from db");
1153-
1154-
assert_eq!(block_state, BlockInfo::from(block_proposal_1.clone()).state);
11551120
}
11561121

11571122
#[test]
@@ -1769,69 +1734,4 @@ mod tests {
17691734
< block_infos[0].proposed_time
17701735
);
17711736
}
1772-
1773-
#[test]
1774-
fn signer_last_accepted_block() {
1775-
let db_path = tmp_db_path();
1776-
let mut db = SignerDb::new(db_path).expect("Failed to create signer db");
1777-
1778-
let (mut block_info_1, _block_proposal_1) = create_block_override(|b| {
1779-
b.block.header.miner_signature = MessageSignature([0x01; 65]);
1780-
b.block.header.chain_length = 1;
1781-
b.burn_height = 1;
1782-
});
1783-
1784-
let (mut block_info_2, _block_proposal_2) = create_block_override(|b| {
1785-
b.block.header.miner_signature = MessageSignature([0x02; 65]);
1786-
b.block.header.chain_length = 2;
1787-
b.burn_height = 1;
1788-
});
1789-
1790-
let (mut block_info_3, _block_proposal_3) = create_block_override(|b| {
1791-
b.block.header.miner_signature = MessageSignature([0x02; 65]);
1792-
b.block.header.chain_length = 2;
1793-
b.burn_height = 4;
1794-
});
1795-
block_info_3
1796-
.mark_locally_accepted(false)
1797-
.expect("Failed to mark block as locally accepted");
1798-
1799-
db.insert_block(&block_info_1)
1800-
.expect("Unable to insert block into db");
1801-
db.insert_block(&block_info_2)
1802-
.expect("Unable to insert block into db");
1803-
1804-
assert!(db.get_signer_last_accepted_block().unwrap().is_none());
1805-
1806-
block_info_1
1807-
.mark_globally_accepted()
1808-
.expect("Failed to mark block as globally accepted");
1809-
db.insert_block(&block_info_1)
1810-
.expect("Unable to insert block into db");
1811-
1812-
assert_eq!(
1813-
db.get_signer_last_accepted_block().unwrap().unwrap(),
1814-
block_info_1
1815-
);
1816-
1817-
block_info_2
1818-
.mark_globally_accepted()
1819-
.expect("Failed to mark block as globally accepted");
1820-
block_info_2.signed_self = Some(get_epoch_time_secs());
1821-
db.insert_block(&block_info_2)
1822-
.expect("Unable to insert block into db");
1823-
1824-
assert_eq!(
1825-
db.get_signer_last_accepted_block().unwrap().unwrap(),
1826-
block_info_2
1827-
);
1828-
1829-
db.insert_block(&block_info_3)
1830-
.expect("Unable to insert block into db");
1831-
1832-
assert_eq!(
1833-
db.get_signer_last_accepted_block().unwrap().unwrap(),
1834-
block_info_3
1835-
);
1836-
}
18371737
}

0 commit comments

Comments
 (0)