diff --git a/testnet/stacks-node/conf/local-follower-conf.toml b/testnet/stacks-node/conf/local-follower-conf.toml index c828c18373..8186b57f54 100644 --- a/testnet/stacks-node/conf/local-follower-conf.toml +++ b/testnet/stacks-node/conf/local-follower-conf.toml @@ -15,7 +15,6 @@ peer_port = 18444 # Used for sending events to a local stacks-blockchain-api service # [[events_observer]] # endpoint = "localhost:3700" -# retry_count = 255 # events_keys = ["*"] [[ustx_balance]] diff --git a/testnet/stacks-node/conf/mainnet-follower-conf.toml b/testnet/stacks-node/conf/mainnet-follower-conf.toml index 2ecbc80686..6f6bab70d8 100644 --- a/testnet/stacks-node/conf/mainnet-follower-conf.toml +++ b/testnet/stacks-node/conf/mainnet-follower-conf.toml @@ -16,5 +16,4 @@ peer_port = 8333 # Used for sending events to a local stacks-blockchain-api service # [[events_observer]] # endpoint = "localhost:3700" -# retry_count = 255 # events_keys = ["*"] diff --git a/testnet/stacks-node/conf/mocknet-follower-conf.toml b/testnet/stacks-node/conf/mocknet-follower-conf.toml index 3cb9beb5d7..e9a0e7a643 100644 --- a/testnet/stacks-node/conf/mocknet-follower-conf.toml +++ b/testnet/stacks-node/conf/mocknet-follower-conf.toml @@ -13,7 +13,6 @@ mode = "mocknet" # Used for sending events to a local stacks-blockchain-api service # [[events_observer]] # endpoint = "localhost:3700" -# retry_count = 255 # events_keys = ["*"] [[ustx_balance]] diff --git a/testnet/stacks-node/conf/regtest-follower-conf.toml b/testnet/stacks-node/conf/regtest-follower-conf.toml index a2a71c8acb..151446fbaf 100644 --- a/testnet/stacks-node/conf/regtest-follower-conf.toml +++ b/testnet/stacks-node/conf/regtest-follower-conf.toml @@ -17,7 +17,6 @@ peer_port = 18444 # Used for sending events to a local stacks-blockchain-api service # [[events_observer]] # endpoint = "localhost:3700" -# retry_count = 255 # events_keys = ["*"] [[ustx_balance]] diff --git a/testnet/stacks-node/conf/testnet-follower-conf.toml b/testnet/stacks-node/conf/testnet-follower-conf.toml index cb23477b27..5fe717bfb1 100644 --- a/testnet/stacks-node/conf/testnet-follower-conf.toml +++ b/testnet/stacks-node/conf/testnet-follower-conf.toml @@ -17,7 +17,6 @@ peer_port = 18333 # Used for sending events to a local stacks-blockchain-api service # [[events_observer]] # endpoint = "localhost:3700" -# retry_count = 255 # events_keys = ["*"] [[ustx_balance]] diff --git a/testnet/stacks-node/src/config.rs b/testnet/stacks-node/src/config.rs index e90d610040..f4750c6242 100644 --- a/testnet/stacks-node/src/config.rs +++ b/testnet/stacks-node/src/config.rs @@ -89,11 +89,14 @@ const INV_REWARD_CYCLES_TESTNET: u64 = 6; const DEFAULT_MIN_TIME_BETWEEN_BLOCKS_MS: u64 = 1000; #[derive(Clone, Deserialize, Default, Debug)] +#[serde(deny_unknown_fields)] pub struct ConfigFile { pub __path: Option, // Only used for config file reloads pub burnchain: Option, pub node: Option, pub ustx_balance: Option>, + /// Deprecated: use `ustx_balance` instead + pub mstx_balance: Option>, pub events_observer: Option>, pub connection_options: Option, pub fee_estimation: Option, @@ -101,245 +104,6 @@ pub struct ConfigFile { pub atlas: Option, } -#[derive(Clone, Deserialize, Default)] -pub struct LegacyMstxConfigFile { - pub mstx_balance: Option>, -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_config_file() { - assert_eq!( - format!("Invalid path: No such file or directory (os error 2)"), - ConfigFile::from_path("some_path").unwrap_err() - ); - assert_eq!( - format!("Invalid toml: unexpected character found: `/` at line 1 column 1"), - ConfigFile::from_str("//[node]").unwrap_err() - ); - assert!(ConfigFile::from_str("").is_ok()); - } - - #[test] - fn test_config() { - assert_eq!( - format!("node.seed should be a hex encoded string"), - Config::from_config_file( - ConfigFile::from_str( - r#" - [node] - seed = "invalid-hex-value" - "#, - ) - .unwrap(), - false - ) - .unwrap_err() - ); - - assert_eq!( - format!("node.local_peer_seed should be a hex encoded string"), - Config::from_config_file( - ConfigFile::from_str( - r#" - [node] - local_peer_seed = "invalid-hex-value" - "#, - ) - .unwrap(), - false - ) - .unwrap_err() - ); - - let expected_err_prefix = - "Invalid burnchain.peer_host: failed to lookup address information:"; - let actual_err_msg = Config::from_config_file( - ConfigFile::from_str( - r#" - [burnchain] - peer_host = "bitcoin2.blockstack.com" - "#, - ) - .unwrap(), - false, - ) - .unwrap_err(); - assert_eq!( - expected_err_prefix, - &actual_err_msg[..expected_err_prefix.len()] - ); - - assert!(Config::from_config_file(ConfigFile::from_str("").unwrap(), false).is_ok()); - } - - #[test] - fn should_load_legacy_mstx_balances_toml() { - let config = ConfigFile::from_str( - r#" - [[ustx_balance]] - address = "ST2QKZ4FKHAH1NQKYKYAYZPY440FEPK7GZ1R5HBP2" - amount = 10000000000000000 - - [[ustx_balance]] - address = "ST319CF5WV77KYR1H3GT0GZ7B8Q4AQPY42ETP1VPF" - amount = 10000000000000000 - - [[mstx_balance]] # legacy property name - address = "ST221Z6TDTC5E0BYR2V624Q2ST6R0Q71T78WTAX6H" - amount = 10000000000000000 - - [[mstx_balance]] # legacy property name - address = "ST2TFVBMRPS5SSNP98DQKQ5JNB2B6NZM91C4K3P7B" - amount = 10000000000000000 - "#, - ); - let config = config.unwrap(); - assert!(config.ustx_balance.is_some()); - let balances = config - .ustx_balance - .expect("Failed to parse stx balances from toml"); - assert_eq!(balances.len(), 4); - assert_eq!( - balances[0].address, - "ST2QKZ4FKHAH1NQKYKYAYZPY440FEPK7GZ1R5HBP2" - ); - assert_eq!( - balances[1].address, - "ST319CF5WV77KYR1H3GT0GZ7B8Q4AQPY42ETP1VPF" - ); - assert_eq!( - balances[2].address, - "ST221Z6TDTC5E0BYR2V624Q2ST6R0Q71T78WTAX6H" - ); - assert_eq!( - balances[3].address, - "ST2TFVBMRPS5SSNP98DQKQ5JNB2B6NZM91C4K3P7B" - ); - } - - #[test] - fn should_load_auth_token() { - let config = Config::from_config_file( - ConfigFile::from_str( - r#" - [connection_options] - auth_token = "password" - "#, - ) - .unwrap(), - false, - ) - .expect("Expected to be able to parse block proposal token from file"); - - assert_eq!( - config.connection_options.auth_token, - Some("password".to_string()) - ); - } - - #[test] - fn should_load_affirmation_map() { - let affirmation_string = "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnppnnnnnnnnnnnnnnnnnnnnnnnnpppppnnnnnnnnnnnnnnnnnnnnnnnpppppppppppppppnnnnnnnnnnnnnnnnnnnnnnnppppppppppnnnnnnnnnnnnnnnnnnnppppnnnnnnnnnnnnnnnnnnnnnnnppppppppnnnnnnnnnnnnnnnnnnnnnnnppnppnnnnnnnnnnnnnnnnnnnnnnnppppnnnnnnnnnnnnnnnnnnnnnnnnnppppppnnnnnnnnnnnnnnnnnnnnnnnnnppnnnnnnnnnnnnnnnnnnnnnnnnnpppppppnnnnnnnnnnnnnnnnnnnnnnnnnnpnnnnnnnnnnnnnnnnnnnnnnnnnpppnppppppppppppppnnppppnpa"; - let affirmation = - AffirmationMap::decode(affirmation_string).expect("Failed to decode affirmation map"); - let config = Config::from_config_file( - ConfigFile::from_str(&format!( - r#" - [[burnchain.affirmation_overrides]] - reward_cycle = 413 - affirmation = "{affirmation_string}" - "# - )) - .expect("Expected to be able to parse config file from string"), - false, - ) - .expect("Expected to be able to parse affirmation map from file"); - - assert_eq!(config.burnchain.affirmation_overrides.len(), 1); - assert_eq!(config.burnchain.affirmation_overrides.get(&0), None); - assert_eq!( - config.burnchain.affirmation_overrides.get(&413), - Some(&affirmation) - ); - } - - #[test] - fn should_fail_to_load_invalid_affirmation_map() { - let bad_affirmation_string = "bad_map"; - let file = ConfigFile::from_str(&format!( - r#" - [[burnchain.affirmation_overrides]] - reward_cycle = 1 - affirmation = "{bad_affirmation_string}" - "# - )) - .expect("Expected to be able to parse config file from string"); - - assert!(Config::from_config_file(file, false).is_err()); - } - - #[test] - fn should_load_empty_affirmation_map() { - let config = Config::from_config_file( - ConfigFile::from_str(r#""#) - .expect("Expected to be able to parse config file from string"), - false, - ) - .expect("Expected to be able to parse affirmation map from file"); - - assert!(config.burnchain.affirmation_overrides.is_empty()); - } - - #[test] - fn should_include_xenon_default_affirmation_overrides() { - let config = Config::from_config_file( - ConfigFile::from_str( - r#" - [burnchain] - chain = "bitcoin" - mode = "xenon" - "#, - ) - .expect("Expected to be able to parse config file from string"), - false, - ) - .expect("Expected to be able to parse affirmation map from file"); - // Should default add xenon affirmation overrides - assert_eq!(config.burnchain.affirmation_overrides.len(), 5); - } - - #[test] - fn should_override_xenon_default_affirmation_overrides() { - let affirmation_string = "aaapnnnnnnnnnnnnnnnnnnnnnnnnnnnnppnnnnnnnnnnnnnnnnnnnnnnnnpppppnnnnnnnnnnnnnnnnnnnnnnnpppppppppppppppnnnnnnnnnnnnnnnnnnnnnnnppppppppppnnnnnnnnnnnnnnnnnnnppppnnnnnnnnnnnnnnnnnnnnnnnppppppppnnnnnnnnnnnnnnnnnnnnnnnppnppnnnnnnnnnnnnnnnnnnnnnnnppppnnnnnnnnnnnnnnnnnnnnnnnnnppppppnnnnnnnnnnnnnnnnnnnnnnnnnppnnnnnnnnnnnnnnnnnnnnnnnnnpppppppnnnnnnnnnnnnnnnnnnnnnnnnnnpnnnnnnnnnnnnnnnnnnnnnnnnnpppnppppppppppppppnnppppnpa"; - let affirmation = - AffirmationMap::decode(affirmation_string).expect("Failed to decode affirmation map"); - - let config = Config::from_config_file( - ConfigFile::from_str(&format!( - r#" - [burnchain] - chain = "bitcoin" - mode = "xenon" - - [[burnchain.affirmation_overrides]] - reward_cycle = 413 - affirmation = "{affirmation_string}" - "#, - )) - .expect("Expected to be able to parse config file from string"), - false, - ) - .expect("Expected to be able to parse affirmation map from file"); - // Should default add xenon affirmation overrides, but overwrite with the configured one above - assert_eq!(config.burnchain.affirmation_overrides.len(), 5); - assert_eq!(config.burnchain.affirmation_overrides[&413], affirmation); - } -} - impl ConfigFile { pub fn from_path(path: &str) -> Result { let content = fs::read_to_string(path).map_err(|e| format!("Invalid path: {}", &e))?; @@ -351,13 +115,16 @@ impl ConfigFile { pub fn from_str(content: &str) -> Result { let mut config: ConfigFile = toml::from_str(content).map_err(|e| format!("Invalid toml: {}", e))?; - let legacy_config: LegacyMstxConfigFile = toml::from_str(content).unwrap(); - if let Some(mstx_balance) = legacy_config.mstx_balance { - warn!("'mstx_balance' inside toml config is deprecated, replace with 'ustx_balance'"); - config.ustx_balance = match config.ustx_balance { - Some(balance) => Some([balance, mstx_balance].concat()), - None => Some(mstx_balance), - }; + if let Some(mstx_balance) = config.mstx_balance.take() { + warn!("'mstx_balance' in the config is deprecated; please use 'ustx_balance' instead."); + match config.ustx_balance { + Some(ref mut ustx_balance) => { + ustx_balance.extend(mstx_balance); + } + None => { + config.ustx_balance = Some(mstx_balance); + } + } } Ok(config) } @@ -1552,10 +1319,12 @@ pub struct AffirmationOverride { } #[derive(Clone, Deserialize, Default, Debug)] +#[serde(deny_unknown_fields)] pub struct BurnchainConfigFile { pub chain: Option, - pub burn_fee_cap: Option, pub mode: Option, + pub chain_id: Option, + pub burn_fee_cap: Option, pub commit_anchor_block_within: Option, pub peer_host: Option, pub peer_port: Option, @@ -1702,10 +1471,22 @@ impl BurnchainConfigFile { let mut config = BurnchainConfig { chain: self.chain.unwrap_or(default_burnchain_config.chain), - chain_id: if is_mainnet { - CHAIN_ID_MAINNET - } else { - CHAIN_ID_TESTNET + chain_id: match self.chain_id { + Some(chain_id) => { + if is_mainnet && chain_id != CHAIN_ID_MAINNET { + return Err(format!( + "Attempted to run mainnet node with chain_id {chain_id}", + )); + } + chain_id + } + None => { + if is_mainnet { + CHAIN_ID_MAINNET + } else { + CHAIN_ID_TESTNET + } + } }, peer_version: if is_mainnet { PEER_VERSION_MAINNET @@ -1841,6 +1622,7 @@ impl BurnchainConfigFile { Ok(config) } } + #[derive(Clone, Debug)] pub struct NodeConfig { pub name: String, @@ -2420,6 +2202,7 @@ impl Default for MinerConfig { } #[derive(Clone, Default, Deserialize, Debug)] +#[serde(deny_unknown_fields)] pub struct ConnectionOptionsFile { pub inbox_maxlen: Option, pub outbox_maxlen: Option, @@ -2603,6 +2386,7 @@ impl ConnectionOptionsFile { } #[derive(Clone, Deserialize, Default, Debug)] +#[serde(deny_unknown_fields)] pub struct NodeConfigFile { pub name: Option, pub seed: Option, @@ -2737,6 +2521,7 @@ impl NodeConfigFile { } #[derive(Clone, Deserialize, Default, Debug)] +#[serde(deny_unknown_fields)] pub struct FeeEstimationConfigFile { pub cost_estimator: Option, pub fee_estimator: Option, @@ -2748,6 +2533,7 @@ pub struct FeeEstimationConfigFile { } #[derive(Clone, Deserialize, Default, Debug)] +#[serde(deny_unknown_fields)] pub struct MinerConfigFile { pub first_attempt_time_ms: Option, pub subsequent_attempt_time_ms: Option, @@ -2890,6 +2676,7 @@ impl MinerConfigFile { } } #[derive(Clone, Deserialize, Default, Debug)] +#[serde(deny_unknown_fields)] pub struct AtlasConfigFile { pub attachments_max_size: Option, pub max_uninstantiated_attachments: Option, @@ -2918,6 +2705,7 @@ impl AtlasConfigFile { } #[derive(Clone, Deserialize, Default, Debug, Hash, PartialEq, Eq, PartialOrd)] +#[serde(deny_unknown_fields)] pub struct EventObserverConfigFile { pub endpoint: String, pub events_keys: Vec, @@ -3020,7 +2808,449 @@ pub struct InitialBalance { } #[derive(Clone, Deserialize, Default, Debug)] +#[serde(deny_unknown_fields)] pub struct InitialBalanceFile { pub address: String, pub amount: u64, } + +#[cfg(test)] +mod tests { + use std::path::Path; + + use super::*; + + #[test] + fn test_config_file() { + assert_eq!( + format!("Invalid path: No such file or directory (os error 2)"), + ConfigFile::from_path("some_path").unwrap_err() + ); + assert_eq!( + format!("Invalid toml: unexpected character found: `/` at line 1 column 1"), + ConfigFile::from_str("//[node]").unwrap_err() + ); + assert!(ConfigFile::from_str("").is_ok()); + } + + #[test] + fn test_config() { + assert_eq!( + format!("node.seed should be a hex encoded string"), + Config::from_config_file( + ConfigFile::from_str( + r#" + [node] + seed = "invalid-hex-value" + "#, + ) + .unwrap(), + false + ) + .unwrap_err() + ); + + assert_eq!( + format!("node.local_peer_seed should be a hex encoded string"), + Config::from_config_file( + ConfigFile::from_str( + r#" + [node] + local_peer_seed = "invalid-hex-value" + "#, + ) + .unwrap(), + false + ) + .unwrap_err() + ); + + let expected_err_prefix = + "Invalid burnchain.peer_host: failed to lookup address information:"; + let actual_err_msg = Config::from_config_file( + ConfigFile::from_str( + r#" + [burnchain] + peer_host = "bitcoin2.blockstack.com" + "#, + ) + .unwrap(), + false, + ) + .unwrap_err(); + assert_eq!( + expected_err_prefix, + &actual_err_msg[..expected_err_prefix.len()] + ); + + assert!(Config::from_config_file(ConfigFile::from_str("").unwrap(), false).is_ok()); + } + + #[test] + fn test_deny_unknown_fields() { + { + let err = ConfigFile::from_str( + r#" + [node] + name = "test" + unknown_field = "test" + "#, + ) + .unwrap_err(); + assert!(err.starts_with("Invalid toml: unknown field `unknown_field`")); + } + + { + let err = ConfigFile::from_str( + r#" + [burnchain] + chain_id = 0x00000500 + unknown_field = "test" + chain = "bitcoin" + "#, + ) + .unwrap_err(); + assert!(err.starts_with("Invalid toml: unknown field `unknown_field`")); + } + + { + let err = ConfigFile::from_str( + r#" + [node] + rpc_bind = "0.0.0.0:20443" + unknown_field = "test" + p2p_bind = "0.0.0.0:20444" + "#, + ) + .unwrap_err(); + assert!(err.starts_with("Invalid toml: unknown field `unknown_field`")); + } + + { + let err = ConfigFile::from_str( + r#" + [[ustx_balance]] + address = "ST3AM1A56AK2C1XAFJ4115ZSV26EB49BVQ10MGCS0" + amount = 10000000000000000 + unknown_field = "test" + "#, + ) + .unwrap_err(); + assert!(err.starts_with("Invalid toml: unknown field `unknown_field`")); + } + + { + let err = ConfigFile::from_str( + r#" + [[events_observer]] + endpoint = "localhost:30000" + unknown_field = "test" + events_keys = ["stackerdb", "block_proposal", "burn_blocks"] + "#, + ) + .unwrap_err(); + assert!(err.starts_with("Invalid toml: unknown field `unknown_field`")); + } + + { + let err = ConfigFile::from_str( + r#" + [connection_options] + inbox_maxlen = 100 + outbox_maxlen = 200 + unknown_field = "test" + "#, + ) + .unwrap_err(); + assert!(err.starts_with("Invalid toml: unknown field `unknown_field`")); + } + + { + let err = ConfigFile::from_str( + r#" + [fee_estimation] + cost_estimator = "foo" + unknown_field = "test" + "#, + ) + .unwrap_err(); + assert!(err.starts_with("Invalid toml: unknown field `unknown_field`")); + } + + { + let err = ConfigFile::from_str( + r#" + [miner] + first_attempt_time_ms = 180_000 + unknown_field = "test" + subsequent_attempt_time_ms = 360_000 + "#, + ) + .unwrap_err(); + println!("{}", err); + assert!(err.starts_with("Invalid toml: unknown field `unknown_field`")); + } + + { + let err = ConfigFile::from_str( + r#" + [atlas] + attachments_max_size = 100 + unknown_field = "test" + "#, + ) + .unwrap_err(); + assert!(err.starts_with("Invalid toml: unknown field `unknown_field`")); + } + } + + #[test] + fn test_example_confs() { + // For each config file in the ../conf/ directory, we should be able to parse it + let conf_dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("conf"); + println!("Reading config files from: {:?}", conf_dir); + let conf_files = fs::read_dir(conf_dir).unwrap(); + + for entry in conf_files { + let entry = entry.unwrap(); + let path = entry.path(); + if path.is_file() { + let file_name = path.file_name().unwrap().to_str().unwrap(); + if file_name.ends_with(".toml") { + let _config = ConfigFile::from_path(path.to_str().unwrap()).unwrap(); + debug!("Parsed config file: {}", file_name); + } + } + } + } + + #[test] + fn should_load_legacy_mstx_balances_toml() { + let config = ConfigFile::from_str( + r#" + [[ustx_balance]] + address = "ST2QKZ4FKHAH1NQKYKYAYZPY440FEPK7GZ1R5HBP2" + amount = 10000000000000000 + + [[ustx_balance]] + address = "ST319CF5WV77KYR1H3GT0GZ7B8Q4AQPY42ETP1VPF" + amount = 10000000000000000 + + [[mstx_balance]] # legacy property name + address = "ST221Z6TDTC5E0BYR2V624Q2ST6R0Q71T78WTAX6H" + amount = 10000000000000000 + + [[mstx_balance]] # legacy property name + address = "ST2TFVBMRPS5SSNP98DQKQ5JNB2B6NZM91C4K3P7B" + amount = 10000000000000000 + "#, + ); + let config = config.unwrap(); + assert!(config.ustx_balance.is_some()); + let balances = config + .ustx_balance + .expect("Failed to parse stx balances from toml"); + assert_eq!(balances.len(), 4); + assert_eq!( + balances[0].address, + "ST2QKZ4FKHAH1NQKYKYAYZPY440FEPK7GZ1R5HBP2" + ); + assert_eq!( + balances[1].address, + "ST319CF5WV77KYR1H3GT0GZ7B8Q4AQPY42ETP1VPF" + ); + assert_eq!( + balances[2].address, + "ST221Z6TDTC5E0BYR2V624Q2ST6R0Q71T78WTAX6H" + ); + assert_eq!( + balances[3].address, + "ST2TFVBMRPS5SSNP98DQKQ5JNB2B6NZM91C4K3P7B" + ); + } + + #[test] + fn should_load_auth_token() { + let config = Config::from_config_file( + ConfigFile::from_str( + r#" + [connection_options] + auth_token = "password" + "#, + ) + .unwrap(), + false, + ) + .expect("Expected to be able to parse block proposal token from file"); + + assert_eq!( + config.connection_options.auth_token, + Some("password".to_string()) + ); + } + + #[test] + fn should_load_affirmation_map() { + let affirmation_string = "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnppnnnnnnnnnnnnnnnnnnnnnnnnpppppnnnnnnnnnnnnnnnnnnnnnnnpppppppppppppppnnnnnnnnnnnnnnnnnnnnnnnppppppppppnnnnnnnnnnnnnnnnnnnppppnnnnnnnnnnnnnnnnnnnnnnnppppppppnnnnnnnnnnnnnnnnnnnnnnnppnppnnnnnnnnnnnnnnnnnnnnnnnppppnnnnnnnnnnnnnnnnnnnnnnnnnppppppnnnnnnnnnnnnnnnnnnnnnnnnnppnnnnnnnnnnnnnnnnnnnnnnnnnpppppppnnnnnnnnnnnnnnnnnnnnnnnnnnpnnnnnnnnnnnnnnnnnnnnnnnnnpppnppppppppppppppnnppppnpa"; + let affirmation = + AffirmationMap::decode(affirmation_string).expect("Failed to decode affirmation map"); + let config = Config::from_config_file( + ConfigFile::from_str(&format!( + r#" + [[burnchain.affirmation_overrides]] + reward_cycle = 413 + affirmation = "{affirmation_string}" + "# + )) + .expect("Expected to be able to parse config file from string"), + false, + ) + .expect("Expected to be able to parse affirmation map from file"); + + assert_eq!(config.burnchain.affirmation_overrides.len(), 1); + assert_eq!(config.burnchain.affirmation_overrides.get(&0), None); + assert_eq!( + config.burnchain.affirmation_overrides.get(&413), + Some(&affirmation) + ); + } + + #[test] + fn should_fail_to_load_invalid_affirmation_map() { + let bad_affirmation_string = "bad_map"; + let file = ConfigFile::from_str(&format!( + r#" + [[burnchain.affirmation_overrides]] + reward_cycle = 1 + affirmation = "{bad_affirmation_string}" + "# + )) + .expect("Expected to be able to parse config file from string"); + + assert!(Config::from_config_file(file, false).is_err()); + } + + #[test] + fn should_load_empty_affirmation_map() { + let config = Config::from_config_file( + ConfigFile::from_str(r#""#) + .expect("Expected to be able to parse config file from string"), + false, + ) + .expect("Expected to be able to parse affirmation map from file"); + + assert!(config.burnchain.affirmation_overrides.is_empty()); + } + + #[test] + fn should_include_xenon_default_affirmation_overrides() { + let config = Config::from_config_file( + ConfigFile::from_str( + r#" + [burnchain] + chain = "bitcoin" + mode = "xenon" + "#, + ) + .expect("Expected to be able to parse config file from string"), + false, + ) + .expect("Expected to be able to parse affirmation map from file"); + // Should default add xenon affirmation overrides + assert_eq!(config.burnchain.affirmation_overrides.len(), 5); + } + + #[test] + fn should_override_xenon_default_affirmation_overrides() { + let affirmation_string = "aaapnnnnnnnnnnnnnnnnnnnnnnnnnnnnppnnnnnnnnnnnnnnnnnnnnnnnnpppppnnnnnnnnnnnnnnnnnnnnnnnpppppppppppppppnnnnnnnnnnnnnnnnnnnnnnnppppppppppnnnnnnnnnnnnnnnnnnnppppnnnnnnnnnnnnnnnnnnnnnnnppppppppnnnnnnnnnnnnnnnnnnnnnnnppnppnnnnnnnnnnnnnnnnnnnnnnnppppnnnnnnnnnnnnnnnnnnnnnnnnnppppppnnnnnnnnnnnnnnnnnnnnnnnnnppnnnnnnnnnnnnnnnnnnnnnnnnnpppppppnnnnnnnnnnnnnnnnnnnnnnnnnnpnnnnnnnnnnnnnnnnnnnnnnnnnpppnppppppppppppppnnppppnpa"; + let affirmation = + AffirmationMap::decode(affirmation_string).expect("Failed to decode affirmation map"); + + let config = Config::from_config_file( + ConfigFile::from_str(&format!( + r#" + [burnchain] + chain = "bitcoin" + mode = "xenon" + + [[burnchain.affirmation_overrides]] + reward_cycle = 413 + affirmation = "{affirmation_string}" + "#, + )) + .expect("Expected to be able to parse config file from string"), + false, + ) + .expect("Expected to be able to parse affirmation map from file"); + // Should default add xenon affirmation overrides, but overwrite with the configured one above + assert_eq!(config.burnchain.affirmation_overrides.len(), 5); + assert_eq!(config.burnchain.affirmation_overrides[&413], affirmation); + } + + #[test] + fn test_into_config_default_chain_id() { + // Helper function to create BurnchainConfigFile with mode and optional chain_id + fn make_burnchain_config_file(mainnet: bool, chain_id: Option) -> BurnchainConfigFile { + let mut config = BurnchainConfigFile::default(); + if mainnet { + config.mode = Some("mainnet".to_string()); + } + config.chain_id = chain_id; + config + } + let default_burnchain_config = BurnchainConfig::default(); + + // **Case 1a:** Should panic when `is_mainnet` is true and `chain_id` != `CHAIN_ID_MAINNET` + { + let config_file = make_burnchain_config_file(true, Some(CHAIN_ID_TESTNET)); + + let result = config_file.into_config_default(default_burnchain_config.clone()); + + assert!( + result.is_err(), + "Expected error when chain_id != CHAIN_ID_MAINNET on mainnet" + ); + } + + // **Case 1b:** Should not panic when `is_mainnet` is true and `chain_id` == `CHAIN_ID_MAINNET` + { + let config_file = make_burnchain_config_file(true, Some(CHAIN_ID_MAINNET)); + + let config = config_file + .into_config_default(default_burnchain_config.clone()) + .expect("Should not panic"); + assert_eq!(config.chain_id, CHAIN_ID_MAINNET); + } + + // **Case 1c:** Should not panic when `is_mainnet` is false; chain_id should be as provided + { + let chain_id = 123456; + let config_file = make_burnchain_config_file(false, Some(chain_id)); + + let config = config_file + .into_config_default(default_burnchain_config.clone()) + .expect("Should not panic"); + assert_eq!(config.chain_id, chain_id); + } + + // **Case 2a:** Should not panic when `chain_id` is None and `is_mainnet` is true + { + let config_file = make_burnchain_config_file(true, None); + + let config = config_file + .into_config_default(default_burnchain_config.clone()) + .expect("Should not panic"); + assert_eq!(config.chain_id, CHAIN_ID_MAINNET); + } + + // **Case 2b:** Should not panic when `chain_id` is None and `is_mainnet` is false + { + let config_file = make_burnchain_config_file(false, None); + + let config = config_file + .into_config_default(default_burnchain_config.clone()) + .expect("Should not panic"); + assert_eq!(config.chain_id, CHAIN_ID_TESTNET); + } + } +} diff --git a/testnet/stacks-node/src/tests/epoch_205.rs b/testnet/stacks-node/src/tests/epoch_205.rs index 0ad7000631..076a5f61f3 100644 --- a/testnet/stacks-node/src/tests/epoch_205.rs +++ b/testnet/stacks-node/src/tests/epoch_205.rs @@ -25,7 +25,7 @@ use stacks_common::types::chainstate::{ use stacks_common::util::hash::hex_bytes; use stacks_common::util::sleep_ms; -use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; +use crate::config::{EventKeyType, InitialBalance}; use crate::tests::bitcoin_regtest::BitcoinCoreController; use crate::tests::neon_integrations::*; use crate::tests::{ @@ -78,8 +78,14 @@ fn test_exact_block_costs() { (ok 1))) "; - let contract_publish_tx = - make_contract_publish(&spender_sk, 0, 210_000, contract_name, contract_content); + let contract_publish_tx = make_contract_publish( + &spender_sk, + 0, + 210_000, + conf.burnchain.chain_id, + contract_name, + contract_content, + ); // make txs that alternate between let txs: Vec<_> = (1..transactions_to_broadcast + 1) @@ -89,6 +95,7 @@ fn test_exact_block_costs() { &spender_sk, nonce, 200_000, + conf.burnchain.chain_id, &spender_addr_c32, contract_name, "db-get2", @@ -99,6 +106,7 @@ fn test_exact_block_costs() { &spender_sk, nonce, 200_000, + conf.burnchain.chain_id, &spender_addr_c32, contract_name, "db-get2", @@ -307,14 +315,22 @@ fn test_dynamic_db_method_costs() { amount: 200_000_000, }); - let contract_publish_tx = - make_contract_publish(&spender_sk, 0, 210_000, contract_name, contract_content); + let contract_publish_tx = make_contract_publish( + &spender_sk, + 0, + 210_000, + conf.burnchain.chain_id, + contract_name, + contract_content, + ); + let chain_id = conf.burnchain.chain_id; let make_db_get1_call = |nonce| { make_contract_call( &spender_sk, nonce, 200_000, + chain_id, &spender_addr_c32, contract_name, "db-get1", @@ -327,6 +343,7 @@ fn test_dynamic_db_method_costs() { &spender_sk, nonce, 200_000, + chain_id, &spender_addr_c32, contract_name, "db-get2", @@ -800,6 +817,7 @@ fn test_cost_limit_switch_version205() { &creator_sk, 0, 1100000, + conf.burnchain.chain_id, "increment-contract", &giant_contract, ), @@ -828,6 +846,7 @@ fn test_cost_limit_switch_version205() { &alice_sk, 0, 1000, + conf.burnchain.chain_id, &creator_addr.into(), "increment-contract", "increment-many", @@ -862,6 +881,7 @@ fn test_cost_limit_switch_version205() { &bob_sk, 0, 1000, + conf.burnchain.chain_id, &creator_addr.into(), "increment-contract", "increment-many", @@ -902,65 +922,6 @@ fn bigger_microblock_streams_in_2_05() { .collect(); let spender_addrs: Vec = spender_sks.iter().map(|x| to_addr(x).into()).collect(); - let txs: Vec> = spender_sks - .iter() - .enumerate() - .map(|(ix, spender_sk)| { - // almost fills a whole block - make_contract_publish_microblock_only( - spender_sk, - 0, - 1049230, - &format!("large-{}", ix), - &format!(" - ;; a single one of these transactions consumes over half the runtime budget - (define-constant BUFF_TO_BYTE (list - 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f - 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f - 0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 0x29 0x2a 0x2b 0x2c 0x2d 0x2e 0x2f - 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x3a 0x3b 0x3c 0x3d 0x3e 0x3f - 0x40 0x41 0x42 0x43 0x44 0x45 0x46 0x47 0x48 0x49 0x4a 0x4b 0x4c 0x4d 0x4e 0x4f - 0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5a 0x5b 0x5c 0x5d 0x5e 0x5f - 0x60 0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f - 0x70 0x71 0x72 0x73 0x74 0x75 0x76 0x77 0x78 0x79 0x7a 0x7b 0x7c 0x7d 0x7e 0x7f - 0x80 0x81 0x82 0x83 0x84 0x85 0x86 0x87 0x88 0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f - 0x90 0x91 0x92 0x93 0x94 0x95 0x96 0x97 0x98 0x99 0x9a 0x9b 0x9c 0x9d 0x9e 0x9f - 0xa0 0xa1 0xa2 0xa3 0xa4 0xa5 0xa6 0xa7 0xa8 0xa9 0xaa 0xab 0xac 0xad 0xae 0xaf - 0xb0 0xb1 0xb2 0xb3 0xb4 0xb5 0xb6 0xb7 0xb8 0xb9 0xba 0xbb 0xbc 0xbd 0xbe 0xbf - 0xc0 0xc1 0xc2 0xc3 0xc4 0xc5 0xc6 0xc7 0xc8 0xc9 0xca 0xcb 0xcc 0xcd 0xce 0xcf - 0xd0 0xd1 0xd2 0xd3 0xd4 0xd5 0xd6 0xd7 0xd8 0xd9 0xda 0xdb 0xdc 0xdd 0xde 0xdf - 0xe0 0xe1 0xe2 0xe3 0xe4 0xe5 0xe6 0xe7 0xe8 0xe9 0xea 0xeb 0xec 0xed 0xee 0xef - 0xf0 0xf1 0xf2 0xf3 0xf4 0xf5 0xf6 0xf7 0xf8 0xf9 0xfa 0xfb 0xfc 0xfd 0xfe 0xff - )) - (define-private (crash-me-folder (input (buff 1)) (ctr uint)) - (begin - (unwrap-panic (index-of BUFF_TO_BYTE input)) - (unwrap-panic (index-of BUFF_TO_BYTE input)) - (unwrap-panic (index-of BUFF_TO_BYTE input)) - (unwrap-panic (index-of BUFF_TO_BYTE input)) - (unwrap-panic (index-of BUFF_TO_BYTE input)) - (unwrap-panic (index-of BUFF_TO_BYTE input)) - (unwrap-panic (index-of BUFF_TO_BYTE input)) - (unwrap-panic (index-of BUFF_TO_BYTE input)) - (+ u1 ctr) - ) - ) - (define-public (crash-me (name (string-ascii 128))) - (begin - (fold crash-me-folder BUFF_TO_BYTE u0) - (print name) - (ok u0) - ) - ) - (begin - (crash-me \"{}\")) - ", - &format!("large-contract-{}", &ix) - ) - ) - }) - .collect(); - let (mut conf, miner_account) = neon_integration_test_conf(); for spender_addr in spender_addrs.iter() { @@ -1022,6 +983,66 @@ fn bigger_microblock_streams_in_2_05() { ]); conf.burnchain.pox_2_activation = Some(10_003); + let txs: Vec> = spender_sks + .iter() + .enumerate() + .map(|(ix, spender_sk)| { + // almost fills a whole block + make_contract_publish_microblock_only( + spender_sk, + 0, + 1049230, + conf.burnchain.chain_id, + &format!("large-{}", ix), + &format!(" + ;; a single one of these transactions consumes over half the runtime budget + (define-constant BUFF_TO_BYTE (list + 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f + 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f + 0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 0x29 0x2a 0x2b 0x2c 0x2d 0x2e 0x2f + 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x3a 0x3b 0x3c 0x3d 0x3e 0x3f + 0x40 0x41 0x42 0x43 0x44 0x45 0x46 0x47 0x48 0x49 0x4a 0x4b 0x4c 0x4d 0x4e 0x4f + 0x50 0x51 0x52 0x53 0x54 0x55 0x56 0x57 0x58 0x59 0x5a 0x5b 0x5c 0x5d 0x5e 0x5f + 0x60 0x61 0x62 0x63 0x64 0x65 0x66 0x67 0x68 0x69 0x6a 0x6b 0x6c 0x6d 0x6e 0x6f + 0x70 0x71 0x72 0x73 0x74 0x75 0x76 0x77 0x78 0x79 0x7a 0x7b 0x7c 0x7d 0x7e 0x7f + 0x80 0x81 0x82 0x83 0x84 0x85 0x86 0x87 0x88 0x89 0x8a 0x8b 0x8c 0x8d 0x8e 0x8f + 0x90 0x91 0x92 0x93 0x94 0x95 0x96 0x97 0x98 0x99 0x9a 0x9b 0x9c 0x9d 0x9e 0x9f + 0xa0 0xa1 0xa2 0xa3 0xa4 0xa5 0xa6 0xa7 0xa8 0xa9 0xaa 0xab 0xac 0xad 0xae 0xaf + 0xb0 0xb1 0xb2 0xb3 0xb4 0xb5 0xb6 0xb7 0xb8 0xb9 0xba 0xbb 0xbc 0xbd 0xbe 0xbf + 0xc0 0xc1 0xc2 0xc3 0xc4 0xc5 0xc6 0xc7 0xc8 0xc9 0xca 0xcb 0xcc 0xcd 0xce 0xcf + 0xd0 0xd1 0xd2 0xd3 0xd4 0xd5 0xd6 0xd7 0xd8 0xd9 0xda 0xdb 0xdc 0xdd 0xde 0xdf + 0xe0 0xe1 0xe2 0xe3 0xe4 0xe5 0xe6 0xe7 0xe8 0xe9 0xea 0xeb 0xec 0xed 0xee 0xef + 0xf0 0xf1 0xf2 0xf3 0xf4 0xf5 0xf6 0xf7 0xf8 0xf9 0xfa 0xfb 0xfc 0xfd 0xfe 0xff + )) + (define-private (crash-me-folder (input (buff 1)) (ctr uint)) + (begin + (unwrap-panic (index-of BUFF_TO_BYTE input)) + (unwrap-panic (index-of BUFF_TO_BYTE input)) + (unwrap-panic (index-of BUFF_TO_BYTE input)) + (unwrap-panic (index-of BUFF_TO_BYTE input)) + (unwrap-panic (index-of BUFF_TO_BYTE input)) + (unwrap-panic (index-of BUFF_TO_BYTE input)) + (unwrap-panic (index-of BUFF_TO_BYTE input)) + (unwrap-panic (index-of BUFF_TO_BYTE input)) + (+ u1 ctr) + ) + ) + (define-public (crash-me (name (string-ascii 128))) + (begin + (fold crash-me-folder BUFF_TO_BYTE u0) + (print name) + (ok u0) + ) + ) + (begin + (crash-me \"{}\")) + ", + &format!("large-contract-{}", &ix) + ) + ) + }) + .collect(); + test_observer::spawn(); test_observer::register_any(&mut conf); diff --git a/testnet/stacks-node/src/tests/epoch_21.rs b/testnet/stacks-node/src/tests/epoch_21.rs index 4490fa5b07..8f6c466318 100644 --- a/testnet/stacks-node/src/tests/epoch_21.rs +++ b/testnet/stacks-node/src/tests/epoch_21.rs @@ -35,7 +35,7 @@ use stacks_common::util::secp256k1::{Secp256k1PrivateKey, Secp256k1PublicKey}; use stacks_common::util::sleep_ms; use crate::burnchains::bitcoin_regtest_controller::UTXO; -use crate::config::{Config, EventKeyType, EventObserverConfig, InitialBalance}; +use crate::config::{Config, InitialBalance}; use crate::neon::RunLoopCounter; use crate::operations::BurnchainOpSigner; use crate::stacks_common::address::AddressHashMode; @@ -360,6 +360,7 @@ fn transition_adds_burn_block_height() { &spender_sk, 0, (2 * contract.len()) as u64, + conf.burnchain.chain_id, "test-burn-headers", contract, ); @@ -373,6 +374,7 @@ fn transition_adds_burn_block_height() { &spender_sk, 1, (2 * contract.len()) as u64, + conf.burnchain.chain_id, &spender_addr_c32, "test-burn-headers", "test-burn-headers", @@ -1107,6 +1109,7 @@ fn transition_adds_get_pox_addr_recipients() { &spender_sk, 0, 300, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -1147,6 +1150,7 @@ fn transition_adds_get_pox_addr_recipients() { &spender_sk, 0, 300, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -1184,6 +1188,7 @@ fn transition_adds_get_pox_addr_recipients() { &spender_sks[0], 1, (2 * contract.len()) as u64, + conf.burnchain.chain_id, "test-get-pox-addrs", contract, ); @@ -1209,6 +1214,7 @@ fn transition_adds_get_pox_addr_recipients() { &spender_sks[0], 2, (2 * contract.len()) as u64, + conf.burnchain.chain_id, &spender_addr_c32, "test-get-pox-addrs", "test-get-pox-addrs", @@ -1578,6 +1584,7 @@ fn transition_removes_pox_sunset() { &spender_sk, 0, 260, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox", "stack-stx", @@ -1640,6 +1647,7 @@ fn transition_removes_pox_sunset() { &spender_sk, 1, 260 * 2, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -2273,6 +2281,7 @@ fn test_pox_reorgs_three_flaps() { pk, 0, 1360, + conf_template.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -2296,7 +2305,9 @@ fn test_pox_reorgs_three_flaps() { let all_txs: Vec<_> = privks .iter() .enumerate() - .map(|(i, pk)| make_random_tx_chain(pk, (25 * i) as u64, false)) + .map(|(i, pk)| { + make_random_tx_chain(pk, (25 * i) as u64, conf_template.burnchain.chain_id, false) + }) .collect(); // everyone locks up @@ -2810,6 +2821,7 @@ fn test_pox_reorg_one_flap() { pk, 0, 1360, + conf_template.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -2833,7 +2845,9 @@ fn test_pox_reorg_one_flap() { let all_txs: Vec<_> = privks .iter() .enumerate() - .map(|(i, pk)| make_random_tx_chain(pk, (25 * i) as u64, false)) + .map(|(i, pk)| { + make_random_tx_chain(pk, (25 * i) as u64, conf_template.burnchain.chain_id, false) + }) .collect(); // everyone locks up @@ -3235,6 +3249,7 @@ fn test_pox_reorg_flap_duel() { pk, 0, 1360, + conf_template.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -3258,7 +3273,9 @@ fn test_pox_reorg_flap_duel() { let all_txs: Vec<_> = privks .iter() .enumerate() - .map(|(i, pk)| make_random_tx_chain(pk, (25 * i) as u64, false)) + .map(|(i, pk)| { + make_random_tx_chain(pk, (25 * i) as u64, conf_template.burnchain.chain_id, false) + }) .collect(); // everyone locks up @@ -3670,6 +3687,7 @@ fn test_pox_reorg_flap_reward_cycles() { pk, 0, 1360, + conf_template.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -3693,7 +3711,9 @@ fn test_pox_reorg_flap_reward_cycles() { let all_txs: Vec<_> = privks .iter() .enumerate() - .map(|(i, pk)| make_random_tx_chain(pk, (25 * i) as u64, false)) + .map(|(i, pk)| { + make_random_tx_chain(pk, (25 * i) as u64, conf_template.burnchain.chain_id, false) + }) .collect(); // everyone locks up @@ -4099,6 +4119,7 @@ fn test_pox_missing_five_anchor_blocks() { pk, 0, 1360, + conf_template.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -4122,7 +4143,9 @@ fn test_pox_missing_five_anchor_blocks() { let all_txs: Vec<_> = privks .iter() .enumerate() - .map(|(i, pk)| make_random_tx_chain(pk, (25 * i) as u64, false)) + .map(|(i, pk)| { + make_random_tx_chain(pk, (25 * i) as u64, conf_template.burnchain.chain_id, false) + }) .collect(); // everyone locks up @@ -4500,6 +4523,7 @@ fn test_sortition_divergence_pre_21() { pk, 0, 1360, + conf_template.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox", "stack-stx", @@ -4523,7 +4547,9 @@ fn test_sortition_divergence_pre_21() { let all_txs: Vec<_> = privks .iter() .enumerate() - .map(|(i, pk)| make_random_tx_chain(pk, (25 * i) as u64, false)) + .map(|(i, pk)| { + make_random_tx_chain(pk, (25 * i) as u64, conf_template.burnchain.chain_id, false) + }) .collect(); // everyone locks up @@ -4798,13 +4824,34 @@ fn trait_invocation_cross_epoch() { let tip_info = get_chain_info(&conf); assert_eq!(tip_info.burn_block_height, epoch_2_05 + 1); - let tx = make_contract_publish(&spender_sk, 0, 10_000, "simple-trait", trait_contract); + let tx = make_contract_publish( + &spender_sk, + 0, + 10_000, + conf.burnchain.chain_id, + "simple-trait", + trait_contract, + ); let trait_txid = submit_tx(&http_origin, &tx); - let tx = make_contract_publish(&spender_sk, 1, 10_000, "impl-simple", impl_contract); + let tx = make_contract_publish( + &spender_sk, + 1, + 10_000, + conf.burnchain.chain_id, + "impl-simple", + impl_contract, + ); let impl_txid = submit_tx(&http_origin, &tx); - let tx = make_contract_publish(&spender_sk, 2, 10_000, "use-simple", use_contract); + let tx = make_contract_publish( + &spender_sk, + 2, + 10_000, + conf.burnchain.chain_id, + "use-simple", + use_contract, + ); let use_txid = submit_tx(&http_origin, &tx); // mine the transactions and advance to epoch 2.1 @@ -4815,7 +4862,14 @@ fn trait_invocation_cross_epoch() { let tip_info = get_chain_info(&conf); assert_eq!(tip_info.burn_block_height, epoch_2_1 + 1); - let tx = make_contract_publish(&spender_sk, 3, 10_000, "invoke-simple", invoke_contract); + let tx = make_contract_publish( + &spender_sk, + 3, + 10_000, + conf.burnchain.chain_id, + "invoke-simple", + invoke_contract, + ); let invoke_txid = submit_tx(&http_origin, &tx); for _ in 0..2 { @@ -4826,6 +4880,7 @@ fn trait_invocation_cross_epoch() { &spender_sk, 4, 10_000, + conf.burnchain.chain_id, &spender_addr_c32, "invoke-simple", "invocation-1", @@ -4837,6 +4892,7 @@ fn trait_invocation_cross_epoch() { &spender_sk, 5, 10_000, + conf.burnchain.chain_id, &spender_addr_c32, "invoke-simple", "invocation-2", @@ -5042,6 +5098,7 @@ fn test_v1_unlock_height_with_current_stackers() { &spender_sk, 0, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox", "stack-stx", @@ -5078,6 +5135,7 @@ fn test_v1_unlock_height_with_current_stackers() { &spender_sk, 1, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -5306,6 +5364,7 @@ fn test_v1_unlock_height_with_delay_and_current_stackers() { &spender_sk, 0, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox", "stack-stx", @@ -5354,6 +5413,7 @@ fn test_v1_unlock_height_with_delay_and_current_stackers() { &spender_sk, 1, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", diff --git a/testnet/stacks-node/src/tests/epoch_22.rs b/testnet/stacks-node/src/tests/epoch_22.rs index fecf5c4652..9bffca7c8a 100644 --- a/testnet/stacks-node/src/tests/epoch_22.rs +++ b/testnet/stacks-node/src/tests/epoch_22.rs @@ -227,6 +227,7 @@ fn disable_pox() { &spender_sk, 0, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox", "stack-stx", @@ -275,6 +276,7 @@ fn disable_pox() { &spender_sk, 1, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -293,6 +295,7 @@ fn disable_pox() { &spender_2_sk, 0, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -324,6 +327,7 @@ fn disable_pox() { &spender_sk, 2, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-increase", @@ -350,6 +354,7 @@ fn disable_pox() { &spender_sk, aborted_increase_nonce, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-increase", @@ -761,6 +766,7 @@ fn pox_2_unlock_all() { &spender_sk, 0, tx_fee, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox", "stack-stx", @@ -811,6 +817,7 @@ fn pox_2_unlock_all() { &spender_sk, 1, tx_fee, + conf.burnchain.chain_id, "unlock-height", "(define-public (unlock-height (x principal)) (ok (get unlock-height (stx-account x))))", ); @@ -820,6 +827,7 @@ fn pox_2_unlock_all() { &spender_sk, 2, tx_fee, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -839,6 +847,7 @@ fn pox_2_unlock_all() { &spender_2_sk, 0, tx_fee, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -869,6 +878,7 @@ fn pox_2_unlock_all() { &spender_sk, 3, tx_fee, + conf.burnchain.chain_id, &to_addr(&spender_sk), "unlock-height", "unlock-height", @@ -888,6 +898,7 @@ fn pox_2_unlock_all() { &spender_sk, 4, tx_fee, + conf.burnchain.chain_id, &to_addr(&spender_sk), "unlock-height", "unlock-height", @@ -977,7 +988,14 @@ fn pox_2_unlock_all() { ); // perform a transfer - let tx = make_stacks_transfer(&spender_sk, 5, tx_fee, &spender_3_addr, 1_000_000); + let tx = make_stacks_transfer( + &spender_sk, + 5, + tx_fee, + conf.burnchain.chain_id, + &spender_3_addr, + 1_000_000, + ); info!("Submit stack transfer tx to {:?}", &http_origin); submit_tx(&http_origin, &tx); @@ -1508,6 +1526,7 @@ fn test_pox_reorg_one_flap() { pk, 0, 1360, + conf_template.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -1531,7 +1550,9 @@ fn test_pox_reorg_one_flap() { let all_txs: Vec<_> = privks .iter() .enumerate() - .map(|(i, pk)| make_random_tx_chain(pk, (25 * i) as u64, false)) + .map(|(i, pk)| { + make_random_tx_chain(pk, (25 * i) as u64, conf_template.burnchain.chain_id, false) + }) .collect(); // everyone locks up diff --git a/testnet/stacks-node/src/tests/epoch_23.rs b/testnet/stacks-node/src/tests/epoch_23.rs index 7d0a5216a0..2355f7521d 100644 --- a/testnet/stacks-node/src/tests/epoch_23.rs +++ b/testnet/stacks-node/src/tests/epoch_23.rs @@ -22,7 +22,7 @@ use stacks::core; use stacks::core::STACKS_EPOCH_MAX; use stacks_common::util::sleep_ms; -use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; +use crate::config::InitialBalance; use crate::tests::bitcoin_regtest::BitcoinCoreController; use crate::tests::neon_integrations::*; use crate::tests::*; @@ -180,6 +180,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, "simple-trait", trait_contract, ); @@ -190,6 +191,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, "impl-simple", impl_contract, ); @@ -200,6 +202,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, "use-simple", use_contract, ); @@ -210,6 +213,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, "invoke-simple", invoke_contract, ); @@ -241,6 +245,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "invoke-simple", "invocation-1", @@ -253,6 +258,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "invoke-simple", "invocation-2", @@ -274,6 +280,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "invoke-simple", "invocation-1", @@ -286,6 +293,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "invoke-simple", "invocation-2", @@ -312,6 +320,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "invoke-simple", "invocation-1", @@ -324,6 +333,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "invoke-simple", "invocation-2", @@ -344,6 +354,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, "wrap-simple", wrapper_contract, ); @@ -359,6 +370,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "wrap-simple", "invocation-1", @@ -371,6 +383,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "wrap-simple", "invocation-2", @@ -397,6 +410,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "wrap-simple", "invocation-1", @@ -409,6 +423,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "wrap-simple", "invocation-2", @@ -431,6 +446,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "wrap-simple", "invocation-1", @@ -443,6 +459,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "wrap-simple", "invocation-2", @@ -464,6 +481,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "invoke-simple", "invocation-1", @@ -476,6 +494,7 @@ fn trait_invocation_behavior() { &spender_sk, spender_nonce, fee_amount, + conf.burnchain.chain_id, &contract_addr, "invoke-simple", "invocation-2", diff --git a/testnet/stacks-node/src/tests/epoch_24.rs b/testnet/stacks-node/src/tests/epoch_24.rs index 9c57a732d0..26ad007ca7 100644 --- a/testnet/stacks-node/src/tests/epoch_24.rs +++ b/testnet/stacks-node/src/tests/epoch_24.rs @@ -35,7 +35,7 @@ use stacks_common::util::hash::{bytes_to_hex, hex_bytes, Hash160}; use stacks_common::util::secp256k1::Secp256k1PublicKey; use stacks_common::util::sleep_ms; -use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; +use crate::config::InitialBalance; use crate::stacks_common::codec::StacksMessageCodec; use crate::tests::bitcoin_regtest::BitcoinCoreController; use crate::tests::neon_integrations::{ @@ -249,6 +249,7 @@ fn fix_to_pox_contract() { &spender_sk, 0, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox", "stack-stx", @@ -298,6 +299,7 @@ fn fix_to_pox_contract() { &spender_sk, 1, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -332,6 +334,7 @@ fn fix_to_pox_contract() { &spender_sk, aborted_increase_nonce_2_2, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-increase", @@ -357,6 +360,7 @@ fn fix_to_pox_contract() { &spender_sk, aborted_increase_nonce_2_3, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-increase", @@ -395,6 +399,7 @@ fn fix_to_pox_contract() { &spender_sk, 4, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-3", "stack-stx", @@ -414,6 +419,7 @@ fn fix_to_pox_contract() { &spender_2_sk, 0, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-3", "stack-stx", @@ -445,6 +451,7 @@ fn fix_to_pox_contract() { &spender_sk, 5, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-3", "stack-increase", @@ -889,6 +896,7 @@ fn verify_auto_unlock_behavior() { &spender_sk, 0, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox", "stack-stx", @@ -938,6 +946,7 @@ fn verify_auto_unlock_behavior() { &spender_sk, 1, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "stack-stx", @@ -1023,6 +1032,7 @@ fn verify_auto_unlock_behavior() { &spender_sk, 2, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-3", "stack-stx", @@ -1042,6 +1052,7 @@ fn verify_auto_unlock_behavior() { &spender_2_sk, 0, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-3", "stack-stx", @@ -1123,6 +1134,7 @@ fn verify_auto_unlock_behavior() { &spender_sk, 3, 3000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-3", "stack-increase", diff --git a/testnet/stacks-node/src/tests/epoch_25.rs b/testnet/stacks-node/src/tests/epoch_25.rs index 345aec4557..6af1bee626 100644 --- a/testnet/stacks-node/src/tests/epoch_25.rs +++ b/testnet/stacks-node/src/tests/epoch_25.rs @@ -21,7 +21,7 @@ use stacks::core; use stacks_common::consts::STACKS_EPOCH_MAX; use stacks_common::types::chainstate::StacksPrivateKey; -use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; +use crate::config::InitialBalance; use crate::tests::bitcoin_regtest::BitcoinCoreController; use crate::tests::nakamoto_integrations::wait_for; use crate::tests::neon_integrations::{ @@ -162,7 +162,14 @@ fn microblocks_disabled() { // push us to block 205 next_block_and_wait(&mut btc_regtest_controller, &blocks_processed); - let tx = make_stacks_transfer_mblock_only(&spender_1_sk, 0, 500, &spender_2_addr, 500); + let tx = make_stacks_transfer_mblock_only( + &spender_1_sk, + 0, + 500, + conf.burnchain.chain_id, + &spender_2_addr, + 500, + ); submit_tx(&http_origin, &tx); // wait until just before epoch 2.5 @@ -194,7 +201,14 @@ fn microblocks_disabled() { ); assert_eq!(account.nonce, 1); - let tx = make_stacks_transfer_mblock_only(&spender_1_sk, 1, 500, &spender_2_addr, 500); + let tx = make_stacks_transfer_mblock_only( + &spender_1_sk, + 1, + 500, + conf.burnchain.chain_id, + &spender_2_addr, + 500, + ); submit_tx(&http_origin, &tx); let mut last_block_height = get_chain_info(&conf).burn_block_height; diff --git a/testnet/stacks-node/src/tests/integrations.rs b/testnet/stacks-node/src/tests/integrations.rs index 694d27ca15..236d76b000 100644 --- a/testnet/stacks-node/src/tests/integrations.rs +++ b/testnet/stacks-node/src/tests/integrations.rs @@ -25,7 +25,7 @@ use stacks::clarity_vm::clarity::ClarityConnection; use stacks::codec::StacksMessageCodec; use stacks::core::mempool::MAXIMUM_MEMPOOL_TX_CHAINING; use stacks::core::{ - StacksEpoch, StacksEpochId, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, + StacksEpoch, StacksEpochId, CHAIN_ID_TESTNET, PEER_VERSION_EPOCH_2_0, PEER_VERSION_EPOCH_2_05, PEER_VERSION_EPOCH_2_1, }; use stacks::net::api::callreadonly::CallReadOnlyRequestBody; @@ -211,8 +211,14 @@ fn integration_test_get_info() { if round == 1 { // block-height = 2 eprintln!("Tenure in 1 started!"); - let publish_tx = - make_contract_publish(&contract_sk, 0, 10, "get-info", GET_INFO_CONTRACT); + let publish_tx = make_contract_publish( + &contract_sk, + 0, + 10, + CHAIN_ID_TESTNET, + "get-info", + GET_INFO_CONTRACT, + ); tenure .mem_pool .submit_raw( @@ -225,8 +231,14 @@ fn integration_test_get_info() { &StacksEpochId::Epoch21, ) .unwrap(); - let publish_tx = - make_contract_publish(&contract_sk, 1, 10, "other", OTHER_CONTRACT); + let publish_tx = make_contract_publish( + &contract_sk, + 1, + 10, + CHAIN_ID_TESTNET, + "other", + OTHER_CONTRACT, + ); tenure .mem_pool .submit_raw( @@ -239,8 +251,14 @@ fn integration_test_get_info() { &StacksEpochId::Epoch21, ) .unwrap(); - let publish_tx = - make_contract_publish(&contract_sk, 2, 10, "main", CALL_READ_CONTRACT); + let publish_tx = make_contract_publish( + &contract_sk, + 2, + 10, + CHAIN_ID_TESTNET, + "main", + CALL_READ_CONTRACT, + ); tenure .mem_pool .submit_raw( @@ -272,6 +290,7 @@ fn integration_test_get_info() { &contract_sk, 3, 10, + CHAIN_ID_TESTNET, "impl-trait-contract", IMPL_TRAIT_CONTRACT, ); @@ -294,6 +313,7 @@ fn integration_test_get_info() { &principal_sk, (round - 3).into(), 10, + CHAIN_ID_TESTNET, &to_addr(&contract_sk), "get-info", "update-info", @@ -319,6 +339,7 @@ fn integration_test_get_info() { &spender_sk, (round - 1).into(), 10, + CHAIN_ID_TESTNET, &StacksAddress::from_string(ADDR_4).unwrap().into(), 100, ); @@ -797,8 +818,13 @@ fn integration_test_get_info() { eprintln!("Test: POST {} (valid)", path); // tx_xfer is 180 bytes long - let tx_xfer = make_stacks_transfer(&spender_sk, round.into(), 200, - &StacksAddress::from_string(ADDR_4).unwrap().into(), 123); + let tx_xfer = make_stacks_transfer( + &spender_sk, + round.into(), + 200, + CHAIN_ID_TESTNET, + &StacksAddress::from_string(ADDR_4).unwrap().into(), + 123); let res: String = client.post(&path) .header("Content-Type", "application/octet-stream") @@ -829,7 +855,8 @@ fn integration_test_get_info() { eprintln!("Test: POST {} (invalid)", path); // tx_xfer_invalid is 180 bytes long - let tx_xfer_invalid = make_stacks_transfer(&spender_sk, (round + 30).into(), 200, // bad nonce + // bad nonce + let tx_xfer_invalid = make_stacks_transfer(&spender_sk, (round + 30).into(), 200, CHAIN_ID_TESTNET, &StacksAddress::from_string(ADDR_4).unwrap().into(), 456); let tx_xfer_invalid_tx = StacksTransaction::consensus_deserialize(&mut &tx_xfer_invalid[..]).unwrap(); @@ -1114,8 +1141,14 @@ fn contract_stx_transfer() { if round == 1 { // block-height = 2 - let xfer_to_contract = - make_stacks_transfer(&sk_3, 0, 10, &contract_identifier.into(), 1000); + let xfer_to_contract = make_stacks_transfer( + &sk_3, + 0, + 10, + CHAIN_ID_TESTNET, + &contract_identifier.into(), + 1000, + ); tenure .mem_pool .submit_raw( @@ -1130,8 +1163,14 @@ fn contract_stx_transfer() { .unwrap(); } else if round == 2 { // block-height > 2 - let publish_tx = - make_contract_publish(&contract_sk, 0, 10, "faucet", FAUCET_CONTRACT); + let publish_tx = make_contract_publish( + &contract_sk, + 0, + 10, + CHAIN_ID_TESTNET, + "faucet", + FAUCET_CONTRACT, + ); tenure .mem_pool .submit_raw( @@ -1146,8 +1185,14 @@ fn contract_stx_transfer() { .unwrap(); } else if round == 3 { // try to publish again - let publish_tx = - make_contract_publish(&contract_sk, 1, 10, "faucet", FAUCET_CONTRACT); + let publish_tx = make_contract_publish( + &contract_sk, + 1, + 10, + CHAIN_ID_TESTNET, + "faucet", + FAUCET_CONTRACT, + ); let (consensus_hash, block_hash) = ( &tenure.parent_block.metadata.consensus_hash, @@ -1170,6 +1215,7 @@ fn contract_stx_transfer() { &sk_2, 0, 10, + CHAIN_ID_TESTNET, &to_addr(&contract_sk), "faucet", "spout", @@ -1194,6 +1240,7 @@ fn contract_stx_transfer() { &sk_3, 1 + i, 200, + CHAIN_ID_TESTNET, &contract_identifier.clone().into(), 1000, ); @@ -1215,8 +1262,14 @@ fn contract_stx_transfer() { .unwrap(); } // this one should fail because the nonce is already in the mempool - let xfer_to_contract = - make_stacks_transfer(&sk_3, 3, 190, &contract_identifier.clone().into(), 1000); + let xfer_to_contract = make_stacks_transfer( + &sk_3, + 3, + 190, + CHAIN_ID_TESTNET, + &contract_identifier.clone().into(), + 1000, + ); let xfer_to_contract = StacksTransaction::consensus_deserialize(&mut &xfer_to_contract[..]).unwrap(); match tenure @@ -1446,8 +1499,14 @@ fn mine_transactions_out_of_order() { if round == 1 { // block-height = 2 - let xfer_to_contract = - make_stacks_transfer(&sk, 1, 10, &contract_identifier.into(), 1000); + let xfer_to_contract = make_stacks_transfer( + &sk, + 1, + 10, + CHAIN_ID_TESTNET, + &contract_identifier.into(), + 1000, + ); tenure .mem_pool .submit_raw( @@ -1462,7 +1521,8 @@ fn mine_transactions_out_of_order() { .unwrap(); } else if round == 2 { // block-height > 2 - let publish_tx = make_contract_publish(&sk, 2, 10, "faucet", FAUCET_CONTRACT); + let publish_tx = + make_contract_publish(&sk, 2, 10, CHAIN_ID_TESTNET, "faucet", FAUCET_CONTRACT); tenure .mem_pool .submit_raw( @@ -1476,8 +1536,14 @@ fn mine_transactions_out_of_order() { ) .unwrap(); } else if round == 3 { - let xfer_to_contract = - make_stacks_transfer(&sk, 3, 10, &contract_identifier.into(), 1000); + let xfer_to_contract = make_stacks_transfer( + &sk, + 3, + 10, + CHAIN_ID_TESTNET, + &contract_identifier.into(), + 1000, + ); tenure .mem_pool .submit_raw( @@ -1491,8 +1557,14 @@ fn mine_transactions_out_of_order() { ) .unwrap(); } else if round == 4 { - let xfer_to_contract = - make_stacks_transfer(&sk, 0, 10, &contract_identifier.into(), 1000); + let xfer_to_contract = make_stacks_transfer( + &sk, + 0, + 10, + CHAIN_ID_TESTNET, + &contract_identifier.into(), + 1000, + ); tenure .mem_pool .submit_raw( @@ -1593,8 +1665,14 @@ fn mine_contract_twice() { if round == 1 { // block-height = 2 - let publish_tx = - make_contract_publish(&contract_sk, 0, 10, "faucet", FAUCET_CONTRACT); + let publish_tx = make_contract_publish( + &contract_sk, + 0, + 10, + CHAIN_ID_TESTNET, + "faucet", + FAUCET_CONTRACT, + ); let (consensus_hash, block_hash) = ( &tenure.parent_block.metadata.consensus_hash, &tenure.parent_block.metadata.anchored_header.block_hash(), @@ -1691,8 +1769,14 @@ fn bad_contract_tx_rollback() { if round == 1 { // block-height = 2 - let xfer_to_contract = - make_stacks_transfer(&sk_3, 0, 10, &contract_identifier.into(), 1000); + let xfer_to_contract = make_stacks_transfer( + &sk_3, + 0, + 10, + CHAIN_ID_TESTNET, + &contract_identifier.into(), + 1000, + ); let (consensus_hash, block_hash) = ( &tenure.parent_block.metadata.consensus_hash, &tenure.parent_block.metadata.anchored_header.block_hash(), @@ -1711,7 +1795,8 @@ fn bad_contract_tx_rollback() { .unwrap(); } else if round == 2 { // block-height = 3 - let xfer_to_contract = make_stacks_transfer(&sk_3, 1, 10, &addr_2.into(), 1000); + let xfer_to_contract = + make_stacks_transfer(&sk_3, 1, 10, CHAIN_ID_TESTNET, &addr_2.into(), 1000); let (consensus_hash, block_hash) = ( &tenure.parent_block.metadata.consensus_hash, &tenure.parent_block.metadata.anchored_header.block_hash(), @@ -1730,7 +1815,8 @@ fn bad_contract_tx_rollback() { .unwrap(); // doesn't consistently get mined by the StacksBlockBuilder, because order matters! - let xfer_to_contract = make_stacks_transfer(&sk_3, 2, 10, &addr_2.into(), 3000); + let xfer_to_contract = + make_stacks_transfer(&sk_3, 2, 10, CHAIN_ID_TESTNET, &addr_2.into(), 3000); tenure .mem_pool .submit_raw( @@ -1744,8 +1830,14 @@ fn bad_contract_tx_rollback() { ) .unwrap(); - let publish_tx = - make_contract_publish(&contract_sk, 0, 10, "faucet", FAUCET_CONTRACT); + let publish_tx = make_contract_publish( + &contract_sk, + 0, + 10, + CHAIN_ID_TESTNET, + "faucet", + FAUCET_CONTRACT, + ); tenure .mem_pool .submit_raw( @@ -1759,8 +1851,14 @@ fn bad_contract_tx_rollback() { ) .unwrap(); - let publish_tx = - make_contract_publish(&contract_sk, 1, 10, "faucet", FAUCET_CONTRACT); + let publish_tx = make_contract_publish( + &contract_sk, + 1, + 10, + CHAIN_ID_TESTNET, + "faucet", + FAUCET_CONTRACT, + ); tenure .mem_pool .submit_raw( @@ -2014,6 +2112,7 @@ fn block_limit_runtime_test() { &contract_sk, 0, 10, + CHAIN_ID_TESTNET, "hello-contract", EXPENSIVE_CONTRACT.as_str(), ); @@ -2042,6 +2141,7 @@ fn block_limit_runtime_test() { sk, 0, 10, + CHAIN_ID_TESTNET, &to_addr(&contract_sk), "hello-contract", "do-it", @@ -2132,8 +2232,14 @@ fn mempool_errors() { if round == 1 { // block-height = 2 - let publish_tx = - make_contract_publish(&contract_sk, 0, 10, "get-info", GET_INFO_CONTRACT); + let publish_tx = make_contract_publish( + &contract_sk, + 0, + 10, + CHAIN_ID_TESTNET, + "get-info", + GET_INFO_CONTRACT, + ); eprintln!("Tenure in 1 started!"); tenure .mem_pool @@ -2176,6 +2282,7 @@ fn mempool_errors() { &spender_sk, 30, // bad nonce -- too much chaining 200, + CHAIN_ID_TESTNET, &send_to, 456, ); @@ -2217,6 +2324,7 @@ fn mempool_errors() { &spender_sk, 0, 1, // bad fee + CHAIN_ID_TESTNET, &send_to, 456, ); @@ -2250,6 +2358,7 @@ fn mempool_errors() { &contract_sk, 1, 2000, // not enough funds! + CHAIN_ID_TESTNET, &send_to, 456, ); @@ -2294,6 +2403,7 @@ fn mempool_errors() { 1 + MAXIMUM_MEMPOOL_TX_CHAINING, 1, 2000, + CHAIN_ID_TESTNET, &send_to, 1000, ); diff --git a/testnet/stacks-node/src/tests/mempool.rs b/testnet/stacks-node/src/tests/mempool.rs index 6221c6cf11..b701e70a15 100644 --- a/testnet/stacks-node/src/tests/mempool.rs +++ b/testnet/stacks-node/src/tests/mempool.rs @@ -112,8 +112,14 @@ fn mempool_setup_chainstate() { if round == 1 { eprintln!("Tenure in 1 started!"); - let publish_tx1 = - make_contract_publish(&contract_sk, 0, 100, "foo_contract", FOO_CONTRACT); + let publish_tx1 = make_contract_publish( + &contract_sk, + 0, + 100, + CHAIN_ID_TESTNET, + "foo_contract", + FOO_CONTRACT, + ); tenure .mem_pool .submit_raw( @@ -127,8 +133,14 @@ fn mempool_setup_chainstate() { ) .unwrap(); - let publish_tx2 = - make_contract_publish(&contract_sk, 1, 100, "trait-contract", TRAIT_CONTRACT); + let publish_tx2 = make_contract_publish( + &contract_sk, + 1, + 100, + CHAIN_ID_TESTNET, + "trait-contract", + TRAIT_CONTRACT, + ); tenure .mem_pool .submit_raw( @@ -146,6 +158,7 @@ fn mempool_setup_chainstate() { &contract_sk, 2, 100, + CHAIN_ID_TESTNET, "use-trait-contract", USE_TRAIT_CONTRACT, ); @@ -166,6 +179,7 @@ fn mempool_setup_chainstate() { &contract_sk, 3, 100, + CHAIN_ID_TESTNET, "implement-trait-contract", IMPLEMENT_TRAIT_CONTRACT, ); @@ -186,6 +200,7 @@ fn mempool_setup_chainstate() { &contract_sk, 4, 100, + CHAIN_ID_TESTNET, "bad-trait-contract", BAD_TRAIT_CONTRACT, ); @@ -234,8 +249,14 @@ fn mempool_setup_chainstate() { // let's throw some transactions at it. // first a couple valid ones: - let tx_bytes = - make_contract_publish(&contract_sk, 5, 1000, "bar_contract", FOO_CONTRACT); + let tx_bytes = make_contract_publish( + &contract_sk, + 5, + 1000, + CHAIN_ID_TESTNET, + "bar_contract", + FOO_CONTRACT, + ); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); chain_state @@ -252,6 +273,7 @@ fn mempool_setup_chainstate() { &contract_sk, 5, 200, + CHAIN_ID_TESTNET, &contract_addr, "foo_contract", "bar", @@ -269,7 +291,8 @@ fn mempool_setup_chainstate() { ) .unwrap(); - let tx_bytes = make_stacks_transfer(&contract_sk, 5, 200, &other_addr, 1000); + let tx_bytes = + make_stacks_transfer(&contract_sk, 5, 200, CHAIN_ID_TESTNET, &other_addr, 1000); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); chain_state @@ -321,6 +344,7 @@ fn mempool_setup_chainstate() { &contract_sk, 5, 200, + CHAIN_ID_TESTNET, &bad_addr, "foo_contract", "bar", @@ -354,7 +378,8 @@ fn mempool_setup_chainstate() { .unwrap() .into(); - let tx_bytes = make_stacks_transfer(&contract_sk, 5, 200, &bad_addr, 1000); + let tx_bytes = + make_stacks_transfer(&contract_sk, 5, 200, CHAIN_ID_TESTNET, &bad_addr, 1000); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -373,7 +398,8 @@ fn mempool_setup_chainstate() { }); // bad fees - let tx_bytes = make_stacks_transfer(&contract_sk, 5, 0, &other_addr, 1000); + let tx_bytes = + make_stacks_transfer(&contract_sk, 5, 0, CHAIN_ID_TESTNET, &other_addr, 1000); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -393,7 +419,8 @@ fn mempool_setup_chainstate() { }); // bad nonce - let tx_bytes = make_stacks_transfer(&contract_sk, 0, 200, &other_addr, 1000); + let tx_bytes = + make_stacks_transfer(&contract_sk, 0, 200, CHAIN_ID_TESTNET, &other_addr, 1000); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -413,7 +440,14 @@ fn mempool_setup_chainstate() { }); // not enough funds - let tx_bytes = make_stacks_transfer(&contract_sk, 5, 110000, &other_addr, 1000); + let tx_bytes = make_stacks_transfer( + &contract_sk, + 5, + 110000, + CHAIN_ID_TESTNET, + &other_addr, + 1000, + ); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -434,7 +468,14 @@ fn mempool_setup_chainstate() { // sender == recipient let contract_princ = PrincipalData::from(contract_addr.clone()); - let tx_bytes = make_stacks_transfer(&contract_sk, 5, 300, &contract_princ, 1000); + let tx_bytes = make_stacks_transfer( + &contract_sk, + 5, + 300, + CHAIN_ID_TESTNET, + &contract_princ, + 1000, + ); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -457,7 +498,14 @@ fn mempool_setup_chainstate() { let mut mainnet_recipient = to_addr(&other_sk); mainnet_recipient.version = C32_ADDRESS_VERSION_MAINNET_SINGLESIG; let mainnet_princ = mainnet_recipient.into(); - let tx_bytes = make_stacks_transfer(&contract_sk, 5, 300, &mainnet_princ, 1000); + let tx_bytes = make_stacks_transfer( + &contract_sk, + 5, + 300, + CHAIN_ID_TESTNET, + &mainnet_princ, + 1000, + ); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -488,6 +536,7 @@ fn mempool_setup_chainstate() { &contract_sk, 5, 300, + CHAIN_ID_TESTNET, TransactionAnchorMode::OnChainOnly, TransactionVersion::Mainnet, ); @@ -510,7 +559,8 @@ fn mempool_setup_chainstate() { }); // send amount must be positive - let tx_bytes = make_stacks_transfer(&contract_sk, 5, 300, &other_addr, 0); + let tx_bytes = + make_stacks_transfer(&contract_sk, 5, 300, CHAIN_ID_TESTNET, &other_addr, 0); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -530,7 +580,14 @@ fn mempool_setup_chainstate() { }); // not enough funds - let tx_bytes = make_stacks_transfer(&contract_sk, 5, 110000, &other_addr, 1000); + let tx_bytes = make_stacks_transfer( + &contract_sk, + 5, + 110000, + CHAIN_ID_TESTNET, + &other_addr, + 1000, + ); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -549,7 +606,14 @@ fn mempool_setup_chainstate() { false }); - let tx_bytes = make_stacks_transfer(&contract_sk, 5, 99700, &other_addr, 1000); + let tx_bytes = make_stacks_transfer( + &contract_sk, + 5, + 99700, + CHAIN_ID_TESTNET, + &other_addr, + 1000, + ); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -572,6 +636,7 @@ fn mempool_setup_chainstate() { &contract_sk, 5, 200, + CHAIN_ID_TESTNET, &contract_addr, "bar_contract", "bar", @@ -599,6 +664,7 @@ fn mempool_setup_chainstate() { &contract_sk, 5, 200, + CHAIN_ID_TESTNET, &contract_addr, "foo_contract", "foobar", @@ -626,6 +692,7 @@ fn mempool_setup_chainstate() { &contract_sk, 5, 200, + CHAIN_ID_TESTNET, &contract_addr, "foo_contract", "bar", @@ -649,8 +716,14 @@ fn mempool_setup_chainstate() { false }); - let tx_bytes = - make_contract_publish(&contract_sk, 5, 1000, "foo_contract", FOO_CONTRACT); + let tx_bytes = make_contract_publish( + &contract_sk, + 5, + 1000, + CHAIN_ID_TESTNET, + "foo_contract", + FOO_CONTRACT, + ); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -685,7 +758,14 @@ fn mempool_setup_chainstate() { signature: MessageSignature([1; 65]), }; - let tx_bytes = make_poison(&contract_sk, 5, 1000, microblock_1, microblock_2); + let tx_bytes = make_poison( + &contract_sk, + 5, + 1000, + CHAIN_ID_TESTNET, + microblock_1, + microblock_2, + ); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -716,7 +796,14 @@ fn mempool_setup_chainstate() { signature: MessageSignature([0; 65]), }; - let tx_bytes = make_poison(&contract_sk, 5, 1000, microblock_1, microblock_2); + let tx_bytes = make_poison( + &contract_sk, + 5, + 1000, + CHAIN_ID_TESTNET, + microblock_1, + microblock_2, + ); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -750,7 +837,14 @@ fn mempool_setup_chainstate() { microblock_1.sign(&other_sk).unwrap(); microblock_2.sign(&other_sk).unwrap(); - let tx_bytes = make_poison(&contract_sk, 5, 1000, microblock_1, microblock_2); + let tx_bytes = make_poison( + &contract_sk, + 5, + 1000, + CHAIN_ID_TESTNET, + microblock_1, + microblock_2, + ); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -765,7 +859,7 @@ fn mempool_setup_chainstate() { eprintln!("Err: {:?}", e); assert!(matches!(e, MemPoolRejection::Other(_))); - let tx_bytes = make_coinbase(&contract_sk, 5, 1000); + let tx_bytes = make_coinbase(&contract_sk, 5, 1000, CHAIN_ID_TESTNET); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -823,7 +917,14 @@ fn mempool_setup_chainstate() { microblock_1.sign(&secret_key).unwrap(); microblock_2.sign(&secret_key).unwrap(); - let tx_bytes = make_poison(&contract_sk, 5, 1000, microblock_1, microblock_2); + let tx_bytes = make_poison( + &contract_sk, + 5, + 1000, + CHAIN_ID_TESTNET, + microblock_1, + microblock_2, + ); let tx = StacksTransaction::consensus_deserialize(&mut tx_bytes.as_slice()).unwrap(); let e = chain_state @@ -848,6 +949,7 @@ fn mempool_setup_chainstate() { &contract_sk, 5, 250, + CHAIN_ID_TESTNET, &contract_addr, "use-trait-contract", "baz", @@ -875,6 +977,7 @@ fn mempool_setup_chainstate() { &contract_sk, 5, 250, + CHAIN_ID_TESTNET, &contract_addr, "use-trait-contract", "baz", diff --git a/testnet/stacks-node/src/tests/mod.rs b/testnet/stacks-node/src/tests/mod.rs index ba88584f39..cfa1653287 100644 --- a/testnet/stacks-node/src/tests/mod.rs +++ b/testnet/stacks-node/src/tests/mod.rs @@ -94,6 +94,7 @@ lazy_static! { .unwrap(), 0, 10, + CHAIN_ID_TESTNET, "store", STORE_CONTRACT ); @@ -134,6 +135,7 @@ pub fn serialize_sign_sponsored_sig_tx_anchor_mode_version( sender_nonce: u64, payer_nonce: u64, tx_fee: u64, + chain_id: u32, anchor_mode: TransactionAnchorMode, version: TransactionVersion, ) -> Vec { @@ -144,6 +146,7 @@ pub fn serialize_sign_sponsored_sig_tx_anchor_mode_version( sender_nonce, Some(payer_nonce), tx_fee, + chain_id, anchor_mode, version, ) @@ -154,12 +157,14 @@ pub fn serialize_sign_standard_single_sig_tx( sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, + chain_id: u32, ) -> Vec { serialize_sign_standard_single_sig_tx_anchor_mode( payload, sender, nonce, tx_fee, + chain_id, TransactionAnchorMode::OnChainOnly, ) } @@ -169,6 +174,7 @@ pub fn serialize_sign_standard_single_sig_tx_anchor_mode( sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, + chain_id: u32, anchor_mode: TransactionAnchorMode, ) -> Vec { serialize_sign_standard_single_sig_tx_anchor_mode_version( @@ -176,6 +182,7 @@ pub fn serialize_sign_standard_single_sig_tx_anchor_mode( sender, nonce, tx_fee, + chain_id, anchor_mode, TransactionVersion::Testnet, ) @@ -186,6 +193,7 @@ pub fn serialize_sign_standard_single_sig_tx_anchor_mode_version( sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, + chain_id: u32, anchor_mode: TransactionAnchorMode, version: TransactionVersion, ) -> Vec { @@ -196,6 +204,7 @@ pub fn serialize_sign_standard_single_sig_tx_anchor_mode_version( nonce, None, tx_fee, + chain_id, anchor_mode, version, ) @@ -208,6 +217,7 @@ pub fn serialize_sign_tx_anchor_mode_version( sender_nonce: u64, payer_nonce: Option, tx_fee: u64, + chain_id: u32, anchor_mode: TransactionAnchorMode, version: TransactionVersion, ) -> Vec { @@ -234,7 +244,7 @@ pub fn serialize_sign_tx_anchor_mode_version( let mut unsigned_tx = StacksTransaction::new(version, auth, payload); unsigned_tx.anchor_mode = anchor_mode; unsigned_tx.post_condition_mode = TransactionPostConditionMode::Allow; - unsigned_tx.chain_id = CHAIN_ID_TESTNET; + unsigned_tx.chain_id = chain_id; let mut tx_signer = StacksTransactionSigner::new(&unsigned_tx); tx_signer.sign_origin(sender).unwrap(); @@ -255,6 +265,7 @@ pub fn make_contract_publish_versioned( sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, + chain_id: u32, contract_name: &str, contract_content: &str, version: Option, @@ -265,23 +276,33 @@ pub fn make_contract_publish_versioned( let payload = TransactionPayload::SmartContract(TransactionSmartContract { name, code_body }, version); - serialize_sign_standard_single_sig_tx(payload, sender, nonce, tx_fee) + serialize_sign_standard_single_sig_tx(payload, sender, nonce, tx_fee, chain_id) } pub fn make_contract_publish( sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, + chain_id: u32, contract_name: &str, contract_content: &str, ) -> Vec { - make_contract_publish_versioned(sender, nonce, tx_fee, contract_name, contract_content, None) + make_contract_publish_versioned( + sender, + nonce, + tx_fee, + chain_id, + contract_name, + contract_content, + None, + ) } pub fn make_contract_publish_microblock_only_versioned( sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, + chain_id: u32, contract_name: &str, contract_content: &str, version: Option, @@ -297,6 +318,7 @@ pub fn make_contract_publish_microblock_only_versioned( sender, nonce, tx_fee, + chain_id, TransactionAnchorMode::OffChainOnly, ) } @@ -305,6 +327,7 @@ pub fn make_contract_publish_microblock_only( sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, + chain_id: u32, contract_name: &str, contract_content: &str, ) -> Vec { @@ -312,6 +335,7 @@ pub fn make_contract_publish_microblock_only( sender, nonce, tx_fee, + chain_id, contract_name, contract_content, None, @@ -392,12 +416,13 @@ pub fn make_stacks_transfer( sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, + chain_id: u32, recipient: &PrincipalData, amount: u64, ) -> Vec { let payload = TransactionPayload::TokenTransfer(recipient.clone(), amount, TokenTransferMemo([0; 34])); - serialize_sign_standard_single_sig_tx(payload.into(), sender, nonce, tx_fee) + serialize_sign_standard_single_sig_tx(payload.into(), sender, nonce, tx_fee, chain_id) } pub fn make_sponsored_stacks_transfer_on_testnet( @@ -406,6 +431,7 @@ pub fn make_sponsored_stacks_transfer_on_testnet( sender_nonce: u64, payer_nonce: u64, tx_fee: u64, + chain_id: u32, recipient: &PrincipalData, amount: u64, ) -> Vec { @@ -418,6 +444,7 @@ pub fn make_sponsored_stacks_transfer_on_testnet( sender_nonce, payer_nonce, tx_fee, + chain_id, TransactionAnchorMode::OnChainOnly, TransactionVersion::Testnet, ) @@ -427,6 +454,7 @@ pub fn make_stacks_transfer_mblock_only( sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, + chain_id: u32, recipient: &PrincipalData, amount: u64, ) -> Vec { @@ -437,6 +465,7 @@ pub fn make_stacks_transfer_mblock_only( sender, nonce, tx_fee, + chain_id, TransactionAnchorMode::OffChainOnly, ) } @@ -445,22 +474,24 @@ pub fn make_poison( sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, + chain_id: u32, header_1: StacksMicroblockHeader, header_2: StacksMicroblockHeader, ) -> Vec { let payload = TransactionPayload::PoisonMicroblock(header_1, header_2); - serialize_sign_standard_single_sig_tx(payload.into(), sender, nonce, tx_fee) + serialize_sign_standard_single_sig_tx(payload.into(), sender, nonce, tx_fee, chain_id) } -pub fn make_coinbase(sender: &StacksPrivateKey, nonce: u64, tx_fee: u64) -> Vec { +pub fn make_coinbase(sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, chain_id: u32) -> Vec { let payload = TransactionPayload::Coinbase(CoinbasePayload([0; 32]), None, None); - serialize_sign_standard_single_sig_tx(payload.into(), sender, nonce, tx_fee) + serialize_sign_standard_single_sig_tx(payload.into(), sender, nonce, tx_fee, chain_id) } pub fn make_contract_call( sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, + chain_id: u32, contract_addr: &StacksAddress, contract_name: &str, function_name: &str, @@ -476,13 +507,14 @@ pub fn make_contract_call( function_args: function_args.iter().map(|x| x.clone()).collect(), }; - serialize_sign_standard_single_sig_tx(payload.into(), sender, nonce, tx_fee) + serialize_sign_standard_single_sig_tx(payload.into(), sender, nonce, tx_fee, chain_id) } pub fn make_contract_call_mblock_only( sender: &StacksPrivateKey, nonce: u64, tx_fee: u64, + chain_id: u32, contract_addr: &StacksAddress, contract_name: &str, function_name: &str, @@ -503,6 +535,7 @@ pub fn make_contract_call_mblock_only( sender, nonce, tx_fee, + chain_id, TransactionAnchorMode::OffChainOnly, ) } @@ -921,7 +954,7 @@ fn should_succeed_handling_malformed_and_valid_txs() { 1 => { // On round 1, publish the KV contract let contract_sk = StacksPrivateKey::from_hex(SK_1).unwrap(); - let publish_contract = make_contract_publish(&contract_sk, 0, 10, "store", STORE_CONTRACT); + let publish_contract = make_contract_publish(&contract_sk, 0, 10, CHAIN_ID_TESTNET, "store", STORE_CONTRACT); tenure.mem_pool.submit_raw(&mut chainstate_copy, &sortdb, &consensus_hash, &header_hash,publish_contract, &ExecutionCost::max_value(), &StacksEpochId::Epoch20, diff --git a/testnet/stacks-node/src/tests/nakamoto_integrations.rs b/testnet/stacks-node/src/tests/nakamoto_integrations.rs index e25b7799a9..83b68e541d 100644 --- a/testnet/stacks-node/src/tests/nakamoto_integrations.rs +++ b/testnet/stacks-node/src/tests/nakamoto_integrations.rs @@ -78,7 +78,7 @@ use stacks::util_lib::signed_structured_data::pox4::{ use stacks_common::address::AddressHashMode; use stacks_common::bitvec::BitVec; use stacks_common::codec::StacksMessageCodec; -use stacks_common::consts::{CHAIN_ID_TESTNET, STACKS_EPOCH_MAX}; +use stacks_common::consts::STACKS_EPOCH_MAX; use stacks_common::types::chainstate::{ BlockHeaderHash, BurnchainHeaderHash, StacksAddress, StacksPrivateKey, StacksPublicKey, TrieHash, @@ -91,7 +91,7 @@ use stacks_signer::chainstate::{ProposalEvalConfig, SortitionsView}; use stacks_signer::signerdb::{BlockInfo, BlockState, ExtraBlockInfo, SignerDb}; use super::bitcoin_regtest::BitcoinCoreController; -use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; +use crate::config::{EventKeyType, InitialBalance}; use crate::nakamoto_node::miner::{ TEST_BLOCK_ANNOUNCE_STALL, TEST_BROADCAST_STALL, TEST_MINE_STALL, TEST_SKIP_P2P_BROADCAST, }; @@ -848,7 +848,7 @@ pub fn boot_to_epoch_3( &signer_sk, reward_cycle.into(), &Pox4SignatureTopic::StackStx, - CHAIN_ID_TESTNET, + naka_conf.burnchain.chain_id, 12_u128, u128::MAX, 1, @@ -862,6 +862,7 @@ pub fn boot_to_epoch_3( &stacker_sk, 0, 1000, + naka_conf.burnchain.chain_id, &StacksAddress::burn_address(false), "pox-4", "stack-stx", @@ -924,6 +925,7 @@ pub fn boot_to_epoch_3( signer_sk, 0, 300, + naka_conf.burnchain.chain_id, &StacksAddress::burn_address(false), SIGNERS_VOTING_NAME, SIGNERS_VOTING_FUNCTION_NAME, @@ -1008,7 +1010,7 @@ pub fn boot_to_pre_epoch_3_boundary( &signer_sk, reward_cycle.into(), &Pox4SignatureTopic::StackStx, - CHAIN_ID_TESTNET, + naka_conf.burnchain.chain_id, 12_u128, u128::MAX, 1, @@ -1022,6 +1024,7 @@ pub fn boot_to_pre_epoch_3_boundary( &stacker_sk, 0, 1000, + naka_conf.burnchain.chain_id, &StacksAddress::burn_address(false), "pox-4", "stack-stx", @@ -1084,6 +1087,7 @@ pub fn boot_to_pre_epoch_3_boundary( signer_sk, 0, 300, + naka_conf.burnchain.chain_id, &StacksAddress::burn_address(false), SIGNERS_VOTING_NAME, SIGNERS_VOTING_FUNCTION_NAME, @@ -1245,7 +1249,7 @@ pub fn setup_epoch_3_reward_set( &signer_sk, reward_cycle.into(), &Pox4SignatureTopic::StackStx, - CHAIN_ID_TESTNET, + naka_conf.burnchain.chain_id, lock_period, u128::MAX, 1, @@ -1258,6 +1262,7 @@ pub fn setup_epoch_3_reward_set( &stacker_sk, 0, 1000, + naka_conf.burnchain.chain_id, &StacksAddress::burn_address(false), "pox-4", "stack-stx", @@ -1527,7 +1532,14 @@ fn simple_neon_integration() { } // Submit a TX - let transfer_tx = make_stacks_transfer(&sender_sk, 0, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + 0, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); let transfer_tx_hex = format!("0x{}", to_hex(&transfer_tx)); let tip = NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb) @@ -1787,7 +1799,14 @@ fn flash_blocks_on_epoch_3() { } // Submit a TX - let transfer_tx = make_stacks_transfer(&sender_sk, 0, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + 0, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); let transfer_tx_hex = format!("0x{}", to_hex(&transfer_tx)); let tip = NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb) @@ -2025,8 +2044,14 @@ fn mine_multiple_per_tenure_integration() { .get_stacks_blocks_processed(); // submit a tx so that the miner will mine an extra block let sender_nonce = tenure_ix * inter_blocks_per_tenure + interim_block_ix; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); loop { @@ -2277,8 +2302,14 @@ fn multiple_miners() { .get_stacks_blocks_processed(); // submit a tx so that the miner will mine an extra block let sender_nonce = tenure_ix * inter_blocks_per_tenure + interim_block_ix; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); wait_for(20, || { @@ -2484,7 +2515,7 @@ fn correct_burn_outs() { &sender_signer_sk, reward_cycle.into(), &Pox4SignatureTopic::StackStx, - CHAIN_ID_TESTNET, + naka_conf.burnchain.chain_id, 1_u128, u128::MAX, 1, @@ -2496,6 +2527,7 @@ fn correct_burn_outs() { &account.0, account.2.nonce, 1000, + naka_conf.burnchain.chain_id, &StacksAddress::burn_address(false), "pox-4", "stack-stx", @@ -2837,6 +2869,7 @@ fn block_proposal_api_endpoint() { &account_keys[0], 0, 100, + conf.burnchain.chain_id, &to_addr(&account_keys[1]).into(), 10000, ); @@ -3514,7 +3547,7 @@ fn follower_bootup() { &node_info.node_public_key.unwrap(), naka_conf.node.p2p_bind ), - CHAIN_ID_TESTNET, + naka_conf.burnchain.chain_id, PEER_VERSION_TESTNET, ); @@ -3574,8 +3607,14 @@ fn follower_bootup() { let sender_nonce = account .nonce .max(last_nonce.as_ref().map(|ln| *ln + 1).unwrap_or(0)); - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); last_nonce = Some(sender_nonce); @@ -3860,7 +3899,7 @@ fn follower_bootup_across_multiple_cycles() { &node_info.node_public_key.unwrap(), naka_conf.node.p2p_bind ), - CHAIN_ID_TESTNET, + naka_conf.burnchain.chain_id, PEER_VERSION_TESTNET, ); @@ -3918,6 +3957,338 @@ fn follower_bootup_across_multiple_cycles() { follower_thread.join().unwrap(); } +/// Boot up a node and a follower with a non-default chain id +#[test] +#[ignore] +fn follower_bootup_custom_chain_id() { + if env::var("BITCOIND_TEST") != Ok("1".into()) { + return; + } + + let (mut naka_conf, _miner_account) = naka_neon_integration_conf(None); + naka_conf.burnchain.chain_id = 0x87654321; + let http_origin = format!("http://{}", &naka_conf.node.rpc_bind); + naka_conf.miner.wait_on_interim_blocks = Duration::from_secs(1); + let sender_sk = Secp256k1PrivateKey::new(); + let sender_signer_sk = Secp256k1PrivateKey::new(); + let sender_signer_addr = tests::to_addr(&sender_signer_sk); + let mut signers = TestSigners::new(vec![sender_signer_sk.clone()]); + let tenure_count = 5; + let inter_blocks_per_tenure = 9; + // setup sender + recipient for some test stx transfers + // these are necessary for the interim blocks to get mined at all + let sender_addr = tests::to_addr(&sender_sk); + let send_amt = 100; + let send_fee = 180; + naka_conf.add_initial_balance( + PrincipalData::from(sender_addr.clone()).to_string(), + (send_amt + send_fee) * tenure_count * inter_blocks_per_tenure, + ); + naka_conf.add_initial_balance( + PrincipalData::from(sender_signer_addr.clone()).to_string(), + 100000, + ); + let recipient = PrincipalData::from(StacksAddress::burn_address(false)); + let stacker_sk = setup_stacker(&mut naka_conf); + + test_observer::spawn(); + test_observer::register_any(&mut naka_conf); + + let mut btcd_controller = BitcoinCoreController::new(naka_conf.clone()); + btcd_controller + .start_bitcoind() + .expect("Failed starting bitcoind"); + let mut btc_regtest_controller = BitcoinRegtestController::new(naka_conf.clone(), None); + btc_regtest_controller.bootstrap_chain(201); + + let mut run_loop = boot_nakamoto::BootRunLoop::new(naka_conf.clone()).unwrap(); + let run_loop_stopper = run_loop.get_termination_switch(); + let Counters { + blocks_processed, + naka_submitted_commits: commits_submitted, + naka_proposed_blocks: proposals_submitted, + .. + } = run_loop.counters(); + + let coord_channel = run_loop.coordinator_channels(); + + let run_loop_thread = thread::Builder::new() + .name("run_loop".into()) + .spawn(move || run_loop.start(None, 0)) + .unwrap(); + wait_for_runloop(&blocks_processed); + boot_to_epoch_3( + &naka_conf, + &blocks_processed, + &[stacker_sk], + &[sender_signer_sk], + &mut Some(&mut signers), + &mut btc_regtest_controller, + ); + + info!("Bootstrapped to Epoch-3.0 boundary, starting nakamoto miner"); + + let burnchain = naka_conf.get_burnchain(); + let sortdb = burnchain.open_sortition_db(true).unwrap(); + let (chainstate, _) = StacksChainState::open( + naka_conf.is_mainnet(), + naka_conf.burnchain.chain_id, + &naka_conf.get_chainstate_path_str(), + None, + ) + .unwrap(); + + let block_height_pre_3_0 = + NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb) + .unwrap() + .unwrap() + .stacks_block_height; + + info!("Nakamoto miner started..."); + blind_signer(&naka_conf, &signers, proposals_submitted); + + wait_for_first_naka_block_commit(60, &commits_submitted); + + let mut follower_conf = naka_conf.clone(); + follower_conf.node.miner = false; + follower_conf.events_observers.clear(); + follower_conf.node.working_dir = format!("{}-follower", &naka_conf.node.working_dir); + follower_conf.node.seed = vec![0x01; 32]; + follower_conf.node.local_peer_seed = vec![0x02; 32]; + + let rpc_port = gen_random_port(); + let p2p_port = gen_random_port(); + + let localhost = "127.0.0.1"; + follower_conf.node.rpc_bind = format!("{localhost}:{rpc_port}"); + follower_conf.node.p2p_bind = format!("{localhost}:{p2p_port}"); + follower_conf.node.data_url = format!("http://{localhost}:{rpc_port}"); + follower_conf.node.p2p_address = format!("{localhost}:{p2p_port}"); + follower_conf.node.pox_sync_sample_secs = 30; + + let node_info = get_chain_info(&naka_conf); + follower_conf.node.add_bootstrap_node( + &format!( + "{}@{}", + &node_info.node_public_key.unwrap(), + naka_conf.node.p2p_bind + ), + naka_conf.burnchain.chain_id, + PEER_VERSION_TESTNET, + ); + + let mut follower_run_loop = boot_nakamoto::BootRunLoop::new(follower_conf.clone()).unwrap(); + let follower_run_loop_stopper = follower_run_loop.get_termination_switch(); + let follower_coord_channel = follower_run_loop.coordinator_channels(); + + debug!( + "Booting follower-thread ({},{})", + &follower_conf.node.p2p_bind, &follower_conf.node.rpc_bind + ); + debug!( + "Booting follower-thread: neighbors = {:?}", + &follower_conf.node.bootstrap_node + ); + + // spawn a follower thread + let follower_thread = thread::Builder::new() + .name("follower-thread".into()) + .spawn(move || follower_run_loop.start(None, 0)) + .unwrap(); + + debug!("Booted follower-thread"); + + // Mine `tenure_count` nakamoto tenures + for tenure_ix in 0..tenure_count { + debug!("follower_bootup: Miner runs tenure {}", tenure_ix); + let commits_before = commits_submitted.load(Ordering::SeqCst); + next_block_and_process_new_stacks_block(&mut btc_regtest_controller, 60, &coord_channel) + .unwrap(); + + let mut last_tip = BlockHeaderHash([0x00; 32]); + let mut last_nonce = None; + + debug!( + "follower_bootup: Miner mines interum blocks for tenure {}", + tenure_ix + ); + + // mine the interim blocks + for _ in 0..inter_blocks_per_tenure { + let blocks_processed_before = coord_channel + .lock() + .expect("Mutex poisoned") + .get_stacks_blocks_processed(); + + let account = loop { + // submit a tx so that the miner will mine an extra block + let Ok(account) = get_account_result(&http_origin, &sender_addr) else { + debug!("follower_bootup: Failed to load miner account"); + thread::sleep(Duration::from_millis(100)); + continue; + }; + break account; + }; + + let sender_nonce = account + .nonce + .max(last_nonce.as_ref().map(|ln| *ln + 1).unwrap_or(0)); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); + submit_tx(&http_origin, &transfer_tx); + + last_nonce = Some(sender_nonce); + + let tx = StacksTransaction::consensus_deserialize(&mut &transfer_tx[..]).unwrap(); + + debug!("follower_bootup: Miner account: {:?}", &account); + debug!("follower_bootup: Miner sent {}: {:?}", &tx.txid(), &tx); + + let now = get_epoch_time_secs(); + while get_epoch_time_secs() < now + 10 { + let Ok(info) = get_chain_info_result(&naka_conf) else { + debug!("follower_bootup: Could not get miner chain info"); + thread::sleep(Duration::from_millis(100)); + continue; + }; + + let Ok(follower_info) = get_chain_info_result(&follower_conf) else { + debug!("follower_bootup: Could not get follower chain info"); + thread::sleep(Duration::from_millis(100)); + continue; + }; + + if follower_info.burn_block_height < info.burn_block_height { + debug!("follower_bootup: Follower is behind miner's burnchain view"); + thread::sleep(Duration::from_millis(100)); + continue; + } + + if info.stacks_tip == last_tip { + debug!( + "follower_bootup: Miner stacks tip hasn't changed ({})", + &info.stacks_tip + ); + thread::sleep(Duration::from_millis(100)); + continue; + } + + let blocks_processed = coord_channel + .lock() + .expect("Mutex poisoned") + .get_stacks_blocks_processed(); + + if blocks_processed > blocks_processed_before { + break; + } + + debug!("follower_bootup: No blocks processed yet"); + thread::sleep(Duration::from_millis(100)); + } + + // compare chain tips + loop { + let Ok(info) = get_chain_info_result(&naka_conf) else { + debug!("follower_bootup: failed to load tip info"); + thread::sleep(Duration::from_millis(100)); + continue; + }; + + let Ok(follower_info) = get_chain_info_result(&follower_conf) else { + debug!("follower_bootup: Could not get follower chain info"); + thread::sleep(Duration::from_millis(100)); + continue; + }; + if info.stacks_tip == follower_info.stacks_tip { + debug!( + "follower_bootup: Follower has advanced to miner's tip {}", + &info.stacks_tip + ); + } else { + debug!( + "follower_bootup: Follower has NOT advanced to miner's tip: {} != {}", + &info.stacks_tip, follower_info.stacks_tip + ); + } + + last_tip = info.stacks_tip; + break; + } + } + + debug!("follower_bootup: Wait for next block-commit"); + let start_time = Instant::now(); + while commits_submitted.load(Ordering::SeqCst) <= commits_before { + if start_time.elapsed() >= Duration::from_secs(20) { + panic!("Timed out waiting for block-commit"); + } + thread::sleep(Duration::from_millis(100)); + } + debug!("follower_bootup: Block commit submitted"); + } + + // load the chain tip, and assert that it is a nakamoto block and at least 30 blocks have advanced in epoch 3 + let tip = NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb) + .unwrap() + .unwrap(); + info!( + "Latest tip"; + "height" => tip.stacks_block_height, + "is_nakamoto" => tip.anchored_header.as_stacks_nakamoto().is_some(), + ); + + assert!(tip.anchored_header.as_stacks_nakamoto().is_some()); + assert_eq!( + tip.stacks_block_height, + block_height_pre_3_0 + ((inter_blocks_per_tenure + 1) * tenure_count), + "Should have mined (1 + interim_blocks_per_tenure) * tenure_count nakamoto blocks" + ); + + // wait for follower to reach the chain tip + loop { + sleep_ms(1000); + let follower_node_info = get_chain_info(&follower_conf); + + info!( + "Follower tip is now {}/{}", + &follower_node_info.stacks_tip_consensus_hash, &follower_node_info.stacks_tip + ); + if follower_node_info.stacks_tip_consensus_hash == tip.consensus_hash + && follower_node_info.stacks_tip == tip.anchored_header.block_hash() + { + break; + } + } + + // Verify both nodes have the correct chain id + let miner_info = get_chain_info(&naka_conf); + assert_eq!(miner_info.network_id, 0x87654321); + + let follower_info = get_chain_info(&follower_conf); + assert_eq!(follower_info.network_id, 0x87654321); + + coord_channel + .lock() + .expect("Mutex poisoned") + .stop_chains_coordinator(); + run_loop_stopper.store(false, Ordering::SeqCst); + + follower_coord_channel + .lock() + .expect("Mutex poisoned") + .stop_chains_coordinator(); + follower_run_loop_stopper.store(false, Ordering::SeqCst); + + run_loop_thread.join().unwrap(); + follower_thread.join().unwrap(); +} + #[test] #[ignore] /// Test out various burn operations being processed in Nakamoto. @@ -4152,6 +4523,7 @@ fn burn_ops_integration_test() { &signer_sk_1, 1, 500, + naka_conf.burnchain.chain_id, &StacksAddress::burn_address(false), "pox-4", "set-signer-key-authorization", @@ -4354,8 +4726,14 @@ fn burn_ops_integration_test() { .expect("Mutex poisoned") .get_stacks_blocks_processed(); // submit a tx so that the miner will mine an extra block - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, 200, &stacker_addr_1.into(), 10000); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + 200, + naka_conf.burnchain.chain_id, + &stacker_addr_1.into(), + 10000, + ); sender_nonce += 1; submit_tx(&http_origin, &transfer_tx); @@ -4765,8 +5143,14 @@ fn forked_tenure_is_ignored() { // submit a tx so that the miner will mine an extra block let sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); info!("Submitted tx {tx} in Tenure C to mine a second block"); @@ -4964,6 +5348,7 @@ fn check_block_heights() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract0_name, contract_clarity1, ); @@ -5049,6 +5434,7 @@ fn check_block_heights() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract1_name, contract_clarity1, Some(ClarityVersion::Clarity2), @@ -5065,6 +5451,7 @@ fn check_block_heights() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract3_name, contract_clarity3, ); @@ -5172,8 +5559,14 @@ fn check_block_heights() { .expect("Mutex poisoned") .get_stacks_blocks_processed(); // submit a tx so that the miner will mine an extra block - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); sender_nonce += 1; submit_tx(&http_origin, &transfer_tx); @@ -5464,8 +5857,14 @@ fn nakamoto_attempt_time() { let mut sender_nonce = account.nonce; for _ in 0..txs_per_block { - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, tx_fee, &recipient, amount); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + tx_fee, + naka_conf.burnchain.chain_id, + &recipient, + amount, + ); sender_nonce += 1; submit_tx(&http_origin, &transfer_tx); } @@ -5557,8 +5956,14 @@ fn nakamoto_attempt_time() { 'submit_txs: loop { let acct = &mut account[acct_idx]; for _ in 0..MAXIMUM_MEMPOOL_TX_CHAINING { - let transfer_tx = - make_stacks_transfer(&acct.privk, acct.nonce, tx_fee, &recipient, amount); + let transfer_tx = make_stacks_transfer( + &acct.privk, + acct.nonce, + tx_fee, + naka_conf.burnchain.chain_id, + &recipient, + amount, + ); submit_tx(&http_origin, &transfer_tx); tx_total_size += transfer_tx.len(); tx_count += 1; @@ -5708,6 +6113,7 @@ fn clarity_burn_state() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract_name, contract, ); @@ -5739,6 +6145,7 @@ fn clarity_burn_state() { &sender_sk, sender_nonce, tx_fee, + naka_conf.burnchain.chain_id, &sender_addr, contract_name, "bar", @@ -5827,6 +6234,7 @@ fn clarity_burn_state() { &sender_sk, sender_nonce, tx_fee, + naka_conf.burnchain.chain_id, &sender_addr, contract_name, "bar", @@ -6122,8 +6530,14 @@ fn signer_chainstate() { // submit a tx to trigger an intermediate block let sender_nonce = i; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); let timer = Instant::now(); @@ -6637,7 +7051,14 @@ fn continue_tenure_extend() { .unwrap(); // Submit a TX - let transfer_tx = make_stacks_transfer(&sender_sk, 0, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + 0, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); let transfer_tx_hex = format!("0x{}", to_hex(&transfer_tx)); let tip = NakamotoChainState::get_canonical_block_header(chainstate.db(), &sortdb) @@ -6869,6 +7290,7 @@ fn check_block_times() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract0_name, contract_clarity1, ); @@ -6912,6 +7334,7 @@ fn check_block_times() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract1_name, contract_clarity1, Some(ClarityVersion::Clarity2), @@ -6929,6 +7352,7 @@ fn check_block_times() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract3_name, contract_clarity3, ); @@ -7024,8 +7448,14 @@ fn check_block_times() { info!("Mining Nakamoto block"); // submit a tx so that the miner will mine an extra block - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); sender_nonce += 1; submit_tx(&http_origin, &transfer_tx); @@ -7105,8 +7535,14 @@ fn check_block_times() { .get_stacks_blocks_processed(); // submit a tx so that the miner will mine an extra block - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); loop { @@ -7352,6 +7788,7 @@ fn check_block_info() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract0_name, contract_clarity1, ); @@ -7390,6 +7827,7 @@ fn check_block_info() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract1_name, contract_clarity1, Some(ClarityVersion::Clarity2), @@ -7422,6 +7860,7 @@ fn check_block_info() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract3_name, contract_clarity3, ); @@ -7528,8 +7967,14 @@ fn check_block_info() { .get_stacks_blocks_processed(); // submit a tx so that the miner will mine an extra block - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); sender_nonce += 1; submit_tx(&http_origin, &transfer_tx); @@ -7635,8 +8080,14 @@ fn check_block_info() { .get_stacks_blocks_processed(); // submit a tx so that the miner will mine an extra block - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); loop { @@ -7861,6 +8312,7 @@ fn check_block_info_rewards() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract0_name, contract_clarity1, ); @@ -7899,6 +8351,7 @@ fn check_block_info_rewards() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract1_name, contract_clarity1, Some(ClarityVersion::Clarity2), @@ -7924,6 +8377,7 @@ fn check_block_info_rewards() { &sender_sk, sender_nonce, deploy_fee, + naka_conf.burnchain.chain_id, contract3_name, contract_clarity3, ); @@ -7944,8 +8398,14 @@ fn check_block_info_rewards() { .get_stacks_blocks_processed(); // submit a tx so that the miner will mine an extra block - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); sender_nonce += 1; submit_tx(&http_origin, &transfer_tx); @@ -7971,8 +8431,14 @@ fn check_block_info_rewards() { .get_stacks_blocks_processed(); // submit a tx so that the miner will mine an extra block - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); loop { @@ -8233,7 +8699,7 @@ fn mock_mining() { &node_info.node_public_key.unwrap(), naka_conf.node.p2p_bind ), - CHAIN_ID_TESTNET, + naka_conf.burnchain.chain_id, PEER_VERSION_TESTNET, ); @@ -8298,8 +8764,14 @@ fn mock_mining() { .get_stacks_blocks_processed(); // submit a tx so that the miner will mine an extra block let sender_nonce = tenure_ix * inter_blocks_per_tenure + interim_block_ix; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); loop { @@ -8678,8 +9150,14 @@ fn v3_signer_api_endpoint() { .get_stacks_blocks_processed(); // submit a tx so that the miner will mine an extra stacks block let sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); wait_for(30, || { @@ -8833,6 +9311,7 @@ fn skip_mining_long_tx() { &sender_2_sk, 0, 9_000, + naka_conf.burnchain.chain_id, "large_contract", &format!( "(define-constant INP_LIST (list {input_list})) @@ -8856,8 +9335,14 @@ fn skip_mining_long_tx() { TEST_SKIP_P2P_BROADCAST.lock().unwrap().replace(false); } else { - let transfer_tx = - make_stacks_transfer(&sender_1_sk, i - 1, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_1_sk, + i - 1, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); wait_for(30, || { diff --git a/testnet/stacks-node/src/tests/neon_integrations.rs b/testnet/stacks-node/src/tests/neon_integrations.rs index 14ec15447f..d6373a3b44 100644 --- a/testnet/stacks-node/src/tests/neon_integrations.rs +++ b/testnet/stacks-node/src/tests/neon_integrations.rs @@ -1517,6 +1517,7 @@ fn deep_contract() { &spender_sk, 0, 1000, + conf.burnchain.chain_id, "test-publish", &exceeds_stack_depth_list, ); @@ -1694,11 +1695,25 @@ fn liquid_ustx_integration() { let _sort_height = channel.get_sortitions_processed(); - let publish = make_contract_publish(&spender_sk, 0, 1000, "caller", caller_src); + let publish = make_contract_publish( + &spender_sk, + 0, + 1000, + conf.burnchain.chain_id, + "caller", + caller_src, + ); let replaced_txid = submit_tx(&http_origin, &publish); - let publish = make_contract_publish(&spender_sk, 0, 1100, "caller", caller_src); + let publish = make_contract_publish( + &spender_sk, + 0, + 1100, + conf.burnchain.chain_id, + "caller", + caller_src, + ); submit_tx(&http_origin, &publish); let dropped_txs = test_observer::get_memtx_drops(); @@ -1715,6 +1730,7 @@ fn liquid_ustx_integration() { &spender_sk, 1, 1000, + conf.burnchain.chain_id, &spender_addr, "caller", "execute", @@ -2274,6 +2290,7 @@ fn stx_delegate_btc_integration_test() { &recipient_sk, 0, 293, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-2", "delegate-stack-stx", @@ -2562,6 +2579,7 @@ fn stack_stx_burn_op_test() { &signer_sk_1, 0, 500, + conf.burnchain.chain_id, &boot_code_addr(false), POX_4_NAME, "set-signer-key-authorization", @@ -2923,6 +2941,7 @@ fn vote_for_aggregate_key_burn_op_test() { &spender_sk, 0, 500, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox-4", "stack-stx", @@ -3145,6 +3164,7 @@ fn bitcoind_resubmission_test() { &spender_sk, 0, 100, + conf.burnchain.chain_id, &PrincipalData::from(StacksAddress::burn_address(false)), 1000, ); @@ -3488,12 +3508,24 @@ fn microblock_fork_poison_integration_test() { info!("Test microblock"); let recipient = StacksAddress::from_string(ADDR_4).unwrap(); - let unconfirmed_tx_bytes = - make_stacks_transfer_mblock_only(&spender_sk, 0, 1000, &recipient.into(), 1000); + let unconfirmed_tx_bytes = make_stacks_transfer_mblock_only( + &spender_sk, + 0, + 1000, + conf.burnchain.chain_id, + &recipient.into(), + 1000, + ); let unconfirmed_tx = StacksTransaction::consensus_deserialize(&mut &unconfirmed_tx_bytes[..]).unwrap(); - let second_unconfirmed_tx_bytes = - make_stacks_transfer_mblock_only(&second_spender_sk, 0, 1000, &recipient.into(), 1500); + let second_unconfirmed_tx_bytes = make_stacks_transfer_mblock_only( + &second_spender_sk, + 0, + 1000, + conf.burnchain.chain_id, + &recipient.into(), + 1500, + ); let second_unconfirmed_tx = StacksTransaction::consensus_deserialize(&mut &second_unconfirmed_tx_bytes[..]).unwrap(); @@ -3722,7 +3754,14 @@ fn microblock_integration_test() { // okay, let's push a transaction that is marked microblock only! let recipient = StacksAddress::from_string(ADDR_4).unwrap(); - let tx = make_stacks_transfer_mblock_only(&spender_sk, 0, 1000, &recipient.into(), 1000); + let tx = make_stacks_transfer_mblock_only( + &spender_sk, + 0, + 1000, + conf.burnchain.chain_id, + &recipient.into(), + 1000, + ); submit_tx(&http_origin, &tx); info!("Try to mine a microblock-only tx"); @@ -3752,12 +3791,24 @@ fn microblock_integration_test() { // push another two transactions that are marked microblock only let recipient = StacksAddress::from_string(ADDR_4).unwrap(); - let unconfirmed_tx_bytes = - make_stacks_transfer_mblock_only(&spender_sk, 1, 1000, &recipient.into(), 1000); + let unconfirmed_tx_bytes = make_stacks_transfer_mblock_only( + &spender_sk, + 1, + 1000, + conf.burnchain.chain_id, + &recipient.into(), + 1000, + ); let unconfirmed_tx = StacksTransaction::consensus_deserialize(&mut &unconfirmed_tx_bytes[..]).unwrap(); - let second_unconfirmed_tx_bytes = - make_stacks_transfer_mblock_only(&second_spender_sk, 0, 1000, &recipient.into(), 1500); + let second_unconfirmed_tx_bytes = make_stacks_transfer_mblock_only( + &second_spender_sk, + 0, + 1000, + conf.burnchain.chain_id, + &recipient.into(), + 1500, + ); let second_unconfirmed_tx = StacksTransaction::consensus_deserialize(&mut &second_unconfirmed_tx_bytes[..]).unwrap(); @@ -4080,6 +4131,7 @@ fn microblock_integration_test() { &spender_sk, next_nonce, 1000, + conf.burnchain.chain_id, &recipient.into(), 1000, ); @@ -4163,6 +4215,14 @@ fn filter_low_fee_tx_integration_test() { .collect(); let spender_addrs: Vec = spender_sks.iter().map(|x| to_addr(x).into()).collect(); + let (mut conf, _) = neon_integration_test_conf(); + for spender_addr in spender_addrs.iter() { + conf.initial_balances.push(InitialBalance { + address: spender_addr.clone(), + amount: 1049230, + }); + } + let txs: Vec<_> = spender_sks .iter() .enumerate() @@ -4171,22 +4231,28 @@ fn filter_low_fee_tx_integration_test() { if ix < 5 { // low-fee - make_stacks_transfer(&spender_sk, 0, 1000 + (ix as u64), &recipient.into(), 1000) + make_stacks_transfer( + &spender_sk, + 0, + 1000 + (ix as u64), + conf.burnchain.chain_id, + &recipient.into(), + 1000, + ) } else { // high-fee - make_stacks_transfer(&spender_sk, 0, 2000 + (ix as u64), &recipient.into(), 1000) + make_stacks_transfer( + &spender_sk, + 0, + 2000 + (ix as u64), + conf.burnchain.chain_id, + &recipient.into(), + 1000, + ) } }) .collect(); - let (mut conf, _) = neon_integration_test_conf(); - for spender_addr in spender_addrs.iter() { - conf.initial_balances.push(InitialBalance { - address: spender_addr.clone(), - amount: 1049230, - }); - } - let mut btcd_controller = BitcoinCoreController::new(conf.clone()); btcd_controller .start_bitcoind() @@ -4257,15 +4323,6 @@ fn filter_long_runtime_tx_integration_test() { .collect(); let spender_addrs: Vec = spender_sks.iter().map(|x| to_addr(x).into()).collect(); - let txs: Vec<_> = spender_sks - .iter() - .enumerate() - .map(|(ix, spender_sk)| { - let recipient = StacksAddress::from_string(ADDR_4).unwrap(); - make_stacks_transfer(&spender_sk, 0, 1000 + (ix as u64), &recipient.into(), 1000) - }) - .collect(); - let (mut conf, _) = neon_integration_test_conf(); for spender_addr in spender_addrs.iter() { conf.initial_balances.push(InitialBalance { @@ -4278,6 +4335,22 @@ fn filter_long_runtime_tx_integration_test() { conf.miner.first_attempt_time_ms = 0; conf.miner.subsequent_attempt_time_ms = 0; + let txs: Vec<_> = spender_sks + .iter() + .enumerate() + .map(|(ix, spender_sk)| { + let recipient = StacksAddress::from_string(ADDR_4).unwrap(); + make_stacks_transfer( + &spender_sk, + 0, + 1000 + (ix as u64), + conf.burnchain.chain_id, + &recipient.into(), + 1000, + ) + }) + .collect(); + let mut btcd_controller = BitcoinCoreController::new(conf.clone()); btcd_controller .start_bitcoind() @@ -4343,8 +4416,6 @@ fn miner_submit_twice() { (define-private (bar) (foo 56)) "; - let tx_1 = make_contract_publish(&spender_sk, 0, 50_000, "first-contract", contract_content); - let tx_2 = make_contract_publish(&spender_sk, 1, 50_000, "second-contract", contract_content); let (mut conf, _) = neon_integration_test_conf(); conf.initial_balances.push(InitialBalance { @@ -4357,6 +4428,23 @@ fn miner_submit_twice() { conf.miner.first_attempt_time_ms = 20; conf.miner.subsequent_attempt_time_ms = 30_000; + let tx_1 = make_contract_publish( + &spender_sk, + 0, + 50_000, + conf.burnchain.chain_id, + "first-contract", + contract_content, + ); + let tx_2 = make_contract_publish( + &spender_sk, + 1, + 50_000, + conf.burnchain.chain_id, + "second-contract", + contract_content, + ); + // note: this test depends on timing of how long it takes to assemble a block, // but it won't flake if the miner behaves correctly: a correct miner should // always be able to mine both transactions by the end of this test. an incorrect @@ -4435,18 +4523,28 @@ fn size_check_integration_test() { .collect(); let spender_addrs: Vec = spender_sks.iter().map(|x| to_addr(x).into()).collect(); + let (mut conf, miner_account) = neon_integration_test_conf(); + // make a bunch of txs that will only fit one per block. let txs: Vec<_> = spender_sks .iter() .enumerate() .map(|(ix, spender_sk)| { if ix % 2 == 0 { - make_contract_publish(spender_sk, 0, 1049230, "large-0", &giant_contract) + make_contract_publish( + spender_sk, + 0, + 1049230, + conf.burnchain.chain_id, + "large-0", + &giant_contract, + ) } else { let tx = make_contract_publish_microblock_only( spender_sk, 0, 1049230, + conf.burnchain.chain_id, "large-0", &giant_contract, ); @@ -4457,8 +4555,6 @@ fn size_check_integration_test() { }) .collect(); - let (mut conf, miner_account) = neon_integration_test_conf(); - for spender_addr in spender_addrs.iter() { conf.initial_balances.push(InitialBalance { address: spender_addr.clone(), @@ -4603,6 +4699,8 @@ fn size_overflow_unconfirmed_microblocks_integration_test() { .collect(); let spender_addrs: Vec = spender_sks.iter().map(|x| to_addr(x).into()).collect(); + let (mut conf, miner_account) = neon_integration_test_conf(); + let txs: Vec> = spender_sks .iter() .enumerate() @@ -4613,6 +4711,7 @@ fn size_overflow_unconfirmed_microblocks_integration_test() { spender_sk, 0, 1100000, + conf.burnchain.chain_id, "large-0", &giant_contract, )] @@ -4623,6 +4722,7 @@ fn size_overflow_unconfirmed_microblocks_integration_test() { spender_sk, i as u64, 1100000, + conf.burnchain.chain_id, &format!("small-{}", i), &small_contract, ); @@ -4633,8 +4733,6 @@ fn size_overflow_unconfirmed_microblocks_integration_test() { }) .collect(); - let (mut conf, miner_account) = neon_integration_test_conf(); - for spender_addr in spender_addrs.iter() { conf.initial_balances.push(InitialBalance { address: spender_addr.clone(), @@ -4810,20 +4908,6 @@ fn size_overflow_unconfirmed_stream_microblocks_integration_test() { .collect(); let spender_addrs: Vec = spender_sks.iter().map(|x| to_addr(x).into()).collect(); - let txs: Vec<_> = spender_sks - .iter() - .map(|spender_sk| { - let tx = make_contract_publish_microblock_only( - spender_sk, - 0, - 600000, - "small", - &small_contract, - ); - tx - }) - .collect(); - let (mut conf, miner_account) = neon_integration_test_conf(); for spender_addr in spender_addrs.iter() { @@ -4843,6 +4927,21 @@ fn size_overflow_unconfirmed_stream_microblocks_integration_test() { conf.miner.first_attempt_time_ms = i64::MAX as u64; conf.miner.subsequent_attempt_time_ms = i64::MAX as u64; + let txs: Vec<_> = spender_sks + .iter() + .map(|spender_sk| { + let tx = make_contract_publish_microblock_only( + spender_sk, + 0, + 600000, + conf.burnchain.chain_id, + "small", + &small_contract, + ); + tx + }) + .collect(); + test_observer::spawn(); test_observer::register_any(&mut conf); @@ -4997,20 +5096,6 @@ fn size_overflow_unconfirmed_invalid_stream_microblocks_integration_test() { .collect(); let spender_addrs: Vec = spender_sks.iter().map(|x| to_addr(x).into()).collect(); - let txs: Vec> = spender_sks - .iter() - .map(|spender_sk| { - let tx = make_contract_publish_microblock_only( - spender_sk, - 0, - 1149230, - "small", - &small_contract, - ); - tx - }) - .collect(); - let (mut conf, miner_account) = neon_integration_test_conf(); for spender_addr in spender_addrs.iter() { @@ -5027,6 +5112,21 @@ fn size_overflow_unconfirmed_invalid_stream_microblocks_integration_test() { conf.node.max_microblocks = 65536; conf.burnchain.max_rbf = 1000000; + let txs: Vec> = spender_sks + .iter() + .map(|spender_sk| { + let tx = make_contract_publish_microblock_only( + spender_sk, + 0, + 1149230, + conf.burnchain.chain_id, + "small", + &small_contract, + ); + tx + }) + .collect(); + let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); epochs[1].block_limit = core::BLOCK_LIMIT_MAINNET_20; conf.burnchain.epochs = Some(epochs); @@ -5160,6 +5260,27 @@ fn runtime_overflow_unconfirmed_microblocks_integration_test() { let spender_addrs_c32: Vec = spender_sks.iter().map(|x| to_addr(x).into()).collect(); + let (mut conf, miner_account) = neon_integration_test_conf(); + + for spender_addr in spender_addrs.iter() { + conf.initial_balances.push(InitialBalance { + address: spender_addr.clone(), + amount: 1049230, + }); + } + + conf.node.mine_microblocks = true; + conf.node.wait_time_for_microblocks = 0; + conf.node.microblock_frequency = 15000; + conf.miner.microblock_attempt_time_ms = 120_000; + + conf.miner.first_attempt_time_ms = i64::MAX as u64; + conf.miner.subsequent_attempt_time_ms = i64::MAX as u64; + + let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); + epochs[1].block_limit = core::BLOCK_LIMIT_MAINNET_20; + conf.burnchain.epochs = Some(epochs); + let txs: Vec> = spender_sks .iter() .enumerate() @@ -5170,6 +5291,7 @@ fn runtime_overflow_unconfirmed_microblocks_integration_test() { spender_sk, 0, 1049230, + conf.burnchain.chain_id, &format!("large-{}", ix), &format!(" ;; a single one of these transactions consumes over half the runtime budget @@ -5224,6 +5346,7 @@ fn runtime_overflow_unconfirmed_microblocks_integration_test() { spender_sk, i as u64, 210000, + conf.burnchain.chain_id, &format!("small-{}-{}", ix, i), &format!(" ;; a single one of these transactions consumes over half the runtime budget @@ -5276,27 +5399,6 @@ fn runtime_overflow_unconfirmed_microblocks_integration_test() { }) .collect(); - let (mut conf, miner_account) = neon_integration_test_conf(); - - for spender_addr in spender_addrs.iter() { - conf.initial_balances.push(InitialBalance { - address: spender_addr.clone(), - amount: 1049230, - }); - } - - conf.node.mine_microblocks = true; - conf.node.wait_time_for_microblocks = 0; - conf.node.microblock_frequency = 15000; - conf.miner.microblock_attempt_time_ms = 120_000; - - conf.miner.first_attempt_time_ms = i64::MAX as u64; - conf.miner.subsequent_attempt_time_ms = i64::MAX as u64; - - let mut epochs = core::STACKS_EPOCHS_REGTEST.to_vec(); - epochs[1].block_limit = core::BLOCK_LIMIT_MAINNET_20; - conf.burnchain.epochs = Some(epochs); - test_observer::spawn(); test_observer::register_any(&mut conf); @@ -5514,7 +5616,14 @@ fn block_replay_integration_test() { assert_eq!(account.nonce, 0); let recipient = StacksAddress::from_string(ADDR_4).unwrap(); - let tx = make_stacks_transfer(&spender_sk, 0, 1000, &recipient.into(), 1000); + let tx = make_stacks_transfer( + &spender_sk, + 0, + 1000, + conf.burnchain.chain_id, + &recipient.into(), + 1000, + ); submit_tx(&http_origin, &tx); next_block_and_wait(&mut btc_regtest_controller, &blocks_processed); @@ -5652,9 +5761,30 @@ fn cost_voting_integration() { assert_eq!(res.nonce, 0); let transactions = vec![ - make_contract_publish(&spender_sk, 0, 1000, "cost-definer", cost_definer_src), - make_contract_publish(&spender_sk, 1, 1000, "caller", caller_src), - make_contract_publish(&spender_sk, 2, 1000, "voter", power_vote_src), + make_contract_publish( + &spender_sk, + 0, + 1000, + conf.burnchain.chain_id, + "cost-definer", + cost_definer_src, + ), + make_contract_publish( + &spender_sk, + 1, + 1000, + conf.burnchain.chain_id, + "caller", + caller_src, + ), + make_contract_publish( + &spender_sk, + 2, + 1000, + conf.burnchain.chain_id, + "voter", + power_vote_src, + ), ]; for tx in transactions.into_iter() { @@ -5668,6 +5798,7 @@ fn cost_voting_integration() { &spender_sk, 3, 1000, + conf.burnchain.chain_id, &spender_addr, "voter", "propose-vote-confirm", @@ -5678,6 +5809,7 @@ fn cost_voting_integration() { &spender_sk, 4, 1000, + conf.burnchain.chain_id, &spender_addr, "caller", "execute-2", @@ -5729,6 +5861,7 @@ fn cost_voting_integration() { &spender_sk, 5, 1000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "cost-voting", "confirm-miners", @@ -5779,6 +5912,7 @@ fn cost_voting_integration() { &spender_sk, 6, 1000, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "cost-voting", "confirm-miners", @@ -5823,6 +5957,7 @@ fn cost_voting_integration() { &spender_sk, 7, 1000, + conf.burnchain.chain_id, &spender_addr, "caller", "execute-2", @@ -5884,11 +6019,6 @@ fn mining_events_integration_test() { let spender_sk_2 = StacksPrivateKey::from_hex(SK_2).unwrap(); let addr_2 = to_addr(&spender_sk_2); - let tx = make_contract_publish(&spender_sk, 0, 600000, "small", &small_contract); - let tx_2 = make_contract_publish(&spender_sk, 1, 610000, "small", &small_contract); - let mb_tx = - make_contract_publish_microblock_only(&spender_sk_2, 0, 620000, "small", &small_contract); - let (mut conf, _) = neon_integration_test_conf(); conf.initial_balances.push(InitialBalance { @@ -5907,6 +6037,31 @@ fn mining_events_integration_test() { conf.miner.first_attempt_time_ms = i64::MAX as u64; conf.miner.subsequent_attempt_time_ms = i64::MAX as u64; + let tx = make_contract_publish( + &spender_sk, + 0, + 600000, + conf.burnchain.chain_id, + "small", + &small_contract, + ); + let tx_2 = make_contract_publish( + &spender_sk, + 1, + 610000, + conf.burnchain.chain_id, + "small", + &small_contract, + ); + let mb_tx = make_contract_publish_microblock_only( + &spender_sk_2, + 0, + 620000, + conf.burnchain.chain_id, + "small", + &small_contract, + ); + test_observer::spawn(); test_observer::register( &mut conf, @@ -6146,15 +6301,6 @@ fn block_limit_hit_integration_test() { let third_spender_sk = StacksPrivateKey::new(); let third_spender_addr: PrincipalData = to_addr(&third_spender_sk).into(); - // included in first block - let tx = make_contract_publish(&spender_sk, 0, 555_000, "over", &oversize_contract_src); - // contract limit hit; included in second block - let tx_2 = make_contract_publish(&spender_sk, 1, 555_000, "over-2", &oversize_contract_src); - // skipped over since contract limit was hit; included in second block - let tx_3 = make_contract_publish(&second_spender_sk, 0, 150_000, "max", &max_contract_src); - // included in first block - let tx_4 = make_stacks_transfer(&third_spender_sk, 0, 180, &PrincipalData::from(addr), 100); - let (mut conf, _miner_account) = neon_integration_test_conf(); conf.initial_balances.push(InitialBalance { @@ -6177,6 +6323,43 @@ fn block_limit_hit_integration_test() { conf.miner.first_attempt_time_ms = i64::MAX as u64; conf.miner.subsequent_attempt_time_ms = i64::MAX as u64; + // included in first block + let tx = make_contract_publish( + &spender_sk, + 0, + 555_000, + conf.burnchain.chain_id, + "over", + &oversize_contract_src, + ); + // contract limit hit; included in second block + let tx_2 = make_contract_publish( + &spender_sk, + 1, + 555_000, + conf.burnchain.chain_id, + "over-2", + &oversize_contract_src, + ); + // skipped over since contract limit was hit; included in second block + let tx_3 = make_contract_publish( + &second_spender_sk, + 0, + 150_000, + conf.burnchain.chain_id, + "max", + &max_contract_src, + ); + // included in first block + let tx_4 = make_stacks_transfer( + &third_spender_sk, + 0, + 180, + conf.burnchain.chain_id, + &PrincipalData::from(addr), + 100, + ); + test_observer::spawn(); test_observer::register_any(&mut conf); @@ -6330,39 +6513,6 @@ fn microblock_limit_hit_integration_test() { let third_spender_sk = StacksPrivateKey::new(); let third_spender_addr: PrincipalData = to_addr(&third_spender_sk).into(); - // included in the first block - let tx = make_contract_publish_microblock_only( - &spender_sk, - 0, - 555_000, - "over", - &oversize_contract_src, - ); - // contract limit hit; included in second block - let tx_2 = make_contract_publish_microblock_only( - &spender_sk, - 1, - 555_000, - "over-2", - &oversize_contract_src, - ); - // skipped over since contract limit was hit; included in second block - let tx_3 = make_contract_publish_microblock_only( - &second_spender_sk, - 0, - 150_000, - "max", - &max_contract_src, - ); - // included in first block - let tx_4 = make_stacks_transfer_mblock_only( - &third_spender_sk, - 0, - 180, - &PrincipalData::from(addr), - 100, - ); - let (mut conf, _) = neon_integration_test_conf(); conf.initial_balances.push(InitialBalance { @@ -6428,6 +6578,43 @@ fn microblock_limit_hit_integration_test() { ]); conf.burnchain.pox_2_activation = Some(10_003); + // included in the first block + let tx = make_contract_publish_microblock_only( + &spender_sk, + 0, + 555_000, + conf.burnchain.chain_id, + "over", + &oversize_contract_src, + ); + // contract limit hit; included in second block + let tx_2 = make_contract_publish_microblock_only( + &spender_sk, + 1, + 555_000, + conf.burnchain.chain_id, + "over-2", + &oversize_contract_src, + ); + // skipped over since contract limit was hit; included in second block + let tx_3 = make_contract_publish_microblock_only( + &second_spender_sk, + 0, + 150_000, + conf.burnchain.chain_id, + "max", + &max_contract_src, + ); + // included in first block + let tx_4 = make_stacks_transfer_mblock_only( + &third_spender_sk, + 0, + 180, + conf.burnchain.chain_id, + &PrincipalData::from(addr), + 100, + ); + test_observer::spawn(); test_observer::register_any(&mut conf); @@ -6569,10 +6756,6 @@ fn block_large_tx_integration_test() { let spender_sk = StacksPrivateKey::new(); let spender_addr = to_addr(&spender_sk); - // higher fee for tx means it will get mined first - let tx = make_contract_publish(&spender_sk, 0, 671_000, "small", &small_contract_src); - let tx_2 = make_contract_publish(&spender_sk, 1, 670_000, "over", &oversize_contract_src); - let (mut conf, miner_account) = neon_integration_test_conf(); test_observer::spawn(); test_observer::register_any(&mut conf); @@ -6593,6 +6776,24 @@ fn block_large_tx_integration_test() { conf.miner.first_attempt_time_ms = i64::MAX as u64; conf.miner.subsequent_attempt_time_ms = i64::MAX as u64; + // higher fee for tx means it will get mined first + let tx = make_contract_publish( + &spender_sk, + 0, + 671_000, + conf.burnchain.chain_id, + "small", + &small_contract_src, + ); + let tx_2 = make_contract_publish( + &spender_sk, + 1, + 670_000, + conf.burnchain.chain_id, + "over", + &oversize_contract_src, + ); + let mut btcd_controller = BitcoinCoreController::new(conf.clone()); btcd_controller .start_bitcoind() @@ -6691,21 +6892,6 @@ fn microblock_large_tx_integration_test_FLAKY() { let spender_sk = StacksPrivateKey::new(); let addr = to_addr(&spender_sk); - let tx = make_contract_publish_microblock_only( - &spender_sk, - 0, - 150_000, - "small", - &small_contract_src, - ); - let tx_2 = make_contract_publish_microblock_only( - &spender_sk, - 1, - 670_000, - "over", - &oversize_contract_src, - ); - let (mut conf, miner_account) = neon_integration_test_conf(); test_observer::spawn(); @@ -6728,6 +6914,23 @@ fn microblock_large_tx_integration_test_FLAKY() { conf.burnchain.max_rbf = 10_000_000; conf.node.wait_time_for_blocks = 1_000; + let tx = make_contract_publish_microblock_only( + &spender_sk, + 0, + 150_000, + conf.burnchain.chain_id, + "small", + &small_contract_src, + ); + let tx_2 = make_contract_publish_microblock_only( + &spender_sk, + 1, + 670_000, + conf.burnchain.chain_id, + "over", + &oversize_contract_src, + ); + let mut btcd_controller = BitcoinCoreController::new(conf.clone()); btcd_controller .start_bitcoind() @@ -6981,6 +7184,7 @@ fn pox_integration_test() { &spender_sk, 0, 260, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox", "stack-stx", @@ -7096,6 +7300,7 @@ fn pox_integration_test() { &spender_2_sk, 0, 260, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox", "stack-stx", @@ -7119,6 +7324,7 @@ fn pox_integration_test() { &spender_3_sk, 0, 260, + conf.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "pox", "stack-stx", @@ -7461,6 +7667,7 @@ fn atlas_integration_test() { &user_1, 0, 260, + conf_bootstrap_node.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "bns", "namespace-preorder", @@ -7520,6 +7727,7 @@ fn atlas_integration_test() { &user_1, 1, 1000, + conf_bootstrap_node.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "bns", "namespace-reveal", @@ -7582,6 +7790,7 @@ fn atlas_integration_test() { &user_1, 2, 500, + conf_bootstrap_node.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "bns", "name-import", @@ -7699,6 +7908,7 @@ fn atlas_integration_test() { }; let burnchain_config = Burnchain::regtest(&conf_follower_node.get_burn_db_path()); + let chain_id = conf_follower_node.burnchain.chain_id; let http_origin = format!("http://{}", &conf_follower_node.node.rpc_bind); eprintln!("Chain bootstrapped..."); @@ -7777,6 +7987,7 @@ fn atlas_integration_test() { &user_1, 2 + i, 500, + chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "bns", "name-import", @@ -8245,6 +8456,7 @@ fn atlas_stress_integration_test() { &user_1, 0, 1000, + conf_bootstrap_node.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "bns", "namespace-preorder", @@ -8304,6 +8516,7 @@ fn atlas_stress_integration_test() { &user_1, 1, 1000, + conf_bootstrap_node.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "bns", "namespace-reveal", @@ -8392,6 +8605,7 @@ fn atlas_stress_integration_test() { &user_1, 2 + (batch_size * i + j) as u64, 1000, + conf_bootstrap_node.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "bns", "name-import", @@ -8461,6 +8675,7 @@ fn atlas_stress_integration_test() { &user_1, 2 + (batch_size as u64) * (batches as u64), 1000, + conf_bootstrap_node.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "bns", "namespace-ready", @@ -8521,6 +8736,7 @@ fn atlas_stress_integration_test() { &users[batches * batch_size + j], 0, 1000, + conf_bootstrap_node.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "bns", "name-preorder", @@ -8580,6 +8796,7 @@ fn atlas_stress_integration_test() { &users[batches * batch_size + j], 1, 1000, + conf_bootstrap_node.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "bns", "name-register", @@ -8643,6 +8860,7 @@ fn atlas_stress_integration_test() { &users[batches * batch_size + j], 2, 1000, + conf_bootstrap_node.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "bns", "name-update", @@ -8705,6 +8923,7 @@ fn atlas_stress_integration_test() { &users[batches * batch_size + j], 3, 1000, + conf_bootstrap_node.burnchain.chain_id, &StacksAddress::from_string("ST000000000000000000002AMW42H").unwrap(), "bns", "name-renewal", @@ -8960,6 +9179,7 @@ fn fuzzed_median_fee_rate_estimation_test(window_size: u64, expected_final_value &spender_sk, 0, 110000, + conf.burnchain.chain_id, "increment-contract", &max_contract_src, ), @@ -8977,6 +9197,7 @@ fn fuzzed_median_fee_rate_estimation_test(window_size: u64, expected_final_value &spender_sk, i, // nonce i * 100000, // payment + conf.burnchain.chain_id, &spender_addr.into(), "increment-contract", "increment-many", @@ -9172,15 +9393,27 @@ fn use_latest_tip_integration_test() { // Make microblock with two transactions. let recipient = StacksAddress::from_string(ADDR_4).unwrap(); - let transfer_tx = - make_stacks_transfer_mblock_only(&spender_sk, 0, 1000, &recipient.into(), 1000); + let transfer_tx = make_stacks_transfer_mblock_only( + &spender_sk, + 0, + 1000, + conf.burnchain.chain_id, + &recipient.into(), + 1000, + ); let caller_src = " (define-public (execute) (ok stx-liquid-supply)) "; - let publish_tx = - make_contract_publish_microblock_only(&spender_sk, 1, 1000, "caller", caller_src); + let publish_tx = make_contract_publish_microblock_only( + &spender_sk, + 1, + 1000, + conf.burnchain.chain_id, + "caller", + caller_src, + ); let tx_1 = StacksTransaction::consensus_deserialize(&mut &transfer_tx[..]).unwrap(); let tx_2 = StacksTransaction::consensus_deserialize(&mut &publish_tx[..]).unwrap(); @@ -9527,6 +9760,7 @@ fn test_problematic_txs_are_not_stored() { &spender_sk_1, 0, (tx_edge_body.len() * 100) as u64, + conf.burnchain.chain_id, "test-edge", &tx_edge_body, ); @@ -9544,6 +9778,7 @@ fn test_problematic_txs_are_not_stored() { &spender_sk_2, 0, (tx_exceeds_body.len() * 100) as u64, + conf.burnchain.chain_id, "test-exceeds", &tx_exceeds_body, ); @@ -9561,6 +9796,7 @@ fn test_problematic_txs_are_not_stored() { &spender_sk_3, 0, (tx_high_body.len() * 100) as u64, + conf.burnchain.chain_id, "test-high", &tx_high_body, ); @@ -9770,6 +10006,7 @@ fn test_problematic_blocks_are_not_mined() { &spender_sk_2, 0, (tx_exceeds_body.len() * 100) as u64, + conf.burnchain.chain_id, "test-exceeds", &tx_exceeds_body, ); @@ -9787,6 +10024,7 @@ fn test_problematic_blocks_are_not_mined() { &spender_sk_3, 0, (tx_high_body.len() * 100) as u64, + conf.burnchain.chain_id, "test-high", &tx_high_body, ); @@ -10123,6 +10361,7 @@ fn test_problematic_blocks_are_not_relayed_or_stored() { &spender_sk_2, 0, (tx_exceeds_body.len() * 100) as u64, + conf.burnchain.chain_id, "test-exceeds", &tx_exceeds_body, ); @@ -10139,6 +10378,7 @@ fn test_problematic_blocks_are_not_relayed_or_stored() { &spender_sk_3, 0, (tx_high_body.len() * 100) as u64, + conf.burnchain.chain_id, "test-high", &tx_high_body, ); @@ -10518,6 +10758,7 @@ fn test_problematic_microblocks_are_not_mined() { &spender_sk_2, 0, (tx_exceeds_body.len() * 100) as u64, + conf.burnchain.chain_id, "test-exceeds", &tx_exceeds_body, ); @@ -10536,6 +10777,7 @@ fn test_problematic_microblocks_are_not_mined() { &spender_sk_3, 0, (tx_high_body.len() * 100) as u64, + conf.burnchain.chain_id, "test-high", &tx_high_body, ); @@ -10898,6 +11140,7 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() { &spender_sk_2, 0, (tx_exceeds_body.len() * 100) as u64, + conf.burnchain.chain_id, "test-exceeds", &tx_exceeds_body, ); @@ -10916,6 +11159,7 @@ fn test_problematic_microblocks_are_not_relayed_or_stored() { &spender_sk_3, 0, (tx_high_body.len() * 100) as u64, + conf.burnchain.chain_id, "test-high", &tx_high_body, ); @@ -11389,6 +11633,7 @@ enum TxChainStrategy { pub fn make_expensive_tx_chain( privk: &StacksPrivateKey, fee_plus: u64, + chain_id: u32, mblock_only: bool, ) -> Vec> { let addr = to_addr(&privk); @@ -11403,6 +11648,7 @@ pub fn make_expensive_tx_chain( privk, nonce, 1049230 + nonce + fee_plus, + chain_id, &contract_name, &make_runtime_sized_contract(256, nonce, &addr_prefix), ) @@ -11411,6 +11657,7 @@ pub fn make_expensive_tx_chain( privk, nonce, 1049230 + nonce + fee_plus, + chain_id, &contract_name, &make_runtime_sized_contract(256, nonce, &addr_prefix), ) @@ -11423,6 +11670,7 @@ pub fn make_expensive_tx_chain( pub fn make_random_tx_chain( privk: &StacksPrivateKey, fee_plus: u64, + chain_id: u32, mblock_only: bool, ) -> Vec> { let addr = to_addr(&privk); @@ -11448,6 +11696,7 @@ pub fn make_random_tx_chain( privk, nonce, 1049230 + nonce + fee_plus + random_extra_fee, + chain_id, &contract_name, &make_runtime_sized_contract(random_iters, nonce, &addr_prefix), ) @@ -11456,6 +11705,7 @@ pub fn make_random_tx_chain( privk, nonce, 1049230 + nonce + fee_plus + random_extra_fee, + chain_id, &contract_name, &make_runtime_sized_contract(random_iters, nonce, &addr_prefix), ) @@ -11465,7 +11715,7 @@ pub fn make_random_tx_chain( chain } -fn make_mblock_tx_chain(privk: &StacksPrivateKey, fee_plus: u64) -> Vec> { +fn make_mblock_tx_chain(privk: &StacksPrivateKey, fee_plus: u64, chain_id: u32) -> Vec> { let addr = to_addr(&privk); let mut chain = vec![]; @@ -11488,6 +11738,7 @@ fn make_mblock_tx_chain(privk: &StacksPrivateKey, fee_plus: u64) -> Vec> privk, nonce, 1049230 + nonce + fee_plus + random_extra_fee, + chain_id, &contract_name, &make_runtime_sized_contract(1, nonce, &addr_prefix), ); @@ -11547,6 +11798,8 @@ fn test_competing_miners_build_on_same_chain( confs.push(conf); } + let chain_id = confs[0].burnchain.chain_id; + let node_privkey_1 = Secp256k1PrivateKey::from_seed(&confs[0].node.local_peer_seed); for i in 1..num_miners { let chain_id = confs[0].burnchain.chain_id; @@ -11674,8 +11927,12 @@ fn test_competing_miners_build_on_same_chain( .iter() .enumerate() .map(|(i, pk)| match chain_strategy { - TxChainStrategy::Expensive => make_expensive_tx_chain(pk, (25 * i) as u64, mblock_only), - TxChainStrategy::Random => make_random_tx_chain(pk, (25 * i) as u64, mblock_only), + TxChainStrategy::Expensive => { + make_expensive_tx_chain(pk, (25 * i) as u64, chain_id, mblock_only) + } + TxChainStrategy::Random => { + make_random_tx_chain(pk, (25 * i) as u64, chain_id, mblock_only) + } }) .collect(); let mut cnt = 0; @@ -11755,6 +12012,7 @@ fn test_competing_miners_build_anchor_blocks_and_microblocks_on_same_chain() { #[ignore] fn microblock_miner_multiple_attempts() { let (mut conf, miner_account) = neon_integration_test_conf(); + let chain_id = conf.burnchain.chain_id; conf.node.mine_microblocks = true; conf.miner.microblock_attempt_time_ms = 2_000; @@ -11823,7 +12081,7 @@ fn microblock_miner_multiple_attempts() { let all_txs: Vec<_> = privks .iter() .enumerate() - .map(|(i, pk)| make_mblock_tx_chain(pk, (25 * i) as u64)) + .map(|(i, pk)| make_mblock_tx_chain(pk, (25 * i) as u64, chain_id)) .collect(); let _handle = thread::spawn(move || { @@ -11923,6 +12181,7 @@ fn min_txs() { &spender_sk, i as u64, 1000, + conf.burnchain.chain_id, &format!("test-publish-{}", &i), &code, ); @@ -12026,6 +12285,7 @@ fn filter_txs_by_type() { &spender_sk, i as u64, 1000, + conf.burnchain.chain_id, &format!("test-publish-{}", &i), &code, ); @@ -12136,6 +12396,7 @@ fn filter_txs_by_origin() { &spender_sk, i as u64, 1000, + conf.burnchain.chain_id, &format!("test-publish-{}", &i), &code, ); diff --git a/testnet/stacks-node/src/tests/signer/v0.rs b/testnet/stacks-node/src/tests/signer/v0.rs index d1ceedfebf..25a09a6e24 100644 --- a/testnet/stacks-node/src/tests/signer/v0.rs +++ b/testnet/stacks-node/src/tests/signer/v0.rs @@ -139,6 +139,7 @@ impl SignerTest { &stacker_sk, 0, 1000, + self.running_nodes.conf.burnchain.chain_id, &StacksAddress::burn_address(false), "pox-4", "stack-stx", @@ -1140,8 +1141,14 @@ fn forked_tenure_testing( let start_time = Instant::now(); // submit a tx so that the miner will mine an extra block let sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + naka_conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); info!("Submitted tx {tx} in Tenure C to mine a second block"); while mined_blocks.load(Ordering::SeqCst) <= blocks_before { @@ -2083,8 +2090,14 @@ fn end_of_tenure() { let start_height = info.stacks_tip_height; // submit a tx so that the miner will mine an extra block let sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); info!("Submitted transfer tx and waiting for block proposal"); @@ -2194,8 +2207,14 @@ fn retry_on_rejection() { let start_time = Instant::now(); // submit a tx so that the miner will mine a stacks block let mut sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); sender_nonce += 1; info!("Submitted tx {tx} in to mine the first Nakamoto block"); @@ -2231,8 +2250,14 @@ fn retry_on_rejection() { .load(Ordering::SeqCst); // submit a tx so that the miner will mine a block - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); info!("Submitted transfer tx and waiting for block proposal"); @@ -2338,8 +2363,14 @@ fn signers_broadcast_signed_blocks() { // submit a tx so that the miner will mine a blockn let sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); debug!("Transaction sent; waiting for block-mining"); @@ -2484,8 +2515,14 @@ fn empty_sortition() { // submit a tx so that the miner will mine an extra block let sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); std::thread::sleep(block_proposal_timeout.add(Duration::from_secs(1))); @@ -3040,8 +3077,14 @@ fn signer_set_rollover() { info!("---- Mining a block to trigger the signer set -----"); // submit a tx so that the miner will mine an extra block let sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); signer_test.mine_nakamoto_block(short_timeout); let mined_block = test_observer::get_mined_nakamoto_blocks().pop().unwrap(); @@ -3091,6 +3134,7 @@ fn signer_set_rollover() { &stacker_sk, 0, 1000, + signer_test.running_nodes.conf.burnchain.chain_id, &StacksAddress::burn_address(false), "pox-4", "stack-stx", @@ -3163,8 +3207,14 @@ fn signer_set_rollover() { info!("---- Mining a block to verify new signer set -----"); let sender_nonce = 1; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); signer_test.mine_nakamoto_block(short_timeout); let mined_block = test_observer::get_mined_nakamoto_blocks().pop().unwrap(); @@ -3248,8 +3298,14 @@ fn min_gap_between_blocks() { // Submit a tx so that the miner will mine a block let sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); submit_tx(&http_origin, &transfer_tx); info!("Submitted transfer tx and waiting for block to be processed. Ensure it does not arrive before the gap is exceeded"); @@ -3574,8 +3630,14 @@ fn multiple_miners_with_nakamoto_blocks() { let blocks_processed_before = blocks_mined1.load(Ordering::SeqCst) + blocks_mined2.load(Ordering::SeqCst); // submit a tx so that the miner will mine an extra block - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); sender_nonce += 1; submit_tx(&http_origin, &transfer_tx); @@ -3915,8 +3977,14 @@ fn partial_tenure_fork() { // submit a tx so that the miner will mine an extra block let sender_nonce = (btc_blocks_mined - 1) * inter_blocks_per_tenure + interim_block_ix; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); // This may fail if the forking miner wins too many tenures and this account's // nonces get too high (TooMuchChaining) match submit_tx_fallible(&http_origin, &transfer_tx) { @@ -4100,8 +4168,14 @@ fn locally_accepted_blocks_overriden_by_global_rejection() { let blocks_before = mined_blocks.load(Ordering::SeqCst); // submit a tx so that the miner will mine a stacks block let mut sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); info!("Submitted tx {tx} in to mine block N"); wait_for(short_timeout_secs, || { @@ -4143,8 +4217,14 @@ fn locally_accepted_blocks_overriden_by_global_rejection() { .unwrap() .replace(rejecting_signers.clone()); test_observer::clear(); - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); sender_nonce += 1; info!("Submitted tx {tx} to mine block N+1"); @@ -4171,8 +4251,14 @@ fn locally_accepted_blocks_overriden_by_global_rejection() { .unwrap() .replace(Vec::new()); - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); info!("Submitted tx {tx} to mine block N+1'"); @@ -4271,8 +4357,14 @@ fn locally_rejected_blocks_overriden_by_global_acceptance() { // submit a tx so that the miner will mine a stacks block N let mut sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); sender_nonce += 1; info!("Submitted tx {tx} in to mine block N"); @@ -4325,8 +4417,14 @@ fn locally_rejected_blocks_overriden_by_global_acceptance() { .stacks_client .get_peer_info() .expect("Failed to get peer info"); - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); sender_nonce += 1; info!("Submitted tx {tx} in to mine block N+1"); @@ -4381,8 +4479,14 @@ fn locally_rejected_blocks_overriden_by_global_acceptance() { .replace(Vec::new()); // submit a tx so that the miner will mine a stacks block N+2 and ensure ALL signers accept it - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); info!("Submitted tx {tx} in to mine block N+2"); wait_for(30, || { @@ -4474,8 +4578,14 @@ fn reorg_locally_accepted_blocks_across_tenures_succeeds() { // submit a tx so that the miner will mine a stacks block let mut sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); sender_nonce += 1; info!("Submitted tx {tx} in to mine block N"); @@ -4516,8 +4626,14 @@ fn reorg_locally_accepted_blocks_across_tenures_succeeds() { test_observer::clear(); // submit a tx so that the miner will ATTEMPT to mine a stacks block N+1 - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); info!("Submitted tx {tx} in to attempt to mine block N+1"); @@ -4684,8 +4800,14 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() { // submit a tx so that the miner will mine a stacks block let mut sender_nonce = 0; - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); info!("Submitted tx {tx} in to mine block N"); @@ -4727,8 +4849,14 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() { .get_peer_info() .expect("Failed to get peer info"); - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); sender_nonce += 1; let tx = submit_tx(&http_origin, &transfer_tx); @@ -4890,8 +5018,14 @@ fn miner_recovers_when_broadcast_block_delay_across_tenures_occurs() { } // Induce block N+2 to get mined - let transfer_tx = - make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt); + let transfer_tx = make_stacks_transfer( + &sender_sk, + sender_nonce, + send_fee, + signer_test.running_nodes.conf.burnchain.chain_id, + &recipient, + send_amt, + ); let tx = submit_tx(&http_origin, &transfer_tx); info!("Submitted tx {tx} in to attempt to mine block N+2"); diff --git a/testnet/stacks-node/src/tests/stackerdb.rs b/testnet/stacks-node/src/tests/stackerdb.rs index fbc47e0c3c..aa620d349b 100644 --- a/testnet/stacks-node/src/tests/stackerdb.rs +++ b/testnet/stacks-node/src/tests/stackerdb.rs @@ -25,7 +25,7 @@ use {reqwest, serde_json}; use super::bitcoin_regtest::BitcoinCoreController; use crate::burnchains::BurnchainController; -use crate::config::{EventKeyType, EventObserverConfig, InitialBalance}; +use crate::config::{EventKeyType, InitialBalance}; use crate::tests::neon_integrations::{ neon_integration_test_conf, next_block_and_wait, submit_tx, test_observer, wait_for_runloop, }; @@ -206,7 +206,14 @@ fn test_stackerdb_load_store() { let http_origin = format!("http://{}", &conf.node.rpc_bind); eprintln!("Send contract-publish..."); - let tx = make_contract_publish(&privks[0], 0, 10_000, "hello-world", stackerdb_contract); + let tx = make_contract_publish( + &privks[0], + 0, + 10_000, + conf.burnchain.chain_id, + "hello-world", + stackerdb_contract, + ); submit_tx(&http_origin, &tx); // mine it @@ -336,7 +343,14 @@ fn test_stackerdb_event_observer() { let http_origin = format!("http://{}", &conf.node.rpc_bind); eprintln!("Send contract-publish..."); - let tx = make_contract_publish(&privks[0], 0, 10_000, "hello-world", stackerdb_contract); + let tx = make_contract_publish( + &privks[0], + 0, + 10_000, + conf.burnchain.chain_id, + "hello-world", + stackerdb_contract, + ); submit_tx(&http_origin, &tx); // mine it