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

Add casper-sse notification trigger for deposits, implement deposit-manager (in favor of #110) #133

Closed
wants to merge 63 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
90c747b
kairos: normalize and use latest casper-types version
marijanp May 24, 2024
b8d8f82
casper-deploy-notifier: make types module public
marijanp May 24, 2024
f9a169a
kairos-contracts: factor out contract-utils
marijanp May 24, 2024
562df3f
kairos-server/config: add kairos demo contract hash
marijanp May 24, 2024
3c0d5e9
kairos-server: add deposit deploy handler
marijanp May 24, 2024
a59a9c5
audit: temporarity ignore RUSTSEC-2022-0054 wee_alloc is Unmaintained
marijanp May 24, 2024
425ff23
flake: add git-mock to circumvent casper-client-rs git build time req…
marijanp May 24, 2024
e84e14a
Merge remote-tracking branch 'origin/normalize-casper-client' into in…
marijanp May 31, 2024
2754158
kairos-cli: fixup casper-client invocations after update
marijanp May 31, 2024
cb7dbf3
update casper-types and casper-hashing
marijanp May 31, 2024
17f2c11
flake/kairos-contracts: ignore RUSTSEC-2022-0093 and RUSTSEC-2022-0054
marijanp May 31, 2024
9ae895c
flake/kairos: remove obsolete ignores
marijanp May 31, 2024
413291b
flake/lint-checks: add pname and rename check output
marijanp May 31, 2024
de4bb4b
kairos-contracts: use workspace dependencies
marijanp May 31, 2024
ae5feab
kairos-server: add FIXME comment for nonce
marijanp May 31, 2024
a787c74
kairos-server: add casper sse URL configuration option
marijanp Jun 4, 2024
966e8f1
nixos/kairos: add casperSseUrl option
marijanp Jun 4, 2024
09eddd6
kairos/kairos-cli: add contract hash argument, pass it as a Key
marijanp Jun 5, 2024
ac90304
nixos/cctl: add deploy contract utility
marijanp Jun 5, 2024
136019d
nixos/kairos: add demo contract hash option
marijanp Jun 5, 2024
c33ce02
tests/e2e: initial refactoring to test kairos-cli deposit
marijanp Jun 5, 2024
57dee9d
kairos-cli: pass a ContractHash to the demo-contract
marijanp Jun 5, 2024
b70b966
kairos: use workspace dependencies
marijanp Jun 6, 2024
ab0a7b0
kairos-contracts: use upstream casper-types
marijanp Jun 6, 2024
ef01764
kairos-server/config: use ContractHash type
marijanp Jun 6, 2024
6310326
kairos-server/on-deploy: refactor
marijanp Jun 6, 2024
e6c8767
kairos-contract: use u32 for the last_processed_deposit_counter
marijanp Jun 6, 2024
7226b57
nixos/cctl: strip key from contract-hash-key
marijanp Jun 6, 2024
1241bc6
kairos: fixup tests
marijanp Jun 6, 2024
78162b9
kairos-test-utils/cctl: implement and test deploy_contract function
marijanp Jun 7, 2024
651f45f
nixos/cctl: add contract option
marijanp Jun 7, 2024
b2d8eda
kairos-cli: fix linter complaints
marijanp Jun 7, 2024
f6288a0
kairos-cli/tests: use updated cctl utils
marijanp Jun 7, 2024
7a33dcb
kairos-server/tests: use updated cctl utils
marijanp Jun 7, 2024
3d24f0a
tests/e2e: use updated cctl utils
marijanp Jun 7, 2024
2b40f8c
nixos/configurations: set mandatory contractHash temporarily to empty
marijanp Jun 7, 2024
bf8ebd0
kairos/audit: ignore issues introduced by casper-client
marijanp Jun 7, 2024
24eb030
Merge remote-tracking branch 'origin/main' into integrate-deploy-noti…
marijanp Jun 7, 2024
53b52c0
kairos: use casper-event-toolkit 0.1.3
marijanp Jun 7, 2024
6351d61
Merge remote-tracking branch 'origin/main' into integrate-deploy-noti…
marijanp Jun 7, 2024
6ce26be
nixos/configurations: set mandatory contractHash temporarily to zero
marijanp Jun 10, 2024
80c0a92
flake/kairos: remove yet unneeded git-mock
marijanp Jun 10, 2024
abbc8e2
Merge remote-tracking branch 'origin/main' into integrate-deploy-noti…
marijanp Jun 11, 2024
698f7dd
Merge remote-tracking branch 'origin/main' into integrate-deploy-noti…
marijanp Jun 11, 2024
d141370
kairos-test-utils: remove unused code
marijanp Jun 11, 2024
eeae427
Merge remote-tracking branch 'origin/main' into integrate-deploy-noti…
marijanp Jun 13, 2024
b7c01b7
Merge remote-tracking branch 'origin/main' into integrate-deploy-noti…
marijanp Jun 17, 2024
60ae9a6
Merge remote-tracking branch 'origin/main' into integrate-deploy-noti…
marijanp Jun 19, 2024
9dc8b88
kairos-server: add the sse event trigger
marijanp Jun 20, 2024
36d470d
kairos-server: keep track of known deposits
marijanp Jun 20, 2024
6dba2c8
kairos-server: refactor the event manager to deposit manager
marijanp Jun 22, 2024
0a18415
kairos-test-utils/cctl: add get_contract_hash_for
marijanp Jun 22, 2024
5e7cbfa
kairos-test-utils/kairos: start kairos with a contract hash
marijanp Jun 22, 2024
73a71d8
kairos-cli: remove unused casper-types dependency
marijanp Jun 22, 2024
e26fc45
Merge remote-tracking branch 'origin/main' into deposit-manager
marijanp Jun 22, 2024
18dc9c4
Merge remote-tracking branch 'origin/main' into deposit-manager
marijanp Jun 24, 2024
d3abc1b
kairos-test-utils/cctl: remove num_args for deploy_contract argument
marijanp Jun 24, 2024
561b701
nixos/cctl: increase startup timeout
marijanp Jun 24, 2024
a70326c
kairos-server/deposit_manager: assert that the next_deposit_index <= …
marijanp Jun 24, 2024
548157f
nixos/cctl: increase timeout
marijanp Jun 24, 2024
5234188
Merge remote-tracking branch 'origin/main' into deposit-manager
marijanp Jul 4, 2024
577bdec
factor back DepositManager -> EventManager
marijanp Jul 4, 2024
8fb9c91
Merge remote-tracking branch 'origin/main' into deposit-manager
marijanp Jul 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
factor back DepositManager -> EventManager
marijanp committed Jul 4, 2024
commit 577bdec2a8dd37dddec0e35f7275e9b3d50267ac
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -3,14 +3,11 @@ pub mod error;
use anyhow::{anyhow, Result};
use backoff::{future::retry, Error, ExponentialBackoff};
use casper_client::{
get_state_root_hash, query_global_state, types::DeployHash, types::StoredValue, JsonRpcId,
Verbosity,
get_state_root_hash, query_global_state, types::StoredValue, JsonRpcId, Verbosity,
};
use rand::Rng;
use reqwest::Url;
use std::collections::HashSet;
use std::sync::atomic::{AtomicU32, Ordering};
use tokio::sync::RwLock;

use crate::state::BatchStateManager;
use casper_client_types::ContractHash;
@@ -23,15 +20,14 @@ use contract_utils::constants::KAIROS_LAST_PROCESSED_DEPOSIT_COUNTER;
use error::DepositManagerError;
use kairos_circuit_logic::transactions::{KairosTransaction, L1Deposit};

pub struct DepositManager {
pub struct EventManager {
/// The last deposit event index that was added to the batch
last_deposit_added_to_batch: AtomicU32,
pub known_deposit_deploys: RwLock<HashSet<DeployHash>>,
fetcher: Fetcher,
schemas: Schemas,
}

impl DepositManager {
impl EventManager {
pub async fn new(
casper_rpc_url: &Url,
contract_hash: &ContractHash,
@@ -79,11 +75,10 @@ impl DepositManager {

tracing::info!("On-chain stored last processed deposit index fetched successfully");

Ok(DepositManager {
Ok(EventManager {
last_deposit_added_to_batch: AtomicU32::new(last_processed_deposit_index + 1),
fetcher,
schemas,
known_deposit_deploys: RwLock::new(HashSet::new()),
})
}

22 changes: 11 additions & 11 deletions kairos-server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
pub mod config;
pub mod deposit_manager;
pub mod errors;
pub mod event_manager;
pub mod routes;
pub mod state;

mod utils;

use std::collections::HashSet;
use std::sync::Arc;
use tokio::sync::mpsc;
use tokio::sync::RwLock;
use tokio::time::{self, Duration};

use casper_client::types::DeployHash;
@@ -21,7 +23,7 @@ use casper_client_types::ContractHash;
pub use errors::AppErr;

use crate::config::ServerConfig;
use crate::deposit_manager::DepositManager;
use crate::event_manager::EventManager;
use crate::state::{BatchStateManager, ServerState, ServerStateInner};

/// TODO: support secp256k1
@@ -53,24 +55,25 @@ pub async fn run(config: ServerConfig) {
.unwrap_or_else(|err| panic!("Failed to bind to address {}: {}", config.socket_addr, err));
tracing::info!("listening on `{}`", listener.local_addr().unwrap());

let deposit_manager = if config.kairos_demo_contract_hash == ContractHash::default() {
let event_manager = if config.kairos_demo_contract_hash == ContractHash::default() {
tracing::warn!(
"Casper contract hash not configured, L1 synchronization will NOT be enabled."
);
None
} else {
DepositManager::new(&config.casper_rpc, &config.kairos_demo_contract_hash)
EventManager::new(&config.casper_rpc, &config.kairos_demo_contract_hash)
.await
.ok()
};

let state = Arc::new(ServerStateInner {
batch_state_manager: BatchStateManager::new_empty(&config),
server_config: config.clone(),
deposit_manager,
event_manager,
known_deposit_deploys: RwLock::new(HashSet::new()),
});

if state.deposit_manager.is_some() {
if state.event_manager.is_some() {
// deploy notifier
let (tx, mut rx) = mpsc::channel(100);
let mut deploy_notifier = DeployNotifier::new(config.casper_sse.as_str());
@@ -101,7 +104,7 @@ pub async fn run(config: ServerConfig) {

tracing::debug!("Triggering periodic L1 sync");
state_clone
.deposit_manager
.event_manager
.as_ref()
.unwrap()
.add_new_events_to(&state_clone.batch_state_manager)
@@ -117,9 +120,6 @@ pub async fn run(config: ServerConfig) {
let deploy_hash =
DeployHash::new(Digest::from_hex(notification.deploy_hash).unwrap());
match state_clone
.deposit_manager
.as_ref()
.unwrap()
.known_deposit_deploys
.write()
.await
@@ -128,7 +128,7 @@ pub async fn run(config: ServerConfig) {
None => continue,
Some(_) => {
state_clone
.deposit_manager
.event_manager
.as_ref()
.unwrap()
.add_new_events_to(&state_clone.batch_state_manager)
5 changes: 1 addition & 4 deletions kairos-server/src/routes/deposit.rs
Original file line number Diff line number Diff line change
@@ -39,11 +39,8 @@ pub async fn deposit_handler(
.await
.map_err(Into::<AppErr>::into)?;
if response.id == expected_rpc_id {
if state.deposit_manager.is_some() {
if state.event_manager.is_some() {
assert!(state
.deposit_manager
.as_ref()
.unwrap()
.known_deposit_deploys
.write()
.await
9 changes: 7 additions & 2 deletions kairos-server/src/state.rs
Original file line number Diff line number Diff line change
@@ -2,11 +2,15 @@ pub mod submit_batch;
pub mod transactions;
mod trie;

use std::collections::HashSet;
use std::{sync::Arc, thread};
use tokio::sync::RwLock;
use tokio::{sync::mpsc, task};

use casper_client::types::DeployHash;

pub use self::trie::TrieStateThreadMsg;
use crate::deposit_manager::DepositManager;
use crate::event_manager::EventManager;
use crate::{config::ServerConfig, state::submit_batch::submit_proof_to_contract};
use kairos_circuit_logic::transactions::KairosTransaction;
use kairos_trie::{stored::memory_db::MemoryDb, NodeHash, TrieRoot};
@@ -16,7 +20,8 @@ pub type ServerState = Arc<ServerStateInner>;
pub struct ServerStateInner {
pub batch_state_manager: BatchStateManager,
pub server_config: ServerConfig,
pub deposit_manager: Option<DepositManager>,
pub event_manager: Option<EventManager>,
pub known_deposit_deploys: RwLock<HashSet<DeployHash>>,
}

/// The `BatchStateManager` is a piece of Axum state.