Skip to content

Commit

Permalink
[genesis] do not bump sequence number for DiemRoot
Browse files Browse the repository at this point in the history
In older versions of Diem, the genesis transaction was a signed transaction sent from the DiemRoot account. To reflect this, the genesis write set incremented the sequence number for DiemRoot so that the first transaction sent from this account would have sequence number 1.

Since then, genesis has been given its own transaction type with no sender address. Thus, we no longer need this sequence number bump.

Closes: aptos-labs#9751
  • Loading branch information
Zekun Li authored and bors-libra committed Nov 16, 2021
1 parent 8b71992 commit b9d1dd4
Show file tree
Hide file tree
Showing 35 changed files with 61 additions and 88 deletions.
2 changes: 1 addition & 1 deletion api/src/tests/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl TestContext {
}

pub fn root_account(&self) -> LocalAccount {
LocalAccount::new(diem_root_address(), self.root_keys.root_key.clone(), 1)
LocalAccount::new(diem_root_address(), self.root_keys.root_key.clone(), 0)
}

pub fn gen_account(&mut self) -> LocalAccount {
Expand Down
29 changes: 1 addition & 28 deletions diem-move/vm-genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use move_bytecode_utils::Modules;
use move_core_types::{
account_address::AccountAddress,
identifier::Identifier,
language_storage::{ModuleId, StructTag, TypeTag},
language_storage::{ModuleId, TypeTag},
value::{serialize_values, MoveValue},
};
use move_vm_runtime::{move_vm::MoveVM, session::Session};
Expand Down Expand Up @@ -98,20 +98,12 @@ pub fn encode_genesis_change_set(
let move_vm = MoveVM::new(diem_vm::natives::diem_natives()).unwrap();
let mut session = move_vm.new_session(&data_cache);

let xdx_ty = TypeTag::Struct(StructTag {
address: *account_config::XDX_MODULE.address(),
module: account_config::XDX_MODULE.name().to_owned(),
name: account_config::XDX_IDENTIFIER.to_owned(),
type_params: vec![],
});

create_and_initialize_main_accounts(
&mut session,
diem_root_key,
treasury_compliance_key,
vm_publishing_option,
consensus_config,
&xdx_ty,
chain_id,
);
// generate the genesis WriteSet
Expand Down Expand Up @@ -196,7 +188,6 @@ fn create_and_initialize_main_accounts(
treasury_compliance_key: &Ed25519PublicKey,
publishing_option: VMPublishingOption,
consensus_config: OnChainConsensusConfig,
xdx_ty: &TypeTag,
chain_id: ChainId,
) {
let diem_root_auth_key = AuthenticationKey::ed25519(diem_root_key);
Expand Down Expand Up @@ -241,24 +232,6 @@ fn create_and_initialize_main_accounts(
MoveValue::vector_u8(consensus_config_bytes),
]),
);

// Bump the sequence number for the Association account. If we don't do this and a
// subsequent transaction (e.g., minting) is sent from the Assocation account, a problem
// arises: both the genesis transaction and the subsequent transaction have sequence
// number 0
exec_function(
session,
"DiemAccount",
"epilogue",
vec![xdx_ty.clone()],
serialize_values(&vec![
MoveValue::Signer(root_diem_root_address),
MoveValue::U64(/* txn_sequence_number */ 0),
MoveValue::U64(/* txn_gas_price */ 0),
MoveValue::U64(/* txn_max_gas_units */ 0),
MoveValue::U64(/* gas_units_remaining */ 0),
]),
);
}

fn create_and_initialize_testnet_minting(
Expand Down
2 changes: 1 addition & 1 deletion execution/executor/tests/storage_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ fn test_change_publishing_option_to_custom() {
};
let txn5 = get_test_signed_transaction(
genesis_account,
/* sequence_number = */ 1,
/* sequence_number = */ 0,
genesis_key.clone(),
genesis_key.public_key(),
Some(TransactionPayload::Script(Script::new(
Expand Down
2 changes: 1 addition & 1 deletion language/e2e-testsuite/src/tests/account_limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ fn account_limits() {
let diem_root = Account::new_diem_root();
let blessed = Account::new_blessed_tc();
let dd = Account::new_testing_dd();
let dr_sequence_number = 1;
let dr_sequence_number = 0;
let tc_sequence_number = 0;
let dd_sequence_number = 0;

Expand Down
6 changes: 3 additions & 3 deletions language/e2e-testsuite/src/tests/admin_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ main(dr_account: signer, account: signer, auth_key_prefix: vector<u8>) {
),
execute_as: *new_account.address(),
})
.sequence_number(1)
.sequence_number(0)
.sign();
executor.new_block();
let output = executor.execute_and_apply(txn);
Expand Down Expand Up @@ -115,7 +115,7 @@ main(dr_account: signer, account: signer, auth_key_prefix: vector<u8>) {
),
execute_as: *new_account.address(),
})
.sequence_number(1)
.sequence_number(0)
.sign();
executor.new_block();
let output = executor.execute_and_apply(txn);
Expand Down Expand Up @@ -175,7 +175,7 @@ main(account: signer, auth_key_prefix: vector<u8>) {
),
execute_as: *new_account.address(),
})
.sequence_number(1)
.sequence_number(0)
.sign();
executor.new_block();
let output = executor.execute_transaction(txn);
Expand Down
2 changes: 1 addition & 1 deletion language/e2e-testsuite/src/tests/crsn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn init(executor: &mut FakeExecutor) {
}
"#;
let script = compile_script(program, vec![]);
let txn = dr.transaction().script(script).sequence_number(1).sign();
let txn = dr.transaction().script(script).sequence_number(0).sign();
executor.execute_and_apply(txn);
}

