Skip to content

Commit

Permalink
Clippy + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Feb 7, 2023
1 parent ee06465 commit ffde19d
Show file tree
Hide file tree
Showing 15 changed files with 253 additions and 155 deletions.
7 changes: 6 additions & 1 deletion apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2810,7 +2810,12 @@ pub mod args {
"The maximum amount of gas needed to run transaction",
),
)
.arg(EXPIRATION_OPT.def().about("The expiration datetime of the transaction, after which the tx won't be accepted anymore. All of these examples are equivalent:\n2012-12-12T12:12:12Z\n2012-12-12 12:12:12Z\n2012- 12-12T12: 12:12Z"))
.arg(EXPIRATION_OPT.def().about(
"The expiration datetime of the transaction, after which the \
tx won't be accepted anymore. All of these examples are \
equivalent:\n2012-12-12T12:12:12Z\n2012-12-12 \
12:12:12Z\n2012- 12-12T12: 12:12Z",
))
.arg(
SIGNING_KEY_OPT
.def()
Expand Down
6 changes: 3 additions & 3 deletions apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1755,9 +1755,9 @@ pub async fn query_bonded_stake(ctx: Context, args: args::QueryBondedStake) {
};
let is_active = validator_set.active.contains(&weighted);
if !is_active {
debug_assert!(validator_set
.inactive
.contains(&weighted));
debug_assert!(
validator_set.inactive.contains(&weighted)
);
}
println!(
"Validator {} is {}, bonded stake: {}",
Expand Down
114 changes: 50 additions & 64 deletions apps/src/lib/node/ledger/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ where
.into_iter()
.map(|tx_bytes| {
match Tx::try_from(tx_bytes.as_slice()) {
Ok(tx) => {
Ok(tx) => {
let tx_expiration = tx.expiration;
if let Ok(TxType::Wrapper(_)) = process_tx(tx) {
// Check tx expiration against proposed block
Expand All @@ -65,40 +65,31 @@ where
Some(&block_time) => {
match TryInto::<DateTimeUtc>::try_into(block_time.to_owned()) {
Ok(datetime) => {

if datetime > exp {
record::remove(tx_bytes)
} else {
record::keep(tx_bytes)
}
if datetime > exp {
record::remove(tx_bytes)
} else {
record::keep(tx_bytes)
}
},
Err(_) => {

// Default to last block datetime which has already been checked by mempool_validate, so accept the tx
record::keep(tx_bytes)
// Default to last block datetime which has already been checked by mempool_validate, so accept the tx
record::keep(tx_bytes)
}
}
},
None => {

// Default to last block datetime which has already been checked by mempool_validate, so accept the tx
record::keep(tx_bytes)
// Default to last block datetime which has already been checked by mempool_validate, so accept the tx
record::keep(tx_bytes)
}
}
},
None => record::keep(tx_bytes)
}


} else {
} else {
record::remove(tx_bytes)
}
}
Err(_) => record::remove(tx_bytes),




}
})
.take_while(|tx_record| {
Expand Down Expand Up @@ -129,31 +120,27 @@ if datetime > exp {
Some(block_time) => {
match TryInto::<DateTimeUtc>::try_into(block_time.to_owned()) {
Ok(datetime) => {

if datetime > exp { None
} else {
Some(tx_bytes)
}
if datetime > exp {
None
} else {
Some(tx_bytes)
}
},
Err(_) => {

// Default to last block datetime which has already been checked by mempool_validate, so accept the tx
Some(tx_bytes)
}
}
},
None => {

// Default to last block datetime which has already been checked by mempool_validate, so accept the tx
Some(tx_bytes)
}
}
},
None => Some(tx_bytes)
}


} else {
} else {
None
}
}
Expand Down Expand Up @@ -440,54 +427,53 @@ mod test_prepare_proposal {
/// Test that expired wrapper transactions are not included in the block
#[test]
fn test_expired_wrapper_tx() {

let (shell, _) = TestShell::new();
let (shell, _) = TestShell::new();
let keypair = gen_keypair();
let tx_time = DateTimeUtc::now();
let tx = Tx::new(
"wasm_code".as_bytes().to_owned(),
Some("transaction data".as_bytes().to_owned()),
shell.chain_id.clone(),
None,
);
let wrapper_tx = WrapperTx::new(
Fee {
amount: 0.into(),
token: shell.wl_storage.storage.native_token.clone(),
},
&keypair,
0.into(),
tx,
Default::default(),
#[cfg(not(feature = "mainnet"))]
None,
);
let wrapper = wrapper_tx
.sign(&keypair, shell.chain_id.clone(), Some(tx_time))
.expect("Test failed");
let tx = Tx::new(
"wasm_code".as_bytes().to_owned(),
Some("transaction data".as_bytes().to_owned()),
shell.chain_id.clone(),
None,
);
let wrapper_tx = WrapperTx::new(
Fee {
amount: 0.into(),
token: shell.wl_storage.storage.native_token.clone(),
},
&keypair,
0.into(),
tx,
Default::default(),
#[cfg(not(feature = "mainnet"))]
None,
);
let wrapper = wrapper_tx
.sign(&keypair, shell.chain_id.clone(), Some(tx_time))
.expect("Test failed");

let time = DateTimeUtc::now();
let mut block_time = namada::core::tendermint_proto::google::protobuf::Timestamp::default();
block_time.seconds =
time.0.timestamp();
block_time.nanos =
time.0.timestamp_subsec_nanos() as i32;
let req = RequestPrepareProposal {
let time = DateTimeUtc::now();
let block_time =
namada::core::tendermint_proto::google::protobuf::Timestamp {
seconds: time.0.timestamp(),
nanos: time.0.timestamp_subsec_nanos() as i32,
};
let req = RequestPrepareProposal {
txs: vec![wrapper.to_bytes()],
max_tx_bytes: 0,
time: Some(block_time) ,
..Default::default()
time: Some(block_time),
..Default::default()
};
#[cfg(feature = "abcipp")]
assert_eq!(
shell.prepare_proposal(req).tx_records,
vec![record::remove(tx.to_bytes())]
);
#[cfg(not(feature = "abcipp"))]
#[cfg(not(feature = "abcipp"))]
{
let result = shell.prepare_proposal(req);
eprintln!("Proposal: {:?}", result.txs);
assert!(result.txs.is_empty());
assert!(result.txs.is_empty());
}
}
}
2 changes: 1 addition & 1 deletion apps/src/lib/node/ledger/shell/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ mod test_process_proposal {
},
&keypair,
0.into(),
tx.clone(),
tx,
Default::default(),
#[cfg(not(feature = "mainnet"))]
None,
Expand Down
24 changes: 16 additions & 8 deletions apps/src/lib/node/ledger/shims/abcipp_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,26 @@ impl AbcippShim {
Ok(t) => t,
Err(_) => {
// Default to last committed block time
self.service.wl_storage
.storage
.get_last_block_timestamp()
.expect("Failed to retrieve last block timestamp")
self.service
.wl_storage
.storage
.get_last_block_timestamp()
.expect(
"Failed to retrieve last block \
timestamp",
)
}
},
None => {
// Default to last committed block time
self.service.wl_storage
.storage
.get_last_block_timestamp()
.expect("Failed to retrieve last block timestamp")
self.service
.wl_storage
.storage
.get_last_block_timestamp()
.expect(
"Failed to retrieve last block \
timestamp",
)
}
},
None => {
Expand Down
2 changes: 1 addition & 1 deletion core/src/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ where
Ok(self
.db
.read_block_header(last_block_height)?
.map_or_else(|| DateTimeUtc::now(), |header| header.time))
.map_or_else(DateTimeUtc::now, |header| header.time))
}

