Skip to content

Commit

Permalink
Rename AtomicCounter::get_increment to simply next
Browse files Browse the repository at this point in the history
Its a counter, `next` is super clear, `get_increment` is a bit
less so.
  • Loading branch information
TheBlueMatt committed Sep 11, 2024
1 parent 5073de8 commit dccdd3c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lightning/src/ln/interactivetxs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,7 +1328,7 @@ mod tests {
impl EntropySource for TestEntropySource {
fn get_secure_random_bytes(&self) -> [u8; 32] {
let mut res = [0u8; 32];
let increment = self.0.get_increment();
let increment = self.0.next();
for (i, byte) in res.iter_mut().enumerate() {
// Rotate the increment value by 'i' bits to the right, to avoid clashes
// when `generate_local_serial_id` does a parity flip on consecutive calls for the
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/ln/peer_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM

fn get_ephemeral_key(&self) -> SecretKey {
let mut ephemeral_hash = self.ephemeral_key_midstate.clone();
let counter = self.peer_counter.get_increment();
let counter = self.peer_counter.next();
ephemeral_hash.input(&counter.to_le_bytes());
SecretKey::from_slice(&Sha256::from_engine(ephemeral_hash).to_byte_array()).expect("You broke SHA-256!")
}
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/sign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2504,7 +2504,7 @@ impl RandomBytes {

impl EntropySource for RandomBytes {
fn get_secure_random_bytes(&self) -> [u8; 32] {
let index = self.index.get_increment();
let index = self.index.next();
let mut nonce = [0u8; 16];
nonce[..8].copy_from_slice(&index.to_be_bytes());
ChaCha20::get_single_block(&self.seed, &nonce)
Expand Down
2 changes: 1 addition & 1 deletion lightning/src/util/atomic_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl AtomicCounter {
counter: Mutex::new(0),
}
}
pub(crate) fn get_increment(&self) -> u64 {
pub(crate) fn next(&self) -> u64 {
#[cfg(target_has_atomic = "64")] {
self.counter.fetch_add(1, Ordering::AcqRel)
}
Expand Down

0 comments on commit dccdd3c

Please sign in to comment.