Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:iotaledger/iota into core-node/f…
Browse files Browse the repository at this point in the history
…ix/rest-api-version-1
  • Loading branch information
muXxer committed Oct 29, 2024
2 parents 72a36e9 + 83f0483 commit 880dc2b
Show file tree
Hide file tree
Showing 33 changed files with 555 additions and 1,383 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ iota-rosetta = { path = "crates/iota-rosetta" }
iota-rpc-loadgen = { path = "crates/iota-rpc-loadgen" }
iota-sdk = { path = "crates/iota-sdk" }
# core-types with json format for REST API
iota-sdk2 = { package = "iota-rust-sdk", git = "ssh://[email protected]/iotaledger/iota-rust-sdk.git", rev = "46d46d64237e001e8e23f322caecb3211c9a8c97", features = ["hash", "serde", "schemars"] }
iota-sdk2 = { package = "iota-rust-sdk", git = "ssh://[email protected]/iotaledger/iota-rust-sdk.git", rev = "ed6173d434c77604ddc93aaa1550168fdbe97b09", features = ["hash", "serde", "schemars"] }
iota-simulator = { path = "crates/iota-simulator" }
iota-snapshot = { path = "crates/iota-snapshot" }
iota-source-validation = { path = "crates/iota-source-validation" }
Expand Down
3 changes: 2 additions & 1 deletion crates/iota-benchmark/tests/simtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,8 @@ mod test {
}

