Skip to content

Commit

Permalink
decrement block version everywhere (master branch) (#1700)
Browse files Browse the repository at this point in the history
* decrement block version everywhere

we have to decrement block version because of a compatibility issue
it turns out that v1.0 always published block version = 0, and not
one as the source code indicated after a bunch of development.

* fix remoun comment (use constant at top of file)

* try to fix fog local network test

* fix argparse stuff

* fix rct_bulletproof tests block version range

* fix typo in local network python, and update transaction builder tests
  • Loading branch information
cbeck88 authored Mar 28, 2022
1 parent e648990 commit 4561317
Show file tree
Hide file tree
Showing 33 changed files with 120 additions and 120 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,14 @@ commands:
MC_LOG="info,rustls=warn,hyper=warn,tokio_reactor=warn,mio=warn,want=warn,rusoto_core=error,h2=error,reqwest=error,rocket=error,<unknown>=error" \
LEDGER_BASE=$(pwd)/ledger \
python3 tools/fog-local-network/fog_local_network.py --network-type dense5 --skip-build &
python3 tools/fog-local-network/fog_local_network.py --network-type dense5 --skip-build --block-version 2 &
sleep 20
./target/release/sample-keys --num 4 --output-dir fog_keys --fog-report-url 'insecure-fog://localhost:6200' --fog-authority-root $FOG_AUTHORITY_ROOT
./target/release/fog-distribution \
--block-version 3 \
--block-version 2 \
--sample-data-dir . \
--max-threads 1 \
--peer insecure-mc://localhost:3200/ \
Expand Down
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
16 changes: 6 additions & 10 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,
BLOCK_VERSION,
&origin_block,
&Default::default(),
&block_contents,
Expand Down Expand Up @@ -2570,12 +2570,8 @@ mod ledger_db_test {
..Default::default()
};
let parent = ledger_db.get_block(n_blocks - 1).unwrap();
let block = Block::new_with_parent(
BlockVersion::ONE,
&parent,
&Default::default(),
&block_contents,
);
let block =
Block::new_with_parent(BLOCK_VERSION, &parent, &Default::default(), &block_contents);

ledger_db
.append_block(&block, &block_contents, None)
Expand Down Expand Up @@ -2610,7 +2606,7 @@ mod ledger_db_test {
..Default::default()
};
let block = Block::new_with_parent(
BlockVersion::ONE,
BLOCK_VERSION,
&origin_block,
&Default::default(),
&block_contents,
Expand Down Expand Up @@ -2699,7 +2695,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 tools/fog-local-network/fog_local_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def stop(self):
parser = argparse.ArgumentParser(description='Local network tester')
parser.add_argument('--network-type', help='Type of network to create', required=True)
parser.add_argument('--skip-build', help='Skip building binaries', action='store_true')
parser.add_argument('--block-version', help='Set the block version argument', type=int)
args = parser.parse_args()

FogNetwork().default_entry_point(args.network_type, args.skip_build)
FogNetwork().default_entry_point(args.network_type, args.skip_build, args.block_version)
13 changes: 9 additions & 4 deletions tools/local-network/local_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __repr__(self):


class Node:
def __init__(self, name, node_num, client_port, peer_port, admin_port, admin_http_gateway_port, peers, quorum_set):
def __init__(self, name, node_num, client_port, peer_port, admin_port, admin_http_gateway_port, peers, quorum_set, block_version):
assert all(isinstance(peer, Peer) for peer in peers)
assert isinstance(quorum_set, QuorumSet)

Expand All @@ -154,6 +154,7 @@ def __init__(self, name, node_num, client_port, peer_port, admin_port, admin_htt
self.peers = peers
self.quorum_set = quorum_set
self.minimum_fee = 400_000_000
self.block_version = block_version or 2

self.consensus_process = None
self.ledger_distribution_process = None
Expand Down Expand Up @@ -249,7 +250,7 @@ def start(self, network):
f'--ias-api-key={IAS_API_KEY}',
f'--ias-spid={IAS_SPID}',
f'--origin-block-path {LEDGER_BASE}',
f'--block-version 3',
f'--block-version {self.block_version}',
f'--ledger-path {self.ledger_dir}',
f'--admin-listen-uri="insecure-mca://0.0.0.0:{self.admin_port}/"',
f'--client-listen-uri="insecure-mc://0.0.0.0:{self.client_port}/"',
Expand Down Expand Up @@ -467,6 +468,7 @@ def add_node(self, name, peers, quorum_set):
BASE_ADMIN_HTTP_GATEWAY_PORT + node_num,
peers,
quorum_set,
self.block_version,
))

def get_node(self, name):
Expand Down Expand Up @@ -539,7 +541,9 @@ def stop(self):
raise


def default_entry_point(self, network_type, skip_build=False):
def default_entry_point(self, network_type, skip_build=False, block_version=None):
self.block_version = block_version

if network_type == 'dense5':
# 5 node interconnected network requiring 4 out of 5 nodes.
num_nodes = 5
Expand Down Expand Up @@ -589,6 +593,7 @@ def default_entry_point(self, network_type, skip_build=False):
parser = argparse.ArgumentParser(description='Local network tester')
parser.add_argument('--network-type', help='Type of network to create', required=True)
parser.add_argument('--skip-build', help='Skip building binaries', action='store_true')
parser.add_argument('--block-version', help='Set the block version argument', type=int)
args = parser.parse_args()

Network().default_entry_point(args.network_type, args.skip_build)
Network().default_entry_point(args.network_type, args.skip_build, args.block_version)
Loading

0 comments on commit 4561317

Please sign in to comment.