Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lr/variable stake table #3893

Merged
merged 51 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c3aa374
Initial commit
lukaszrzasik Nov 15, 2024
09ca3cb
WIP: adding epoch to proposal and vote data, not compiling yet
lukaszrzasik Nov 15, 2024
51cb073
Make it compile
lukaszrzasik Nov 18, 2024
69d9538
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Nov 18, 2024
7539714
Adjust tests
lukaszrzasik Nov 18, 2024
1bd8716
Add a test type for two stake tables for even and odd epochs
lukaszrzasik Nov 19, 2024
ce2fd93
Debugging
lukaszrzasik Nov 19, 2024
5c8604e
Fix extended voting
lukaszrzasik Nov 19, 2024
358ac8a
Merge branch 'lr/fix-extended-voting' into lr/variable-stake-table
lukaszrzasik Nov 19, 2024
7ac36b1
Try "in epoch transition" approach
lukaszrzasik Nov 19, 2024
77efd42
Continue debugging
lukaszrzasik Nov 20, 2024
a5b9729
Use correct epoch with Membership
lukaszrzasik Nov 20, 2024
50c6b79
Adjust tests and lints
lukaszrzasik Nov 20, 2024
e0d00ee
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Nov 21, 2024
606d509
Adapt to variable stake table after merge
lukaszrzasik Nov 21, 2024
4d5ae09
Fix accidentally pulled bug in eQC rule
lukaszrzasik Nov 21, 2024
504c3be
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Nov 21, 2024
dbf46db
Commit includes epoch for vote and proposal data types
lukaszrzasik Nov 21, 2024
4688aca
Prune dependencies (#3787)
QuentinI Nov 21, 2024
e7eee96
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Nov 21, 2024
4c3568b
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Nov 21, 2024
131168a
add new message types and gate outgoing messages
ss-es Nov 21, 2024
91d6033
Use the proper message for the proposal response
lukaszrzasik Nov 22, 2024
0446338
Modify commit for `Leaf2` and `QuorumData2`
lukaszrzasik Nov 25, 2024
0a598ac
Adjust tests
lukaszrzasik Nov 25, 2024
dd51a2a
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Nov 25, 2024
c0b94ba
Clean up debug traces
lukaszrzasik Nov 25, 2024
f658a36
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Nov 25, 2024
ebe4602
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Nov 26, 2024
25e98bb
Add TODO
lukaszrzasik Nov 26, 2024
e0767fc
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Nov 27, 2024
b67910f
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Dec 2, 2024
5740919
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Dec 2, 2024
6819a41
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Dec 3, 2024
285858d
Adjust marketplace ver number
lukaszrzasik Dec 3, 2024
128a7ae
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Dec 4, 2024
356a0e2
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Dec 5, 2024
627636b
Merge branch 'main' into lr/variable-stake-table
lukaszrzasik Dec 6, 2024
9a9cf07
Merge branch 'main' into lr/variable-stake-table
ss-es Dec 6, 2024
4a031bc
fix types
ss-es Dec 6, 2024
e42d1ea
fix viewsync, timeout and vid
ss-es Dec 9, 2024
4a841c3
fix upgrade and tests
ss-es Dec 9, 2024
57fd79b
Merge branch 'main' into lr/variable-stake-table
ss-es Dec 9, 2024
d8e291d
add VidDisperseMsg2 response
ss-es Dec 11, 2024
c201f29
remove extraneous check from quorum_proposal_recv
ss-es Dec 11, 2024
2c0d46f
simplify leaf commitment
ss-es Dec 11, 2024
2eb70ff
remove epoch from commitments
ss-es Dec 11, 2024
cf721b1
Merge branch 'main' into lr/variable-stake-table
ss-es Dec 11, 2024
751d7be
fix merge
ss-es Dec 11, 2024
4b492f8
revert transaction view change logic
ss-es Dec 11, 2024
8550559
impl HasEpoch for VidDisperse, VidDisperseShare2 and DaData2
ss-es Dec 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 69 additions & 21 deletions crates/example-types/src/node_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use hotshot::traits::{
randomized_committee_members::RandomizedCommitteeMembers,
static_committee::StaticCommittee,
static_committee_leader_two_views::StaticCommitteeLeaderForTwoViews,
two_static_committees::TwoStaticCommittees,
},
implementations::{CombinedNetworks, Libp2pNetwork, MemoryNetwork, PushCdnNetwork},
NodeImplementation,
Expand Down Expand Up @@ -51,6 +52,8 @@ use crate::{
/// to select our traits
pub struct TestTypes;
impl NodeType for TestTypes {
const EPOCH_HEIGHT: u64 = 10;

type AuctionResult = TestAuctionResult;
type View = ViewNumber;
type Epoch = EpochNumber;
Expand Down Expand Up @@ -81,6 +84,8 @@ impl NodeType for TestTypes {
/// to select our traits
pub struct TestTypesRandomizedLeader;
impl NodeType for TestTypesRandomizedLeader {
const EPOCH_HEIGHT: u64 = 10;

type AuctionResult = TestAuctionResult;
type View = ViewNumber;
type Epoch = EpochNumber;
Expand Down Expand Up @@ -114,6 +119,8 @@ pub struct TestTypesRandomizedCommitteeMembers<CONFIG: QuorumFilterConfig> {
}

impl<CONFIG: QuorumFilterConfig> NodeType for TestTypesRandomizedCommitteeMembers<CONFIG> {
const EPOCH_HEIGHT: u64 = 10;

type AuctionResult = TestAuctionResult;
type View = ViewNumber;
type Epoch = EpochNumber;
Expand Down Expand Up @@ -145,6 +152,8 @@ impl<CONFIG: QuorumFilterConfig> NodeType for TestTypesRandomizedCommitteeMember
/// to select our traits
pub struct TestConsecutiveLeaderTypes;
impl NodeType for TestConsecutiveLeaderTypes {
const EPOCH_HEIGHT: u64 = 10;

type AuctionResult = TestAuctionResult;
type View = ViewNumber;
type Epoch = EpochNumber;
Expand All @@ -158,6 +167,38 @@ impl NodeType for TestConsecutiveLeaderTypes {
type BuilderSignatureKey = BuilderKey;
}

#[derive(
Copy,
Clone,
Debug,
Default,
Hash,
PartialEq,
Eq,
PartialOrd,
Ord,
serde::Serialize,
serde::Deserialize,
)]
/// filler struct to implement node type and allow us
/// to select our traits
pub struct TestTwoStakeTablesTypes;
impl NodeType for TestTwoStakeTablesTypes {
const EPOCH_HEIGHT: u64 = 10;

type AuctionResult = TestAuctionResult;
type View = ViewNumber;
type Epoch = EpochNumber;
type BlockHeader = TestBlockHeader;
type BlockPayload = TestBlockPayload;
type SignatureKey = BLSPubKey;
type Transaction = TestTransaction;
type ValidatedState = TestValidatedState;
type InstanceState = TestInstanceState;
type Membership = TwoStaticCommittees<TestTwoStakeTablesTypes>;
type BuilderSignatureKey = BuilderKey;
}

/// The Push CDN implementation
#[derive(Clone, Debug, Deserialize, Serialize, Hash, Eq, PartialEq)]
pub struct PushCdnImpl;
Expand Down Expand Up @@ -264,7 +305,7 @@ impl Versions for EpochsTestVersions {
0, 0,
];

type Marketplace = StaticVersion<0, 99>;
type Marketplace = StaticVersion<0, 3>;

type Epochs = StaticVersion<0, 4>;
}
Expand All @@ -273,52 +314,59 @@ impl Versions for EpochsTestVersions {
mod tests {
use committable::{Commitment, Committable};
use hotshot_types::{
message::UpgradeLock, simple_vote::VersionedVoteData,
data::EpochNumber,
impl_has_epoch,
message::UpgradeLock,
simple_vote::{HasEpoch, VersionedVoteData},
traits::node_implementation::ConsensusTime,
};
use serde::{Deserialize, Serialize};

use crate::node_types::{MarketplaceTestVersions, NodeType, TestTypes};
#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Hash, Eq)]
/// Dummy data used for test
struct TestData {
struct TestData<TYPES: NodeType> {
data: u64,
epoch: TYPES::Epoch,
}

impl Committable for TestData {
impl<TYPES: NodeType> Committable for TestData<TYPES> {
fn commit(&self) -> Commitment<Self> {
committable::RawCommitmentBuilder::new("Test data")
.u64(self.data)
.finalize()
}
}

impl_has_epoch!(TestData<TYPES>);

#[tokio::test(flavor = "multi_thread")]
/// Test that the view number affects the commitment post-marketplace
async fn test_versioned_commitment_includes_view() {
let upgrade_lock = UpgradeLock::new();

let data = TestData { data: 10 };
let data = TestData {
data: 10,
epoch: EpochNumber::new(0),
};

let view_0 = <TestTypes as NodeType>::View::new(0);
let view_1 = <TestTypes as NodeType>::View::new(1);

let versioned_data_0 =
VersionedVoteData::<TestTypes, TestData, MarketplaceTestVersions>::new(
data,
view_0,
&upgrade_lock,
)
.await
.unwrap();
let versioned_data_1 =
VersionedVoteData::<TestTypes, TestData, MarketplaceTestVersions>::new(
data,
view_1,
&upgrade_lock,
)
.await
.unwrap();
let versioned_data_0 = VersionedVoteData::<
TestTypes,
TestData<TestTypes>,
MarketplaceTestVersions,
>::new(data, view_0, &upgrade_lock)
.await
.unwrap();
let versioned_data_1 = VersionedVoteData::<
TestTypes,
TestData<TestTypes>,
MarketplaceTestVersions,
>::new(data, view_1, &upgrade_lock)
.await
.unwrap();

let versioned_data_commitment_0: [u8; 32] = versioned_data_0.commit().into();
let versioned_data_commitment_1: [u8; 32] = versioned_data_1.commit().into();
Expand Down
25 changes: 25 additions & 0 deletions crates/example-types/src/storage_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use hotshot_types::{
consensus::CommitmentMap,
data::{
DaProposal, DaProposal2, Leaf, Leaf2, QuorumProposal, QuorumProposal2, VidDisperseShare,
VidDisperseShare2,
},
event::HotShotAction,
message::Proposal,
Expand All @@ -36,9 +37,15 @@ type VidShares<TYPES> = HashMap<
<TYPES as NodeType>::View,
HashMap<<TYPES as NodeType>::SignatureKey, Proposal<TYPES, VidDisperseShare<TYPES>>>,
>;
type VidShares2<TYPES> = HashMap<
<TYPES as NodeType>::View,
HashMap<<TYPES as NodeType>::SignatureKey, Proposal<TYPES, VidDisperseShare2<TYPES>>>,
>;

#[derive(Clone, Debug)]
pub struct TestStorageState<TYPES: NodeType> {
vids: VidShares<TYPES>,
vid2: VidShares2<TYPES>,
das: HashMap<TYPES::View, Proposal<TYPES, DaProposal<TYPES>>>,
da2s: HashMap<TYPES::View, Proposal<TYPES, DaProposal2<TYPES>>>,
proposals: BTreeMap<TYPES::View, Proposal<TYPES, QuorumProposal<TYPES>>>,
Expand All @@ -53,6 +60,7 @@ impl<TYPES: NodeType> Default for TestStorageState<TYPES> {
fn default() -> Self {
Self {
vids: HashMap::new(),
vid2: HashMap::new(),
das: HashMap::new(),
da2s: HashMap::new(),
proposals: BTreeMap::new(),
Expand Down Expand Up @@ -131,6 +139,23 @@ impl<TYPES: NodeType> Storage<TYPES> for TestStorage<TYPES> {
Ok(())
}

async fn append_vid2(
&self,
proposal: &Proposal<TYPES, VidDisperseShare2<TYPES>>,
) -> Result<()> {
if self.should_return_err {
bail!("Failed to append VID proposal to storage");
}
Self::run_delay_settings_from_config(&self.delay_config).await;
let mut inner = self.inner.write().await;
inner
.vid2
.entry(proposal.data.view_number)
.or_default()
.insert(proposal.data.recipient_key.clone(), proposal.clone());
Ok(())
}

async fn append_da(
&self,
proposal: &Proposal<TYPES, DaProposal<TYPES>>,
Expand Down
33 changes: 19 additions & 14 deletions crates/hotshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ pub use hotshot_types::error::HotShotError;
use hotshot_types::{
consensus::{Consensus, ConsensusMetricsValue, OuterConsensus, View, ViewInner},
constants::{EVENT_CHANNEL_SIZE, EXTERNAL_EVENT_CHANNEL_SIZE},
data::{Leaf, Leaf2, QuorumProposal, QuorumProposal2},
data::{Leaf2, QuorumProposal, QuorumProposal2},
event::{EventType, LeafInfo},
message::{convert_proposal, DataMessage, Message, MessageKind, Proposal},
simple_certificate::{QuorumCertificate, QuorumCertificate2, UpgradeCertificate},
simple_certificate::{QuorumCertificate2, UpgradeCertificate},
traits::{
consensus_api::ConsensusApi,
election::Membership,
Expand All @@ -63,15 +63,16 @@ use hotshot_types::{
storage::Storage,
EncodeBytes,
},
utils::epoch_from_block_number,
HotShotConfig,
};
// -- Rexports
// External
/// Reexport rand crate
pub use rand;
use tokio::{spawn, time::sleep};
use tracing::{debug, instrument, trace};

// -- Rexports
// External
use crate::{
tasks::{add_consensus_tasks, add_network_tasks},
traits::NodeImplementation,
Expand Down Expand Up @@ -291,6 +292,10 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
)),
};

let epoch = TYPES::Epoch::new(epoch_from_block_number(
anchored_leaf.height(),
config.epoch_height,
));
// Insert the validated state to state map.
let mut validated_state_map = BTreeMap::default();
validated_state_map.insert(
Expand All @@ -300,6 +305,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
leaf: anchored_leaf.commit(),
state: Arc::clone(&validated_state),
delta: initializer.state_delta.clone(),
epoch,
},
},
);
Expand Down Expand Up @@ -403,14 +409,15 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
let event_stream = self.internal_event_stream.0.clone();
let next_view_timeout = self.config.next_view_timeout;
let start_view = self.start_view;
let start_epoch = self.start_epoch;

// Spawn a task that will sleep for the next view timeout and then send a timeout event
// if not cancelled
spawn({
async move {
sleep(Duration::from_millis(next_view_timeout)).await;
broadcast_event(
Arc::new(HotShotEvent::Timeout(start_view + 1)),
Arc::new(HotShotEvent::Timeout(start_view + 1, start_epoch + 1)),
&event_stream,
)
.await;
Expand Down Expand Up @@ -438,9 +445,11 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> SystemContext<T
TYPES::ValidatedState::genesis(&self.instance_state);

let qc = Arc::new(
QuorumCertificate::genesis::<V>(&validated_state, self.instance_state.as_ref())
.await
.to_qc2(),
QuorumCertificate2::genesis::<V>(
&validated_state,
self.instance_state.as_ref(),
)
.await,
);

broadcast_event(
Expand Down Expand Up @@ -1010,14 +1019,10 @@ impl<TYPES: NodeType> HotShotInitializer<TYPES> {
instance_state: TYPES::InstanceState,
) -> Result<Self, HotShotError<TYPES>> {
let (validated_state, state_delta) = TYPES::ValidatedState::genesis(&instance_state);
let high_qc = QuorumCertificate::genesis::<V>(&validated_state, &instance_state)
.await
.to_qc2();
let high_qc = QuorumCertificate2::genesis::<V>(&validated_state, &instance_state).await;

Ok(Self {
inner: Leaf::genesis(&validated_state, &instance_state)
.await
.into(),
inner: Leaf2::genesis(&validated_state, &instance_state).await,
validated_state: Some(Arc::new(validated_state)),
state_delta: Some(Arc::new(state_delta)),
start_view: TYPES::View::new(0),
Expand Down
1 change: 1 addition & 0 deletions crates/hotshot/src/tasks/task_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, V: Versions> CreateTaskState

Self {
latest_proposed_view: handle.cur_view().await,
cur_epoch: handle.cur_epoch().await,
proposal_dependencies: BTreeMap::new(),
consensus: OuterConsensus::new(consensus),
instance_state: handle.hotshot.instance_state(),
Expand Down
2 changes: 2 additions & 0 deletions crates/hotshot/src/traits/election/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub mod static_committee;

/// static (round robin leader for 2 consecutive views) committee election
pub mod static_committee_leader_two_views;
/// two static (round robin) committees for even and odd epochs
pub mod two_static_committees;

/// general helpers
pub mod helpers;
Loading
Loading