Skip to content

Commit

Permalink
Bug fix: wrong call_index type and use recv_timeout (#2893)
Browse files Browse the repository at this point in the history
* Fix call_index type

* Try to use recv_timeout
  • Loading branch information
Kailai-Wang committed Jul 12, 2024
1 parent 8b6a76e commit dd80e7d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ use itp_ocall_api::EnclaveOnChainOCallApi;
use itp_types::parentchain::ParentchainId;
use lc_parachain_extrinsic_task_sender::init_parachain_extrinsic_sender_storage;
use log::*;
use std::{format, string::String, sync::Arc, time, vec};
use std::{
format,
string::String,
sync::{mpsc::RecvTimeoutError, Arc},
time, vec,
};

const MAX_BATCH_SIZE: usize = 500;
const BATCH_EXTRINSIC_INTERVAL: time::Duration = time::Duration::from_secs(6);
const TASK_RECV_INTERVAL: time::Duration = time::Duration::from_secs(1);

pub fn run_parachain_extrinsic_task_receiver<ExtrinsicsFactory, OCallApi>(
api: Arc<OCallApi>,
Expand All @@ -32,13 +38,18 @@ where
loop {
let start_time = time::Instant::now();
while start_time.elapsed() < BATCH_EXTRINSIC_INTERVAL {
if let Ok(call) = task_receiver.recv() {
calls.push(call);
}
if calls.len() == MAX_BATCH_SIZE {
break
match task_receiver.recv_timeout(TASK_RECV_INTERVAL) {
Ok(call) => {
calls.push(call);
if calls.len() == MAX_BATCH_SIZE {
break
}
},
Err(RecvTimeoutError::Timeout) => continue,
Err(RecvTimeoutError::Disconnected) => break,
}
}

if !calls.is_empty() {
let extrinsic =
match extrinsic_factory.create_batch_extrinsic(calls.drain(..).collect(), None) {
Expand Down
2 changes: 1 addition & 1 deletion tee-worker/litentry/core/vc-task/receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ where
let call_index = node_metadata_repo
.get_from_metadata(|m| m.vc_issued_call_indexes())
.map_err(|e| RequestVcErrorDetail::MetadataRetrievalFailed(e.to_string()))?
.map_err(|e| RequestVcErrorDetail::InvalidMetadata(format!("{:?}", e)));
.map_err(|e| RequestVcErrorDetail::InvalidMetadata(format!("{:?}", e)))?;

let key = maybe_key.ok_or(RequestVcErrorDetail::MissingAesKey)?;
let call = OpaqueCall::from_tuple(&(
Expand Down

0 comments on commit dd80e7d

Please sign in to comment.