Skip to content

Commit

Permalink
[sync] Checkpoint basic types, store, logic and messages (MystenLabs#…
Browse files Browse the repository at this point in the history
…1100)

* Initial waypoint logic
* More flexible sequence_numbers
* Added proper error type
* Move waypoints to base types
* Allow generic items
* Added database for checkpoints
* Logic to open the DB
* Added watermark levels
* Simplify interface for sequence numbers
* Return latest checkpoint watermark
* Added errors and test for errors
* Added proposal logic to checkpoints
* Use descriptive types
* Integrate waypoints and diffs into checkpointing
* Integrate name into proposal
* Separate tests + key checkpoints by AuthorityName
* Ser + Deser key structs
* Define checkpoint structures for messaging
* Added negative test
* Added docs and proper Request / Response structures
* Align authority checkpoint with new checkpoint types
* Add authority information to checkpoint store
* Use arc swap to cache proposals
* Define handlers to deal with checkpoint related messages
* Added more internal functions for checkpointing
* Complete external handlers
* Complete interface
* Added tests to getting and setting checkpoint cert
* Add licence
* Persist locals
* Add crash recovery test
* Added an integration test for the whole flow
* Link checkpointing to authority
* Register new batches with the checkpoint mechanism
* Added checkpoint command
* Added checkpoint request / response endpoint
* Added client side handlers for the checkpoint calls
* Added start-up and batch follow tests
* Added fragments + fixed tests
* Skeleton to process fragments of checkpoints
* More logic about fragments
* Find large components from checkpoint fragments
* Logic to inject fragments from consensus, and order fragments from consensus
* Added consensus abstraction
* Added more tests for fragment processing
* Improve the fragment consensus output processing
* Added extensive test showing the active flow
* Added second checkpoint reconstruction strategy
* Ergonomic generic errors
* Protect the checkpoint logic using a mutex
* Make tests more lenient
* Make all checkpoint function &mut
* Changes from the review

Co-authored-by: George Danezis <[email protected]>
Co-authored-by: Alberto Sonnino <[email protected]>
  • Loading branch information
3 people authored May 18, 2022
1 parent acb2b97 commit 22c8012
Show file tree
Hide file tree
Showing 33 changed files with 4,433 additions and 81 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

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

