Skip to content

Commit

Permalink
removes feature gate code separating durable nonce from blockhash dom…
Browse files Browse the repository at this point in the history
…ain (#26055)
  • Loading branch information
behzadnouri authored Jul 6, 2022
1 parent d33c548 commit 6f5857a
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 523 deletions.
5 changes: 1 addition & 4 deletions account-decoder/src/parse_account_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,7 @@ mod test {
assert_eq!(parsed.program, "vote".to_string());
assert_eq!(parsed.space, VoteState::size_of() as u64);

let nonce_data = Versions::new(
State::Initialized(Data::default()),
true, // separate_domains
);
let nonce_data = Versions::new(State::Initialized(Data::default()));
let nonce_account_data = bincode::serialize(&nonce_data).unwrap();
let parsed = parse_account_data(
&account_pubkey,
Expand Down
5 changes: 1 addition & 4 deletions account-decoder/src/parse_nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ mod test {

#[test]
fn test_parse_nonce() {
let nonce_data = Versions::new(
State::Initialized(Data::default()),
true, // separate_domains
);
let nonce_data = Versions::new(State::Initialized(Data::default()));
let nonce_account_data = bincode::serialize(&nonce_data).unwrap();
assert_eq!(
parse_nonce(&nonce_account_data).unwrap(),
Expand Down
68 changes: 25 additions & 43 deletions cli/src/nonce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1006,14 +1006,14 @@ mod tests {

#[test]
fn test_check_nonce_account() {
let durable_nonce =
DurableNonce::from_blockhash(&Hash::default(), /*separate_domains:*/ true);
let durable_nonce = DurableNonce::from_blockhash(&Hash::default());
let blockhash = *durable_nonce.as_hash();
let nonce_pubkey = solana_sdk::pubkey::new_rand();
let data = Versions::new(
State::Initialized(nonce::state::Data::new(nonce_pubkey, durable_nonce, 0)),
true, // separate_domains
);
let data = Versions::new(State::Initialized(nonce::state::Data::new(
nonce_pubkey,
durable_nonce,
0,
)));
let valid = Account::new_data(1, &data, &system_program::ID);
assert!(check_nonce_account(&valid.unwrap(), &nonce_pubkey, &blockhash).is_ok());

Expand All @@ -1031,16 +1031,12 @@ mod tests {
assert_eq!(err, Error::InvalidAccountData,);
}

let invalid_durable_nonce =
DurableNonce::from_blockhash(&hash(b"invalid"), /*separate_domains:*/ true);
let data = Versions::new(
State::Initialized(nonce::state::Data::new(
nonce_pubkey,
invalid_durable_nonce,
0,
)),
true, // separate_domains
);
let invalid_durable_nonce = DurableNonce::from_blockhash(&hash(b"invalid"));
let data = Versions::new(State::Initialized(nonce::state::Data::new(
nonce_pubkey,
invalid_durable_nonce,
0,
)));
let invalid_hash = Account::new_data(1, &data, &system_program::ID).unwrap();
if let CliError::InvalidNonce(err) =
check_nonce_account(&invalid_hash, &nonce_pubkey, &blockhash).unwrap_err()
Expand All @@ -1055,14 +1051,11 @@ mod tests {
}

let new_nonce_authority = solana_sdk::pubkey::new_rand();
let data = Versions::new(
State::Initialized(nonce::state::Data::new(
new_nonce_authority,
durable_nonce,
0,
)),
true, // separate_domains
);
let data = Versions::new(State::Initialized(nonce::state::Data::new(
new_nonce_authority,
durable_nonce,
0,
)));
let invalid_authority = Account::new_data(1, &data, &system_program::ID);
if let CliError::InvalidNonce(err) =
check_nonce_account(&invalid_authority.unwrap(), &nonce_pubkey, &blockhash).unwrap_err()
Expand All @@ -1076,7 +1069,7 @@ mod tests {
);
}

let data = Versions::new(State::Uninitialized, /*separate_domains:*/ true);
let data = Versions::new(State::Uninitialized);
let invalid_state = Account::new_data(1, &data, &system_program::ID);
if let CliError::InvalidNonce(err) =
check_nonce_account(&invalid_state.unwrap(), &nonce_pubkey, &blockhash).unwrap_err()
Expand All @@ -1087,8 +1080,7 @@ mod tests {

#[test]
fn test_account_identity_ok() {
let nonce_account =
nonce_account::create_account(1, /*separate_domains:*/ true).into_inner();
let nonce_account = nonce_account::create_account(1).into_inner();
assert_eq!(account_identity_ok(&nonce_account), Ok(()));

let system_account = Account::new(1, 0, &system_program::id());
Expand All @@ -1107,18 +1099,13 @@ mod tests {

#[test]
fn test_state_from_account() {
let mut nonce_account =
nonce_account::create_account(1, /*separate_domains:*/ true).into_inner();
let mut nonce_account = nonce_account::create_account(1).into_inner();
assert_eq!(state_from_account(&nonce_account), Ok(State::Uninitialized));

let durable_nonce =
DurableNonce::from_blockhash(&Hash::new(&[42u8; 32]), /*separate_domains:*/ true);
let durable_nonce = DurableNonce::from_blockhash(&Hash::new(&[42u8; 32]));
let data = nonce::state::Data::new(Pubkey::new(&[1u8; 32]), durable_nonce, 42);
nonce_account
.set_state(&Versions::new(
State::Initialized(data.clone()),
true, // separate_domains
))
.set_state(&Versions::new(State::Initialized(data.clone())))
.unwrap();
assert_eq!(
state_from_account(&nonce_account),
Expand All @@ -1134,8 +1121,7 @@ mod tests {

#[test]
fn test_data_from_helpers() {
let mut nonce_account =
nonce_account::create_account(1, /*separate_domains:*/ true).into_inner();
let mut nonce_account = nonce_account::create_account(1).into_inner();
let state = state_from_account(&nonce_account).unwrap();
assert_eq!(
data_from_state(&state),
Expand All @@ -1146,14 +1132,10 @@ mod tests {
Err(Error::InvalidStateForOperation)
);

let durable_nonce =
DurableNonce::from_blockhash(&Hash::new(&[42u8; 32]), /*separate_domains:*/ true);
let durable_nonce = DurableNonce::from_blockhash(&Hash::new(&[42u8; 32]));
let data = nonce::state::Data::new(Pubkey::new(&[1u8; 32]), durable_nonce, 42);
nonce_account
.set_state(&Versions::new(
State::Initialized(data.clone()),
true, // separate_domains
))
.set_state(&Versions::new(State::Initialized(data.clone())))
.unwrap();
let state = state_from_account(&nonce_account).unwrap();
assert_eq!(data_from_state(&state), Ok(&data));
Expand Down
8 changes: 2 additions & 6 deletions client/src/blockhash_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ mod tests {
.get_blockhash_and_fee_calculator(&rpc_client, CommitmentConfig::default())
.is_err());

let durable_nonce =
DurableNonce::from_blockhash(&Hash::new(&[2u8; 32]), /*separate_domains:*/ true);
let durable_nonce = DurableNonce::from_blockhash(&Hash::new(&[2u8; 32]));
let nonce_blockhash = *durable_nonce.as_hash();
let nonce_fee_calc = FeeCalculator::new(4242);
let data = nonce::state::Data {
Expand All @@ -427,10 +426,7 @@ mod tests {
};
let nonce_account = Account::new_data_with_space(
42,
&nonce::state::Versions::new(
nonce::State::Initialized(data),
true, // separate_domains
),
&nonce::state::Versions::new(nonce::State::Initialized(data)),
nonce::State::size(),
&system_program::id(),
)
Expand Down
9 changes: 5 additions & 4 deletions rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5582,10 +5582,11 @@ pub mod tests {
let authority = Pubkey::new_unique();
let account = AccountSharedData::new_data(
42,
&nonce::state::Versions::new(
nonce::State::new_initialized(&authority, DurableNonce::default(), 1000),
true, // separate_domains
),
&nonce::state::Versions::new(nonce::State::new_initialized(
&authority,
DurableNonce::default(),
1000,
)),
&system_program::id(),
)
.unwrap();
Expand Down
13 changes: 5 additions & 8 deletions rpc/src/transaction_status_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,13 @@ pub(crate) mod tests {
let expected_transaction = transaction.clone();
let pubkey = Pubkey::new_unique();

let mut nonce_account =
nonce_account::create_account(1, /*separate_domains:*/ true).into_inner();
let durable_nonce =
DurableNonce::from_blockhash(&Hash::new(&[42u8; 32]), /*separate_domains:*/ true);
let mut nonce_account = nonce_account::create_account(1).into_inner();
let durable_nonce = DurableNonce::from_blockhash(&Hash::new(&[42u8; 32]));
let data = nonce::state::Data::new(Pubkey::new(&[1u8; 32]), durable_nonce, 42);
nonce_account
.set_state(&nonce::state::Versions::new(
nonce::State::Initialized(data),
true, // separate_domains
))
.set_state(&nonce::state::Versions::new(nonce::State::Initialized(
data,
)))
.unwrap();

let message = build_message();
Expand Down
Loading

0 comments on commit 6f5857a

Please sign in to comment.