Skip to content

Commit

Permalink
Add audit database in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
kingsleydon committed Jan 19, 2024
1 parent 4c6d8df commit 068b9ed
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 129 deletions.
30 changes: 16 additions & 14 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions contracts/index_executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ pink-json = { version = "0.4.0", git = "https://github.com/Phala-Network/pink-js
pink-subrpc = { version = "0.4.4", git = "https://github.com/Phala-Network/phala-blockchain.git", branch = "subrpc-0.4.4", default-features = false }

worker_key_store = { package = "key_store", path = "../key_store", default-features = false, features = ["ink-as-dependency"] }
regex = { version = "1.10.2", default-features = false }
chrono = { version = "0.4.31", default-features = false }

[dev-dependencies]
env_logger = "0.10.0"
Expand Down
21 changes: 10 additions & 11 deletions contracts/index_executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ mod index_executor {
self.ensure_running()?;
let config = self.ensure_configured()?;
let client = StorageClient::new(config.db_url.clone(), config.db_token.clone());
let (mut task, task_doc) = client
let mut task = client
.read::<Task>(&id)
.map_err(|_| Error::FailedToReadStorage)?
.ok_or(Error::TaskNotFoundInStorage)?;
Expand All @@ -405,7 +405,7 @@ mod index_executor {
.map_err(|_| Error::FailedToReRunTask)?;
// Upload task data to storage
client
.update(task.id.as_ref(), &task.encode(), task_doc)
.update(task.id.as_ref(), &task.encode())
.map_err(|_| Error::FailedToUploadTask)?;
}
Ok(())
Expand All @@ -430,15 +430,15 @@ mod index_executor {

let mut tasks: Vec<Task> = Vec::new();
for worker_account in self.worker_accounts.iter() {
if let Some((task_id, _)) = client
if let Some(task_id) = client
.read::<TaskId>(&worker_account.account32)
.map_err(|_| Error::FailedToReadStorage)?
{
pink_extension::debug!(
"Trying to read pending task data from remote storage, task id: {:?}",
&hex::encode(task_id)
);
let (task, _) = client
let task = client
.read::<Task>(&task_id)
.map_err(|_| Error::FailedToReadStorage)?
.ok_or(Error::TaskNotFoundInStorage)?;
Expand All @@ -454,10 +454,9 @@ mod index_executor {
pub fn get_task(&self, id: TaskId) -> Result<Option<Task>> {
let config = self.ensure_configured()?;
let client = StorageClient::new(config.db_url.clone(), config.db_token.clone());
Ok(client
client
.read::<Task>(&id)
.map_err(|_| Error::FailedToReadStorage)?
.map(|(task, _)| task))
.map_err(|_| Error::FailedToReadStorage)
}

#[ink(message)]
Expand All @@ -470,7 +469,7 @@ mod index_executor {
Ok(client
.read::<Solution>(&solution_id)
.map_err(|_| Error::FailedToReadStorage)?
.map(|(solution, _)| solution.encode()))
.map(|solution| solution.encode()))
}

/// Returs the interior registry, callable to all
Expand Down Expand Up @@ -538,15 +537,15 @@ mod index_executor {
/// Execute tasks from all supported blockchains. This is a query operation
/// that scheduler invokes periodically.
pub fn execute_task(&self, client: &StorageClient, worker: [u8; 32]) -> Result<()> {
if let Some((id, _)) = client
if let Some(id) = client
.read::<TaskId>(&worker)
.map_err(|_| Error::FailedToReadStorage)?
{
pink_extension::debug!(
"Trying to read pending task data from remote storage, task id: {:?}",
&hex::encode(id)
);
let (mut task, task_doc) = client
let mut task = client
.read::<Task>(&id)
.map_err(|_| Error::FailedToReadStorage)?
.ok_or(Error::TaskNotFoundInStorage)?;
Expand Down Expand Up @@ -596,7 +595,7 @@ mod index_executor {
}
}
client
.update(task.id.as_ref(), &task.encode(), task_doc)
.update(task.id.as_ref(), &task.encode())
.map_err(|_| Error::FailedToUploadTask)?;
} else {
pink_extension::debug!(
Expand Down
Loading

0 comments on commit 068b9ed

Please sign in to comment.