From e3aa014f60c5cb4abacaef23804af09bd2c80678 Mon Sep 17 00:00:00 2001 From: Ludovic Galabru Date: Wed, 16 Dec 2020 15:09:02 -0500 Subject: [PATCH 1/5] fix: possible discrepency --- src/chainstate/stacks/db/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/chainstate/stacks/db/mod.rs b/src/chainstate/stacks/db/mod.rs index b66b263b7c..c7d8bae196 100644 --- a/src/chainstate/stacks/db/mod.rs +++ b/src/chainstate/stacks/db/mod.rs @@ -987,8 +987,11 @@ impl StacksChainState { clarity_tx.connection().as_transaction(|clarity| { clarity .with_clarity_db(|db| { - for (block_height, schedule) in lockups_per_block.into_iter() { - let key = Value::UInt(block_height.into()); + let mut ordered_keys: Vec<_> = lockups_per_block.keys().clone().collect(); + ordered_keys.sort(); + for block_height in ordered_keys.into_iter() { + let schedule = lockups_per_block.remove(&block_height).unwrap(); + let key = Value::UInt(*block_height as u128); db.insert_entry( &lockup_contract_id, "lockups", From 040f794bbf9a429bb45b0fb6fd60c603ac434abc Mon Sep 17 00:00:00 2001 From: Ludovic Galabru Date: Wed, 16 Dec 2020 15:27:24 -0500 Subject: [PATCH 2/5] chore: cargo fmt, avoid clone --- src/chainstate/stacks/db/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/chainstate/stacks/db/mod.rs b/src/chainstate/stacks/db/mod.rs index c7d8bae196..6a2f4be992 100644 --- a/src/chainstate/stacks/db/mod.rs +++ b/src/chainstate/stacks/db/mod.rs @@ -962,6 +962,7 @@ impl StacksChainState { if let Some(get_schedules) = boot_data.get_bulk_initial_lockups.take() { info!("Initializing chain with lockups"); let mut lockups_per_block: HashMap> = HashMap::new(); + let mut sorted_keys = vec![]; let initial_lockups = get_schedules(); for schedule in initial_lockups { let stx_address = @@ -978,20 +979,21 @@ impl StacksChainState { schedules.into_mut().push(value); } Entry::Vacant(entry) => { + sorted_keys.push(schedule.block_height); let schedules = vec![value]; entry.insert(schedules); } }; } + sorted_keys.sort(); + let lockup_contract_id = boot_code_id("lockup"); clarity_tx.connection().as_transaction(|clarity| { clarity .with_clarity_db(|db| { - let mut ordered_keys: Vec<_> = lockups_per_block.keys().clone().collect(); - ordered_keys.sort(); - for block_height in ordered_keys.into_iter() { + for block_height in sorted_keys { let schedule = lockups_per_block.remove(&block_height).unwrap(); - let key = Value::UInt(*block_height as u128); + let key = Value::UInt(block_height as u128); db.insert_entry( &lockup_contract_id, "lockups", From 14ab6c0a0bb7ba5fc7da63d29edacd8654850f81 Mon Sep 17 00:00:00 2001 From: Ludovic Galabru Date: Wed, 16 Dec 2020 16:08:48 -0500 Subject: [PATCH 3/5] chore: update magic byte --- testnet/stacks-node/src/config.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testnet/stacks-node/src/config.rs b/testnet/stacks-node/src/config.rs index d4d6fa1da7..23db914c2f 100644 --- a/testnet/stacks-node/src/config.rs +++ b/testnet/stacks-node/src/config.rs @@ -236,7 +236,7 @@ impl ConfigFile { rpc_port: Some(18332), peer_port: Some(18333), peer_host: Some("bitcoind.xenon.blockstack.org".to_string()), - magic_bytes: Some("Xe".into()), + magic_bytes: Some("X2".into()), ..BurnchainConfigFile::default() }; From 7ea12d1cc4474e731294fdaa39a530db540f7522 Mon Sep 17 00:00:00 2001 From: Ludovic Galabru Date: Wed, 16 Dec 2020 16:22:01 -0500 Subject: [PATCH 4/5] fix: use BTreeMap instead of HashMap --- src/chainstate/stacks/db/mod.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/chainstate/stacks/db/mod.rs b/src/chainstate/stacks/db/mod.rs index 6a2f4be992..8183c8ecec 100644 --- a/src/chainstate/stacks/db/mod.rs +++ b/src/chainstate/stacks/db/mod.rs @@ -28,7 +28,7 @@ use rusqlite::Row; use rusqlite::Transaction; use rusqlite::NO_PARAMS; -use std::collections::{hash_map::Entry, HashMap}; +use std::collections::{btree_map::Entry, BTreeMap}; use std::fmt; use std::fs; use std::io; @@ -961,8 +961,7 @@ impl StacksChainState { if let Some(get_schedules) = boot_data.get_bulk_initial_lockups.take() { info!("Initializing chain with lockups"); - let mut lockups_per_block: HashMap> = HashMap::new(); - let mut sorted_keys = vec![]; + let mut lockups_per_block: BTreeMap> = BTreeMap::new(); let initial_lockups = get_schedules(); for schedule in initial_lockups { let stx_address = @@ -979,21 +978,18 @@ impl StacksChainState { schedules.into_mut().push(value); } Entry::Vacant(entry) => { - sorted_keys.push(schedule.block_height); let schedules = vec![value]; entry.insert(schedules); } }; } - sorted_keys.sort(); let lockup_contract_id = boot_code_id("lockup"); clarity_tx.connection().as_transaction(|clarity| { clarity .with_clarity_db(|db| { - for block_height in sorted_keys { - let schedule = lockups_per_block.remove(&block_height).unwrap(); - let key = Value::UInt(block_height as u128); + for (block_height, schedule) in lockups_per_block.into_iter() { + let key = Value::UInt(block_height.into()); db.insert_entry( &lockup_contract_id, "lockups", From cb99a3a4366860c1349b23c10ce3c14423ed34c7 Mon Sep 17 00:00:00 2001 From: Ludovic Galabru Date: Wed, 16 Dec 2020 16:55:02 -0500 Subject: [PATCH 5/5] fix: integration test --- testnet/stacks-node/src/tests/neon_integrations.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testnet/stacks-node/src/tests/neon_integrations.rs b/testnet/stacks-node/src/tests/neon_integrations.rs index f6f1a80a5a..d0ed0431c5 100644 --- a/testnet/stacks-node/src/tests/neon_integrations.rs +++ b/testnet/stacks-node/src/tests/neon_integrations.rs @@ -62,7 +62,7 @@ fn neon_integration_test_conf() -> (Config, StacksAddress) { let magic_bytes = Config::from_config_file(ConfigFile::xenon()) .burnchain .magic_bytes; - assert_eq!(magic_bytes.as_bytes(), &['X' as u8, 'e' as u8]); + assert_eq!(magic_bytes.as_bytes(), &['X' as u8, '2' as u8]); conf.burnchain.magic_bytes = magic_bytes; conf.burnchain.poll_time_secs = 1; conf.node.pox_sync_sample_secs = 1;