Expand Down
4 changes: 2 additions & 2 deletions language/e2e-testsuite/src/tests/module_publishing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ pub fn test_publishing_no_modules_non_allowlist_script_proper_sender() {
let txn = sender
.transaction()
.module(random_module)
.sequence_number(1)
.sequence_number(0)
.sign();
assert_eq!(executor.verify_transaction(txn.clone()).status(), None);
assert_eq!(
Expand Down Expand Up @@ -348,7 +348,7 @@ pub fn test_publishing_no_modules_proper_sender() {
let txn = sender
.transaction()
.module(random_script)
.sequence_number(1)
.sequence_number(0)
.sign();
assert_eq!(executor.verify_transaction(txn.clone()).status(), None);
assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion language/e2e-testsuite/src/tests/on_chain_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ fn update_script_allow_list() {
let txn = dr
.transaction()
.script(Script::new(random_script, vec![], vec![]))
.sequence_number(1)
.sequence_number(0)
.sign();

assert_eq!(
Expand Down
2 changes: 1 addition & 1 deletion language/e2e-testsuite/src/tests/transaction_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ fn add_child_currencies() {
let dr_account = Account::new_diem_root();
let tc_sequence_number = 0;

currencies::add_currency_to_system(&mut executor, "COIN", &dr_account, 1);
currencies::add_currency_to_system(&mut executor, "COIN", &dr_account, 0);

executor.execute_and_apply(
blessed
Expand Down
4 changes: 2 additions & 2 deletions language/e2e-testsuite/src/tests/transaction_fuzzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ proptest! {
) {
let executor = FakeExecutor::from_genesis_file();
let accounts = vec![
(Account::new_diem_root(), 1),
(Account::new_diem_root(), 0),
(Account::new_blessed_tc(), 0),
];
let num_accounts = accounts.len();
Expand Down Expand Up @@ -59,7 +59,7 @@ proptest! {
vec![],
i % 2 == 0,
))
.sequence_number(i as u64 + 1)
.sequence_number(i as u64)
.sign(),
);
accounts.push((account, 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn validator_add_max_number() {

executor.set_golden_file(current_function_name!());

let output = try_add_validator(&mut executor, &Account::new_diem_root(), 1);
let output = try_add_validator(&mut executor, &Account::new_diem_root(), 0);

assert_aborted_with(output, 1800);
}
Expand Down
6 changes: 3 additions & 3 deletions language/e2e-testsuite/src/tests/verify_txn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ pub fn test_no_publishing_diem_root_sender() {
let txn = sender
.transaction()
.module(random_module)
.sequence_number(1)
.sequence_number(0)
.max_gas_amount(100_000)
.sign();
assert_eq!(executor.verify_transaction(txn.clone()).status(), None);
Expand Down Expand Up @@ -1552,7 +1552,7 @@ pub fn publish_and_register_new_currency() {
let txn = sender
.transaction()
.module(module)
.sequence_number(1)
.sequence_number(0)
.sign();
assert_eq!(executor.verify_transaction(txn.clone()).status(), None);
assert_eq!(
Expand Down Expand Up @@ -1581,7 +1581,7 @@ pub fn publish_and_register_new_currency() {
script: Script::new(program, vec![], vec![]),
execute_as: *tc_account.address(),
})
.sequence_number(2)
.sequence_number(1)
.sign();
executor.new_block();
executor.execute_and_apply(txn);
Expand Down
2 changes: 1 addition & 1 deletion language/e2e-testsuite/src/tests/write_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn bad_writesets() {
write_set.clone(),
vec![],
)))
.sequence_number(1)
.sequence_number(0)
.sign();
assert_prologue_parity!(
executor.verify_transaction(writeset_txn.clone()).status(),
Expand Down
4 changes: 2 additions & 2 deletions language/e2e-testsuite/src/tests/writeset_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn build_upgrade_writeset() {
let writeset_txn = genesis_account
.transaction()
.write_set(WriteSetPayload::Direct(change_set))
.sequence_number(1)
.sequence_number(0)
.sign();

let output = executor.execute_transaction(writeset_txn.clone());
Expand Down Expand Up @@ -89,7 +89,7 @@ main(lr_account: signer) {
let txn = genesis_account
.transaction()
.script(Script::new(script_body, vec![], vec![]))
.sequence_number(2)
.sequence_number(1)
.sign();

let output = executor.execute_transaction(txn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ script {
use DiemFramework::DiemAccount;

fun main() {
// check that the sequence number of the Association account (which sent the genesis txn) has been
// check that the sequence number of the Association account (which sent the genesis txn) has not been
// incremented...
assert!(DiemAccount::sequence_number(@DiemRoot) == 1, 66);
assert!(DiemAccount::sequence_number(@DiemRoot) == 0, 66);
}
}
Loading

0 comments on commit b9d1dd4

Please sign in to comment.