Skip to content

Commit 2929d69

Browse files
authored
Merge branch 'release/2.5.0.0.0' into fix/2.5-changelog_btc-height
2 parents dbc4785 + 560cce4 commit 2929d69

File tree

7 files changed

+152
-8
lines changed

7 files changed

+152
-8
lines changed

.github/actions/dockerfiles/Dockerfile.alpine-binary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ RUN case ${TARGETPLATFORM} in \
2323
&& unzip ${BIN_ARCH}.zip -d /out
2424

2525
FROM --platform=${TARGETPLATFORM} alpine
26-
COPY --from=builder /out/stacks-node /bin/
26+
COPY --from=builder /out/stacks-node /out/stacks-signer /bin/
2727
CMD ["stacks-node", "mainnet"]

.github/actions/dockerfiles/Dockerfile.debian-binary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ RUN case ${TARGETPLATFORM} in \
2323
&& unzip ${BIN_ARCH}.zip -d /out
2424

2525
FROM --platform=${TARGETPLATFORM} debian:bookworm
26-
COPY --from=builder /out/stacks-node /bin/
26+
COPY --from=builder /out/stacks-node /out/stacks-signer /bin/
2727
CMD ["stacks-node", "mainnet"]

stacks-signer/src/cli.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ pub enum Command {
6464
GenerateFiles(GenerateFilesArgs),
6565
/// Generate a signature for Stacking transactions
6666
GenerateStackingSignature(GenerateStackingSignatureArgs),
67+
/// Check a configuration file and output config information
68+
CheckConfig(RunSignerArgs),
6769
}
6870

6971
/// Basic arguments for all cyrptographic and stacker-db functionality

stacks-signer/src/config.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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

17+
use std::fmt::Display;
1718
use std::fs;
1819
use std::net::{SocketAddr, ToSocketAddrs};
1920
use std::path::PathBuf;
@@ -329,6 +330,39 @@ impl GlobalConfig {
329330
pub fn load_from_file(path: &str) -> Result<Self, ConfigError> {
330331
Self::try_from(&PathBuf::from(path))
331332
}
333+
334+
/// Return a string with non-sensitive configuration
335+
/// information for logging purposes
336+
pub fn config_to_log_string(&self) -> String {
337+
let tx_fee = match self.tx_fee_ustx {
338+
0 => "default".to_string(),
339+
_ => (self.tx_fee_ustx as f64 / 1_000_000.0).to_string(),
340+
};
341+
format!(
342+
r#"
343+
Stacks node host: {node_host}
344+
Signer endpoint: {endpoint}
345+
Stacks address: {stacks_address}
346+
Public key: {public_key}
347+
Network: {network}
348+
Database path: {db_path}
349+
DKG transaction fee: {tx_fee} uSTX
350+
"#,
351+
node_host = self.node_host,
352+
endpoint = self.endpoint,
353+
stacks_address = self.stacks_address.to_string(),
354+
public_key = StacksPublicKey::from_private(&self.stacks_private_key).to_hex(),
355+
network = self.network,
356+
db_path = self.db_path.to_str().unwrap_or_default(),
357+
tx_fee = tx_fee
358+
)
359+
}
360+
}
361+
362+
impl Display for GlobalConfig {
363+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
364+
write!(f, "{}", self.config_to_log_string())
365+
}
332366
}
333367

334368
/// Helper function for building a signer config for each provided signer private key
@@ -412,4 +446,24 @@ mod tests {
412446

413447
assert_eq!(config.auth_password, "melon");
414448
}
449+
450+
#[test]
451+
fn test_config_to_string() {
452+
let config = GlobalConfig::load_from_file("./src/tests/conf/signer-0.toml").unwrap();
453+
let config_str = config.config_to_log_string();
454+
assert_eq!(
455+
config_str,
456+
format!(
457+
r#"
458+
Stacks node host: 127.0.0.1:20443
459+
Signer endpoint: [::1]:30000
460+
Stacks address: ST3FPN8KBZ3YPBP0ZJGAAHTVFMQDTJCR5QPS7VTNJ
461+
Public key: 03bc489f27da3701d9f9e577c88de5567cf4023111b7577042d55cde4d823a3505
462+
Network: testnet
463+
Database path: :memory:
464+
DKG transaction fee: 0.01 uSTX
465+
"#
466+
)
467+
);
468+
}
415469
}

