Skip to content

Commit

Permalink
[core] Use Envelope for TransactionEffects
Browse files Browse the repository at this point in the history
  • Loading branch information
lxfind committed Nov 12, 2022
1 parent fb7be5a commit 071a963
Show file tree
Hide file tree
Showing 30 changed files with 161 additions and 210 deletions.
10 changes: 5 additions & 5 deletions crates/sui-benchmark/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ExecutionEffects {
pub fn mutated(&self) -> Vec<(ObjectRef, Owner)> {
match self {
ExecutionEffects::CertifiedTransactionEffects(certified_effects) => {
certified_effects.effects.mutated.clone()
certified_effects.data().mutated.clone()
}
ExecutionEffects::SuiTransactionEffects(sui_tx_effects) => sui_tx_effects
.mutated
Expand All @@ -59,7 +59,7 @@ impl ExecutionEffects {
pub fn created(&self) -> Vec<(ObjectRef, Owner)> {
match self {
ExecutionEffects::CertifiedTransactionEffects(certified_effects) => {
certified_effects.effects.created.clone()
certified_effects.data().created.clone()
}
ExecutionEffects::SuiTransactionEffects(sui_tx_effects) => sui_tx_effects
.created
Expand All @@ -73,7 +73,7 @@ impl ExecutionEffects {
pub fn quorum_sig(&self) -> Option<&AuthorityStrongQuorumSignInfo> {
match self {
ExecutionEffects::CertifiedTransactionEffects(certified_effects) => {
Some(&certified_effects.auth_signature)
Some(certified_effects.auth_sig())
}
ExecutionEffects::SuiTransactionEffects(_) => None,
}
Expand All @@ -82,7 +82,7 @@ impl ExecutionEffects {
pub fn gas_object(&self) -> (ObjectRef, Owner) {
match self {
ExecutionEffects::CertifiedTransactionEffects(certified_effects) => {
certified_effects.effects.gas_object
certified_effects.data().gas_object
}
ExecutionEffects::SuiTransactionEffects(sui_tx_effects) => {
let refe = &sui_tx_effects.gas_object;
Expand Down Expand Up @@ -275,7 +275,7 @@ impl ValidatorProxy for FullNodeProxy {
}

async fn reconfig(&self) {
// TOOD poll FN untils it has proceeds to next epoch
// TODO poll FN until it has proceeds to next epoch
// and update self.committee
return;
}
Expand Down
30 changes: 17 additions & 13 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ impl AuthorityState {
let digest = *certificate.digest();
debug!(?digest, "handle_certificate_with_effects");
fp_ensure!(
effects.effects.transaction_digest == digest,
effects.data().transaction_digest == digest,
SuiError::ErrorWhileProcessingCertificate {
err: "effects/tx digest mismatch".to_string()
}
Expand All @@ -707,7 +707,7 @@ impl AuthorityState {
if certificate.contains_shared_object() {
self.database.acquire_shared_locks_from_effects(
certificate,
&effects.effects,
effects.data(),
&tx_guard,
)?;
}
Expand All @@ -723,7 +723,7 @@ impl AuthorityState {
error!(
?expected_effects_digest,
?observed_effects_digest,
?effects.effects,
expected_effects=?effects.data(),
?resp.signed_effects,
input_objects = ?certificate.data().data.input_objects(),
"Locally executed effects do not match canonical effects!");
Expand Down Expand Up @@ -891,7 +891,7 @@ impl AuthorityState {
};

let input_object_count = inner_temporary_store.objects.len();
let shared_object_count = signed_effects.effects.shared_objects.len();
let shared_object_count = signed_effects.data().shared_objects.len();

// If commit_certificate returns an error, tx_guard will be dropped and the certificate
// will be persisted in the log for later recovery.
Expand Down Expand Up @@ -1073,7 +1073,8 @@ impl AuthorityState {
);

// TODO: Distribute gas charge and rebate, which can be retrieved from effects.
let signed_effects = effects.to_sign_effects(self.epoch(), &self.name, &*self.secret);
let signed_effects =
SignedTransactionEffects::new(self.epoch(), effects, &*self.secret, self.name);
Ok((inner_temp_store, signed_effects))
}

Expand Down Expand Up @@ -1139,7 +1140,7 @@ impl AuthorityState {
.iter()
.map(|o| o.object_id()),
effects
.effects
.data()
.all_mutated()
.map(|(obj_ref, owner, _kind)| (*obj_ref, *owner)),
cert.data()
Expand Down Expand Up @@ -1204,14 +1205,14 @@ impl AuthorityState {
// Emit events
if let Some(event_handler) = &self.event_handler {
event_handler
.process_events(&effects.effects, timestamp_ms, seq)
.process_events(effects.data(), timestamp_ms, seq)
.await
.tap_ok(|_| self.metrics.post_processing_total_tx_had_event_processed.inc())
.tap_err(|e| warn!(tx_digest=?digest, "Post processing - Couldn't process events for tx: {}", e))?;

self.metrics
.post_processing_total_events_emitted
.inc_by(effects.effects.events.len() as u64);
.inc_by(effects.data().events.len() as u64);
}

Ok(())
Expand Down Expand Up @@ -2106,15 +2107,18 @@ impl AuthorityState {
// obtain an effects certificate at the current epoch.
if let Some(effects) = info.signed_effects.take() {
let cur_epoch = self.epoch();
let new_effects = if effects.auth_signature.epoch < cur_epoch {
let new_effects = if effects.epoch() < cur_epoch {
debug!(
effects_epoch=?effects.auth_signature.epoch,
effects_epoch=?effects.epoch(),
?cur_epoch,
"Re-signing the effects with the current epoch"
);
effects
.effects
.to_sign_effects(cur_epoch, &self.name, &*self.secret)
SignedTransactionEffects::new(
cur_epoch,
effects.into_data(),
&*self.secret,
self.name,
)
} else {
effects
};
Expand Down
14 changes: 7 additions & 7 deletions crates/sui-core/src/authority/authority_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ impl<S: Eq + Debug + Serialize + for<'de> Deserialize<'de>> SuiDataStore<S> {
self.perpetual_tables
.effects
.get(transaction_digest)?
.map(|data| data.effects)
.map(|data| data.into_data())
.ok_or(SuiError::TransactionNotFound {
digest: *transaction_digest,
})
Expand Down Expand Up @@ -347,7 +347,7 @@ impl<S: Eq + Debug + Serialize + for<'de> Deserialize<'de>> SuiDataStore<S> {
}

/// When making changes, please see if check_sequenced_input_objects() below needs
/// similiar changes as well.
/// similar changes as well.
pub fn get_missing_input_objects(
&self,
digest: &TransactionDigest,
Expand Down Expand Up @@ -398,7 +398,7 @@ impl<S: Eq + Debug + Serialize + for<'de> Deserialize<'de>> SuiDataStore<S> {
}

/// When making changes, please see if get_missing_input_objects() above needs
/// similiar changes as well.
/// similar changes as well.
pub fn check_sequenced_input_objects(
&self,
digest: &TransactionDigest,
Expand Down Expand Up @@ -748,7 +748,7 @@ impl<S: Eq + Debug + Serialize + for<'de> Deserialize<'de>> SuiDataStore<S> {
.await?;

self.effects_notify_read
.notify(transaction_digest, &effects.effects);
.notify(transaction_digest, effects.data());

Ok(seq)
}
Expand Down Expand Up @@ -790,10 +790,10 @@ impl<S: Eq + Debug + Serialize + for<'de> Deserialize<'de>> SuiDataStore<S> {
for (_, (object, kind)) in mutated_objects {
temporary_store.write_object(&ctx, object, kind);
}
for obj_ref in &effects.effects.deleted {
for obj_ref in &effects.data().deleted {
temporary_store.delete_object(&ctx, &obj_ref.0, obj_ref.1, DeleteKind::Normal);
}
for obj_ref in &effects.effects.wrapped {
for obj_ref in &effects.data().wrapped {
temporary_store.delete_object(&ctx, &obj_ref.0, obj_ref.1, DeleteKind::Wrap);
}
let (inner_temporary_store, _events) = temporary_store.into_inner();
Expand Down Expand Up @@ -1466,7 +1466,7 @@ impl SuiDataStore<AuthoritySignInfo> {
.get(transaction_digest)?
.map(|t| t.into());
Ok(if let Some(signed_tx) = tx {
signed_tx.auth_sig().epoch == cur_epoch
signed_tx.epoch() == cur_epoch
} else {
false
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{

use crate::authority_active::checkpoint_driver::CheckpointMetrics;
use std::{collections::BTreeSet, sync::Arc, time::Duration};
use sui_types::message_envelope::Message;
use sui_types::messages::ExecutionStatus;

use sui_macros::*;
Expand Down Expand Up @@ -55,11 +56,11 @@ async fn checkpoint_active_flow_happy_path() {

// Check whether this is a success?
assert!(matches!(
effects.effects.status,
effects.data().status,
ExecutionStatus::Success { .. }
));
println!("Execute at {:?}", tokio::time::Instant::now());
println!("Effects: {:?}", effects.effects.digest());
println!("Effects: {:?}", effects.data().digest());

// Add some delay between transactions
tokio::time::sleep(Duration::from_secs(27)).await;
Expand Down Expand Up @@ -147,7 +148,7 @@ async fn checkpoint_active_flow_crash_client_with_gossip() {

// Check whether this is a success?
assert!(matches!(
_response.signed_effects.unwrap().effects.status,
_response.signed_effects.unwrap().into_data().status,
ExecutionStatus::Success { .. }
));
println!("Execute at {:?}", tokio::time::Instant::now());
Expand Down Expand Up @@ -237,7 +238,7 @@ async fn checkpoint_active_flow_crash_client_no_gossip() {

// Check whether this is a success?
assert!(matches!(
_response.signed_effects.unwrap().effects.status,
_response.signed_effects.unwrap().into_data().status,
ExecutionStatus::Success { .. }
));
println!("Execute at {:?}", tokio::time::Instant::now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ async fn pending_exec_notify_ready_certificates() {

// Check whether this is a success?
assert!(matches!(
effects.effects.status,
effects.data().status,
ExecutionStatus::Success { .. }
));
println!("Execute at {:?}", tokio::time::Instant::now());
Expand Down Expand Up @@ -187,7 +187,7 @@ async fn pending_exec_full() {

// Check whether this is a success?
assert!(matches!(
effects.effects.status,
effects.data().status,
ExecutionStatus::Success { .. }
));
println!("Execute at {:?}", tokio::time::Instant::now());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use sui_types::batch::{AuthorityBatch, SignedBatch, UpdateItem};
use sui_types::committee::Committee;
use sui_types::crypto::{get_key_pair, AuthorityKeyPair};
use sui_types::error::SuiError;
use sui_types::message_envelope::Message;
use sui_types::messages::{
AccountInfoRequest, AccountInfoResponse, BatchInfoRequest, BatchInfoResponseItem,
CertifiedTransaction, CheckpointStreamRequest, CommitteeInfoRequest, CommitteeInfoResponse,
Expand Down
18 changes: 10 additions & 8 deletions crates/sui-core/src/authority_aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,19 @@ impl EffectsStakeMap {
weight: StakeUnit,
committee: &Committee,
) -> bool {
let epoch = effects.auth_signature.epoch;
let epoch = effects.epoch();
let digest = *effects.digest();
let (effects, sig) = effects.into_data_and_sig();
let entry = self
.effects_map
.entry((epoch, *effects.digest()))
.entry((epoch, digest))
.or_insert(EffectsStakeInfo {
stake: 0,
effects: effects.effects,
effects,
signatures: vec![],
});
entry.stake += weight;
entry.signatures.push(effects.auth_signature);
entry.signatures.push(sig);

if entry.stake >= committee.quorum_threshold() {
self.efects_cert = CertifiedTransactionEffects::new(
Expand Down Expand Up @@ -530,8 +532,8 @@ where
.signed_effects
.ok_or(SuiError::AuthorityInformationUnavailable)?;

trace!(tx_digest = ?cert_digest, dependencies =? &signed_effects.effects.dependencies, "Got dependencies from source");
for returned_digest in &signed_effects.effects.dependencies {
trace!(tx_digest = ?cert_digest, dependencies =? &signed_effects.data().dependencies, "Got dependencies from source");
for returned_digest in &signed_effects.data().dependencies {
trace!(tx_digest =? returned_digest, "Found parent of missing cert");

let inner_transaction_info = source_client
Expand Down Expand Up @@ -1677,7 +1679,7 @@ where
Ok(VerifiedTransactionInfoResponse {
signed_transaction: Some(inner_signed_transaction),
..
}) if inner_signed_transaction.auth_sig().epoch == self.committee.epoch => {
}) if inner_signed_transaction.epoch() == self.committee.epoch => {
let tx_digest = inner_signed_transaction.digest();
debug!(tx_digest = ?tx_digest, ?name, weight, "Received signed transaction from validator handle_transaction");
state.signatures.push(inner_signed_transaction.into_inner().into_data_and_sig().1);
Expand Down Expand Up @@ -1741,7 +1743,7 @@ where
?tx_digest,
name=?name.concise(),
expected_epoch=?self.committee.epoch,
returned_epoch=?inner_signed.auth_sig().epoch,
returned_epoch=?inner_signed.epoch(),
"Returned signed transaction is from wrong epoch"
);
}
Expand Down
4 changes: 3 additions & 1 deletion crates/sui-core/src/checkpoints/causal_order_effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
sync::Arc,
};

use sui_types::message_envelope::Message;
use sui_types::{
base_types::{ExecutionDigests, TransactionDigest},
error::{SuiError, SuiResult},
Expand Down Expand Up @@ -196,7 +197,7 @@ impl EffectsStore for Arc<AuthorityStore> {
.effects
.multi_get(transactions)?
.into_iter()
.map(|item| item.map(|x| x.effects))
.map(|item| item.map(|x| x.into_data()))
.collect())
}
}
Expand Down Expand Up @@ -274,6 +275,7 @@ mod tests {
use crate::checkpoints::CheckpointStore;
use fastcrypto::traits::KeyPair;
use rand::{prelude::StdRng, SeedableRng};
use sui_types::message_envelope::Message;
use sui_types::{
base_types::{ExecutionDigests, ObjectDigest, ObjectID, SequenceNumber, TransactionDigest},
gas::GasCostSummary,
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-core/src/checkpoints/tests/checkpoint_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,7 @@ async fn checkpoint_messaging_flow() {

// Check whether this is a success?
assert!(matches!(
effects.effects.status,
effects.data().status,
ExecutionStatus::Success { .. }
));

Expand Down Expand Up @@ -1996,7 +1996,7 @@ async fn test_no_more_fragments() {

// Check whether this is a success?
assert!(matches!(
effects.effects.status,
effects.data().status,
ExecutionStatus::Success { .. }
));

Expand Down
4 changes: 2 additions & 2 deletions crates/sui-core/src/epoch/tests/reconfiguration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ async fn test_cross_epoch_effects_cert() {
net.committee.epoch += 1;
// Call to execute_transaction can still succeed.
let (tx_cert, effects_cert) = net.execute_transaction(&transaction).await.unwrap();
assert_eq!(tx_cert.auth_sig().epoch, 0);
assert_eq!(effects_cert.auth_signature.epoch, 1);
assert_eq!(tx_cert.epoch(), 0);
assert_eq!(effects_cert.epoch(), 1);
}

fn enable_reconfig(states: &[Arc<AuthorityState>]) {
Expand Down
Loading

0 comments on commit 071a963

Please sign in to comment.