Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ignore old entries for median computation #20

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
672 changes: 396 additions & 276 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 8 additions & 19 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,15 @@ thiserror = "1.0.61"
rusqlite = { version = "0.32" }
serde_json = "1.0.133"
serde = "1.0.215"
tokio = { version = "1.42.0", features = ["rt-multi-thread", "net", "macros"] }
tokio = { version = "1.40.0", features = ["rt-multi-thread", "net", "macros"] }
chrono = "0.4"
prettytable-rs = "0.10"

miden-assembly = { version = "0.11", default-features = false, features = [
"testing",
] }
miden-crypto = { version = "0.12", default-features = false }
miden-lib = { version = "0.6.2", default-features = false, features = [
"concurrent",
"testing",
] }
miden-objects = { version = "0.6.2", default-features = false, features = [
"concurrent",
"testing",
] }
miden-tx = { version = "0.6.2", features = ["concurrent", "testing"] }
miden-client = { git = "https://github.com/0xPolygonMiden/miden-client", branch = "main", features = [
"concurrent",
"testing",
"sqlite",
"tonic",
miden-assembly = { git = "https://github.com/0xPolygonMiden/miden-vm", branch="next", default-features = false, features = [
"testing", "std",
] }
miden-crypto = { git = "https://github.com/0xPolygonMiden/crypto", branch="next", default-features = false }
miden-lib = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false, features = ["testing"] }
miden-objects = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false,features = ["testing"] }
miden-tx = { git = "https://github.com/0xPolygonMiden/miden-base", branch = "next", default-features = false, features = ["async", "concurrent"] }
miden-client = { git = "https://github.com/0xPolygonMiden/miden-client", branch="next", features=["tonic", "sqlite", "concurrent","testing"]}
35 changes: 18 additions & 17 deletions crates/accounts/src/oracle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ use miden_assembly::{
ast::{Module, ModuleKind},
DefaultSourceManager, LibraryPath,
};
use miden_client::{auth::AuthSecretKey, crypto::FeltRng, Client};
use miden_client::{auth::AuthSecretKey, crypto::FeltRng, Client, account::{Account, AccountBuilder, AccountType as ClientAccountType, AccountStorageMode}};
use miden_crypto::{
dsa::rpo_falcon512::{PublicKey, SecretKey},
Felt, Word, ZERO,
};
use miden_lib::{accounts::auth::RpoFalcon512, transaction::TransactionKernel};
use miden_lib::{account::auth::RpoFalcon512, transaction::TransactionKernel};
use miden_objects::{
accounts::{
Account, AccountBuilder, AccountComponent, AccountStorageMode, AccountType, StorageSlot,
},
account::{ AccountComponent,AccountType as ObjectAccountType,StorageSlot},
assembly::Library,
};





pub const ORACLE_ACCOUNT_MASM: &str = include_str!("oracle.masm");

pub fn get_oracle_component_library() -> Library {
Expand All @@ -39,7 +41,7 @@ pub fn get_oracle_component_library() -> Library {

pub struct OracleAccountBuilder<'a, T: FeltRng> {
client: Option<&'a mut Client<T>>,
account_type: AccountType,
account_type: String, // Temporary fix, because AccountType is not consistent between the Client and the Object
storage_slots: Vec<StorageSlot>,
}

Expand All @@ -57,13 +59,13 @@ impl<'a, T: FeltRng> OracleAccountBuilder<'a, T> {

Self {
client: None,
account_type: AccountType::RegularAccountImmutableCode,
account_type: ClientAccountType::RegularAccountImmutableCode.to_string(),
storage_slots: default_storage_slots,
}
}

pub fn with_account_type(mut self, account_type: AccountType) -> Self {
self.account_type = account_type;
pub fn with_account_type(mut self, account_type: ClientAccountType) -> Self {
self.account_type = account_type.to_string();
self
}

Expand All @@ -78,33 +80,32 @@ impl<'a, T: FeltRng> OracleAccountBuilder<'a, T> {
}

pub async fn build(self) -> (Account, Word) {
let object_account_type : ObjectAccountType = self.account_type.parse().unwrap();
let client_account_type: ClientAccountType = self.account_type.parse().unwrap();
let oracle_component =
AccountComponent::new(get_oracle_component_library(), self.storage_slots)
.unwrap()
.with_supported_type(self.account_type);
.with_supported_type(object_account_type);

let client = self.client.expect("build must have a Miden Client!");
let client_rng = client.rng();
let private_key = SecretKey::with_rng(client_rng);
let public_key = private_key.public_key();

let auth_component: RpoFalcon512 = RpoFalcon512::new(PublicKey::new(public_key.into()));

let from_seed = client_rng.gen();
let (account, account_seed) = AccountBuilder::new()
.init_seed(from_seed)
.account_type(self.account_type)
let (account, account_seed) = AccountBuilder::new(from_seed)
.account_type(client_account_type)
.storage_mode(AccountStorageMode::Public)
.with_component(auth_component)
.with_component(oracle_component)
.build()
.unwrap();

client
.insert_account(
.add_account(
&account,
Some(account_seed),
&AuthSecretKey::RpoFalcon512(private_key),
true,
)
.await
.unwrap();
Expand Down
Loading
Loading