stacks-signer/src/main.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ use clap::Parser;
3838
use clarity::vm::types::QualifiedContractIdentifier;
3939
use libsigner::{RunningSigner, Signer, SignerEventReceiver, SignerSession, StackerDBSession};
4040
use libstackerdb::StackerDBChunkData;
41-
use slog::{slog_debug, slog_error};
41+
use slog::{slog_debug, slog_error, slog_info};
4242
use stacks_common::codec::read_next;
4343
use stacks_common::types::chainstate::StacksPrivateKey;
4444
use stacks_common::util::hash::to_hex;
4545
use stacks_common::util::secp256k1::{MessageSignature, Secp256k1PublicKey};
46-
use stacks_common::{debug, error};
46+
use stacks_common::{debug, error, info};
4747
use stacks_signer::cli::{
4848
Cli, Command, GenerateFilesArgs, GenerateStackingSignatureArgs, GetChunkArgs,
4949
GetLatestChunkArgs, PutChunkArgs, RunDkgArgs, RunSignerArgs, SignArgs, StackerDBArgs,
@@ -85,6 +85,7 @@ fn write_chunk_to_stdout(chunk_opt: Option<Vec<u8>>) {
8585
fn spawn_running_signer(path: &PathBuf) -> SpawnedSigner {
8686
let config = GlobalConfig::try_from(path).unwrap();
8787
let endpoint = config.endpoint;
88+
info!("Starting signer with config: {}", config);
8889
let (cmd_send, cmd_recv) = channel();
8990
let (res_send, res_recv) = channel();
9091
let ev = SignerEventReceiver::new(config.network.is_mainnet());
@@ -349,6 +350,11 @@ fn handle_generate_stacking_signature(
349350
signature
350351
}
351352

353+
fn handle_check_config(args: RunSignerArgs) {
354+
let config = GlobalConfig::try_from(&args.config).unwrap();
355+
println!("Config: {}", config);
356+
}
357+
352358
/// Helper function for writing the given contents to filename in the given directory
353359
fn write_file(dir: &Path, filename: &str, contents: &str) {
354360
let file_path = dir.join(filename);
@@ -397,6 +403,9 @@ fn main() {
397403
Command::GenerateStackingSignature(args) => {
398404
handle_generate_stacking_signature(args, true);
399405
}
406+
Command::CheckConfig(args) => {
407+
handle_check_config(args);
408+
}
400409
}
401410
}
402411

testnet/stacks-node/src/config.rs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,32 @@ mod tests {
271271
// Should default add xenon affirmation overrides
272272
assert_eq!(config.burnchain.affirmation_overrides.len(), 5);
273273
}
274+
275+
#[test]
276+
fn should_override_xenon_default_affirmation_overrides() {
277+
let affirmation_string = "aaapnnnnnnnnnnnnnnnnnnnnnnnnnnnnppnnnnnnnnnnnnnnnnnnnnnnnnpppppnnnnnnnnnnnnnnnnnnnnnnnpppppppppppppppnnnnnnnnnnnnnnnnnnnnnnnppppppppppnnnnnnnnnnnnnnnnnnnppppnnnnnnnnnnnnnnnnnnnnnnnppppppppnnnnnnnnnnnnnnnnnnnnnnnppnppnnnnnnnnnnnnnnnnnnnnnnnppppnnnnnnnnnnnnnnnnnnnnnnnnnppppppnnnnnnnnnnnnnnnnnnnnnnnnnppnnnnnnnnnnnnnnnnnnnnnnnnnpppppppnnnnnnnnnnnnnnnnnnnnnnnnnnpnnnnnnnnnnnnnnnnnnnnnnnnnpppnppppppppppppppnnppppnpa";
278+
let affirmation =
279+
AffirmationMap::decode(affirmation_string).expect("Failed to decode affirmation map");
280+
281+
let config = Config::from_config_file(
282+
ConfigFile::from_str(&format!(
283+
r#"
284+
[burnchain]
285+
chain = "bitcoin"
286+
mode = "xenon"
287+
288+
[[burnchain.affirmation_overrides]]
289+
reward_cycle = 413
290+
affirmation = "{affirmation_string}"
291+
"#,
292+
))
293+
.expect("Expected to be able to parse config file from string"),
294+
)
295+
.expect("Expected to be able to parse affirmation map from file");
296+
// Should default add xenon affirmation overrides, but overwrite with the configured one above
297+
assert_eq!(config.burnchain.affirmation_overrides.len(), 5);
298+
assert_eq!(config.burnchain.affirmation_overrides[&413], affirmation);
299+
}
274300
}
275301

276302
impl ConfigFile {
@@ -1470,7 +1496,6 @@ impl BurnchainConfigFile {
14701496
BITCOIN_TESTNET_STACKS_25_BURN_HEIGHT,
14711497
)
14721498
.unwrap();
1473-
eprintln!("last_present_cycle = {last_present_cycle}");
14741499
assert_eq!(
14751500
u64::try_from(affirmations_pre_2_5.len()).unwrap(),
14761501
last_present_cycle - 1
@@ -1481,10 +1506,12 @@ impl BurnchainConfigFile {
14811506
BITCOIN_TESTNET_STACKS_25_REORGED_HEIGHT,
14821507
)
14831508
.unwrap();
1484-
eprintln!("last_present_cycle = {last_present_cycle}, last_override = {last_override}");
1509+
let override_values = ["a", "n"];
14851510

14861511
for (override_index, reward_cycle) in (last_present_cycle + 1..=last_override).enumerate() {
1487-
let affirmation = format!("{affirmations_pre_2_5}{}", "a".repeat(override_index + 1));
1512+
assert!(override_values.len() > override_index);
1513+
let overrides = override_values[..(override_index + 1)].join("");
1514+
let affirmation = format!("{affirmations_pre_2_5}{overrides}");
14881515
default_overrides.push(AffirmationOverride {
14891516
reward_cycle,
14901517
affirmation,
@@ -1493,7 +1520,10 @@ impl BurnchainConfigFile {
14931520

14941521
if let Some(affirmation_overrides) = self.affirmation_overrides.as_mut() {
14951522
for affirmation in default_overrides {
1496-
affirmation_overrides.push(affirmation);
1523+
// insert at front, so that the hashmap uses the configured overrides
1524+
// instead of the defaults (the configured overrides will write over the
1525+
// the defaults because they come later in the list).
1526+
affirmation_overrides.insert(0, affirmation);
14971527
}
14981528
} else {
14991529
self.affirmation_overrides = Some(default_overrides);

testnet/stacks-node/src/neon_node.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,55 @@ impl BlockMinerThread {
11691169
return vec![];
11701170
}
11711171

1172+
let sortdb_tip_handle = burn_db.index_handle_at_tip();
1173+
1174+
let stacks_tips: Vec<_> = stacks_tips
1175+
.into_iter()
1176+
.filter(|candidate| {
1177+
let candidate_ch = &candidate.consensus_hash;
1178+
let candidate_burn_ht = match SortitionDB::get_block_snapshot_consensus(
1179+
sortdb_tip_handle.conn(),
1180+
candidate_ch
1181+
) {
1182+
Ok(Some(x)) => x.block_height,
1183+
Ok(None) => {
1184+
warn!("Tried to evaluate potential chain tip with an unknown consensus hash";
1185+
"consensus_hash" => %candidate_ch,
1186+
"stacks_block_hash" => %candidate.anchored_block_hash);
1187+
return false;
1188+
},
1189+
Err(e) => {
1190+
warn!("Error while trying to evaluate potential chain tip with an unknown consensus hash";
1191+
"consensus_hash" => %candidate_ch,
1192+
"stacks_block_hash" => %candidate.anchored_block_hash,
1193+
"err" => ?e);
1194+
return false;
1195+
},
1196+
};
1197+
let tip_ch = match sortdb_tip_handle.get_consensus_at(candidate_burn_ht) {
1198+
Ok(Some(x)) => x,
1199+
Ok(None) => {
1200+
warn!("Tried to evaluate potential chain tip with a consensus hash ahead of canonical tip";
1201+
"consensus_hash" => %candidate_ch,
1202+
"stacks_block_hash" => %candidate.anchored_block_hash);
1203+
return false;
1204+
},
1205+
Err(e) => {
1206+
warn!("Error while trying to evaluate potential chain tip with an unknown consensus hash";
1207+
"consensus_hash" => %candidate_ch,
1208+
"stacks_block_hash" => %candidate.anchored_block_hash,
1209+
"err" => ?e);
1210+
return false;
1211+
},
1212+
};
1213+
if &tip_ch != candidate_ch {
1214+
false
1215+
} else {
1216+
true
1217+
}
1218+
})
1219+
.collect();
1220+
11721221
let mut considered = HashSet::new();
11731222
let mut candidates = vec![];
11741223
let end_height = stacks_tips[0].height;

0 commit comments

Comments
 (0)