use STACKS_MAX_EPOCH, defined as (i64::MAX as u64), to identify the last possible block (since sqlite doesn't let us store u64)

This commit is contained in:
Jude Nelson
2021-04-27 16:28:45 -04:00
parent 528ca03e69
commit 3a1fb76e5e
4 changed files with 39 additions and 19 deletions

View File

@@ -58,7 +58,7 @@ use chainstate::stacks::*;
use chainstate::ChainstateDB;
use core::FIRST_BURNCHAIN_CONSENSUS_HASH;
use core::FIRST_STACKS_BLOCK_HASH;
use core::{StacksEpoch, StacksEpochId};
use core::{StacksEpoch, StacksEpochId, STACKS_EPOCH_MAX};
use net::neighbors::MAX_NEIGHBOR_BLOCK_DELAY;
use net::{Error as NetError, Error};
use util::db::tx_begin_immediate;
@@ -2126,7 +2126,7 @@ impl SortitionDB {
/// any invalid StacksEpoch structuring should result in a runtime panic.
fn validate_epochs(epochs_ref: &[StacksEpoch]) -> Vec<StacksEpoch> {
// sanity check -- epochs must all be contiguous, each epoch must be unique,
// and the range of epochs should span the whole u64 space.
// and the range of epochs should span the whole non-negative i64 space.
let mut epochs = epochs_ref.to_vec();
let mut seen_epochs = HashSet::new();
epochs.sort();
@@ -2135,7 +2135,7 @@ impl SortitionDB {
for epoch in epochs.iter() {
assert!(
epoch.start_height <= epoch.end_height,
"{} >= {} for {:?}",
"{} > {} for {:?}",
epoch.start_height,
epoch.end_height,
&epoch.epoch_id
@@ -2156,7 +2156,7 @@ impl SortitionDB {
seen_epochs.insert(epoch.epoch_id);
}
assert_eq!(epoch_end_height, i64::MAX as u64);
assert_eq!(epoch_end_height, STACKS_EPOCH_MAX);
epochs
}
@@ -6777,7 +6777,7 @@ pub mod tests {
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: 12,
end_height: i64::MAX as u64,
end_height: STACKS_EPOCH_MAX,
},
],
true,
@@ -6831,7 +6831,7 @@ pub mod tests {
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: 12,
end_height: i64::MAX as u64,
end_height: STACKS_EPOCH_MAX,
},
],
true,
@@ -6866,7 +6866,7 @@ pub mod tests {
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: 12,
end_height: i64::MAX as u64,
end_height: STACKS_EPOCH_MAX,
},
],
true,
@@ -6901,7 +6901,7 @@ pub mod tests {
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: 12,
end_height: i64::MAX as u64,
end_height: STACKS_EPOCH_MAX,
},
],
true,
@@ -6971,7 +6971,7 @@ pub mod tests {
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: 8,
end_height: i64::MAX as u64,
end_height: STACKS_EPOCH_MAX,
},
],
true,

View File

@@ -34,7 +34,7 @@ use crate::types::chainstate::{BlockHeaderHash, BurnchainHeaderHash, SortitionId
use crate::types::chainstate::{StacksAddress, VRFSeed};
use crate::types::proof::{ClarityMarfTrieId, TrieMerkleProof};
use core::{StacksEpoch, StacksEpochId};
use core::{StacksEpoch, StacksEpochId, STACKS_EPOCH_MAX};
use rand::thread_rng;
use rand::RngCore;
@@ -90,7 +90,7 @@ fn test_vm_epoch_switch() {
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: 12,
end_height: i64::MAX as u64,
end_height: STACKS_EPOCH_MAX,
},
],
true,

View File

@@ -72,6 +72,8 @@ pub const INITIAL_MINING_BONUS_WINDOW: u16 = 10_000;
pub const STACKS_2_0_LAST_BLOCK_TO_PROCESS: u64 = 700_000;
pub const STACKS_EPOCH_MAX: u64 = i64::MAX as u64;
// first burnchain block hash
// TODO: update once we know the true first burnchain block
pub const FIRST_BURNCHAIN_CONSENSUS_HASH: ConsensusHash = ConsensusHash([0u8; 20]);
@@ -191,7 +193,7 @@ impl StacksEpoch {
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: first_burnchain_height,
end_height: i64::MAX as u64,
end_height: STACKS_EPOCH_MAX
},
]
}
@@ -211,7 +213,7 @@ impl StacksEpoch {
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: epoch_2_1_block_height,
end_height: i64::MAX as u64,
end_height: STACKS_EPOCH_MAX
},
]
}
@@ -239,12 +241,12 @@ pub const STACKS_EPOCHS_MAINNET: &[StacksEpoch] = &[
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: BITCOIN_MAINNET_FIRST_BLOCK_HEIGHT,
end_height: STACKS_2_0_LAST_BLOCK_TO_PROCESS,
end_height: STACKS_2_0_LAST_BLOCK_TO_PROCESS + 1,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: STACKS_2_0_LAST_BLOCK_TO_PROCESS,
end_height: i64::MAX as u64,
start_height: STACKS_2_0_LAST_BLOCK_TO_PROCESS + 1,
end_height: STACKS_EPOCH_MAX
},
];
@@ -257,10 +259,28 @@ pub const STACKS_EPOCHS_TESTNET: &[StacksEpoch] = &[
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: BITCOIN_TESTNET_FIRST_BLOCK_HEIGHT,
end_height: i64::MAX as u64,
end_height: STACKS_EPOCH_MAX
}, // TODO: add Epoch21 when its start height is decided
];
pub const STACKS_EPOCHS_REGTEST: &[StacksEpoch] = &[
StacksEpoch {
epoch_id: StacksEpochId::Epoch10,
start_height: 0,
end_height: 0,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: 0,
end_height: 1000,
},
StacksEpoch {
epoch_id: StacksEpochId::Epoch21,
start_height: 1000,
end_height: STACKS_EPOCH_MAX,
},
];
/// Synchronize burn transactions from the Bitcoin blockchain
pub fn sync_burnchain_bitcoin(
working_dir: &String,

View File

@@ -1772,7 +1772,7 @@ mod test {
use super::make_all_api_reference;
use super::make_json_api_reference;
use core::{StacksEpoch, StacksEpochId};
use core::{StacksEpoch, StacksEpochId, STACKS_EPOCH_MAX};
struct DocHeadersDB {}
const DOC_HEADER_DB: DocHeadersDB = DocHeadersDB {};
@@ -1837,7 +1837,7 @@ mod test {
Some(StacksEpoch {
epoch_id: StacksEpochId::Epoch20,
start_height: 0,
end_height: u64::MAX,
end_height: STACKS_EPOCH_MAX
})
}
}