72 changes: 72 additions & 0 deletions crates/sui-network/src/generated/sui.validator.Validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,30 @@ pub mod validator_client {
);
self.inner.unary(request.into_request(), path, codec).await
}
pub async fn checkpoint(
&mut self,
request: impl tonic::IntoRequest<
sui_types::messages_checkpoint::CheckpointRequest,
>,
) -> Result<
tonic::Response<sui_types::messages_checkpoint::CheckpointResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::new(
tonic::Code::Unknown,
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = mysten_network::codec::BincodeCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/sui.validator.Validator/Checkpoint",
);
self.inner.unary(request.into_request(), path, codec).await
}
pub async fn batch_info(
&mut self,
request: impl tonic::IntoRequest<sui_types::messages::BatchInfoRequest>,
Expand Down Expand Up @@ -272,6 +296,13 @@ pub mod validator_server {
tonic::Response<sui_types::messages::TransactionInfoResponse>,
tonic::Status,
>;
async fn checkpoint(
&self,
request: tonic::Request<sui_types::messages_checkpoint::CheckpointRequest>,
) -> Result<
tonic::Response<sui_types::messages_checkpoint::CheckpointResponse>,
tonic::Status,
>;
///Server streaming response type for the BatchInfo method.
type BatchInfoStream: futures_core::Stream<
Item = Result<sui_types::messages::BatchInfoResponseItem, tonic::Status>,
Expand Down Expand Up @@ -581,6 +612,47 @@ pub mod validator_server {
};
Box::pin(fut)
}
"/sui.validator.Validator/Checkpoint" => {
#[allow(non_camel_case_types)]
struct CheckpointSvc<T: Validator>(pub Arc<T>);
impl<
T: Validator,
> tonic::server::UnaryService<
sui_types::messages_checkpoint::CheckpointRequest,
> for CheckpointSvc<T> {
type Response = sui_types::messages_checkpoint::CheckpointResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<
sui_types::messages_checkpoint::CheckpointRequest,
>,
) -> Self::Future {
let inner = self.0.clone();
let fut = async move { (*inner).checkpoint(request).await };
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let inner = self.inner.clone();
let fut = async move {
let inner = inner.0;
let method = CheckpointSvc(inner);
let codec = mysten_network::codec::BincodeCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/sui.validator.Validator/BatchInfo" => {
#[allow(non_camel_case_types)]
struct BatchInfoSvc<T: Validator>(pub Arc<T>);
Expand Down
9 changes: 9 additions & 0 deletions crates/sui-network/tests/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ fn bootstrap() {
.codec_path(codec_path)
.build(),
)
.method(
Method::builder()
.name("checkpoint")
.route_name("Checkpoint")
.input_type("sui_types::messages_checkpoint::CheckpointRequest")
.output_type("sui_types::messages_checkpoint::CheckpointResponse")
.codec_path(codec_path)
.build(),
)
.method(
Method::builder()
.name("batch_info")
Expand Down
1 change: 1 addition & 0 deletions crates/sui-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ once_cell = "1.10.0"
rand = "0.7.3"
serde = { version = "1.0.137", features = ["derive"] }
ed25519-dalek = { version = "1.0.1", features = ["batch", "serde"] }
curve25519-dalek = { version = "3", default-features = false, features = ["serde"] }
serde-name = "0.2.0"
sha3 = "0.10.1"
thiserror = "1.0.31"
Expand Down
39 changes: 34 additions & 5 deletions crates/sui-types/src/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,37 @@
// SPDX-License-Identifier: Apache-2.0

use std::collections::{HashMap, HashSet};

use crate::crypto::PublicKeyBytes;
use crate::error::SuiError;

use hex::FromHex;
use rand::Rng;
use serde::{Deserialize, Serialize};
use std::borrow::Borrow;

use std::convert::{TryFrom, TryInto};
use std::fmt;
use std::str::FromStr;

use crate::crypto::PublicKeyBytes;
use crate::error::SuiError;
use crate::sui_serde::Base64;
use crate::sui_serde::Hex;
use crate::sui_serde::Readable;

use anyhow::anyhow;
use base64ct::Encoding;
use digest::Digest;
use hex::FromHex;

use move_core_types::account_address::AccountAddress;
use move_core_types::ident_str;
use move_core_types::identifier::IdentStr;
use opentelemetry::{global, Context};
use rand::Rng;

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use serde_with::serde_as;
use serde_with::Bytes;

use sha3::Sha3_256;

#[cfg(test)]
Expand Down Expand Up @@ -189,6 +198,14 @@ pub struct ObjectDigest(
pub [u8; 32],
); // We use SHA3-256 hence 32 bytes here

#[serde_as]
#[derive(Eq, PartialEq, Ord, PartialOrd, Copy, Clone, Hash, Serialize, Deserialize, JsonSchema)]
pub struct TransactionEffectsDigest(
#[schemars(with = "Base64")]
#[serde_as(as = "Readable<Base64, Bytes>")]
pub [u8; TRANSACTION_DIGEST_LENGTH],
);

pub const TX_CONTEXT_MODULE_NAME: &IdentStr = ident_str!("TxContext");
pub const TX_CONTEXT_STRUCT_NAME: &IdentStr = TX_CONTEXT_MODULE_NAME;

Expand Down Expand Up @@ -313,6 +330,18 @@ pub fn context_from_digest(digest: TransactionDigest) -> Context {
global::get_text_map_propagator(|propagator| propagator.extract(&carrier))
}

impl Borrow<[u8]> for TransactionDigest {
fn borrow(&self) -> &[u8] {
&self.0
}
}

impl Borrow<[u8]> for &TransactionDigest {
fn borrow(&self) -> &[u8] {
&self.0
}
}

impl ObjectDigest {
pub const MIN: ObjectDigest = ObjectDigest([u8::MIN; 32]);
pub const MAX: ObjectDigest = ObjectDigest([u8::MAX; 32]);
Expand Down
10 changes: 10 additions & 0 deletions crates/sui-types/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ pub enum SuiError {
SubscriptionItemsDroppedError(u64),
#[error("Subscription service closed.")]
SubscriptionServiceClosed,
#[error("Checkpointing error: {}", error)]
CheckpointingError { error: String },

// Move module publishing related errors
#[error("Failed to load the Move module, reason: {error:?}.")]
Expand Down Expand Up @@ -363,6 +365,14 @@ impl From<tonic::Status> for SuiError {
}
}

impl std::convert::From<&str> for SuiError {
fn from(error: &str) -> Self {
SuiError::GenericAuthorityError {
error: error.to_string(),
}
}
}

impl ExecutionStateError for SuiError {
fn node_error(&self) -> bool {
matches!(
Expand Down
5 changes: 5 additions & 0 deletions crates/sui-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ pub mod gas;
pub mod gas_coin;
pub mod id;
pub mod messages;
pub mod messages_checkpoint;
pub mod move_package;
pub mod object;
pub mod signature_seed;
pub mod storage;
pub mod sui_serde;
pub mod waypoint;

#[path = "./unit_tests/utils.rs"]
pub mod utils;

/// 0x1-- account address where Move stdlib modules are stored
/// Same as the ObjectID
Expand Down
4 changes: 4 additions & 0 deletions crates/sui-types/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,10 @@ impl TransactionEffects {
auth_signature: EmptySignInfo {},
}
}

pub fn digest(&self) -> TransactionEffectsDigest {
TransactionEffectsDigest(sha3_hash(self))
}
}

impl BcsSignable for TransactionEffects {}
Expand Down
Loading

0 comments on commit 22c8012

Please sign in to comment.