Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decrement block version everywhere (master branch) #1700

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android-bindings/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ pub unsafe extern "C" fn Java_com_mobilecoin_lib_TransactionBuilder_init_1jni(
env.get_rust_field(fog_resolver, RUST_OBJ_FIELD)?;
// FIXME: block version should be a parameter, it should be the latest
// version that fog ledger told us about, or that we got from ledger-db
let block_version = BlockVersion::ONE;
let block_version = BlockVersion::ZERO;
// Note: RTHMemoBuilder can be selected here, but we will only actually
// write memos if block_version is large enough that memos are supported.
// If block version is < 2, then transaction builder will filter out memos.
Expand Down
1 change: 1 addition & 0 deletions api/proto/blockchain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ message BlockSignature {
}

// Version 1 of an archived block.
// Note: The block.version field within the block may or may not be equal to 1.
message ArchiveBlockV1 {
// Block
Block block = 1;
Expand Down
2 changes: 1 addition & 1 deletion api/src/convert/archive_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ mod tests {
..Default::default()
};
let block = Block::new(
BlockVersion::ONE,
BlockVersion::ZERO,
&parent_block_id,
99 + block_idx,
400 + block_idx,
Expand Down
8 changes: 4 additions & 4 deletions consensus/enclave/api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,19 @@ mod test {
let config1: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::try_from_iter([(Mob::ID, 100), (TokenId::from(2), 2000)]).unwrap(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::ONE,
block_version: BlockVersion::ZERO,
}
.into();
let config2: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::try_from_iter([(Mob::ID, 100), (TokenId::from(2), 300)]).unwrap(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::ONE,
block_version: BlockVersion::ZERO,
}
.into();
let config3: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::try_from_iter([(Mob::ID, 100), (TokenId::from(30), 300)]).unwrap(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::ONE,
block_version: BlockVersion::ZERO,
}
.into();

Expand Down Expand Up @@ -140,7 +140,7 @@ mod test {
let config4: BlockchainConfigWithDigest = BlockchainConfig {
fee_map: FeeMap::try_from_iter([(Mob::ID, 100), (TokenId::from(30), 300)]).unwrap(),
master_minters_map: MasterMintersMap::default(),
block_version: BlockVersion::TWO,
block_version: BlockVersion::ONE,
}
.into();

Expand Down
2 changes: 1 addition & 1 deletion consensus/enclave/impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ mod tests {
fn form_block_refuses_decreasing_block_version(logger: Logger) {
let mut rng = Hc128Rng::from_seed([77u8; 32]);

for block_version in BlockVersion::iterator() {
for block_version in BlockVersion::iterator().skip(1) {
let enclave = SgxConsensusEnclave::new(logger.clone());
let blockchain_config = BlockchainConfig {
block_version: BlockVersion::try_from(*block_version - 1).unwrap(),
Expand Down
2 changes: 1 addition & 1 deletion consensus/service/src/byzantine_ledger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ mod tests {
};

// Run these tests with a particular block version
const BLOCK_VERSION: BlockVersion = BlockVersion::ONE;
const BLOCK_VERSION: BlockVersion = BlockVersion::ZERO;

fn test_peer_uri(node_id: u32, pubkey: String) -> PeerUri {
PeerUri::from_str(&format!(
Expand Down
6 changes: 3 additions & 3 deletions consensus/service/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub struct Config {
pub tokens_path: Option<PathBuf>,

/// The configured block version
#[clap(long, default_value = "1", parse(try_from_str = parse_block_version), env = "MC_BLOCK_VERSION")]
#[clap(long, default_value = "0", parse(try_from_str = parse_block_version), env = "MC_BLOCK_VERSION")]
pub block_version: BlockVersion,
}

Expand Down Expand Up @@ -196,7 +196,7 @@ mod tests {
client_auth_token_secret: None,
client_auth_token_max_lifetime: Duration::from_secs(60),
tokens_path: None,
block_version: BlockVersion::ONE,
block_version: BlockVersion::ZERO,
};

assert_eq!(
Expand Down Expand Up @@ -263,7 +263,7 @@ mod tests {
client_auth_token_secret: None,
client_auth_token_max_lifetime: Duration::from_secs(60),
tokens_path: None,
block_version: BlockVersion::ONE,
block_version: BlockVersion::ZERO,
};

assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion consensus/service/src/tx_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ mod tests {
#[test_with_logger]
fn test_hashes_to_block(logger: Logger) {
let mut rng: StdRng = SeedableRng::from_seed([77u8; 32]);
let block_version = BlockVersion::ONE;
let block_version = BlockVersion::ZERO;
let sender = AccountKey::random(&mut rng);
let mut ledger = create_ledger();
let n_blocks = 3;
Expand Down
2 changes: 1 addition & 1 deletion fog/ingest/server/tests/three_node_cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ fn add_test_block<T: RngCore + CryptoRng>(ledger: &mut LedgerDB, watcher: &Watch
};

let block = Block::new_with_parent(
BlockVersion::ONE,
BlockVersion::ZERO,
&last_block,
&root_element,
&block_contents,
Expand Down
2 changes: 1 addition & 1 deletion fog/load_testing/src/bin/ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn load_test(ingest_server_binary: &Path, test_params: TestParams, logger: Logge
LedgerDB::create(ledger_db_path.path()).unwrap();
let mut ledger_db = LedgerDB::open(ledger_db_path.path()).unwrap();

let block_version = BlockVersion::ONE;
let block_version = BlockVersion::ZERO;

mc_transaction_core_test_utils::initialize_ledger(
block_version,
Expand Down
2 changes: 1 addition & 1 deletion fog/overseer/server/tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub fn add_test_block<T: RngCore + CryptoRng>(
};

let block = Block::new_with_parent(
BlockVersion::ONE,
BlockVersion::ZERO,
&last_block,
&root_element,
&block_contents,
Expand Down
2 changes: 1 addition & 1 deletion fog/test_infra/src/db_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ pub fn random_block(
num_txs: usize,
) -> (Block, Vec<ETxOutRecord>) {
let block = Block::new(
BlockVersion::ONE,
BlockVersion::ZERO,
&BlockID::default(),
block_index,
0,
Expand Down
2 changes: 1 addition & 1 deletion fog/test_infra/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ pub fn test_block<T: RngCore + CryptoRng, C: FogViewConnection>(
.get_block(block_index - 1)
.unwrap_or_else(|err| panic!("Failed getting block {}: {:?}", block_index - 1, err));
let block = Block::new_with_parent(
BlockVersion::ONE,
BlockVersion::ZERO,
&parent_block,
&Default::default(),
&block_contents,
Expand Down
12 changes: 6 additions & 6 deletions fog/view/server/tests/smoke_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ fn test_view_integration(view_omap_capacity: u64, logger: Logger) {
db.add_block_data(
&invoc_id1,
&Block::new(
BlockVersion::ONE,
BlockVersion::ZERO,
&BlockID::default(),
0,
2,
Expand All @@ -161,7 +161,7 @@ fn test_view_integration(view_omap_capacity: u64, logger: Logger) {
db.add_block_data(
&invoc_id1,
&Block::new(
BlockVersion::ONE,
BlockVersion::ZERO,
&BlockID::default(),
1,
6,
Expand All @@ -184,7 +184,7 @@ fn test_view_integration(view_omap_capacity: u64, logger: Logger) {
db.add_block_data(
&invoc_id2,
&Block::new(
BlockVersion::ONE,
BlockVersion::ZERO,
&BlockID::default(),
2,
12,
Expand Down Expand Up @@ -219,7 +219,7 @@ fn test_view_integration(view_omap_capacity: u64, logger: Logger) {
db.add_block_data(
&invoc_id2,
&Block::new(
BlockVersion::ONE,
BlockVersion::ZERO,
&BlockID::default(),
3,
12,
Expand All @@ -234,7 +234,7 @@ fn test_view_integration(view_omap_capacity: u64, logger: Logger) {
db.add_block_data(
&invoc_id2,
&Block::new(
BlockVersion::ONE,
BlockVersion::ZERO,
&BlockID::default(),
4,
16,
Expand All @@ -251,7 +251,7 @@ fn test_view_integration(view_omap_capacity: u64, logger: Logger) {
db.add_block_data(
&invoc_id2,
&Block::new(
BlockVersion::ONE,
BlockVersion::ZERO,
&BlockID::default(),
5,
20,
Expand Down
10 changes: 5 additions & 5 deletions ledger/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ mod ledger_db_test {
use test::Bencher;

// TODO: Should these tests run over several block versions?
const BLOCK_VERSION: BlockVersion = BlockVersion::ONE;
const BLOCK_VERSION: BlockVersion = BlockVersion::ZERO;

/// Creates a LedgerDB instance.
fn create_db() -> LedgerDB {
Expand Down Expand Up @@ -2528,7 +2528,7 @@ mod ledger_db_test {
..Default::default()
};
let block = Block::new_with_parent(
BlockVersion::ONE,
BlockVersion::ZERO,
cbeck88 marked this conversation as resolved.
Show resolved Hide resolved
&origin_block,
&Default::default(),
&block_contents,
Expand Down Expand Up @@ -2571,7 +2571,7 @@ mod ledger_db_test {
};
let parent = ledger_db.get_block(n_blocks - 1).unwrap();
let block = Block::new_with_parent(
BlockVersion::ONE,
BlockVersion::ZERO,
&parent,
&Default::default(),
&block_contents,
Expand Down Expand Up @@ -2610,7 +2610,7 @@ mod ledger_db_test {
..Default::default()
};
let block = Block::new_with_parent(
BlockVersion::ONE,
BlockVersion::ZERO,
&origin_block,
&Default::default(),
&block_contents,
Expand Down Expand Up @@ -2699,7 +2699,7 @@ mod ledger_db_test {
// All blocks should've been written (+ origin block).
assert_eq!(
ledger_db.num_blocks().unwrap(),
1 + (3 * (*block_version)) as u64
1 + (3 * (*block_version + 1)) as u64
);
}

Expand Down
2 changes: 1 addition & 1 deletion ledger/db/src/test_utils/mock_ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub fn get_test_ledger_blocks(n_blocks: usize) -> Vec<(Block, BlockContents)> {
};

let block = Block::new_with_parent(
BlockVersion::ONE,
BlockVersion::ZERO,
&blocks_and_contents[block_index - 1].0,
&TxOutMembershipElement::default(),
&block_contents,
Expand Down
2 changes: 1 addition & 1 deletion ledger/sync/src/test_app/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn _make_ledger_long(ledger: &mut LedgerDB) {
.collect::<Vec<_>>();

let results: Vec<(Block, BlockContents)> = mc_transaction_core_test_utils::get_blocks(
BlockVersion::ONE,
BlockVersion::ZERO,
&recipient_pub_keys[..],
1,
1000,
Expand Down
2 changes: 1 addition & 1 deletion libmobilecoin/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ pub extern "C" fn mc_transaction_builder_create(
});
// FIXME: block version should be a parameter, it should be the latest
// version that fog ledger told us about, or that we got from ledger-db
let block_version = BlockVersion::ONE;
let block_version = BlockVersion::ZERO;

// TODO #1596: Support token id other than Mob
let token_id = Mob::ID;
Expand Down
2 changes: 1 addition & 1 deletion mobilecoind/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ mod test {

// Set up a db with 3 random recipients and 10 blocks.
let (_ledger_db, mobilecoind_db) =
get_test_databases(BlockVersion::ONE, 3, &vec![], 10, logger.clone(), &mut rng);
get_test_databases(BlockVersion::ZERO, 3, &vec![], 10, logger.clone(), &mut rng);

// A test accouunt.
let account_key = AccountKey::random(&mut rng);
Expand Down
2 changes: 1 addition & 1 deletion mobilecoind/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ mod test {
};

// None of these tests really depend on any of the new features
const BLOCK_VERSION: BlockVersion = BlockVersion::ONE;
const BLOCK_VERSION: BlockVersion = BlockVersion::ZERO;

#[test_with_logger]
fn test_add_monitor_impl(logger: Logger) {
Expand Down
2 changes: 1 addition & 1 deletion mobilecoind/src/utxo_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ mod test {
) -> (Arc<Environment>, LedgerDB, UtxoStore, Vec<UnspentTxOut>) {
// Set up a db with 3 random recipients and 10 blocks.
let (ledger_db, _mobilecoind_db) =
get_test_databases(BlockVersion::ONE, 3, &vec![], 10, logger.clone(), &mut rng);
get_test_databases(BlockVersion::ZERO, 3, &vec![], 10, logger.clone(), &mut rng);

// Get a few TxOuts to play with, and use them to construct UnspentTxOuts.
let utxos: Vec<UnspentTxOut> = (0..5)
Expand Down
3 changes: 2 additions & 1 deletion transaction/core/src/blockchain/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ mod block_tests {
use mc_util_from_random::FromRandom;
use rand::{rngs::StdRng, CryptoRng, RngCore, SeedableRng};

// This is block version 1 to avoid messing with test vectors
const BLOCK_VERSION: BlockVersion = BlockVersion::ONE;

fn get_block_contents<RNG: CryptoRng + RngCore>(rng: &mut RNG) -> BlockContents {
Expand Down Expand Up @@ -388,7 +389,7 @@ mod block_tests {
/// actual block id into the test. This should hopefully catches cases where
/// we add/change Block/BlockContents and accidentally break id
/// calculation of old blocks.
fn test_hashing_is_consistent() {
fn test_hashing_is_consistent_block_version_one() {
let mut rng: StdRng = SeedableRng::from_seed([1u8; 32]);

//Check hash with memo
Expand Down
31 changes: 15 additions & 16 deletions transaction/core/src/blockchain/block_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,43 @@ impl FromStr for BlockVersion {
impl BlockVersion {
/// The maximum value of block_version that this build of
/// mc-transaction-core has support for
pub const MAX: Self = Self(3);
pub const MAX: Self = Self(2);

/// Refers to the block version number at network launch.
/// Note: The origin blocks use block version zero.
pub const ZERO: Self = Self(0);

/// Constant for block version one
pub const ONE: Self = Self(1);

/// Constant for block version two
pub const TWO: Self = Self(2);

/// Constant for block version three
pub const THREE: Self = Self(3);

/// Iterator over block versions from one up to max, inclusive. For use in
/// tests.
pub fn iterator() -> BlockVersionIterator {
BlockVersionIterator(1)
BlockVersionIterator(0)
}

/// The encrypted memos [MCIP #3](https://github.com/mobilecoinfoundation/mcips/pull/3)
/// feature is introduced in block version 2.
/// feature is introduced in block version 1.
pub fn e_memo_feature_is_supported(&self) -> bool {
self.0 >= 2
self.0 >= 1
}

/// The confidential token ids [MCIP #25](https://github.com/mobilecoinfoundation/mcips/pull/3)
/// feature is introduced in block version 3.
/// The confidential token ids [MCIP #25](https://github.com/mobilecoinfoundation/mcips/pull/25)
/// feature is introduced in block version 2.
pub fn masked_token_id_feature_is_supported(&self) -> bool {
self.0 >= 3
self.0 >= 2
}

/// transactions shall be sorted after version 3
/// transactions shall be sorted after version 2
pub fn validate_transaction_outputs_are_sorted(&self) -> bool {
self.0 > 3
self.0 > 2
}

/// mint transactions are introduced in block version 3
/// mint transactions are introduced in block version 2
pub fn mint_transactions_are_supported(&self) -> bool {
self.0 >= 3
self.0 >= 2
}
}

Expand Down Expand Up @@ -148,7 +147,7 @@ mod tests {
#[test]
fn test_block_version_iterator() {
let observed = BlockVersion::iterator().map(|x| *x).collect::<Vec<u32>>();
let expected = (1..=*BlockVersion::MAX).collect::<Vec<u32>>();
let expected = (0..=*BlockVersion::MAX).collect::<Vec<u32>>();
assert_eq!(observed, expected);
}

Expand Down
Loading