Skip to content

Commit

Permalink
feat: add new rpc endpoint to set addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
glihm committed Dec 7, 2023
1 parent e54b38e commit 20b63f6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
13 changes: 13 additions & 0 deletions crates/katana/core/src/hooker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ use starknet::core::types::{BroadcastedInvokeTransaction, FieldElement};

use crate::sequencer::KatanaSequencer;

#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, Copy, PartialEq, Eq)]
pub struct HookerAddresses {
orderbook_arkchain: FieldElement,
executor_starknet: FieldElement,
}

#[async_trait]
pub trait KatanaHooker {
/// Sets a reference to the underlying sequencer.
Expand Down Expand Up @@ -59,4 +65,11 @@ pub trait KatanaHooker {
/// * `call` - The `Call` of the transaction that has failed. Usually the same as
/// `verify_message_to_starknet_before_tx`.
async fn on_starknet_tx_failed(&self, call: Call);

/// Sets important addresses.
///
/// # Arguments
///
/// * `addresses` - Important addresses related to solis.
fn set_addresses(&self, addresses: &HookerAddresses);
}
6 changes: 5 additions & 1 deletion crates/katana/core/src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::backend::storage::transaction::{
use crate::backend::{Backend, ExternalFunctionCall};
use crate::db::{AsStateRefDb, StateExtRef, StateRefDb};
use crate::execution::{MaybeInvalidExecutedTransaction, PendingState};
use crate::hooker::KatanaHooker;
use crate::hooker::{HookerAddresses, KatanaHooker};
use crate::pool::TransactionPool;
use crate::sequencer_error::SequencerError;
use crate::service::block_producer::{BlockProducer, BlockProducerMode};
Expand Down Expand Up @@ -96,6 +96,10 @@ impl KatanaSequencer {
Self { pool, config, backend, block_producer, hooker }
}

pub async fn set_addresses(&self, addresses: &HookerAddresses) {
self.hooker.read().await.set_addresses(addresses);
}

/// Returns the pending state if the sequencer is running in _interval_ mode. Otherwise `None`.
pub fn pending_state(&self) -> Option<Arc<PendingState>> {
match &*self.block_producer.inner.read() {
Expand Down
4 changes: 4 additions & 0 deletions crates/katana/rpc/src/api/katana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use jsonrpsee::proc_macros::rpc;
use jsonrpsee::types::error::CallError;
use jsonrpsee::types::ErrorObject;
use katana_core::accounts::Account;
use katana_core::hooker::HookerAddresses;
use starknet::core::types::FieldElement;

#[derive(thiserror::Error, Clone, Copy, Debug)]
Expand All @@ -24,6 +25,9 @@ impl From<KatanaApiError> for Error {

#[rpc(server, namespace = "katana")]
pub trait KatanaApi {
#[method(name = "setSolisAddresses")]
async fn set_addresses(&self, addresses: HookerAddresses) -> Result<(), Error>;

#[method(name = "generateBlock")]
async fn generate_block(&self) -> Result<(), Error>;

Expand Down
6 changes: 6 additions & 0 deletions crates/katana/rpc/src/katana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::sync::Arc;

use jsonrpsee::core::{async_trait, Error};
use katana_core::accounts::Account;
use katana_core::hooker::HookerAddresses;
use katana_core::sequencer::KatanaSequencer;
use starknet::core::types::FieldElement;
use starknet_api::core::{ContractAddress, PatriciaKey};
Expand All @@ -23,6 +24,11 @@ impl KatanaApi {

#[async_trait]
impl KatanaApiServer for KatanaApi {
async fn set_addresses(&self, addresses: HookerAddresses) -> Result<(), Error> {
self.sequencer.set_addresses(&addresses).await;
Ok(())
}

async fn generate_block(&self) -> Result<(), Error> {
self.sequencer.block_producer().force_mine();
Ok(())
Expand Down

0 comments on commit 20b63f6

Please sign in to comment.