Skip to content

Commit 91c38d0

Browse files
committed
Merge remote-tracking branch 'origin/develop' into feat/retry-pending-block-proposals
2 parents d667a4e + 95139fb commit 91c38d0

File tree

16 files changed

+1112
-226
lines changed

16 files changed

+1112
-226
lines changed

.github/workflows/bitcoin-tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ jobs:
137137
- tests::signer::v0::block_proposal_max_age_rejections
138138
- tests::signer::v0::global_acceptance_depends_on_block_announcement
139139
- tests::signer::v0::no_reorg_due_to_successive_block_validation_ok
140+
- tests::signer::v0::incoming_signers_ignore_block_proposals
141+
- tests::signer::v0::outgoing_signers_ignore_block_proposals
142+
- tests::signer::v0::injected_signatures_are_ignored_across_boundaries
140143
- tests::nakamoto_integrations::burn_ops_integration_test
141144
- tests::nakamoto_integrations::check_block_heights
142145
- 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 & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -768,18 +768,6 @@ impl SignerDb {
768768
try_deserialize(result)
769769
}
770770

771-
/// Return the last accepted block the signer (highest stacks height). It will tie break a match based on which was more recently signed.
772-
pub fn get_signer_last_accepted_block(&self) -> Result<Option<BlockInfo>, DBError> {
773-
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";
774-
let args = params![
775-
&BlockState::GloballyAccepted.to_string(),
776-
&BlockState::LocallyAccepted.to_string()
777-
];
778-
let result: Option<String> = query_row(&self.db, query, args)?;
779-
780-
try_deserialize(result)
781-
}
782-
783771
/// Return the last accepted block in a tenure (identified by its consensus hash).
784772
pub fn get_last_accepted_block(
785773
&self,
@@ -1286,13 +1274,6 @@ mod tests {
12861274
.expect("Unable to get block from db");
12871275

12881276
assert_eq!(BlockInfo::from(block_proposal_2.clone()), block_info);
1289-
// test getting the block state
1290-
let block_state = db
1291-
.get_block_state(&block_proposal_1.block.header.signer_signature_hash())
1292-
.unwrap()
1293-
.expect("Unable to get block state from db");
1294-
1295-
assert_eq!(block_state, BlockInfo::from(block_proposal_1.clone()).state);
12961277
}
12971278

12981279
#[test]
@@ -1911,71 +1892,6 @@ mod tests {
19111892
);
19121893
}
19131894

1914-
#[test]
1915-
fn signer_last_accepted_block() {
1916-
let db_path = tmp_db_path();
1917-
let mut db = SignerDb::new(db_path).expect("Failed to create signer db");
1918-
1919-
let (mut block_info_1, _block_proposal_1) = create_block_override(|b| {
1920-
b.block.header.miner_signature = MessageSignature([0x01; 65]);
1921-
b.block.header.chain_length = 1;
1922-
b.burn_height = 1;
1923-
});
1924-
1925-
let (mut block_info_2, _block_proposal_2) = create_block_override(|b| {
1926-
b.block.header.miner_signature = MessageSignature([0x02; 65]);
1927-
b.block.header.chain_length = 2;
1928-
b.burn_height = 1;
1929-
});
1930-
1931-
let (mut block_info_3, _block_proposal_3) = create_block_override(|b| {
1932-
b.block.header.miner_signature = MessageSignature([0x02; 65]);
1933-
b.block.header.chain_length = 2;
1934-
b.burn_height = 4;
1935-
});
1936-
block_info_3
1937-
.mark_locally_accepted(false)
1938-
.expect("Failed to mark block as locally accepted");
1939-
1940-
db.insert_block(&block_info_1)
1941-
.expect("Unable to insert block into db");
1942-
db.insert_block(&block_info_2)
1943-
.expect("Unable to insert block into db");
1944-
1945-
assert!(db.get_signer_last_accepted_block().unwrap().is_none());
1946-
1947-
block_info_1
1948-
.mark_globally_accepted()
1949-
.expect("Failed to mark block as globally accepted");
1950-
db.insert_block(&block_info_1)
1951-
.expect("Unable to insert block into db");
1952-
1953-
assert_eq!(
1954-
db.get_signer_last_accepted_block().unwrap().unwrap(),
1955-
block_info_1
1956-
);
1957-
1958-
block_info_2
1959-
.mark_globally_accepted()
1960-
.expect("Failed to mark block as globally accepted");
1961-
block_info_2.signed_self = Some(get_epoch_time_secs());
1962-
db.insert_block(&block_info_2)
1963-
.expect("Unable to insert block into db");
1964-
1965-
assert_eq!(
1966-
db.get_signer_last_accepted_block().unwrap().unwrap(),
1967-
block_info_2
1968-
);
1969-
1970-
db.insert_block(&block_info_3)
1971-
.expect("Unable to insert block into db");
1972-
1973-
assert_eq!(
1974-
db.get_signer_last_accepted_block().unwrap().unwrap(),
1975-
block_info_3
1976-
);
1977-
}
1978-
19791895
#[test]
19801896
fn test_get_and_remove_pending_block_validation() {
19811897
let db_path = tmp_db_path();

0 commit comments

Comments
 (0)