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

Finish initial Authority implementation #134

Merged
merged 4 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Fixes to prev Authority PR
  • Loading branch information
ilblackdragon committed Dec 6, 2018
commit 6385d528db2a769220526da88a5ba2e20f931cba
19 changes: 9 additions & 10 deletions core/beacon/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,13 @@ impl Authority {
}
}
}
// assert_eq!(dup_proposals.len(), num_seats);
assert_eq!(dup_proposals.len(), num_seats as usize);
for i in 0..self.authority_config.epoch_length {
// let start: usize = (i * self.authority_config.num_seats_per_slot).into();
// let authorities = dup_proposals[usize::from(i * self.authority_config.num_seats_per_slot)..usize::from((i + 1) * self.authority_config.num_seats_per_slot)];
let authorities = dup_proposals.clone();
let start = (i * self.authority_config.num_seats_per_slot) as usize;
let end = ((i + 1) * self.authority_config.num_seats_per_slot) as usize;
result.insert(
self.current_epoch * self.authority_config.epoch_length + i + 1,
authorities,
dup_proposals[start..end].to_vec(),
);
}
result
Expand Down Expand Up @@ -195,16 +194,16 @@ mod test {

#[test]
fn test_authority_genesis() {
let authority_config = get_test_config(5, 2, 2);
let authority_config = get_test_config(4, 2, 2);
let initial_authorities: Vec<PublicKey> =
authority_config.initial_authorities.iter().map(|a| a.public_key).collect();
let bc = test_blockchain(0);
let mut authority = Authority::new(authority_config, &bc);
assert_eq!(authority.get_authorities(0).unwrap(), vec![]);
assert_eq!(authority.get_authorities(1).unwrap(), initial_authorities);
assert_eq!(authority.get_authorities(2).unwrap(), initial_authorities);
assert_eq!(authority.get_authorities(3).unwrap(), initial_authorities);
assert_eq!(authority.get_authorities(4).unwrap(), initial_authorities);
assert_eq!(authority.get_authorities(1).unwrap(), initial_authorities[0..2].to_vec());
assert_eq!(authority.get_authorities(2).unwrap(), initial_authorities[2..4].to_vec());
assert_eq!(authority.get_authorities(3).unwrap(), initial_authorities[0..2].to_vec());
assert_eq!(authority.get_authorities(4).unwrap(), initial_authorities[2..4].to_vec());
assert!(authority.get_authorities(5).is_err());
let header = BeaconBlockHeader::new(
1,
Expand Down
16 changes: 3 additions & 13 deletions core/beacon/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@ pub struct AuthorityProposal {
pub amount: u64,
}

//pub struct BeaconBlockBody {
// /// Parent hash.
// pub parent_hash: CryptoHash,
// /// Block index.
// pub index: u64,
// /// Authority proposals.
// pub authority_proposal: Vec<AuthorityProposal>,
// /// Shard block hash.
// pub shard_block_hash: CryptoHash,
//}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct BeaconBlockHeaderBody {
/// Parent hash.
Expand All @@ -31,6 +20,7 @@ pub struct BeaconBlockHeaderBody {
pub index: u64,
pub merkle_root_tx: MerkleHash,
pub merkle_root_state: MerkleHash,
/// Authority proposals.
pub authority_proposal: Vec<AuthorityProposal>,
}

Expand Down Expand Up @@ -80,8 +70,8 @@ impl BeaconBlockHeader {

impl Header for BeaconBlockHeader {
fn hash(&self) -> CryptoHash {
// WTF?
hash_struct(&self)
// TODO: must be hash of the block.
hash_struct(&self.body)
}

fn index(&self) -> u64 {
Expand Down
6 changes: 3 additions & 3 deletions core/primitives/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub type UID = u64;
/// Account alias. Can be an easily identifiable string, when hashed creates the AccountId.
pub type AccountAlias = String;
/// Public key alias. Used to human readable public key.
pub type PublicKeyAlias = String;
pub type ReadablePublicKey = String;
/// Account identifier. Provides access to user's state.
pub type AccountId = CryptoHash;
// TODO: Separate cryptographic hash from the hashmap hash.
Expand All @@ -30,8 +30,8 @@ impl<'a> From<&'a AccountAlias> for AccountId {
}
}

impl<'a> From<&'a PublicKeyAlias> for PublicKey {
fn from(alias: &PublicKeyAlias) -> Self {
impl<'a> From<&'a ReadablePublicKey> for PublicKey {
fn from(alias: &ReadablePublicKey) -> Self {
PublicKey::from(alias)
}
}
Expand Down
7 changes: 4 additions & 3 deletions node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use primitives::types::{AccountAlias, PublicKeyAlias};
use serde_json;

use node_runtime::chain_spec::ChainSpec;
use primitives::types::{AccountAlias, ReadablePublicKey};

#[derive(Serialize, Deserialize)]
#[serde(remote = "ChainSpec")]
struct ChainSpecRef {
accounts: Vec<(AccountAlias, PublicKeyAlias, u64)>,
initial_authorities: Vec<(PublicKeyAlias, u64)>,
accounts: Vec<(AccountAlias, ReadablePublicKey, u64)>,
initial_authorities: Vec<(ReadablePublicKey, u64)>,
genesis_wasm: Vec<u8>,
beacon_chain_epoch_length: u64,
beacon_chain_num_seats_per_slot: u64,
Expand Down
9 changes: 5 additions & 4 deletions node/cli2/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use std::fs::File;
use std::io::Read;
use std::path::Path;

use node_runtime::chain_spec::ChainSpec;
use primitives::types::{AccountAlias, PublicKeyAlias};
use serde_json;

use node_runtime::chain_spec::ChainSpec;
use primitives::types::{AccountAlias, ReadablePublicKey};

#[derive(Serialize, Deserialize)]
#[serde(remote = "ChainSpec")]
struct ChainSpecRef {
accounts: Vec<(AccountAlias, PublicKeyAlias, u64)>,
initial_authorities: Vec<(PublicKeyAlias, u64)>,
accounts: Vec<(AccountAlias, ReadablePublicKey, u64)>,
initial_authorities: Vec<(ReadablePublicKey, u64)>,
genesis_wasm: Vec<u8>,
beacon_chain_epoch_length: u64,
beacon_chain_num_seats_per_slot: u64,
Expand Down
6 changes: 3 additions & 3 deletions node/runtime/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use primitives::types::{AccountAlias, PublicKeyAlias};
use primitives::types::{AccountAlias, ReadablePublicKey};

/// Specification of the blockchain in general.
pub struct ChainSpec {
/// Genesis state accounts.
pub accounts: Vec<(AccountAlias, PublicKeyAlias, u64)>,
pub accounts: Vec<(AccountAlias, ReadablePublicKey, u64)>,

/// Genesis smart contract code.
pub genesis_wasm: Vec<u8>,

/// Genesis state authorities that bootstrap the chain.
pub initial_authorities: Vec<(PublicKeyAlias, u64)>,
pub initial_authorities: Vec<(ReadablePublicKey, u64)>,

pub beacon_chain_epoch_length: u64,
pub beacon_chain_num_seats_per_slot: u64,
Expand Down
4 changes: 2 additions & 2 deletions node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use primitives::hash::CryptoHash;
use primitives::signature::PublicKey;
use primitives::traits::{Decode, Encode};
use primitives::types::{
AccountAlias, AccountId, MerkleHash, PublicKeyAlias, SignedTransaction, ViewCall,
AccountAlias, AccountId, MerkleHash, ReadablePublicKey, SignedTransaction, ViewCall,
ViewCallResult, PromiseId,
};
use primitives::utils::concat;
Expand Down Expand Up @@ -323,7 +323,7 @@ impl Runtime {

pub fn apply_genesis_state(
&self,
balances: &[(AccountAlias, PublicKeyAlias, u64)],
balances: &[(AccountAlias, ReadablePublicKey, u64)],
wasm_binary: &[u8],
) -> MerkleHash {
let mut state_db_update =
Expand Down