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

VID share distribution algorithm (2) #2163

Merged
merged 11 commits into from
Dec 8, 2023
43 changes: 11 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/ValidatorConfigOutput
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ValidatorConfig { public_key: BLSPubKey { pub_key: VerKey((QuadExtField(2264797523581107490935262917175769123227923636811928330606075281145117212394 + 15807017392833049888165434456991157794698032464874424842715555348468160607934 * u), QuadExtField(7996517616082121122160563552650547601395271017260499735456299700133762512689 + 7504045709281061282278228438613345070383424761478787301859187055302953740948 * u), QuadExtField(1515973040548822760825076242090160370742046237881440422068330135941139244581 + 20251846261653098602911417004145145971080304248810966341160788194007704966108 * u))) }, private_key: BLSPrivKey { priv_key: SignKey(BigInt([3505488234151006356, 6655477166151225138, 3291219027844407676, 2153641080015542578])) }, stake_value: 1, state_key_pair: StateKeyPair(KeyPair { sk: SignKey(BigInt([2822822805887490846, 6664316196088353173, 4926510007447087464, 116097479308258694])), vk: VerKey(Projective { x: BigInt([11315198235793138814, 4744451806709910489, 6921831025042192557, 1125393823825936625]), y: BigInt([13035879815613524256, 18225673961538637854, 12006860967936477969, 1516668567229692859]), t: BigInt([13450777528397789701, 12242009376162249168, 12596256366242272750, 3368076418495976469]), z: BigInt([10465708325245823445, 13967918689717629445, 14943426723808572731, 621075342718756551]) }) }) }
ValidatorConfig { public_key: BLSPubKey { pub_key: VerKey((QuadExtField(2264797523581107490935262917175769123227923636811928330606075281145117212394 + 15807017392833049888165434456991157794698032464874424842715555348468160607934 * u), QuadExtField(7996517616082121122160563552650547601395271017260499735456299700133762512689 + 7504045709281061282278228438613345070383424761478787301859187055302953740948 * u), QuadExtField(1515973040548822760825076242090160370742046237881440422068330135941139244581 + 20251846261653098602911417004145145971080304248810966341160788194007704966108 * u))) }, private_key: BLSPrivKey { priv_key: SignKey(BigInt([3505488234151006356, 6655477166151225138, 3291219027844407676, 2153641080015542578])) }, stake_value: 1 }
14 changes: 0 additions & 14 deletions crates/hotshot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,74 +21,60 @@ hotshot-testing = []
# libp2p
[[example]]
name = "validator-libp2p"
required-features = ["libp2p/rsa"]
path = "examples/libp2p/validator.rs"

[[example]]
name = "multi-validator-libp2p"
required-features = ["libp2p/rsa"]
path = "examples/libp2p/multi-validator.rs"

[[example]]
name = "orchestrator-libp2p"
required-features = ["libp2p/rsa"]
path = "examples/libp2p/orchestrator.rs"

[[example]]
name = "all-libp2p"
required-features = ["libp2p/rsa"]
path = "examples/libp2p/all.rs"

# webserver
[[example]]
name = "webserver"
required-features = ["libp2p/rsa"]
path = "examples/webserver/webserver.rs"

[[example]]
name = "orchestrator-webserver"
required-features = ["libp2p/rsa"]
path = "examples/webserver/orchestrator.rs"

[[example]]
name = "validator-webserver"
required-features = ["libp2p/rsa"]
path = "examples/webserver/validator.rs"

[[example]]
name = "multi-validator-webserver"
required-features = ["libp2p/rsa"]
path = "examples/webserver/multi-validator.rs"

[[example]]
name = "multi-webserver"
required-features = ["libp2p/rsa"]
path = "examples/webserver/multi-webserver.rs"

[[example]]
name = "all-webserver"
required-features = ["libp2p/rsa"]
path = "examples/webserver/all.rs"

# combined
[[example]]
name = "all-combined"
required-features = ["libp2p/rsa"]
path = "examples/combined/all.rs"

[[example]]
name = "multi-validator-combined"
required-features = ["libp2p/rsa"]
path = "examples/combined/multi-validator.rs"

[[example]]
name = "validator-combined"
required-features = ["libp2p/rsa"]
path = "examples/combined/validator.rs"

[[example]]
name = "orchestrator-combined"
required-features = ["libp2p/rsa"]
path = "examples/combined/orchestrator.rs"

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions crates/hotshot/examples/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ async fn webserver_network_from_config<TYPES: NodeType>(
let WebServerConfig {
url,
wait_between_polls,
}: WebServerConfig = config.clone().web_server_config.unwrap();
}: WebServerConfig = config.web_server_config.unwrap();

WebServerNetwork::create(url, wait_between_polls, pub_key.clone(), false)
WebServerNetwork::create(url, wait_between_polls, pub_key, false)
}

