Skip to content

Commit

Permalink
[sui-node] Add epochs to key signed structures (MystenLabs#1534)
Browse files Browse the repository at this point in the history
* Added epochid to committee
* Added epoch to transaction sign & cert
* Verify epoch when verifying cert
* Init config and cmtee with epoch

Co-authored-by: George Danezis <[email protected]>
gdanezis and George Danezis authored Apr 25, 2022

Verified

This commit was signed with the committer’s verified signature.
matux Matias Pequeno
1 parent 6c9817d commit a230070
Showing 18 changed files with 203 additions and 109 deletions.
1 change: 1 addition & 0 deletions sui/src/benchmark/transaction_creator.rs
Original file line number Diff line number Diff line change
@@ -68,6 +68,7 @@ fn make_serialized_cert(
) -> Vec<u8> {
// Make certificate
let mut certificate = CertifiedTransaction::new(tx);
certificate.epoch = committee.epoch();
for i in 0..committee.quorum_threshold() {
let (pubx, secx) = keys.get(i).unwrap();
let sig = AuthoritySignature::new(&certificate.transaction.data, secx);
2 changes: 1 addition & 1 deletion sui/src/benchmark/validator_preparer.rs
Original file line number Diff line number Diff line change
@@ -88,7 +88,7 @@ impl ValidatorPreparer {
let name = *key_pair.public_key_bytes();
keys.push((name, key_pair));
}
let committee = Committee::new(keys.iter().map(|(k, _)| (*k, 1)).collect());
let committee = Committee::new(0, keys.iter().map(|(k, _)| (*k, 1)).collect());

match running_mode {
RunningMode::LocalSingleValidatorProcess => {
5 changes: 3 additions & 2 deletions sui/src/config.rs
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ use std::sync::Mutex;
use sui_framework::DEFAULT_FRAMEWORK_PATH;
use sui_network::network::PortAllocator;
use sui_types::base_types::*;
use sui_types::committee::Committee;
use sui_types::committee::{Committee, EpochId};
use sui_types::crypto::{get_key_pair, KeyPair};
use tracing::log::trace;

@@ -148,6 +148,7 @@ impl Display for WalletConfig {

#[derive(Serialize, Deserialize)]
pub struct NetworkConfig {
pub epoch: EpochId,
pub authorities: Vec<AuthorityPrivateInfo>,
pub buffer_size: usize,
pub loaded_move_packages: Vec<(PathBuf, ObjectID)>,
@@ -210,7 +211,7 @@ impl From<&NetworkConfig> for Committee {
.iter()
.map(|authority| (*authority.key_pair.public_key_bytes(), authority.stake))
.collect();
Committee::new(voting_rights)
Committee::new(network_config.epoch, voting_rights)
}
}

6 changes: 4 additions & 2 deletions sui/src/gateway_config.rs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ use sui_core::gateway_state::{GatewayClient, GatewayState};
use sui_network::network::NetworkClient;
use sui_network::transport;
use sui_types::base_types::AuthorityName;
use sui_types::committee::Committee;
use sui_types::committee::{Committee, EpochId};

use crate::config::{AuthorityInfo, Config};
use crate::rest_gateway::RestGatewayClient;
@@ -81,6 +81,7 @@ impl GatewayType {

#[derive(Serialize, Deserialize)]
pub struct GatewayConfig {
pub epoch: EpochId,
pub authorities: Vec<AuthorityInfo>,
pub send_timeout: Duration,
pub recv_timeout: Duration,
@@ -97,7 +98,7 @@ impl GatewayConfig {
.iter()
.map(|authority| (authority.name, 1))
.collect();
Committee::new(voting_rights)
Committee::new(self.epoch, voting_rights)
}

pub fn make_authority_clients(&self) -> BTreeMap<AuthorityName, NetworkAuthorityClient> {
@@ -119,6 +120,7 @@ impl GatewayConfig {
impl Default for GatewayConfig {
fn default() -> Self {
Self {
epoch: 0,
authorities: vec![],
send_timeout: Duration::from_micros(4000000),
recv_timeout: Duration::from_micros(4000000),
4 changes: 3 additions & 1 deletion sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
@@ -276,6 +276,7 @@ impl SuiNetwork {
);

let committee = Committee::new(
config.epoch,
config
.authorities
.iter()
@@ -341,6 +342,7 @@ pub async fn genesis(
);

let mut network_config = NetworkConfig {
epoch: 0,
authorities: vec![],
buffer_size: DEFAULT_MAX_DATAGRAM_SIZE,
loaded_move_packages: vec![],
@@ -420,7 +422,7 @@ pub async fn genesis(
}
}

let committee = Committee::new(voting_right);
let committee = Committee::new(network_config.epoch, voting_right);
for authority in &network_config.authorities {
make_server_with_genesis_ctx(
authority,
6 changes: 4 additions & 2 deletions sui_core/src/authority.rs
Original file line number Diff line number Diff line change
@@ -211,7 +211,8 @@ impl AuthorityState {
}
let owned_objects = transaction_input_checker::filter_owned_objects(&all_objects);

let signed_transaction = SignedTransaction::new(transaction, self.name, &*self.secret);
let signed_transaction =
SignedTransaction::new(self.committee.epoch, transaction, self.name, &*self.secret);

// Check and write locks, to signed transaction, into the database
// The call to self.set_transaction_lock checks the lock is not conflicting,
@@ -363,7 +364,8 @@ impl AuthorityState {
gas_status,
)?;
// TODO: Distribute gas charge and rebate, which can be retrieved from effects.
let signed_effects = effects.to_sign_effects(&self.name, &*self.secret);
let signed_effects =
effects.to_sign_effects(self.committee.epoch, &self.name, &*self.secret);

// Update the database in an atomic manner
self.update_state(temporary_store, &certificate, &signed_effects)
1 change: 1 addition & 0 deletions sui_core/src/authority_aggregator.rs
Original file line number Diff line number Diff line change
@@ -842,6 +842,7 @@ where
if state.good_stake >= threshold {
state.certificate =
Some(CertifiedTransaction::new_with_signatures(
self.committee.epoch(),
transaction_ref.clone(),
state.signatures.clone(),
));
8 changes: 6 additions & 2 deletions sui_core/src/unit_tests/authority_aggregator_tests.rs
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@ pub async fn init_local_authorities(
voting_rights.insert(authority_name, 1);
key_pairs.push((authority_name, key_pair));
}
let committee = Committee::new(voting_rights);
let committee = Committee::new(0, voting_rights);

let mut clients = BTreeMap::new();
for ((authority_name, secret), objects) in key_pairs.into_iter().zip(genesis_objects) {
@@ -201,7 +201,11 @@ async fn extract_cert<A: AuthorityAPI>(
let stake: usize = votes.iter().map(|(name, _)| committee.weight(name)).sum();
assert!(stake >= committee.quorum_threshold());

CertifiedTransaction::new_with_signatures(transaction.unwrap().to_transaction(), votes)
CertifiedTransaction::new_with_signatures(
committee.epoch(),
transaction.unwrap().to_transaction(),
votes,
)
}

async fn do_cert<A: AuthorityAPI>(
3 changes: 2 additions & 1 deletion sui_core/src/unit_tests/authority_tests.rs
Original file line number Diff line number Diff line change
@@ -1183,7 +1183,7 @@ fn init_state_parameters() -> (Committee, SuiAddress, KeyPair, Arc<AuthorityStor
/* address */ *authority_key.public_key_bytes(),
/* voting right */ 1,
);
let committee = Committee::new(authorities);
let committee = Committee::new(0, authorities);

// Create a random directory to store the DB

@@ -1261,6 +1261,7 @@ fn init_certified_transfer_transaction(
let transfer_transaction =
init_transfer_transaction(sender, secret, recipient, object_ref, gas_object_ref);
let vote = SignedTransaction::new(
0,
transfer_transaction.clone(),
authority_state.name,
&*authority_state.secret,
4 changes: 2 additions & 2 deletions sui_core/src/unit_tests/batch_tests.rs
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ where
/* address */ *authority_key.public_key_bytes(),
/* voting right */ 1,
);
let committee = Committee::new(authorities);
let committee = Committee::new(0, authorities);

(committee, authority_address, authority_key)
}
@@ -652,7 +652,7 @@ async fn test_safe_batch_stream() {
println!("init public key {:?}", public_key_bytes);

authorities.insert(public_key_bytes, 1);
let committee = Committee::new(authorities);
let committee = Committee::new(0, authorities);
// Create an authority
let mut opts = rocksdb::Options::default();
opts.set_max_open_files(max_files_authority_tests());
Loading

0 comments on commit a230070

Please sign in to comment.