mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-16 17:07:35 +00:00
Correct monero-serai for aggressive clippy
This commit is contained in:
parent
3ca76c51e4
commit
7685cc305f
13 changed files with 40 additions and 36 deletions
|
@ -29,7 +29,6 @@
|
||||||
-D clippy::deref_by_slicing
|
-D clippy::deref_by_slicing
|
||||||
-D clippy::empty_structs_with_brackets
|
-D clippy::empty_structs_with_brackets
|
||||||
-D clippy::get_unwrap
|
-D clippy::get_unwrap
|
||||||
-D clippy::if_then_some_else_none
|
|
||||||
-D clippy::rest_pat_in_fully_bound_structs
|
-D clippy::rest_pat_in_fully_bound_structs
|
||||||
-D clippy::semicolon_inside_block
|
-D clippy::semicolon_inside_block
|
||||||
-D clippy::tests_outside_test_module
|
-D clippy::tests_outside_test_module
|
||||||
|
|
|
@ -249,7 +249,7 @@ impl Clsag {
|
||||||
let mask = random_scalar(rng);
|
let mask = random_scalar(rng);
|
||||||
sum_pseudo_outs += mask;
|
sum_pseudo_outs += mask;
|
||||||
mask
|
mask
|
||||||
}
|
};
|
||||||
|
|
||||||
let mut nonce = Zeroizing::new(random_scalar(rng));
|
let mut nonce = Zeroizing::new(random_scalar(rng));
|
||||||
let (mut clsag, pseudo_out, p, c) = Self::sign_core(
|
let (mut clsag, pseudo_out, p, c) = Self::sign_core(
|
||||||
|
|
|
@ -102,7 +102,7 @@ fn read_epee_vi<R: io::Read>(reader: &mut R) -> io::Result<u64> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait RpcConnection: Clone + Debug {
|
pub trait RpcConnection: Send + Sync + Clone + Debug {
|
||||||
/// Perform a POST request to the specified route with the specified body.
|
/// Perform a POST request to the specified route with the specified body.
|
||||||
///
|
///
|
||||||
/// The implementor is left to handle anything such as authentication.
|
/// The implementor is left to handle anything such as authentication.
|
||||||
|
@ -117,7 +117,7 @@ impl<R: RpcConnection> Rpc<R> {
|
||||||
///
|
///
|
||||||
/// This is NOT a JSON-RPC call. They use a route of "json_rpc" and are available via
|
/// This is NOT a JSON-RPC call. They use a route of "json_rpc" and are available via
|
||||||
/// `json_rpc_call`.
|
/// `json_rpc_call`.
|
||||||
pub async fn rpc_call<Params: Serialize + Debug, Response: DeserializeOwned + Debug>(
|
pub async fn rpc_call<Params: Send + Serialize + Debug, Response: DeserializeOwned + Debug>(
|
||||||
&self,
|
&self,
|
||||||
route: &str,
|
route: &str,
|
||||||
params: Option<Params>,
|
params: Option<Params>,
|
||||||
|
|
|
@ -345,14 +345,15 @@ impl Transaction {
|
||||||
hashes.extend(hash(&buf));
|
hashes.extend(hash(&buf));
|
||||||
buf.clear();
|
buf.clear();
|
||||||
|
|
||||||
match self.rct_signatures.prunable {
|
hashes.extend(&match self.rct_signatures.prunable {
|
||||||
RctPrunable::Null => buf.resize(32, 0),
|
RctPrunable::Null => [0; 32],
|
||||||
_ => {
|
RctPrunable::MlsagBorromean { .. } |
|
||||||
|
RctPrunable::MlsagBulletproofs { .. } |
|
||||||
|
RctPrunable::Clsag { .. } => {
|
||||||
self.rct_signatures.prunable.write(&mut buf, self.rct_signatures.rct_type()).unwrap();
|
self.rct_signatures.prunable.write(&mut buf, self.rct_signatures.rct_type()).unwrap();
|
||||||
buf = hash(&buf).to_vec();
|
hash(&buf)
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
hashes.extend(&buf);
|
|
||||||
|
|
||||||
hash(&hashes)
|
hash(&hashes)
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,8 @@ fn DISTRIBUTION() -> &'static Mutex<Vec<u64>> {
|
||||||
DISTRIBUTION_CELL.get_or_init(|| Mutex::new(Vec::with_capacity(3_000_000)))
|
DISTRIBUTION_CELL.get_or_init(|| Mutex::new(Vec::with_capacity(3_000_000)))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
#[allow(clippy::too_many_arguments, clippy::as_conversions)]
|
||||||
async fn select_n<'a, R: RngCore + CryptoRng, RPC: RpcConnection>(
|
async fn select_n<'a, R: Send + RngCore + CryptoRng, RPC: RpcConnection>(
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
rpc: &Rpc<RPC>,
|
rpc: &Rpc<RPC>,
|
||||||
distribution: &[u64],
|
distribution: &[u64],
|
||||||
|
@ -75,11 +75,9 @@ async fn select_n<'a, R: RngCore + CryptoRng, RPC: RpcConnection>(
|
||||||
age -= TIP_APPLICATION;
|
age -= TIP_APPLICATION;
|
||||||
} else {
|
} else {
|
||||||
// f64 does not have try_from available, which is why these are written with `as`
|
// f64 does not have try_from available, which is why these are written with `as`
|
||||||
#[allow(clippy::as_conversions)]
|
|
||||||
age = (rng.next_u64() % u64::try_from(RECENT_WINDOW * BLOCK_TIME).unwrap()) as f64;
|
age = (rng.next_u64() % u64::try_from(RECENT_WINDOW * BLOCK_TIME).unwrap()) as f64;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::as_conversions)]
|
|
||||||
let o = (age * per_second) as u64;
|
let o = (age * per_second) as u64;
|
||||||
if o < high {
|
if o < high {
|
||||||
let i = distribution.partition_point(|s| *s < (high - 1 - o));
|
let i = distribution.partition_point(|s| *s < (high - 1 - o));
|
||||||
|
@ -149,7 +147,8 @@ impl Decoys {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Select decoys using the same distribution as Monero.
|
/// Select decoys using the same distribution as Monero.
|
||||||
pub async fn select<R: RngCore + CryptoRng, RPC: RpcConnection>(
|
#[allow(clippy::as_conversions)]
|
||||||
|
pub async fn select<R: Send + RngCore + CryptoRng, RPC: RpcConnection>(
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
rpc: &Rpc<RPC>,
|
rpc: &Rpc<RPC>,
|
||||||
ring_len: usize,
|
ring_len: usize,
|
||||||
|
@ -183,7 +182,6 @@ impl Decoys {
|
||||||
let per_second = {
|
let per_second = {
|
||||||
let blocks = distribution.len().min(BLOCKS_PER_YEAR);
|
let blocks = distribution.len().min(BLOCKS_PER_YEAR);
|
||||||
let outputs = high - distribution[distribution.len().saturating_sub(blocks + 1)];
|
let outputs = high - distribution[distribution.len().saturating_sub(blocks + 1)];
|
||||||
#[allow(clippy::as_conversions)]
|
|
||||||
(outputs as f64) / ((blocks * BLOCK_TIME) as f64)
|
(outputs as f64) / ((blocks * BLOCK_TIME) as f64)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -234,6 +232,7 @@ impl Decoys {
|
||||||
let target_median = high * 3 / 5;
|
let target_median = high * 3 / 5;
|
||||||
while ring[ring_len / 2].0 < target_median {
|
while ring[ring_len / 2].0 < target_median {
|
||||||
// If it's not, update the bottom half with new values to ensure the median only moves up
|
// If it's not, update the bottom half with new values to ensure the median only moves up
|
||||||
|
#[allow(clippy::needless_collect)] // Needed for ownership reasons
|
||||||
for removed in ring.drain(0 .. (ring_len / 2)).collect::<Vec<_>>() {
|
for removed in ring.drain(0 .. (ring_len / 2)).collect::<Vec<_>>() {
|
||||||
// If we removed the real spend, add it back
|
// If we removed the real spend, add it back
|
||||||
if removed.0 == o.0 {
|
if removed.0 == o.0 {
|
||||||
|
|
|
@ -133,7 +133,7 @@ impl Extra {
|
||||||
ExtraField::PublicKeys(these_additional) => {
|
ExtraField::PublicKeys(these_additional) => {
|
||||||
additional = additional.or(Some(these_additional));
|
additional = additional.or(Some(these_additional));
|
||||||
}
|
}
|
||||||
_ => (),
|
ExtraField::Nonce(_) | ExtraField::MergeMining(..) => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Don't return any keys if this was non-standard and didn't include the primary key
|
// Don't return any keys if this was non-standard and didn't include the primary key
|
||||||
|
|
|
@ -115,6 +115,7 @@ impl Metadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read<R: Read>(r: &mut R) -> io::Result<Self> {
|
pub fn read<R: Read>(r: &mut R) -> io::Result<Self> {
|
||||||
|
#[allow(clippy::if_then_some_else_none)] // The Result usage makes this invalid
|
||||||
let subaddress = if read_byte(r)? == 1 {
|
let subaddress = if read_byte(r)? == 1 {
|
||||||
Some(
|
Some(
|
||||||
SubaddressIndex::new(read_u32(r)?, read_u32(r)?)
|
SubaddressIndex::new(read_u32(r)?, read_u32(r)?)
|
||||||
|
@ -323,7 +324,7 @@ impl Scanner {
|
||||||
|
|
||||||
for key in [Some(Some(&tx_key)), additional.as_ref().map(|additional| additional.get(o))] {
|
for key in [Some(Some(&tx_key)), additional.as_ref().map(|additional| additional.get(o))] {
|
||||||
let Some(Some(key)) = key else {
|
let Some(Some(key)) = key else {
|
||||||
if let Some(None) = key {
|
if key == Some(None) {
|
||||||
// This is non-standard. There were additional keys, yet not one for this output
|
// This is non-standard. There were additional keys, yet not one for this output
|
||||||
// https://github.com/monero-project/monero/
|
// https://github.com/monero-project/monero/
|
||||||
// blob/04a1e2875d6e35e27bb21497988a6c822d319c28/
|
// blob/04a1e2875d6e35e27bb21497988a6c822d319c28/
|
||||||
|
@ -451,7 +452,7 @@ impl Scanner {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut res = vec![];
|
let mut res = vec![];
|
||||||
for tx in txs.drain(..) {
|
for tx in txs {
|
||||||
if let Some(timelock) = map(self.scan_transaction(&tx), index) {
|
if let Some(timelock) = map(self.scan_transaction(&tx), index) {
|
||||||
res.push(timelock);
|
res.push(timelock);
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ pub enum TransactionError {
|
||||||
FrostError(FrostError),
|
FrostError(FrostError),
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn prepare_inputs<R: RngCore + CryptoRng, RPC: RpcConnection>(
|
async fn prepare_inputs<R: Send + RngCore + CryptoRng, RPC: RpcConnection>(
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
rpc: &Rpc<RPC>,
|
rpc: &Rpc<RPC>,
|
||||||
ring_len: usize,
|
ring_len: usize,
|
||||||
|
@ -665,7 +665,7 @@ impl SignableTransaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sign this transaction.
|
/// Sign this transaction.
|
||||||
pub async fn sign<R: RngCore + CryptoRng, RPC: RpcConnection>(
|
pub async fn sign<R: Send + RngCore + CryptoRng, RPC: RpcConnection>(
|
||||||
mut self,
|
mut self,
|
||||||
rng: &mut R,
|
rng: &mut R,
|
||||||
rpc: &Rpc<RPC>,
|
rpc: &Rpc<RPC>,
|
||||||
|
|
|
@ -367,12 +367,13 @@ impl SignMachine<Transaction> for TransactionSignMachine {
|
||||||
while !sorted.is_empty() {
|
while !sorted.is_empty() {
|
||||||
let value = sorted.remove(0);
|
let value = sorted.remove(0);
|
||||||
|
|
||||||
let mut mask = random_scalar(&mut rng);
|
let mask = if sorted.is_empty() {
|
||||||
if sorted.is_empty() {
|
output_masks - sum_pseudo_outs
|
||||||
mask = output_masks - sum_pseudo_outs;
|
|
||||||
} else {
|
} else {
|
||||||
|
let mask = random_scalar(&mut rng);
|
||||||
sum_pseudo_outs += mask;
|
sum_pseudo_outs += mask;
|
||||||
}
|
mask
|
||||||
|
};
|
||||||
|
|
||||||
tx.prefix.inputs.push(Input::ToKey {
|
tx.prefix.inputs.push(Input::ToKey {
|
||||||
amount: None,
|
amount: None,
|
||||||
|
@ -432,7 +433,9 @@ impl SignatureMachine<Transaction> for TransactionSignatureMachine {
|
||||||
pseudo_outs.push(pseudo_out);
|
pseudo_outs.push(pseudo_out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unreachable!("attempted to sign a multisig TX which wasn't CLSAG"),
|
RctPrunable::MlsagBorromean { .. } | RctPrunable::MlsagBulletproofs { .. } => {
|
||||||
|
unreachable!("attempted to sign a multisig TX which wasn't CLSAG")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(tx)
|
Ok(tx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,7 @@ test!(
|
||||||
let arbitrary_data = vec![b'\0'; MAX_ARBITRARY_DATA_SIZE - 1];
|
let arbitrary_data = vec![b'\0'; MAX_ARBITRARY_DATA_SIZE - 1];
|
||||||
|
|
||||||
// make sure we can add to tx
|
// make sure we can add to tx
|
||||||
let result = builder.add_data(arbitrary_data.clone());
|
builder.add_data(arbitrary_data.clone()).unwrap();
|
||||||
assert!(result.is_ok());
|
|
||||||
|
|
||||||
builder.add_payment(addr, 5);
|
builder.add_payment(addr, 5);
|
||||||
(builder.build().unwrap(), (arbitrary_data,))
|
(builder.build().unwrap(), (arbitrary_data,))
|
||||||
|
@ -37,8 +36,7 @@ test!(
|
||||||
|
|
||||||
// Add data multiple times
|
// Add data multiple times
|
||||||
for data in &data {
|
for data in &data {
|
||||||
let result = builder.add_data(data.clone());
|
builder.add_data(data.clone()).unwrap();
|
||||||
assert!(result.is_ok());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.add_payment(addr, 5);
|
builder.add_payment(addr, 5);
|
||||||
|
@ -65,7 +63,7 @@ test!(
|
||||||
// Reduce data size and retry. The data will now be 255 bytes long (including the added
|
// Reduce data size and retry. The data will now be 255 bytes long (including the added
|
||||||
// marker), exactly
|
// marker), exactly
|
||||||
data.pop();
|
data.pop();
|
||||||
assert!(builder.add_data(data.clone()).is_ok());
|
builder.add_data(data.clone()).unwrap();
|
||||||
|
|
||||||
builder.add_payment(addr, 5);
|
builder.add_payment(addr, 5);
|
||||||
(builder.build().unwrap(), data)
|
(builder.build().unwrap(), data)
|
||||||
|
|
|
@ -102,6 +102,7 @@ pub static SEQUENTIAL: OnceLock<Mutex<()>> = OnceLock::new();
|
||||||
macro_rules! async_sequential {
|
macro_rules! async_sequential {
|
||||||
($(async fn $name: ident() $body: block)*) => {
|
($(async fn $name: ident() $body: block)*) => {
|
||||||
$(
|
$(
|
||||||
|
#[allow(clippy::tests_outside_test_module)]
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn $name() {
|
async fn $name() {
|
||||||
let guard = runner::SEQUENTIAL.get_or_init(|| tokio::sync::Mutex::new(())).lock().await;
|
let guard = runner::SEQUENTIAL.get_or_init(|| tokio::sync::Mutex::new(())).lock().await;
|
||||||
|
|
|
@ -37,8 +37,8 @@ test!(
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
|rpc, mut builder: Builder, addr, mut outputs: Vec<ReceivedOutput>| async move {
|
|rpc, mut builder: Builder, addr, outputs: Vec<ReceivedOutput>| async move {
|
||||||
for output in outputs.drain(..) {
|
for output in outputs {
|
||||||
builder.add_input(SpendableOutput::from(&rpc, output).await.unwrap());
|
builder.add_input(SpendableOutput::from(&rpc, output).await.unwrap());
|
||||||
}
|
}
|
||||||
builder.add_payment(addr, 6);
|
builder.add_payment(addr, 6);
|
||||||
|
|
|
@ -70,7 +70,7 @@ async fn from_wallet_rpc_to_self(spec: AddressSpec) {
|
||||||
|
|
||||||
// make an addr
|
// make an addr
|
||||||
let (_, view_pair, _) = runner::random_address();
|
let (_, view_pair, _) = runner::random_address();
|
||||||
let addr = Address::from_str(&view_pair.address(Network::Mainnet, spec).to_string()[..]).unwrap();
|
let addr = Address::from_str(&view_pair.address(Network::Mainnet, spec).to_string()).unwrap();
|
||||||
|
|
||||||
// refresh & make a tx
|
// refresh & make a tx
|
||||||
wallet_rpc.refresh(None).await.unwrap();
|
wallet_rpc.refresh(None).await.unwrap();
|
||||||
|
@ -103,7 +103,9 @@ async fn from_wallet_rpc_to_self(spec: AddressSpec) {
|
||||||
assert_eq!(output.metadata.payment_id, payment_id);
|
assert_eq!(output.metadata.payment_id, payment_id);
|
||||||
assert_eq!(output.metadata.subaddress, None);
|
assert_eq!(output.metadata.subaddress, None);
|
||||||
}
|
}
|
||||||
_ => assert_eq!(output.metadata.subaddress, None),
|
AddressSpec::Standard | AddressSpec::Featured { .. } => {
|
||||||
|
assert_eq!(output.metadata.subaddress, None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
assert_eq!(output.commitment().amount, 1000000000000);
|
assert_eq!(output.commitment().amount, 1000000000000);
|
||||||
}
|
}
|
||||||
|
@ -228,7 +230,7 @@ test!(
|
||||||
for _ in 0 .. 2 {
|
for _ in 0 .. 2 {
|
||||||
// Subtract 1 since we prefix data with 127
|
// Subtract 1 since we prefix data with 127
|
||||||
let data = vec![b'a'; MAX_TX_EXTRA_NONCE_SIZE - 1];
|
let data = vec![b'a'; MAX_TX_EXTRA_NONCE_SIZE - 1];
|
||||||
assert!(builder.add_data(data).is_ok());
|
builder.add_data(data).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
(builder.build().unwrap(), (wallet_rpc,))
|
(builder.build().unwrap(), (wallet_rpc,))
|
||||||
|
|
Loading…
Reference in a new issue