async fn libp2p_network_from_config<TYPES: NodeType>(
Expand Down
12 changes: 11 additions & 1 deletion crates/hotshot/src/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use hotshot_task_impls::{
vid::{VIDTaskState, VIDTaskTypes},
view_sync::{ViewSyncTaskState, ViewSyncTaskStateTypes},
};
use hotshot_types::traits::election::Membership;
use hotshot_types::{
event::Event,
message::Messages,
Expand Down Expand Up @@ -206,7 +207,15 @@ pub async fn add_consensus_task<TYPES: NodeType, I: NodeImplementation<TYPES>>(
let registry = task_runner.registry.clone();
let (payload, metadata) = <TYPES::BlockPayload as BlockPayload>::genesis();
// Impossible for `unwrap` to fail on the genesis payload.
let payload_commitment = vid_commitment(&payload.encode().unwrap().collect());
let payload_commitment = vid_commitment(
&payload.encode().unwrap().collect(),
handle
.hotshot
.inner
.memberships
.quorum_membership
.total_nodes(),
);
// build the consensus task
let consensus_state = ConsensusTaskState {
registry: registry.clone(),
Expand Down Expand Up @@ -353,6 +362,7 @@ pub async fn add_da_task<TYPES: NodeType, I: NodeImplementation<TYPES>>(
consensus: handle.hotshot.get_consensus(),
da_membership: c_api.inner.memberships.da_membership.clone().into(),
da_network: c_api.inner.networks.da_network.clone().into(),
quorum_membership: c_api.inner.memberships.quorum_membership.clone().into(),
cur_view: TYPES::Time::new(0),
vote_collector: None,
event_stream: event_stream.clone(),
Expand Down
7 changes: 5 additions & 2 deletions crates/hotshot/src/traits/storage/memory_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ mod test {
use hotshot_types::{
data::{fake_commitment, genesis_proposer_id, Leaf},
simple_certificate::QuorumCertificate,
traits::{node_implementation::NodeType, state::ConsensusTime},
traits::{
block_contents::genesis_vid_commitment, node_implementation::NodeType,
state::ConsensusTime,
},
};
use std::marker::PhantomData;
use tracing::instrument;
Expand All @@ -126,7 +129,7 @@ mod test {
let payload = TestBlockPayload::genesis();
let header = TestBlockHeader {
block_number: 0,
payload_commitment: payload.payload_commitment,
payload_commitment: genesis_vid_commitment(),
};
let dummy_leaf_commit = fake_commitment::<Leaf<TestTypes>>();
let data = hotshot_types::simple_vote::QuorumData {
Expand Down
8 changes: 2 additions & 6 deletions crates/task-impls/src/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,8 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
encoded_txns.clone().into_iter(),
leaf.get_block_header().metadata(),
);
if let Err(e) = leaf.fill_block_payload(payload) {
error!(
"Saved block payload and commitment don't match: {:?}",
e
);
}

leaf.fill_block_payload_unchecked(payload);
}

leaf_views.push(leaf.clone());
Expand Down
10 changes: 9 additions & 1 deletion crates/task-impls/src/da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ pub struct DATaskState<
/// Membership for the DA committee
pub da_membership: Arc<TYPES::Membership>,

/// Membership for the quorum committee
/// We need this only for calculating the proper VID scheme
/// from the number of nodes in the quorum.
pub quorum_membership: Arc<TYPES::Membership>,
rob-maron marked this conversation as resolved.
Show resolved Hide resolved

/// Network for DA
pub da_network: Arc<I::CommitteeNetwork>,

Expand Down Expand Up @@ -113,7 +118,10 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
return None;
}

let payload_commitment = vid_commitment(&proposal.data.encoded_transactions);
let payload_commitment = vid_commitment(
&proposal.data.encoded_transactions,
self.quorum_membership.total_nodes(),
);
let encoded_transactions_hash = Sha256::digest(&proposal.data.encoded_transactions);

// ED Is this the right leader?
Expand Down
2 changes: 1 addition & 1 deletion crates/task-impls/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub enum HotShotEvent<TYPES: NodeType> {
VidCommitment,
<TYPES::BlockPayload as BlockPayload>::Metadata,
),
/// Event when the transactions task has sequenced transactions. Contains the encoded transactions
/// Event when the transactions task has sequenced transactions. Contains the encoded transactions, the metadata, and the view number
TransactionsSequenced(
Vec<u8>,
<TYPES::BlockPayload as BlockPayload>::Metadata,
Expand Down
6 changes: 3 additions & 3 deletions crates/task-impls/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl<TYPES: NodeType> NetworkMessageTaskState<TYPES> {
let event = match consensus_message.0 {
Either::Left(general_message) => match general_message {
GeneralConsensusMessage::Proposal(proposal) => {
HotShotEvent::QuorumProposalRecv(proposal.clone(), sender)
HotShotEvent::QuorumProposalRecv(proposal, sender)
}
GeneralConsensusMessage::Vote(vote) => {
HotShotEvent::QuorumVoteRecv(vote.clone())
Expand Down Expand Up @@ -92,7 +92,7 @@ impl<TYPES: NodeType> NetworkMessageTaskState<TYPES> {
},
Either::Right(committee_message) => match committee_message {
CommitteeConsensusMessage::DAProposal(proposal) => {
HotShotEvent::DAProposalRecv(proposal.clone(), sender)
HotShotEvent::DAProposalRecv(proposal, sender)
}
CommitteeConsensusMessage::DAVote(vote) => {
HotShotEvent::DAVoteRecv(vote.clone())
Expand Down Expand Up @@ -236,7 +236,7 @@ impl<TYPES: NodeType, COMMCHANNEL: CommunicationChannel<TYPES>>
HotShotEvent::ViewSyncPreCommitCertificate2Send(certificate, sender) => (
sender,
MessageKind::<TYPES>::from_consensus_message(SequencingMessage(Left(
GeneralConsensusMessage::ViewSyncPreCommitCertificate(certificate.clone()),
GeneralConsensusMessage::ViewSyncPreCommitCertificate(certificate),
))),
TransmitType::Broadcast,
None,
Expand Down
Loading
Loading