/// Initialize a new epoch when the current epoch is finished. Returns
Expand Down
3 changes: 2 additions & 1 deletion core/src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ pub use types::{Dkg, Error, Signed, SignedTxData, Tx};

#[cfg(test)]
mod tests {
use std::time::SystemTime;

use data_encoding::HEXLOWER;
use generated::types::Tx;
use prost::Message;
use std::time::SystemTime;

use super::*;
use crate::types::chain::ChainId;
Expand Down
7 changes: 4 additions & 3 deletions core/src/types/transaction/decrypted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ pub mod decrypted_tx {
.try_to_vec()
.expect("Encrypting transaction should not fail"),
),
// If undecrytable we cannot extract the ChainId and expiration.
// If instead the tx gets decrypted successfully, the correct
// chain id and expiration are serialized inside the data field
// If undecrytable we cannot extract the ChainId and
// expiration. If instead the tx gets decrypted
// successfully, the correct chain id and
// expiration are serialized inside the data field
// of the Tx, while the ones available
// in the chain_id and expiration field are just placeholders
ChainId(String::new()),
Expand Down
3 changes: 2 additions & 1 deletion core/src/types/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ pub mod tx_types {
vec![],
Some(ty.try_to_vec().unwrap()),
ChainId(String::new()), /* No need to provide a valid
* ChainId or expiration when casting back from
* ChainId or expiration when
* casting back from
* TxType */
None,
)
Expand Down
Loading

0 comments on commit ffde19d

Please sign in to comment.