async fn test_protocol_upgrade_compatibility_impl() {
let max_ver = ProtocolVersion::MAX.as_u64();
// TODO: Remove the `+ 1` after we have Protocol version 2
let max_ver = ProtocolVersion::MAX.as_u64() + 1;
let manifest = iota_framework_snapshot::load_bytecode_snapshot_manifest();

let Some((&starting_version, _)) = manifest.range(..max_ver).last() else {
Expand Down
33 changes: 4 additions & 29 deletions crates/iota-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ use iota_types::{
message_envelope::Message,
messages_checkpoint::{
CertifiedCheckpointSummary, CheckpointCommitment, CheckpointContents,
CheckpointContentsDigest, CheckpointDigest, CheckpointRequest, CheckpointRequestV2,
CheckpointResponse, CheckpointResponseV2, CheckpointSequenceNumber, CheckpointSummary,
CheckpointSummaryResponse, CheckpointTimestamp, ECMHLiveObjectSetDigest,
VerifiedCheckpoint,
CheckpointContentsDigest, CheckpointDigest, CheckpointRequest, CheckpointResponse,
CheckpointSequenceNumber, CheckpointSummary, CheckpointSummaryResponse,
CheckpointTimestamp, ECMHLiveObjectSetDigest, VerifiedCheckpoint,
},
messages_consensus::AuthorityCapabilitiesV1,
messages_grpc::{
Expand Down Expand Up @@ -2558,30 +2557,6 @@ impl AuthorityState {
&self,
request: &CheckpointRequest,
) -> IotaResult<CheckpointResponse> {
let summary = match request.sequence_number {
Some(seq) => self
.checkpoint_store
.get_checkpoint_by_sequence_number(seq)?,
None => self.checkpoint_store.get_latest_certified_checkpoint(),
}
.map(|v| v.into_inner());
let contents = match &summary {
Some(s) => self
.checkpoint_store
.get_checkpoint_contents(&s.content_digest)?,
None => None,
};
Ok(CheckpointResponse {
checkpoint: summary,
contents,
})
}

#[instrument(level = "trace", skip_all)]
pub fn handle_checkpoint_request_v2(
&self,
request: &CheckpointRequestV2,
) -> IotaResult<CheckpointResponseV2> {
let summary = if request.certified {
let summary = match request.sequence_number {
Some(seq) => self
Expand All @@ -2606,7 +2581,7 @@ impl AuthorityState {
.get_checkpoint_contents(&s.content_digest())?,
None => None,
};
Ok(CheckpointResponseV2 {
Ok(CheckpointResponse {
checkpoint: summary,
contents,
})
Expand Down
22 changes: 1 addition & 21 deletions crates/iota-core/src/authority_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use iota_types::{
committee::CommitteeWithNetworkMetadata,
error::{IotaError, IotaResult},
iota_system_state::IotaSystemState,
messages_checkpoint::{
CheckpointRequest, CheckpointRequestV2, CheckpointResponse, CheckpointResponseV2,
},
messages_checkpoint::{CheckpointRequest, CheckpointResponse},
messages_grpc::{
HandleCertificateRequestV3, HandleCertificateResponseV2, HandleCertificateResponseV3,
HandleSoftBundleCertificatesRequestV3, HandleSoftBundleCertificatesResponseV3,
Expand Down Expand Up @@ -81,12 +79,6 @@ pub trait AuthorityAPI {
request: CheckpointRequest,
) -> Result<CheckpointResponse, IotaError>;

/// Handles a `CheckpointRequestV2` for this account.
async fn handle_checkpoint_v2(
&self,
request: CheckpointRequestV2,
) -> Result<CheckpointResponseV2, IotaError>;

// This API is exclusively used by the benchmark code.
// Hence it's OK to return a fixed system state type.
async fn handle_system_state_object(
Expand Down Expand Up @@ -243,18 +235,6 @@ impl AuthorityAPI for NetworkAuthorityClient {
.map_err(Into::into)
}

/// Handles a `CheckpointRequestV2` for this account.
async fn handle_checkpoint_v2(
&self,
request: CheckpointRequestV2,
) -> Result<CheckpointResponseV2, IotaError> {
self.client()?
.checkpoint_v2(request)
.await
.map(tonic::Response::into_inner)
.map_err(Into::into)
}

/// This API is exclusively used by the benchmark code.
async fn handle_system_state_object(
&self,
Expand Down
21 changes: 1 addition & 20 deletions crates/iota-core/src/authority_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ use iota_types::{
error::*,
fp_ensure,
iota_system_state::IotaSystemState,
messages_checkpoint::{
CheckpointRequest, CheckpointRequestV2, CheckpointResponse, CheckpointResponseV2,
},
messages_checkpoint::{CheckpointRequest, CheckpointResponse},
messages_consensus::ConsensusTransaction,
messages_grpc::{
HandleCertificateRequestV3, HandleCertificateResponseV2, HandleCertificateResponseV3,
Expand Down Expand Up @@ -927,15 +925,6 @@ impl ValidatorService {
Ok((tonic::Response::new(response), Weight::one()))
}

async fn checkpoint_v2_impl(
&self,
request: tonic::Request<CheckpointRequestV2>,
) -> WrappedServiceResponse<CheckpointResponseV2> {
let request = request.into_inner();
let response = self.state.handle_checkpoint_request_v2(&request)?;
Ok((tonic::Response::new(response), Weight::one()))
}

async fn get_system_state_object_impl(
&self,
_request: tonic::Request<SystemStateRequest>,
Expand Down Expand Up @@ -1213,14 +1202,6 @@ impl Validator for ValidatorService {
handle_with_decoration!(self, checkpoint_impl, request)
}

/// Handles a `CheckpointRequestV2` request.
async fn checkpoint_v2(
&self,
request: tonic::Request<CheckpointRequestV2>,
) -> Result<tonic::Response<CheckpointResponseV2>, tonic::Status> {
handle_with_decoration!(self, checkpoint_v2_impl, request)
}

/// Gets the `IotaSystemState` response.
async fn get_system_state_object(
&self,
Expand Down
16 changes: 8 additions & 8 deletions crates/iota-core/src/checkpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ use iota_types::{
},
message_envelope::Message,
messages_checkpoint::{
CertifiedCheckpointSummary, CheckpointCommitment, CheckpointContents, CheckpointRequestV2,
CheckpointResponseV2, CheckpointSequenceNumber, CheckpointSignatureMessage,
CertifiedCheckpointSummary, CheckpointCommitment, CheckpointContents, CheckpointRequest,
CheckpointResponse, CheckpointSequenceNumber, CheckpointSignatureMessage,
CheckpointSummary, CheckpointSummaryResponse, CheckpointTimestamp, EndOfEpochData,
FullCheckpointContents, SignedCheckpointSummary, TrustedCheckpoint, VerifiedCheckpoint,
VerifiedCheckpointContents,
Expand Down Expand Up @@ -2078,12 +2078,12 @@ async fn diagnose_split_brain(
let client = network_clients
.get(&validator)
.expect("Failed to get network client");
let request = CheckpointRequestV2 {
let request = CheckpointRequest {
sequence_number: Some(local_summary.sequence_number),
request_content: true,
certified: false,
};
client.handle_checkpoint_v2(request)
client.handle_checkpoint(request)
})
.collect::<Vec<_>>();

Expand All @@ -2094,17 +2094,17 @@ async fn diagnose_split_brain(
.zip(digest_name_pair)
.filter_map(|(response, (digest, name))| match response {
Ok(response) => match response {
CheckpointResponseV2 {
CheckpointResponse {
checkpoint: Some(CheckpointSummaryResponse::Pending(summary)),
contents: Some(contents),
} => Some((*name, *digest, summary, contents)),
CheckpointResponseV2 {
CheckpointResponse {
checkpoint: Some(CheckpointSummaryResponse::Certified(_)),
contents: _,
} => {
panic!("Expected pending checkpoint, but got certified checkpoint");
}
CheckpointResponseV2 {
CheckpointResponse {
checkpoint: None,
contents: _,
} => {
Expand All @@ -2114,7 +2114,7 @@ async fn diagnose_split_brain(
);
None
}
CheckpointResponseV2 {
CheckpointResponse {
checkpoint: _,
contents: None,
} => {
Expand Down
76 changes: 0 additions & 76 deletions crates/iota-core/src/safe_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ use iota_types::{
error::{IotaError, IotaResult},
fp_ensure,
iota_system_state::IotaSystemState,
messages_checkpoint::{
CertifiedCheckpointSummary, CheckpointRequest, CheckpointResponse, CheckpointSequenceNumber,
},
messages_grpc::{
HandleCertificateRequestV3, HandleCertificateResponseV2, HandleCertificateResponseV3,
ObjectInfoRequest, ObjectInfoResponse, SystemStateRequest, TransactionInfoRequest,
Expand Down Expand Up @@ -529,79 +526,6 @@ where
Ok(transaction_info)
}

fn verify_checkpoint_sequence(
&self,
expected_seq: Option<CheckpointSequenceNumber>,
checkpoint: &Option<CertifiedCheckpointSummary>,
) -> IotaResult {
let observed_seq = checkpoint.as_ref().map(|c| c.sequence_number);

if let (Some(e), Some(o)) = (expected_seq, observed_seq) {
fp_ensure!(
e == o,
IotaError::from("Expected checkpoint number doesn't match with returned")
);
}
Ok(())
}

fn verify_contents_exist<T, O>(
&self,
request_content: bool,
checkpoint: &Option<T>,
contents: &Option<O>,
) -> IotaResult {
match (request_content, checkpoint, contents) {
// If content is requested, checkpoint is not None, but we are not getting any content,
// it's an error.
// If content is not requested, or checkpoint is None, yet we are still getting content,
// it's an error.
(true, Some(_), None) | (false, _, Some(_)) | (_, None, Some(_)) => Err(
IotaError::from("Checkpoint contents inconsistent with request"),
),
_ => Ok(()),
}
}

fn verify_checkpoint_response(
&self,
request: &CheckpointRequest,
response: &CheckpointResponse,
) -> IotaResult {
// Verify response data was correct for request
let CheckpointResponse {
checkpoint,
contents,
} = &response;
// Checks that the sequence number is correct.
self.verify_checkpoint_sequence(request.sequence_number, checkpoint)?;
self.verify_contents_exist(request.request_content, checkpoint, contents)?;
// Verify signature.
match checkpoint {
Some(c) => {
let epoch_id = c.epoch;
c.verify_with_contents(&*self.get_committee(&epoch_id)?, contents.as_ref())
}
None => Ok(()),
}
}

#[instrument(level = "trace", skip_all, fields(authority = ?self.address.concise()))]
pub async fn handle_checkpoint(
&self,
request: CheckpointRequest,
) -> Result<CheckpointResponse, IotaError> {
let resp = self
.authority_client
.handle_checkpoint(request.clone())
.await?;
self.verify_checkpoint_response(&request, &resp)
.tap_err(|err| {
error!(?err, authority=?self.address, "Client error in handle_checkpoint");
})?;
Ok(resp)
}

#[instrument(level = "trace", skip_all, fields(authority = ?self.address.concise()))]
pub async fn handle_system_state_object(&self) -> Result<IotaSystemState, IotaError> {
self.authority_client
Expand Down
27 changes: 1 addition & 26 deletions crates/iota-core/src/test_authority_clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ use iota_types::{
effects::TransactionEffectsAPI,
error::{IotaError, IotaResult},
iota_system_state::IotaSystemState,
messages_checkpoint::{
CheckpointRequest, CheckpointRequestV2, CheckpointResponse, CheckpointResponseV2,
},
messages_checkpoint::{CheckpointRequest, CheckpointResponse},
messages_grpc::{
HandleCertificateRequestV3, HandleCertificateResponseV2, HandleCertificateResponseV3,
HandleSoftBundleCertificatesRequestV3, HandleSoftBundleCertificatesResponseV3,
Expand Down Expand Up @@ -155,15 +153,6 @@ impl AuthorityAPI for LocalAuthorityClient {
state.handle_checkpoint_request(&request)
}

async fn handle_checkpoint_v2(
&self,
request: CheckpointRequestV2,
) -> Result<CheckpointResponseV2, IotaError> {
let state = self.state.clone();

state.handle_checkpoint_request_v2(&request)
}

async fn handle_system_state_object(
&self,
_request: SystemStateRequest,
Expand Down Expand Up @@ -355,13 +344,6 @@ impl AuthorityAPI for MockAuthorityApi {
unimplemented!();
}

async fn handle_checkpoint_v2(
&self,
_request: CheckpointRequestV2,
) -> Result<CheckpointResponseV2, IotaError> {
unimplemented!();
}

async fn handle_system_state_object(
&self,
_request: SystemStateRequest,
Expand Down Expand Up @@ -440,13 +422,6 @@ impl AuthorityAPI for HandleTransactionTestAuthorityClient {
unimplemented!()
}

async fn handle_checkpoint_v2(
&self,
_request: CheckpointRequestV2,
) -> Result<CheckpointResponseV2, IotaError> {
unimplemented!()
}

async fn handle_system_state_object(
&self,
_request: SystemStateRequest,
Expand Down
11 changes: 1 addition & 10 deletions crates/iota-core/src/validator_tx_finalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,7 @@ mod tests {
error::IotaError,
executable_transaction::VerifiedExecutableTransaction,
iota_system_state::IotaSystemState,
messages_checkpoint::{
CheckpointRequest, CheckpointRequestV2, CheckpointResponse, CheckpointResponseV2,
},
messages_checkpoint::{CheckpointRequest, CheckpointResponse},
messages_grpc::{
HandleCertificateRequestV3, HandleCertificateResponseV2, HandleCertificateResponseV3,
HandleSoftBundleCertificatesRequestV3, HandleSoftBundleCertificatesResponseV3,
Expand Down Expand Up @@ -406,13 +404,6 @@ mod tests {
unimplemented!()
}

async fn handle_checkpoint_v2(
&self,
_request: CheckpointRequestV2,
) -> Result<CheckpointResponseV2, IotaError> {
unimplemented!()
}

async fn handle_system_state_object(
&self,
_request: SystemStateRequest,
Expand Down
Loading

0 comments on commit 880dc2b

Please sign in to comment.