Skip to content

Commit

Permalink
fix: resolve DNS/hostnames for signer node_host value #4466
Browse files Browse the repository at this point in the history
  • Loading branch information
zone117x committed Mar 4, 2024
1 parent 383d586 commit 05e26e0
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 37 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libsigner/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub fn decode_http_body(headers: &HashMap<String, String>, mut buf: &[u8]) -> io
/// Return the HTTP reply, decoded if it was chunked
pub fn run_http_request<S: Read + Write>(
sock: &mut S,
host: &SocketAddr,
host: &str,
verb: &str,
path: &str,
content_type: Option<&str>,
Expand Down
10 changes: 5 additions & 5 deletions libsigner/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub trait SignerSession {
/// connect to the replica
fn connect(
&mut self,
host: SocketAddr,
host: String,
stackerdb_contract_id: QualifiedContractIdentifier,
) -> Result<(), RPCError>;
/// query the replica for a list of chunks
Expand Down Expand Up @@ -66,7 +66,7 @@ pub trait SignerSession {
/// signer session for a stackerdb instance
pub struct StackerDBSession {
/// host we're talking to
pub host: SocketAddr,
pub host: String,
/// contract we're talking to
pub stackerdb_contract_id: QualifiedContractIdentifier,
/// connection to the replica
Expand All @@ -76,7 +76,7 @@ pub struct StackerDBSession {
impl StackerDBSession {
/// instantiate but don't connect
pub fn new(
host: SocketAddr,
host: String,
stackerdb_contract_id: QualifiedContractIdentifier,
) -> StackerDBSession {
StackerDBSession {
Expand All @@ -89,7 +89,7 @@ impl StackerDBSession {
/// connect or reconnect to the node
fn connect_or_reconnect(&mut self) -> Result<(), RPCError> {
debug!("connect to {}", &self.host);
self.sock = Some(TcpStream::connect(self.host)?);
self.sock = Some(TcpStream::connect(&self.host)?);
Ok(())
}

Expand Down Expand Up @@ -134,7 +134,7 @@ impl SignerSession for StackerDBSession {
/// connect to the replica
fn connect(
&mut self,
host: SocketAddr,
host: String,
stackerdb_contract_id: QualifiedContractIdentifier,
) -> Result<(), RPCError> {
self.host = host;
Expand Down
1 change: 1 addition & 0 deletions stacks-signer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
wsts = { workspace = true }
rand = { workspace = true }
url = "2.1.0"

[dev-dependencies]
serial_test = "3.0.0"
Expand Down
2 changes: 1 addition & 1 deletion stacks-signer/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub enum Command {
pub struct StackerDBArgs {
/// The Stacks node to connect to
#[arg(long)]
pub host: SocketAddr,
pub host: String,
/// The stacker-db contract to use. Must be in the format of "STACKS_ADDRESS.CONTRACT_NAME"
#[arg(short, long, value_parser = parse_contract)]
pub contract: QualifiedContractIdentifier,
Expand Down
2 changes: 1 addition & 1 deletion stacks-signer/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ pub(crate) mod tests {
let mut config =
GlobalConfig::load_from_file("./src/tests/conf/signer-0.toml").unwrap();
let (server, mock_server_addr) = mock_server_random();
config.node_host = mock_server_addr;
config.node_host = mock_server_addr.to_string();

let client = StacksClient::from(&config);
Self {
Expand Down
8 changes: 3 additions & 5 deletions stacks-signer/src/client/stackerdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
use std::net::SocketAddr;

use blockstack_lib::chainstate::nakamoto::signer_set::NakamotoSigners;
use blockstack_lib::chainstate::stacks::StacksTransaction;
use blockstack_lib::util_lib::boot::boot_code_addr;
Expand Down Expand Up @@ -55,7 +53,7 @@ pub struct StackerDB {
impl From<&SignerConfig> for StackerDB {
fn from(config: &SignerConfig) -> Self {
StackerDB::new(
config.node_host,
config.node_host.to_string(),
config.stacks_private_key,
config.mainnet,
config.reward_cycle,
Expand All @@ -66,7 +64,7 @@ impl From<&SignerConfig> for StackerDB {
impl StackerDB {
/// Create a new StackerDB client
pub fn new(
host: SocketAddr,
host: String,
stacks_private_key: StacksPrivateKey,
is_mainnet: bool,
reward_cycle: u64,
Expand All @@ -78,7 +76,7 @@ impl StackerDB {
signers_message_stackerdb_sessions.insert(
msg_id,
StackerDBSession::new(
host,
host.to_string(),
QualifiedContractIdentifier::new(
stackerdb_issuer.into(),
ContractName::from(
Expand Down
20 changes: 6 additions & 14 deletions stacks-signer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub struct SignerConfig {
/// The private key for this signer
pub stacks_private_key: StacksPrivateKey,
/// The node host for this signer
pub node_host: SocketAddr,
pub node_host: String,
/// Whether this signer is running on mainnet or not
pub mainnet: bool,
/// timeout to gather DkgPublicShares messages
Expand All @@ -169,7 +169,7 @@ pub struct SignerConfig {
#[derive(Clone, Debug)]
pub struct GlobalConfig {
/// endpoint to the stacks node
pub node_host: SocketAddr,
pub node_host: String,
/// endpoint to the event receiver
pub endpoint: SocketAddr,
/// The Scalar representation of the private key for signer communication
Expand Down Expand Up @@ -254,17 +254,9 @@ impl TryFrom<RawConfigFile> for GlobalConfig {
/// Attempt to decode the raw config file's primitive types into our types.
/// NOTE: network access is required for this to work
fn try_from(raw_data: RawConfigFile) -> Result<Self, Self::Error> {
let node_host = raw_data
.node_host
.to_socket_addrs()
.map_err(|_| {
ConfigError::BadField("node_host".to_string(), raw_data.node_host.clone())
})?
.next()
.ok_or(ConfigError::BadField(
"node_host".to_string(),
raw_data.node_host.clone(),
))?;
url::Url::parse(&format!("http://{}", raw_data.node_host)).map_err(|_| {
ConfigError::BadField("node_host".to_string(), raw_data.node_host.clone())
})?;

let endpoint = raw_data
.endpoint
Expand Down Expand Up @@ -307,7 +299,7 @@ impl TryFrom<RawConfigFile> for GlobalConfig {
let nonce_timeout = raw_data.nonce_timeout_ms.map(Duration::from_millis);
let sign_timeout = raw_data.sign_timeout_ms.map(Duration::from_millis);
Ok(Self {
node_host,
node_host: raw_data.node_host,
endpoint,
stacks_private_key,
ecdsa_private_key,
Expand Down
5 changes: 2 additions & 3 deletions stacks-signer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extern crate toml;

use std::fs::File;
use std::io::{self, BufRead, Write};
use std::net::SocketAddr;
use std::path::{Path, PathBuf};
use std::sync::mpsc::{channel, Receiver, Sender};
use std::time::Duration;
Expand Down Expand Up @@ -63,8 +62,8 @@ struct SpawnedSigner {
}

/// Create a new stacker db session
fn stackerdb_session(host: SocketAddr, contract: QualifiedContractIdentifier) -> StackerDBSession {
let mut session = StackerDBSession::new(host, contract.clone());
fn stackerdb_session(host: String, contract: QualifiedContractIdentifier) -> StackerDBSession {
let mut session = StackerDBSession::new(host.to_string(), contract.clone());
session.connect(host, contract).unwrap();
session
}
Expand Down
2 changes: 1 addition & 1 deletion stacks-signer/src/runloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl RunLoop {
signer_slot_ids: signer_slot_ids.into_values().collect(),
ecdsa_private_key: self.config.ecdsa_private_key,
stacks_private_key: self.config.stacks_private_key,
node_host: self.config.node_host,
node_host: self.config.node_host.to_string(),
mainnet: self.config.network.is_mainnet(),
dkg_end_timeout: self.config.dkg_end_timeout,
dkg_private_timeout: self.config.dkg_private_timeout,
Expand Down
10 changes: 4 additions & 6 deletions testnet/stacks-node/src/nakamoto_node/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ impl BlockMinerThread {
let miners_contract_id = boot_code_id(MINERS_NAME, self.config.is_mainnet());
let stackerdbs = StackerDBs::connect(&self.config.get_stacker_db_file_path(), true)
.expect("FATAL: failed to connect to stacker DB");
let rpc_sock = self.config.node.rpc_bind.parse().expect(&format!(
"Failed to parse socket: {}",
&self.config.node.rpc_bind
));
let Some(miner_privkey) = self.config.miner.mining_key else {
warn!("No mining key configured, cannot mine");
return;
Expand Down Expand Up @@ -204,8 +200,10 @@ impl BlockMinerThread {
Ok(Some(chunk)) => {
// Propose the block to the observing signers through the .miners stackerdb instance
let miner_contract_id = boot_code_id(MINERS_NAME, self.config.is_mainnet());
let mut miners_stackerdb =
StackerDBSession::new(rpc_sock, miner_contract_id);
let mut miners_stackerdb = StackerDBSession::new(
self.config.node.rpc_bind.to_string(),
miner_contract_id,
);
match miners_stackerdb.put_chunk(&chunk) {
Ok(ack) => {
info!("Proposed block to stackerdb: {ack:?}");
Expand Down

0 comments on commit 05e26e0

Please sign in to comment.