1use std::{
10 fmt::Debug,
11 hash::Hash,
12 marker::PhantomData,
13 ops::{Deref, DerefMut},
14};
15
16use alloy_primitives::FixedBytes;
17use committable::{Commitment, Committable};
18use hotshot_utils::anytrace::*;
19use jf_utils::canonical;
20use serde::{Deserialize, Serialize};
21use vbs::version::Version;
22
23use crate::{
24 data::{EpochNumber, Leaf, Leaf2, VidCommitment, ViewNumber},
25 light_client::{CircuitField, LightClientState, StakeTableState},
26 message::UpgradeLock,
27 traits::{
28 node_implementation::NodeType,
29 signature_key::{SignatureKey, StateSignatureKey},
30 },
31 vote::{HasViewNumber, Vote},
32};
33
34pub trait QuorumMarker {}
36
37#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
39#[serde(bound(deserialize = ""))]
40pub struct QuorumData<TYPES: NodeType> {
41 pub leaf_commit: Commitment<Leaf<TYPES>>,
43}
44
45#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Hash, Eq)]
47#[serde(bound(deserialize = ""))]
48pub struct QuorumData2<TYPES: NodeType> {
49 pub leaf_commit: Commitment<Leaf2<TYPES>>,
51 pub epoch: Option<EpochNumber>,
53 pub block_number: Option<u64>,
55}
56
57#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
59#[serde(bound(deserialize = ""))]
60pub struct NextEpochQuorumData2<TYPES: NodeType>(QuorumData2<TYPES>);
61
62#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
64pub struct DaData {
65 pub payload_commit: VidCommitment,
67}
68
69#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
71pub struct DaData2 {
72 pub payload_commit: VidCommitment,
74 pub next_epoch_payload_commit: Option<VidCommitment>,
76 pub epoch: Option<EpochNumber>,
78}
79
80#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
82pub struct TimeoutData {
83 pub view: ViewNumber,
85}
86
87#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
89pub struct TimeoutData2 {
90 pub view: ViewNumber,
92 pub epoch: Option<EpochNumber>,
94}
95
96#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
98pub struct ViewSyncPreCommitData {
99 pub relay: u64,
101 pub round: ViewNumber,
103}
104
105#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
107pub struct ViewSyncPreCommitData2 {
108 pub relay: u64,
110 pub round: ViewNumber,
112 pub epoch: Option<EpochNumber>,
114}
115
116#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
118pub struct ViewSyncCommitData {
119 pub relay: u64,
121 pub round: ViewNumber,
123}
124
125#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
127pub struct ViewSyncCommitData2 {
128 pub relay: u64,
130 pub round: ViewNumber,
132 pub epoch: Option<EpochNumber>,
134}
135
136#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
138pub struct ViewSyncFinalizeData {
139 pub relay: u64,
141 pub round: ViewNumber,
143}
144
145#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
147pub struct ViewSyncFinalizeData2 {
148 pub relay: u64,
150 pub round: ViewNumber,
152 pub epoch: Option<EpochNumber>,
154}
155
156#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
158pub struct UpgradeProposalData {
159 pub old_version: Version,
161 pub new_version: Version,
163 pub decide_by: ViewNumber,
166 #[serde(with = "serde_bytes")]
168 pub new_version_hash: Vec<u8>,
169 pub old_version_last_view: ViewNumber,
171 pub new_version_first_view: ViewNumber,
173}
174
175pub struct UpgradeData2 {
177 pub old_version: Version,
179 pub new_version: Version,
181 pub hash: Vec<u8>,
183 pub epoch: Option<EpochNumber>,
185}
186
187#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
189#[serde(bound(deserialize = ""))]
190pub struct Vote2Data<T: NodeType> {
191 pub leaf_commit: Commitment<Leaf2<T>>,
192 pub epoch: EpochNumber,
193 pub block_number: u64,
194}
195
196impl<T: NodeType> QuorumMarker for Vote2Data<T> {}
197
198impl<T: NodeType> HasEpoch for Vote2Data<T> {
199 fn epoch(&self) -> Option<EpochNumber> {
200 Some(self.epoch)
201 }
202}
203
204impl<T: NodeType> Committable for Vote2Data<T> {
205 fn commit(&self) -> Commitment<Self> {
206 committable::RawCommitmentBuilder::new("Vote2Data")
207 .var_size_bytes(self.leaf_commit.as_ref())
208 .u64(*self.epoch)
209 .u64(self.block_number)
210 .constant_str("Vote2")
211 .finalize()
212 }
213}
214
215pub trait Voteable<TYPES: NodeType>:
219 sealed::Sealed + Committable + Clone + Serialize + Debug + PartialEq + Hash + Eq
220{
221}
222
223pub trait Voteable2<TYPES: NodeType>:
227 sealed::Sealed + HasEpoch + Committable + Clone + Serialize + Debug + PartialEq + Hash + Eq
228{
229}
230
231mod sealed {
235 use committable::Committable;
236
237 pub trait Sealed {}
239
240 impl<C: Committable> Sealed for C {}
242}
243
244impl<T: NodeType> QuorumMarker for QuorumData<T> {}
245impl<T: NodeType> QuorumMarker for QuorumData2<T> {}
246impl<T: NodeType> QuorumMarker for NextEpochQuorumData2<T> {}
247impl QuorumMarker for TimeoutData {}
248impl QuorumMarker for TimeoutData2 {}
249impl QuorumMarker for ViewSyncPreCommitData {}
250impl QuorumMarker for ViewSyncCommitData {}
251impl QuorumMarker for ViewSyncFinalizeData {}
252impl QuorumMarker for ViewSyncPreCommitData2 {}
253impl QuorumMarker for ViewSyncCommitData2 {}
254impl QuorumMarker for ViewSyncFinalizeData2 {}
255impl QuorumMarker for UpgradeProposalData {}
256
257#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
259pub struct SimpleVote<TYPES: NodeType, DATA: Voteable<TYPES>> {
260 pub signature: (
262 TYPES::SignatureKey,
263 <TYPES::SignatureKey as SignatureKey>::PureAssembledSignatureType,
264 ),
265 pub data: DATA,
267 pub view_number: ViewNumber,
269}
270
271impl<TYPES: NodeType, DATA: Voteable<TYPES> + 'static> HasViewNumber for SimpleVote<TYPES, DATA> {
272 fn view_number(&self) -> ViewNumber {
273 self.view_number
274 }
275}
276
277impl<TYPES: NodeType, DATA: Voteable<TYPES> + 'static> Vote<TYPES> for SimpleVote<TYPES, DATA> {
278 type Commitment = DATA;
279
280 fn signing_key(&self) -> <TYPES as NodeType>::SignatureKey {
281 self.signature.0.clone()
282 }
283
284 fn signature(&self) -> <TYPES::SignatureKey as SignatureKey>::PureAssembledSignatureType {
285 self.signature.1.clone()
286 }
287
288 fn date(&self) -> &DATA {
289 &self.data
290 }
291
292 fn data_commitment(&self) -> Commitment<DATA> {
293 self.data.commit()
294 }
295}
296
297impl<TYPES: NodeType, DATA: Voteable<TYPES> + 'static> SimpleVote<TYPES, DATA> {
298 pub fn create_signed_vote(
302 data: DATA,
303 view: ViewNumber,
304 pub_key: &TYPES::SignatureKey,
305 private_key: &<TYPES::SignatureKey as SignatureKey>::PrivateKey,
306 upgrade_lock: &UpgradeLock<TYPES>,
307 ) -> Result<Self> {
308 let commit = VersionedVoteData::new(data.clone(), view, upgrade_lock)?.commit();
309
310 let signature = (
311 pub_key.clone(),
312 TYPES::SignatureKey::sign(private_key, commit.as_ref())
313 .wrap()
314 .context(error!("Failed to sign vote"))?,
315 );
316
317 Ok(Self {
318 signature,
319 data,
320 view_number: view,
321 })
322 }
323}
324
325#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Hash, Eq)]
326pub struct VersionedVoteData<TYPES: NodeType, DATA: Voteable<TYPES>> {
328 data: DATA,
330
331 view: ViewNumber,
333
334 version: Version,
336
337 _pd: PhantomData<TYPES>,
339}
340
341impl<TYPES: NodeType, DATA: Voteable<TYPES>> VersionedVoteData<TYPES, DATA> {
342 pub fn new(data: DATA, view: ViewNumber, upgrade_lock: &UpgradeLock<TYPES>) -> Result<Self> {
348 let version = upgrade_lock.version(view)?;
349
350 Ok(Self {
351 data,
352 view,
353 version,
354 _pd: PhantomData,
355 })
356 }
357
358 pub fn new_infallible(data: DATA, view: ViewNumber, upgrade_lock: &UpgradeLock<TYPES>) -> Self {
362 let version = upgrade_lock.version_infallible(view);
363
364 Self {
365 data,
366 view,
367 version,
368 _pd: PhantomData,
369 }
370 }
371}
372
373impl<TYPES: NodeType, DATA: Voteable<TYPES>> Committable for VersionedVoteData<TYPES, DATA> {
374 fn commit(&self) -> Commitment<Self> {
375 committable::RawCommitmentBuilder::new("Vote")
376 .var_size_bytes(self.data.commit().as_ref())
377 .u64(*self.view)
378 .finalize()
379 }
380}
381
382impl<TYPES: NodeType> Committable for QuorumData<TYPES> {
383 fn commit(&self) -> Commitment<Self> {
384 committable::RawCommitmentBuilder::new("Quorum data")
385 .var_size_bytes(self.leaf_commit.as_ref())
386 .finalize()
387 }
388}
389
390impl<TYPES: NodeType> Committable for QuorumData2<TYPES> {
391 fn commit(&self) -> Commitment<Self> {
392 let QuorumData2 {
393 leaf_commit,
394 epoch,
395 block_number,
396 } = self;
397
398 let mut cb = committable::RawCommitmentBuilder::new("Quorum data")
399 .var_size_bytes(leaf_commit.as_ref());
400
401 if let Some(ref epoch) = *epoch {
402 cb = cb.u64_field("epoch number", **epoch);
403 }
404
405 if let Some(ref block_number) = *block_number {
406 cb = cb.u64_field("block number", *block_number);
407 }
408
409 cb.finalize()
410 }
411}
412
413impl<TYPES: NodeType> Committable for NextEpochQuorumData2<TYPES> {
414 fn commit(&self) -> Commitment<Self> {
415 let NextEpochQuorumData2(QuorumData2 {
416 leaf_commit,
417 epoch,
418 block_number,
419 }) = self;
420
421 let mut cb = committable::RawCommitmentBuilder::new("Quorum data")
422 .var_size_bytes(leaf_commit.as_ref());
423
424 if let Some(ref epoch) = *epoch {
425 cb = cb.u64_field("epoch number", **epoch);
426 }
427
428 if let Some(ref block_number) = *block_number {
429 cb = cb.u64_field("block number", *block_number);
430 }
431
432 cb.finalize()
433 }
434}
435
436impl Committable for TimeoutData {
437 fn commit(&self) -> Commitment<Self> {
438 committable::RawCommitmentBuilder::new("Timeout data")
439 .u64(*self.view)
440 .finalize()
441 }
442}
443
444impl Committable for TimeoutData2 {
445 fn commit(&self) -> Commitment<Self> {
446 let TimeoutData2 { view, epoch: _ } = self;
447
448 committable::RawCommitmentBuilder::new("Timeout data")
449 .u64(**view)
450 .finalize()
451 }
452}
453
454impl Committable for DaData {
455 fn commit(&self) -> Commitment<Self> {
456 committable::RawCommitmentBuilder::new("DA data")
457 .var_size_bytes(self.payload_commit.as_ref())
458 .finalize()
459 }
460}
461
462impl Committable for DaData2 {
463 fn commit(&self) -> Commitment<Self> {
464 let DaData2 {
465 payload_commit,
466 next_epoch_payload_commit,
467 epoch,
468 } = self;
469
470 let mut cb = committable::RawCommitmentBuilder::new("DA data")
471 .var_size_bytes(payload_commit.as_ref());
472
473 if let Some(ref next_epoch_payload_commit) = *next_epoch_payload_commit {
474 cb = cb.var_size_bytes(next_epoch_payload_commit.as_ref());
475 }
476
477 if let Some(ref epoch) = *epoch {
478 cb = cb.u64_field("epoch number", **epoch);
479 }
480
481 cb.finalize()
482 }
483}
484
485impl Committable for UpgradeProposalData {
486 fn commit(&self) -> Commitment<Self> {
487 let builder = committable::RawCommitmentBuilder::new("Upgrade data");
488 builder
489 .u64(*self.decide_by)
490 .u64(*self.new_version_first_view)
491 .u64(*self.old_version_last_view)
492 .var_size_bytes(self.new_version_hash.as_slice())
493 .u16(self.new_version.minor)
494 .u16(self.new_version.major)
495 .u16(self.old_version.minor)
496 .u16(self.old_version.major)
497 .finalize()
498 }
499}
500
501impl Committable for UpgradeData2 {
502 fn commit(&self) -> Commitment<Self> {
503 let UpgradeData2 {
504 old_version,
505 new_version,
506 hash,
507 epoch,
508 } = self;
509
510 let mut cb = committable::RawCommitmentBuilder::new("Upgrade data")
511 .u16(old_version.minor)
512 .u16(old_version.major)
513 .u16(new_version.minor)
514 .u16(new_version.major)
515 .var_size_bytes(hash.as_slice());
516
517 if let Some(ref epoch) = *epoch {
518 cb = cb.u64_field("epoch number", **epoch);
519 }
520
521 cb.finalize()
522 }
523}
524
525fn view_and_relay_commit<T: Committable>(
527 view: ViewNumber,
528 relay: u64,
529 epoch: Option<EpochNumber>,
530 tag: &str,
531) -> Commitment<T> {
532 let builder = committable::RawCommitmentBuilder::new(tag);
533 let mut cb = builder.u64(*view).u64(relay);
534
535 if let Some(epoch) = epoch {
536 cb = cb.u64_field("epoch number", *epoch);
537 }
538
539 cb.finalize()
540}
541
542impl Committable for ViewSyncPreCommitData {
543 fn commit(&self) -> Commitment<Self> {
544 view_and_relay_commit(self.round, self.relay, None, "View Sync Precommit")
545 }
546}
547
548impl Committable for ViewSyncPreCommitData2 {
549 fn commit(&self) -> Commitment<Self> {
550 let ViewSyncPreCommitData2 {
551 relay,
552 round,
553 epoch,
554 } = self;
555
556 view_and_relay_commit(*round, *relay, *epoch, "View Sync Precommit")
557 }
558}
559
560impl Committable for ViewSyncFinalizeData {
561 fn commit(&self) -> Commitment<Self> {
562 view_and_relay_commit(self.round, self.relay, None, "View Sync Finalize")
563 }
564}
565
566impl Committable for ViewSyncFinalizeData2 {
567 fn commit(&self) -> Commitment<Self> {
568 let ViewSyncFinalizeData2 {
569 relay,
570 round,
571 epoch,
572 } = self;
573
574 view_and_relay_commit(*round, *relay, *epoch, "View Sync Finalize")
575 }
576}
577
578impl Committable for ViewSyncCommitData {
579 fn commit(&self) -> Commitment<Self> {
580 view_and_relay_commit(self.round, self.relay, None, "View Sync Commit")
581 }
582}
583
584impl Committable for ViewSyncCommitData2 {
585 fn commit(&self) -> Commitment<Self> {
586 let ViewSyncCommitData2 {
587 relay,
588 round,
589 epoch,
590 } = self;
591
592 view_and_relay_commit(*round, *relay, *epoch, "View Sync Commit")
593 }
594}
595
596pub trait HasEpoch {
598 fn epoch(&self) -> Option<EpochNumber>;
600}
601
602#[macro_export]
604macro_rules! impl_has_epoch {
605 ($($t:ty),*) => {
606 $(
607 impl HasEpoch for $t {
608 fn epoch(&self) -> Option<EpochNumber> {
609 self.epoch
610 }
611 }
612 )*
613 };
614}
615
616impl<NODE: NodeType> HasEpoch for QuorumData2<NODE> {
617 fn epoch(&self) -> Option<EpochNumber> {
618 self.epoch
619 }
620}
621
622impl<NODE: NodeType> HasEpoch for NextEpochQuorumData2<NODE> {
623 fn epoch(&self) -> Option<EpochNumber> {
624 self.0.epoch
625 }
626}
627
628impl_has_epoch!(
629 DaData2,
630 TimeoutData2,
631 ViewSyncPreCommitData2,
632 ViewSyncCommitData2,
633 ViewSyncFinalizeData2,
634 UpgradeData2
635);
636
637#[macro_export]
639macro_rules! impl_has_none_epoch {
640 ($($t:ty),*) => {
641 $(
642 impl HasEpoch for $t {
643 fn epoch(&self) -> Option<EpochNumber> {
644 None
645 }
646 }
647 )*
648 };
649}
650
651impl<NODE: NodeType> HasEpoch for QuorumData<NODE> {
652 fn epoch(&self) -> Option<EpochNumber> {
653 None
654 }
655}
656
657impl_has_none_epoch!(
658 DaData,
659 TimeoutData,
660 ViewSyncPreCommitData,
661 ViewSyncCommitData,
662 ViewSyncFinalizeData,
663 UpgradeProposalData
664);
665
666impl<TYPES: NodeType, DATA: Voteable<TYPES> + HasEpoch> HasEpoch for SimpleVote<TYPES, DATA> {
667 fn epoch(&self) -> Option<EpochNumber> {
668 self.data.epoch()
669 }
670}
671
672impl<
675 TYPES: NodeType,
676 V: sealed::Sealed + Committable + Clone + Serialize + Debug + PartialEq + Hash + Eq,
677> Voteable<TYPES> for V
678{
679}
680
681impl<
684 TYPES: NodeType,
685 V: sealed::Sealed + HasEpoch + Committable + Clone + Serialize + Debug + PartialEq + Hash + Eq,
686> Voteable2<TYPES> for V
687{
688}
689
690impl<TYPES: NodeType> QuorumVote<TYPES> {
691 pub fn to_vote2(self) -> QuorumVote2<TYPES> {
693 let bytes: [u8; 32] = self.data.leaf_commit.into();
694
695 let signature = self.signature;
696 let data = QuorumData2 {
697 leaf_commit: Commitment::from_raw(bytes),
698 epoch: None,
699 block_number: None,
700 };
701 let view_number = self.view_number;
702
703 SimpleVote {
704 signature,
705 data,
706 view_number,
707 }
708 }
709}
710
711impl<TYPES: NodeType> QuorumVote2<TYPES> {
712 pub fn to_vote(self) -> QuorumVote<TYPES> {
714 let bytes: [u8; 32] = self.data.leaf_commit.into();
715
716 let signature = self.signature.clone();
717 let data = QuorumData {
718 leaf_commit: Commitment::from_raw(bytes),
719 };
720 let view_number = self.view_number;
721
722 SimpleVote {
723 signature,
724 data,
725 view_number,
726 }
727 }
728}
729
730impl<TYPES: NodeType> DaVote<TYPES> {
731 pub fn to_vote2(self) -> DaVote2<TYPES> {
733 let signature = self.signature;
734 let data = DaData2 {
735 payload_commit: self.data.payload_commit,
736 next_epoch_payload_commit: None,
737 epoch: None,
738 };
739 let view_number = self.view_number;
740
741 SimpleVote {
742 signature,
743 data,
744 view_number,
745 }
746 }
747}
748
749impl<TYPES: NodeType> DaVote2<TYPES> {
750 pub fn to_vote(self) -> DaVote<TYPES> {
752 let signature = self.signature;
753 let data = DaData {
754 payload_commit: self.data.payload_commit,
755 };
756 let view_number = self.view_number;
757
758 SimpleVote {
759 signature,
760 data,
761 view_number,
762 }
763 }
764}
765
766impl<TYPES: NodeType> TimeoutVote<TYPES> {
767 pub fn to_vote2(self) -> TimeoutVote2<TYPES> {
769 let signature = self.signature;
770 let data = TimeoutData2 {
771 view: self.data.view,
772 epoch: None,
773 };
774 let view_number = self.view_number;
775
776 SimpleVote {
777 signature,
778 data,
779 view_number,
780 }
781 }
782}
783
784impl<TYPES: NodeType> TimeoutVote2<TYPES> {
785 pub fn to_vote(self) -> TimeoutVote<TYPES> {
787 let signature = self.signature;
788 let data = TimeoutData {
789 view: self.data.view,
790 };
791 let view_number = self.view_number;
792
793 SimpleVote {
794 signature,
795 data,
796 view_number,
797 }
798 }
799}
800
801impl<TYPES: NodeType> ViewSyncPreCommitVote<TYPES> {
802 pub fn to_vote2(self) -> ViewSyncPreCommitVote2<TYPES> {
804 let signature = self.signature;
805 let data = ViewSyncPreCommitData2 {
806 relay: self.data.relay,
807 round: self.data.round,
808 epoch: None,
809 };
810 let view_number = self.view_number;
811
812 SimpleVote {
813 signature,
814 data,
815 view_number,
816 }
817 }
818}
819
820impl<TYPES: NodeType> ViewSyncPreCommitVote2<TYPES> {
821 pub fn to_vote(self) -> ViewSyncPreCommitVote<TYPES> {
823 let signature = self.signature;
824 let data = ViewSyncPreCommitData {
825 relay: self.data.relay,
826 round: self.data.round,
827 };
828 let view_number = self.view_number;
829
830 SimpleVote {
831 signature,
832 data,
833 view_number,
834 }
835 }
836}
837
838impl<TYPES: NodeType> ViewSyncCommitVote<TYPES> {
839 pub fn to_vote2(self) -> ViewSyncCommitVote2<TYPES> {
841 let signature = self.signature;
842 let data = ViewSyncCommitData2 {
843 relay: self.data.relay,
844 round: self.data.round,
845 epoch: None,
846 };
847 let view_number = self.view_number;
848
849 SimpleVote {
850 signature,
851 data,
852 view_number,
853 }
854 }
855}
856
857impl<TYPES: NodeType> ViewSyncCommitVote2<TYPES> {
858 pub fn to_vote(self) -> ViewSyncCommitVote<TYPES> {
860 let signature = self.signature;
861 let data = ViewSyncCommitData {
862 relay: self.data.relay,
863 round: self.data.round,
864 };
865 let view_number = self.view_number;
866
867 SimpleVote {
868 signature,
869 data,
870 view_number,
871 }
872 }
873}
874
875impl<TYPES: NodeType> ViewSyncFinalizeVote<TYPES> {
876 pub fn to_vote2(self) -> ViewSyncFinalizeVote2<TYPES> {
878 let signature = self.signature;
879 let data = ViewSyncFinalizeData2 {
880 relay: self.data.relay,
881 round: self.data.round,
882 epoch: None,
883 };
884 let view_number = self.view_number;
885
886 SimpleVote {
887 signature,
888 data,
889 view_number,
890 }
891 }
892}
893
894impl<TYPES: NodeType> ViewSyncFinalizeVote2<TYPES> {
895 pub fn to_vote(self) -> ViewSyncFinalizeVote<TYPES> {
897 let signature = self.signature;
898 let data = ViewSyncFinalizeData {
899 relay: self.data.relay,
900 round: self.data.round,
901 };
902 let view_number = self.view_number;
903
904 SimpleVote {
905 signature,
906 data,
907 view_number,
908 }
909 }
910}
911
912pub type QuorumVote<TYPES> = SimpleVote<TYPES, QuorumData<TYPES>>;
916pub type QuorumVote2<TYPES> = SimpleVote<TYPES, QuorumData2<TYPES>>;
919pub type NextEpochQuorumVote2<TYPES> = SimpleVote<TYPES, NextEpochQuorumData2<TYPES>>;
921pub type DaVote<TYPES> = SimpleVote<TYPES, DaData>;
923pub type DaVote2<TYPES> = SimpleVote<TYPES, DaData2>;
925
926pub type TimeoutVote<TYPES> = SimpleVote<TYPES, TimeoutData>;
928pub type TimeoutVote2<TYPES> = SimpleVote<TYPES, TimeoutData2>;
930
931pub type ViewSyncPreCommitVote<TYPES> = SimpleVote<TYPES, ViewSyncPreCommitData>;
933pub type ViewSyncPreCommitVote2<TYPES> = SimpleVote<TYPES, ViewSyncPreCommitData2>;
935pub type ViewSyncFinalizeVote<TYPES> = SimpleVote<TYPES, ViewSyncFinalizeData>;
937pub type ViewSyncFinalizeVote2<TYPES> = SimpleVote<TYPES, ViewSyncFinalizeData2>;
939pub type ViewSyncCommitVote<TYPES> = SimpleVote<TYPES, ViewSyncCommitData>;
941pub type ViewSyncCommitVote2<TYPES> = SimpleVote<TYPES, ViewSyncCommitData2>;
943pub type UpgradeVote<TYPES> = SimpleVote<TYPES, UpgradeProposalData>;
945pub type UpgradeVote2<TYPES> = SimpleVote<TYPES, UpgradeData2>;
947
948impl<TYPES: NodeType> Deref for NextEpochQuorumData2<TYPES> {
949 type Target = QuorumData2<TYPES>;
950 fn deref(&self) -> &Self::Target {
951 &self.0
952 }
953}
954impl<TYPES: NodeType> DerefMut for NextEpochQuorumData2<TYPES> {
955 fn deref_mut(&mut self) -> &mut Self::Target {
956 &mut self.0
957 }
958}
959impl<TYPES: NodeType> From<QuorumData2<TYPES>> for NextEpochQuorumData2<TYPES> {
960 fn from(data: QuorumData2<TYPES>) -> Self {
961 Self(QuorumData2 {
962 epoch: data.epoch,
963 leaf_commit: data.leaf_commit,
964 block_number: data.block_number,
965 })
966 }
967}
968
969impl<TYPES: NodeType> From<QuorumVote2<TYPES>> for NextEpochQuorumVote2<TYPES> {
970 fn from(qvote: QuorumVote2<TYPES>) -> Self {
971 Self {
972 data: qvote.data.into(),
973 view_number: qvote.view_number,
974 signature: qvote.signature.clone(),
975 }
976 }
977}
978
979#[derive(Serialize, Deserialize, Eq, Hash, PartialEq, Debug, Clone)]
981pub struct LightClientStateUpdateVote<TYPES: NodeType> {
982 pub epoch: EpochNumber,
984 pub light_client_state: LightClientState,
986 pub next_stake_table_state: StakeTableState,
988 pub signature: <TYPES::StateSignatureKey as StateSignatureKey>::StateSignature,
990}
991
992#[derive(Serialize, Deserialize, Eq, Hash, PartialEq, Debug, Clone)]
994pub struct LightClientStateUpdateVote2<TYPES: NodeType> {
995 pub epoch: EpochNumber,
997 pub light_client_state: LightClientState,
999 pub next_stake_table_state: StakeTableState,
1001 pub signature: <TYPES::StateSignatureKey as StateSignatureKey>::StateSignature,
1003 pub v2_signature: <TYPES::StateSignatureKey as StateSignatureKey>::StateSignature,
1005 pub auth_root: FixedBytes<32>,
1007 #[serde(with = "canonical")]
1011 pub signed_state_digest: CircuitField,
1012}
1013
1014impl<TYPES: NodeType> LightClientStateUpdateVote<TYPES> {
1015 pub fn to_vote2(self) -> LightClientStateUpdateVote2<TYPES> {
1016 LightClientStateUpdateVote2 {
1017 epoch: self.epoch,
1018 light_client_state: self.light_client_state,
1019 next_stake_table_state: self.next_stake_table_state,
1020 signature: self.signature.clone(),
1021 v2_signature: self.signature,
1022 auth_root: Default::default(),
1023 signed_state_digest: Default::default(),
1024 }
1025 }
1026}
1027
1028impl<TYPES: NodeType> LightClientStateUpdateVote2<TYPES> {
1029 pub fn to_vote(self) -> LightClientStateUpdateVote<TYPES> {
1030 LightClientStateUpdateVote {
1031 epoch: self.epoch,
1032 light_client_state: self.light_client_state,
1033 next_stake_table_state: self.next_stake_table_state,
1034 signature: self.v2_signature,
1035 }
1036 }
1037}
1038
1039impl<TYPES: NodeType> HasViewNumber for LightClientStateUpdateVote<TYPES> {
1040 fn view_number(&self) -> ViewNumber {
1041 ViewNumber::new(self.light_client_state.view_number)
1042 }
1043}
1044
1045impl<TYPES: NodeType> HasEpoch for LightClientStateUpdateVote<TYPES> {
1046 fn epoch(&self) -> Option<EpochNumber> {
1047 Some(self.epoch)
1048 }
1049}
1050
1051#[derive(Serialize, Deserialize, Eq, Hash, PartialEq, Debug, Clone)]
1052#[serde(bound(deserialize = "QuorumVote2<TYPES>:for<'a> Deserialize<'a>"))]
1053pub struct EpochRootQuorumVote<TYPES: NodeType> {
1054 pub vote: QuorumVote2<TYPES>,
1055 pub state_vote: LightClientStateUpdateVote<TYPES>,
1056}
1057
1058#[derive(Serialize, Deserialize, Eq, Hash, PartialEq, Debug, Clone)]
1059#[serde(bound(deserialize = "QuorumVote2<TYPES>:for<'a> Deserialize<'a>"))]
1060pub struct EpochRootQuorumVote2<TYPES: NodeType> {
1061 pub vote: QuorumVote2<TYPES>,
1062 pub state_vote: LightClientStateUpdateVote2<TYPES>,
1063}
1064
1065impl<TYPES: NodeType> EpochRootQuorumVote<TYPES> {
1066 pub fn to_vote2(self) -> EpochRootQuorumVote2<TYPES> {
1067 EpochRootQuorumVote2 {
1068 vote: self.vote,
1069 state_vote: self.state_vote.to_vote2(),
1070 }
1071 }
1072}
1073
1074impl<TYPES: NodeType> EpochRootQuorumVote2<TYPES> {
1075 pub fn to_vote(self) -> EpochRootQuorumVote<TYPES> {
1076 EpochRootQuorumVote {
1077 vote: self.vote,
1078 state_vote: self.state_vote.to_vote(),
1079 }
1080 }
1081}
1082
1083impl<TYPES: NodeType> HasViewNumber for EpochRootQuorumVote<TYPES> {
1084 fn view_number(&self) -> ViewNumber {
1085 self.vote.view_number()
1086 }
1087}
1088
1089impl<TYPES: NodeType> HasEpoch for EpochRootQuorumVote<TYPES> {
1090 fn epoch(&self) -> Option<EpochNumber> {
1091 self.vote.epoch()
1092 }
1093}
1094
1095impl<TYPES: NodeType> HasViewNumber for EpochRootQuorumVote2<TYPES> {
1096 fn view_number(&self) -> ViewNumber {
1097 self.vote.view_number()
1098 }
1099}
1100
1101impl<TYPES: NodeType> HasEpoch for EpochRootQuorumVote2<TYPES> {
1102 fn epoch(&self) -> Option<EpochNumber> {
1103 self.vote.epoch()
1104 }
1105}