Skip to content

Commit 2d36bd9

Browse files
committed
CRC: remove UpdateTime
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 4205a87 commit 2d36bd9

File tree

6 files changed

+45
-49
lines changed

6 files changed

+45
-49
lines changed

libsigner/src/tests/signer_state.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// You should have received a copy of the GNU General Public License
1414
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
use std::collections::HashMap;
16+
use std::time::SystemTime;
1617

1718
use blockstack_lib::chainstate::stacks::{
1819
StacksTransaction, TokenTransferMemo, TransactionAnchorMode, TransactionAuth,
@@ -27,9 +28,7 @@ use crate::v0::messages::{
2728
StateMachineUpdate as StateMachineUpdateMessage, StateMachineUpdateContent,
2829
StateMachineUpdateMinerState,
2930
};
30-
use crate::v0::signer_state::{
31-
GlobalStateEvaluator, ReplayTransactionSet, SignerStateMachine, UpdateTime,
32-
};
31+
use crate::v0::signer_state::{GlobalStateEvaluator, ReplayTransactionSet, SignerStateMachine};
3332

3433
fn generate_global_state_evaluator(num_addresses: u32) -> GlobalStateEvaluator {
3534
let address_weights = generate_random_address_with_equal_weights(num_addresses);
@@ -240,7 +239,7 @@ fn determine_global_states() {
240239
current_miner: (&current_miner).into(),
241240
active_signer_protocol_version: local_supported_signer_protocol_version, // a majority of signers are saying they support version the same local_supported_signer_protocol_version, so update it here...
242241
tx_replay_set: ReplayTransactionSet::none(),
243-
update_time: UpdateTime::now(),
242+
update_time: SystemTime::now(),
244243
};
245244

246245
global_eval.insert_update(local_address, local_update);
@@ -280,7 +279,7 @@ fn determine_global_states() {
280279
current_miner: (&new_miner).into(),
281280
active_signer_protocol_version: local_supported_signer_protocol_version, // a majority of signers are saying they support version the same local_supported_signer_protocol_version, so update it here...
282281
tx_replay_set: ReplayTransactionSet::none(),
283-
update_time: UpdateTime::now(),
282+
update_time: SystemTime::now(),
284283
};
285284

286285
global_eval.insert_update(local_address, new_update);
@@ -321,7 +320,7 @@ fn determine_global_states_with_tx_replay_set() {
321320
current_miner: (&current_miner).into(),
322321
active_signer_protocol_version, // a majority of signers are saying they support version the same local_supported_signer_protocol_version, so update it here...
323322
tx_replay_set: ReplayTransactionSet::none(),
324-
update_time: UpdateTime::now(),
323+
update_time: SystemTime::now(),
325324
};
326325

327326
let burn_block = ConsensusHash([20u8; 20]);
@@ -359,7 +358,7 @@ fn determine_global_states_with_tx_replay_set() {
359358
current_miner: (&current_miner).into(),
360359
active_signer_protocol_version: local_supported_signer_protocol_version, // a majority of signers are saying they support version the same local_supported_signer_protocol_version, so update it here...
361360
tx_replay_set: ReplayTransactionSet::none(),
362-
update_time: UpdateTime::now(),
361+
update_time: SystemTime::now(),
363362
};
364363

365364
// Let's tip the scales over to the correct burn view
@@ -416,7 +415,7 @@ fn determine_global_states_with_tx_replay_set() {
416415
current_miner: (&current_miner).into(),
417416
active_signer_protocol_version,
418417
tx_replay_set: ReplayTransactionSet::new(vec![tx]),
419-
update_time: UpdateTime::now(),
418+
update_time: SystemTime::now(),
420419
};
421420

422421
assert_eq!(

libsigner/src/v0/signer_state.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl GlobalStateEvaluator {
120120
active_signer_protocol_version,
121121
// We need to calculate the threshold for the tx_replay_set separately
122122
tx_replay_set: ReplayTransactionSet::none(),
123-
update_time: UpdateTime::now(),
123+
update_time: SystemTime::now(),
124124
};
125125
let key = SignerStateMachineKey(state_machine.clone());
126126
let entry = state_views.entry(key).or_insert_with(|| 0);
@@ -240,7 +240,7 @@ impl Default for ReplayTransactionSet {
240240
/// A signer state machine view. This struct can
241241
/// be used to encode the local signer's view or
242242
/// the global view.
243-
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Eq, Hash)]
243+
#[derive(Debug, Clone, Serialize, Deserialize)]
244244
pub struct SignerStateMachine {
245245
/// The tip burn block (i.e., the latest bitcoin block) seen by this signer
246246
pub burn_block: ConsensusHash,
@@ -253,30 +253,30 @@ pub struct SignerStateMachine {
253253
/// Transaction replay set
254254
pub tx_replay_set: ReplayTransactionSet,
255255
/// The time when this state machine was last updated
256-
pub update_time: UpdateTime,
256+
pub update_time: SystemTime,
257257
}
258258

259-
/// A wrapped SystemTime to enforce equality regardless of the value
260-
#[derive(Debug, Clone, Serialize, Deserialize)]
261-
pub struct UpdateTime(pub SystemTime);
262-
263-
impl UpdateTime {
264-
/// Creates a new UpdateTime with SystemTime::now()
265-
pub fn now() -> Self {
266-
UpdateTime(SystemTime::now())
267-
}
268-
}
269-
270-
impl PartialEq for UpdateTime {
271-
fn eq(&self, _: &Self) -> bool {
272-
true
259+
impl PartialEq for SignerStateMachine {
260+
fn eq(&self, other: &Self) -> bool {
261+
// update_time is intentionally ignored
262+
self.burn_block == other.burn_block
263+
&& self.burn_block_height == other.burn_block_height
264+
&& self.current_miner == other.current_miner
265+
&& self.tx_replay_set == other.tx_replay_set
273266
}
274267
}
275268

276-
impl Eq for UpdateTime {}
269+
impl Eq for SignerStateMachine {}
277270

278-
impl Hash for UpdateTime {
279-
fn hash<H: Hasher>(&self, _: &mut H) {}
271+
impl Hash for SignerStateMachine {
272+
fn hash<H: Hasher>(&self, state: &mut H) {
273+
// update_time is intentionally ignored
274+
self.burn_block.hash(state);
275+
self.burn_block_height.hash(state);
276+
self.current_miner.hash(state);
277+
self.active_signer_protocol_version.hash(state);
278+
self.tx_replay_set.hash(state);
279+
}
280280
}
281281

282282
#[derive(Debug)]
@@ -291,7 +291,6 @@ impl PartialEq for SignerStateMachineKey {
291291
&& self.0.burn_block_height == other.0.burn_block_height
292292
&& self.0.current_miner == other.0.current_miner
293293
&& self.0.active_signer_protocol_version == other.0.active_signer_protocol_version
294-
&& self.0.update_time == other.0.update_time // This doesn't actually do anything. But include for completeness sake.
295294
}
296295
}
297296

stacks-signer/src/chainstate/tests/v2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use clarity::types::chainstate::{BurnchainHeaderHash, SortitionId, StacksAddress
3030
use clarity::types::PrivateKey;
3131
use libsigner::v0::messages::RejectReason;
3232
use libsigner::v0::signer_state::{
33-
GlobalStateEvaluator, MinerState, ReplayTransactionSet, SignerStateMachine, UpdateTime,
33+
GlobalStateEvaluator, MinerState, ReplayTransactionSet, SignerStateMachine,
3434
};
3535
use libsigner::{BlockProposal, BlockProposalData};
3636
use stacks_common::bitvec::BitVec;
@@ -142,7 +142,7 @@ fn setup_test_environment(
142142
},
143143
active_signer_protocol_version: 0,
144144
tx_replay_set: ReplayTransactionSet::none(),
145-
update_time: UpdateTime::now(),
145+
update_time: SystemTime::now(),
146146
};
147147

148148
let sortitions_view = GlobalStateView {

stacks-signer/src/tests/signer_state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use libsigner::v0::messages::{
3232
StateMachineUpdateMinerState,
3333
};
3434
use libsigner::v0::signer_state::{
35-
GlobalStateEvaluator, MinerState, ReplayTransactionSet, SignerStateMachine, UpdateTime,
35+
GlobalStateEvaluator, MinerState, ReplayTransactionSet, SignerStateMachine,
3636
};
3737
use stacks_common::bitvec::BitVec;
3838
use stacks_common::function_name;
@@ -181,7 +181,7 @@ fn check_capitulate_miner_view() {
181181
current_miner: (&new_miner).into(),
182182
tx_replay_set: ReplayTransactionSet::none(),
183183
active_signer_protocol_version,
184-
update_time: UpdateTime::now(),
184+
update_time: SystemTime::now(),
185185
};
186186

187187
let mut local_state_machine = LocalStateMachine::Initialized(signer_state_machine.clone());
@@ -392,7 +392,7 @@ fn check_miner_inactivity_timeout() {
392392
current_miner: inactive_miner,
393393
active_signer_protocol_version: 0,
394394
tx_replay_set: ReplayTransactionSet::none(),
395-
update_time: UpdateTime::now(),
395+
update_time: SystemTime::now(),
396396
};
397397
local_state_machine = LocalStateMachine::Initialized(signer_state.clone());
398398
local_state_machine

stacks-signer/src/v0/signer_state.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use libsigner::v0::messages::{
2828
StateMachineUpdateContent, StateMachineUpdateMinerState,
2929
};
3030
use libsigner::v0::signer_state::{
31-
GlobalStateEvaluator, MinerState, ReplayTransactionSet, SignerStateMachine, UpdateTime,
31+
GlobalStateEvaluator, MinerState, ReplayTransactionSet, SignerStateMachine,
3232
};
3333
use serde::{Deserialize, Serialize};
3434
use stacks_common::codec::Error as CodecError;
@@ -223,7 +223,7 @@ impl LocalStateMachine {
223223
current_miner: MinerState::NoValidMiner,
224224
active_signer_protocol_version: version,
225225
tx_replay_set: ReplayTransactionSet::none(),
226-
update_time: UpdateTime::now(),
226+
update_time: SystemTime::now(),
227227
}
228228
}
229229

@@ -241,7 +241,7 @@ impl LocalStateMachine {
241241
pub fn get_update_time(&self) -> Option<SystemTime> {
242242
match self {
243243
LocalStateMachine::Initialized(update)
244-
| LocalStateMachine::Pending { prior: update, .. } => Some(update.update_time.0),
244+
| LocalStateMachine::Pending { prior: update, .. } => Some(update.update_time),
245245
LocalStateMachine::Uninitialized => None,
246246
}
247247
}
@@ -359,7 +359,7 @@ impl LocalStateMachine {
359359
db,
360360
proposal_config.tenure_last_block_proposal_timeout,
361361
)?;
362-
state_machine.update_time = UpdateTime::now();
362+
state_machine.update_time = SystemTime::now();
363363
info!(
364364
"Signer State: Current tenure timed out, setting the active miner to the prior tenure";
365365
"inactive_tenure_ch" => %inactive_tenure_ch,
@@ -497,15 +497,15 @@ impl LocalStateMachine {
497497
"signer_signature_hash" => %signer_signature_hash,
498498
);
499499
prior_state_machine.tx_replay_set = ReplayTransactionSet::none();
500-
prior_state_machine.update_time = UpdateTime::now();
500+
prior_state_machine.update_time = SystemTime::now();
501501
}
502502
}
503503
Ok(None) => {
504504
info!("Signer State: got a new block during replay that wasn't validated by our replay set. Clearing the local replay set.";
505505
"txs" => ?txs,
506506
);
507507
prior_state_machine.tx_replay_set = ReplayTransactionSet::none();
508-
prior_state_machine.update_time = UpdateTime::now()
508+
prior_state_machine.update_time = SystemTime::now()
509509
}
510510
Err(e) => {
511511
warn!("Signer State: Failed to check if block was validated by replay tx";
@@ -549,7 +549,7 @@ impl LocalStateMachine {
549549

550550
*parent_tenure_last_block = *block_id;
551551
*parent_tenure_last_block_height = height;
552-
prior_state_machine.update_time = UpdateTime::now();
552+
prior_state_machine.update_time = SystemTime::now();
553553
*self = LocalStateMachine::Initialized(prior_state_machine);
554554

555555
crate::monitoring::actions::increment_signer_agreement_state_change_reason(
@@ -709,7 +709,7 @@ impl LocalStateMachine {
709709
current_miner: miner_state,
710710
active_signer_protocol_version: prior_state_machine.active_signer_protocol_version,
711711
tx_replay_set,
712-
update_time: UpdateTime::now(),
712+
update_time: SystemTime::now(),
713713
});
714714

715715
if prior_state != *self {
@@ -769,7 +769,7 @@ impl LocalStateMachine {
769769
current_miner: current_miner.into(),
770770
active_signer_protocol_version,
771771
tx_replay_set,
772-
update_time: UpdateTime::now(),
772+
update_time: SystemTime::now(),
773773
});
774774
// Because we updated our active signer protocol version, update local_update so its included in the subsequent evaluations
775775
let Ok(update) =
@@ -819,7 +819,7 @@ impl LocalStateMachine {
819819
current_miner: (&new_miner).into(),
820820
active_signer_protocol_version,
821821
tx_replay_set,
822-
update_time: UpdateTime::now(),
822+
update_time: SystemTime::now(),
823823
});
824824

825825
match new_miner {

testnet/stacks-node/src/tests/signer/multiversion.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1515
use std::sync::mpsc::TryRecvError;
1616
use std::thread;
17-
use std::time::Duration;
17+
use std::time::{Duration, SystemTime};
1818

1919
use libsigner::v0::messages::{SignerMessage, StateMachineUpdate};
20-
use libsigner::v0::signer_state::{
21-
MinerState, ReplayTransactionSet, SignerStateMachine, UpdateTime,
22-
};
20+
use libsigner::v0::signer_state::{MinerState, ReplayTransactionSet, SignerStateMachine};
2321
use stacks::chainstate::stacks::StacksTransaction;
2422
use stacks::util::hash::Hash160;
2523
use stacks::util::secp256k1::Secp256k1PrivateKey;
@@ -106,7 +104,7 @@ pub fn signer_state_machine_v3_1_00_13_to_current(
106104
.map(stacks_transaction_v3_1_00_13_to_current)
107105
.collect(),
108106
),
109-
update_time: UpdateTime::now(),
107+
update_time: SystemTime::now(),
110108
}
111109
}
112110

0 commit comments

Comments
 (0)