diff --git a/data/v99/chain_config.bin b/data/v99/chain_config.bin index b966a83cb..8079cfdb9 100644 Binary files a/data/v99/chain_config.bin and b/data/v99/chain_config.bin differ diff --git a/data/v99/chain_config.json b/data/v99/chain_config.json index 5c39b238a..7695a2f82 100644 --- a/data/v99/chain_config.json +++ b/data/v99/chain_config.json @@ -4,5 +4,6 @@ "chain_id": "35353", "fee_contract": "0x0000000000000000000000000000000000000000", "fee_recipient": "0x0000000000000000000000000000000000000000", - "max_block_size": "10240" + "max_block_size": "10240", + "stake_table_contract": "0x0000000000000000000000000000000000000000" } \ No newline at end of file diff --git a/data/v99/header.bin b/data/v99/header.bin index c07c0e1e6..e3111fcf2 100644 Binary files a/data/v99/header.bin and b/data/v99/header.bin differ diff --git a/data/v99/header.json b/data/v99/header.json index a4cfc7846..5aa145fa7 100644 --- a/data/v99/header.json +++ b/data/v99/header.json @@ -22,7 +22,8 @@ "chain_id": "35353", "fee_contract": "0x0000000000000000000000000000000000000000", "fee_recipient": "0x0000000000000000000000000000000000000000", - "max_block_size": "10240" + "max_block_size": "10240", + "stake_table_contract": "0x0000000000000000000000000000000000000000" } } }, diff --git a/sequencer-sqlite/Cargo.lock b/sequencer-sqlite/Cargo.lock index ad03aad19..fe749395e 100644 --- a/sequencer-sqlite/Cargo.lock +++ b/sequencer-sqlite/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "Inflector" @@ -2752,15 +2752,18 @@ dependencies = [ "committable", "contract-bindings", "derive_more 1.0.0", + "diff-test-bn254", "dyn-clone", "ethers", "fluent-asserter", "futures", "hotshot", + "hotshot-contract-adapter", "hotshot-query-service", "hotshot-types", "itertools 0.12.1", "jf-merkle-tree", + "jf-signature 0.2.0", "jf-utils", "jf-vid", "lru 0.12.5", @@ -3960,11 +3963,14 @@ version = "0.1.0" dependencies = [ "anyhow", "ark-bn254", + "ark-ec", + "ark-ed-on-bn254", "ark-ff", "ark-poly", "ark-serialize", "ark-std", "contract-bindings", + "derive_more 1.0.0", "diff-test-bn254", "ethers", "hotshot-types", @@ -3974,6 +3980,7 @@ dependencies = [ "libp2p", "num-bigint", "num-traits", + "serde", ] [[package]] @@ -4083,7 +4090,7 @@ dependencies = [ [[package]] name = "hotshot-query-service" version = "0.1.75" -source = "git+https://github.com/EspressoSystems/hotshot-query-service?branch=hotshot/0.5.82#5e2c984d19da3826f4cc8d80c5cf1a84dcd377f7" +source = "git+https://github.com/EspressoSystems/hotshot-query-service?tag=v0.1.75#dffefa160f441a663723a67bc54efedb11a88b02" dependencies = [ "anyhow", "ark-serialize", @@ -8409,6 +8416,7 @@ dependencies = [ "futures", "hotshot", "hotshot-contract-adapter", + "hotshot-types", "log-panics", "portpicker", "reqwest 0.11.27", @@ -8417,6 +8425,7 @@ dependencies = [ "surf", "tempfile", "tokio", + "toml 0.8.19", "tracing", "url", ] diff --git a/types/src/reference_tests.rs b/types/src/reference_tests.rs index 96ac43e32..550a15363 100755 --- a/types/src/reference_tests.rs +++ b/types/src/reference_tests.rs @@ -109,7 +109,7 @@ const REFERENCE_V1_CHAIN_CONFIG_COMMITMENT: &str = "CHAIN_CONFIG~L6HmMktJbvnEGgpmRrsiYvQmIBstSj9UtDM7eNFFqYFO"; const REFERENCE_V99_CHAIN_CONFIG_COMMITMENT: &str = - "CHAIN_CONFIG~1mJTBiaJ0Nyuu4Ir5IZTamyI8CjexbktPkRr6R1rtnGh"; + "CHAIN_CONFIG~ucfYQZSMbWCUHdtwYMc6vsw-4jDmlu3hi2lGDBxCRpI-"; fn reference_fee_info() -> FeeInfo { FeeInfo::new( @@ -156,7 +156,7 @@ async fn reference_header(version: Version) -> Header { const REFERENCE_V1_HEADER_COMMITMENT: &str = "BLOCK~dh1KpdvvxSvnnPpOi2yI3DOg8h6ltr2Kv13iRzbQvtN2"; const REFERENCE_V2_HEADER_COMMITMENT: &str = "BLOCK~V0GJjL19nCrlm9n1zZ6gaOKEekSMCT6uR5P-h7Gi6UJR"; -const REFERENCE_V99_HEADER_COMMITMENT: &str = "BLOCK~BGlAadiwOlxmhQxdp2HS7mHpG-ifDOx9ocBkTEJXx05_"; +const REFERENCE_V99_HEADER_COMMITMENT: &str = "BLOCK~nzcKNbVZPDIO-6AepK2pRQKxMXeIi3U98p-CpVv8HNUt"; fn reference_transaction(ns_id: NamespaceId, rng: &mut R) -> Transaction where diff --git a/types/src/v0/impls/stake_table.rs b/types/src/v0/impls/stake_table.rs index c8e1ba4b6..c2af56cf0 100644 --- a/types/src/v0/impls/stake_table.rs +++ b/types/src/v0/impls/stake_table.rs @@ -1,7 +1,7 @@ use super::{L1Client, NodeState, PubKey, SeqTypes}; use contract_bindings::permissioned_stake_table::StakersUpdatedFilter; use ethers::{abi::Address, types::U256}; -use hotshot::types::SignatureKey; +use hotshot::types::SignatureKey as _; use hotshot_contract_adapter::stake_table::NodeInfoJf; use hotshot_types::{ stake_table::StakeTableEntry, @@ -19,26 +19,28 @@ use std::{ use thiserror::Error; use url::Url; +type Epoch = ::Epoch; +type SeqStakeTableEntry = ::StakeTableEntry; +type SignatureKey = ::SignatureKey; + #[derive(Clone, Debug)] pub struct StaticCommittee { /// The nodes eligible for leadership. /// NOTE: This is currently a hack because the DA leader needs to be the quorum /// leader but without voting rights. - eligible_leaders: Vec<::StakeTableEntry>, + eligible_leaders: Vec, /// The nodes on the committee and their stake - stake_table: HashSet<::StakeTableEntry>, + stake_table: HashSet, /// The nodes on the committee and their stake - da_stake_table: HashSet<::StakeTableEntry>, + da_stake_table: HashSet, /// The nodes on the committee and their stake, indexed by public key - indexed_stake_table: - BTreeMap::SignatureKey as SignatureKey>::StakeTableEntry>, + indexed_stake_table: BTreeMap, /// The nodes on the committee and their stake, indexed by public key - indexed_da_stake_table: - BTreeMap::SignatureKey as SignatureKey>::StakeTableEntry>, + indexed_da_stake_table: BTreeMap, /// Number of blocks in an epoch epoch_size: u64, @@ -63,7 +65,7 @@ impl StaticCommittee { .get_stake_table(l1_block_height, self.contract_address.unwrap()) .await; - let added: Vec = updates + let added: Vec<_> = updates .into_iter() .flat_map(|e: StakersUpdatedFilter| e.added.into_iter().map(NodeInfoJf::from)) .collect(); @@ -81,47 +83,43 @@ impl StaticCommittee { pub fn new_stake( // TODO remove `new` from trait and rename this to `new`. // https://github.com/EspressoSystems/HotShot/commit/fcb7d54a4443e29d643b3bbc53761856aef4de8b - committee_members: Vec::SignatureKey>>, - da_members: Vec::SignatureKey>>, + committee_members: Vec>, + da_members: Vec>, instance_state: &NodeState, epoch_size: u64, ) -> Self { // For each eligible leader, get the stake table entry - let eligible_leaders: Vec< - <::SignatureKey as SignatureKey>::StakeTableEntry, - > = committee_members + let eligible_leaders: Vec<_> = committee_members .iter() .map(|member| member.stake_table_entry.clone()) .filter(|entry| entry.stake() > U256::zero()) .collect(); // For each member, get the stake table entry - let members: Vec<::StakeTableEntry> = committee_members + let members: Vec<_> = committee_members .iter() .map(|member| member.stake_table_entry.clone()) .filter(|entry| entry.stake() > U256::zero()) .collect(); // For each member, get the stake table entry - let da_members: Vec<::StakeTableEntry> = da_members + let da_members: Vec<_> = da_members .iter() .map(|member| member.stake_table_entry.clone()) .filter(|entry| entry.stake() > U256::zero()) .collect(); // Index the stake table by public key - let indexed_stake_table: BTreeMap::StakeTableEntry> = - members - .iter() - .map(|entry| (SignatureKey::public_key(entry), entry.clone())) - .collect(); + let indexed_stake_table: BTreeMap = members + .iter() + .map(|entry| (SignatureKey::public_key(entry), entry.clone())) + .collect(); // Index the stake table by public key - let indexed_da_stake_table: BTreeMap::StakeTableEntry> = - da_members - .iter() - .map(|entry| (SignatureKey::public_key(entry), entry.clone())) - .collect(); + let indexed_da_stake_table: BTreeMap = da_members + .iter() + .map(|entry| (SignatureKey::public_key(entry), entry.clone())) + .collect(); Self { eligible_leaders, @@ -140,51 +138,48 @@ impl StaticCommittee { #[error("Could not lookup leader")] // TODO error variants? message? pub struct LeaderLookupError; -impl> Membership for StaticCommittee { +impl Membership for StaticCommittee { type Error = LeaderLookupError; // DO NOT USE. Dummy constructor to comply w/ trait. fn new( // TODO remove `new` from trait and remove this fn as well. // https://github.com/EspressoSystems/HotShot/commit/fcb7d54a4443e29d643b3bbc53761856aef4de8b - committee_members: Vec::SignatureKey>>, - da_members: Vec::SignatureKey>>, + committee_members: Vec>, + da_members: Vec>, ) -> Self { // For each eligible leader, get the stake table entry - let eligible_leaders: Vec<::StakeTableEntry> = committee_members + let eligible_leaders: Vec<_> = committee_members .iter() .map(|member| member.stake_table_entry.clone()) .filter(|entry| entry.stake() > U256::zero()) .collect(); // For each member, get the stake table entry - let members: Vec<::StakeTableEntry> = - committee_members - .iter() - .map(|member| member.stake_table_entry.clone()) - .filter(|entry| entry.stake() > U256::zero()) - .collect(); + let members: Vec<_> = committee_members + .iter() + .map(|member| member.stake_table_entry.clone()) + .filter(|entry| entry.stake() > U256::zero()) + .collect(); // For each member, get the stake table entry - let da_members: Vec<::StakeTableEntry> = da_members + let da_members: Vec<_> = da_members .iter() .map(|member| member.stake_table_entry.clone()) .filter(|entry| entry.stake() > U256::zero()) .collect(); // Index the stake table by public key - let indexed_stake_table: BTreeMap::StakeTableEntry> = - members - .iter() - .map(|entry| (TYPES::SignatureKey::public_key(entry), entry.clone())) - .collect(); + let indexed_stake_table: BTreeMap = members + .iter() + .map(|entry| (SignatureKey::public_key(entry), entry.clone())) + .collect(); // Index the stake table by public key - let indexed_da_stake_table: BTreeMap::StakeTableEntry> = - da_members - .iter() - .map(|entry| (TYPES::SignatureKey::public_key(entry), entry.clone())) - .collect(); + let indexed_da_stake_table: BTreeMap = da_members + .iter() + .map(|entry| (SignatureKey::public_key(entry), entry.clone())) + .collect(); Self { eligible_leaders, @@ -198,93 +193,71 @@ impl> Membership for StaticCommitt } } /// Get the stake table for the current view - fn stake_table( - &self, - _epoch: ::Epoch, - ) -> Vec<<::SignatureKey as SignatureKey>::StakeTableEntry> { + fn stake_table(&self, _epoch: Epoch) -> Vec { self.stake_table.clone().into_iter().collect() } /// Get the stake table for the current view - fn da_stake_table( - &self, - _epoch: ::Epoch, - ) -> Vec<<::SignatureKey as SignatureKey>::StakeTableEntry> { + fn da_stake_table(&self, _epoch: Epoch) -> Vec { self.da_stake_table.clone().into_iter().collect() } /// Get all members of the committee for the current view fn committee_members( &self, - _view_number: ::View, - _epoch: ::Epoch, - ) -> BTreeSet<::SignatureKey> { + _view_number: ::View, + _epoch: Epoch, + ) -> BTreeSet { self.stake_table .iter() - .map(TYPES::SignatureKey::public_key) + .map(SignatureKey::public_key) .collect() } /// Get all members of the committee for the current view fn da_committee_members( &self, - _view_number: ::View, - _epoch: ::Epoch, - ) -> BTreeSet<::SignatureKey> { + _view_number: ::View, + _epoch: Epoch, + ) -> BTreeSet { self.da_stake_table .iter() - .map(TYPES::SignatureKey::public_key) + .map(SignatureKey::public_key) .collect() } /// Get all eligible leaders of the committee for the current view fn committee_leaders( &self, - _view_number: ::View, - _epoch: ::Epoch, - ) -> BTreeSet<::SignatureKey> { + _view_number: ::View, + _epoch: Epoch, + ) -> BTreeSet { self.eligible_leaders .iter() - .map(TYPES::SignatureKey::public_key) + .map(SignatureKey::public_key) .collect() } /// Get the stake table entry for a public key - fn stake( - &self, - pub_key: &::SignatureKey, - _epoch: ::Epoch, - ) -> Option<::StakeTableEntry> { + fn stake(&self, pub_key: &SignatureKey, _epoch: Epoch) -> Option { // Only return the stake if it is above zero self.indexed_stake_table.get(pub_key).cloned() } /// Get the DA stake table entry for a public key - fn da_stake( - &self, - pub_key: &::SignatureKey, - _epoch: ::Epoch, - ) -> Option<::StakeTableEntry> { + fn da_stake(&self, pub_key: &SignatureKey, _epoch: Epoch) -> Option { // Only return the stake if it is above zero self.indexed_da_stake_table.get(pub_key).cloned() } /// Check if a node has stake in the committee - fn has_stake( - &self, - pub_key: &::SignatureKey, - _epoch: ::Epoch, - ) -> bool { + fn has_stake(&self, pub_key: &SignatureKey, _epoch: Epoch) -> bool { self.indexed_stake_table .get(pub_key) .is_some_and(|x| x.stake() > U256::zero()) } /// Check if a node has stake in the committee - fn has_da_stake( - &self, - pub_key: &::SignatureKey, - _epoch: ::Epoch, - ) -> bool { + fn has_da_stake(&self, pub_key: &SignatureKey, _epoch: Epoch) -> bool { self.indexed_da_stake_table .get(pub_key) .is_some_and(|x| x.stake() > U256::zero()) @@ -293,41 +266,41 @@ impl> Membership for StaticCommitt /// Index the vector of public keys with the current view number fn lookup_leader( &self, - view_number: TYPES::View, - _epoch: ::Epoch, - ) -> Result { + view_number: ::View, + _epoch: Epoch, + ) -> Result { let index = *view_number as usize % self.eligible_leaders.len(); let res = self.eligible_leaders[index].clone(); - Ok(TYPES::SignatureKey::public_key(&res)) + Ok(SignatureKey::public_key(&res)) } /// Get the total number of nodes in the committee - fn total_nodes(&self, _epoch: ::Epoch) -> usize { + fn total_nodes(&self, _epoch: Epoch) -> usize { self.stake_table.len() } /// Get the total number of DA nodes in the committee - fn da_total_nodes(&self, _epoch: ::Epoch) -> usize { + fn da_total_nodes(&self, _epoch: Epoch) -> usize { self.da_stake_table.len() } /// Get the voting success threshold for the committee - fn success_threshold(&self, _epoch: ::Epoch) -> NonZeroU64 { + fn success_threshold(&self, _epoch: Epoch) -> NonZeroU64 { NonZeroU64::new(((self.stake_table.len() as u64 * 2) / 3) + 1).unwrap() } /// Get the voting success threshold for the committee - fn da_success_threshold(&self, _epoch: ::Epoch) -> NonZeroU64 { + fn da_success_threshold(&self, _epoch: Epoch) -> NonZeroU64 { NonZeroU64::new(((self.da_stake_table.len() as u64 * 2) / 3) + 1).unwrap() } /// Get the voting failure threshold for the committee - fn failure_threshold(&self, _epoch: ::Epoch) -> NonZeroU64 { + fn failure_threshold(&self, _epoch: Epoch) -> NonZeroU64 { NonZeroU64::new(((self.stake_table.len() as u64) / 3) + 1).unwrap() } /// Get the voting upgrade threshold for the committee - fn upgrade_threshold(&self, _epoch: ::Epoch) -> NonZeroU64 { + fn upgrade_threshold(&self, _epoch: Epoch) -> NonZeroU64 { NonZeroU64::new(max( (self.stake_table.len() as u64 * 9) / 10, ((self.stake_table.len() as u64 * 2) / 3) + 1,