Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions magicblock-aperture/src/geyser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use agave_geyser_plugin_interface::geyser_plugin_interface::{
use json::{JsonValueTrait, Value};
use libloading::{Library, Symbol};
use magicblock_core::link::{
accounts::AccountWithSlot, transactions::TransactionStatus,
accounts::AccountWithSlot, blocks::LatestBlockInner,
transactions::TransactionStatus,
};
use magicblock_ledger::LatestBlockInner;
use solana_account::ReadableAccount;

const ENTRYPOINT_SYMBOL: &[u8] = b"_create_plugin";
Expand Down
7 changes: 4 additions & 3 deletions magicblock-aperture/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::sync::Arc;

use magicblock_config::config::ApertureConfig;
use magicblock_core::link::{
accounts::AccountUpdateRx, blocks::BlockUpdateRx,
transactions::TransactionStatusRx, DispatchEndpoints,
accounts::AccountUpdateRx,
blocks::{BlockUpdateRx, LatestBlockInner},
transactions::TransactionStatusRx,
DispatchEndpoints,
};
use magicblock_ledger::LatestBlockInner;
use tokio_util::sync::CancellationToken;
use tracing::{info, instrument, warn};

Expand Down
6 changes: 4 additions & 2 deletions magicblock-aperture/src/state/blocks.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::{ops::Deref, sync::Arc, time::Duration};

use arc_swap::ArcSwapAny;
use magicblock_core::{link::blocks::BlockHash, Slot};
use magicblock_ledger::LatestBlockInner;
use magicblock_core::{
link::blocks::{BlockHash, LatestBlockInner},
Slot,
};
use solana_rpc_client_api::response::RpcBlockhash;

use super::ExpiringCache;
Expand Down
4 changes: 2 additions & 2 deletions magicblock-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ bytes = { workspace = true }

serde = { workspace = true, features = ["derive"] }
solana-account = { workspace = true }
solana-account-decoder = { workspace = true }
solana-account-decoder = { workspace = true, features = ["agave-unstable-api"] }
solana-clock = { workspace = true }
solana-hash = { workspace = true }
solana-message = { workspace = true }
Expand All @@ -27,7 +27,7 @@ solana-signature = { workspace = true }
solana-transaction = { workspace = true, features = ["blake3", "verify"] }
solana-transaction-context = { workspace = true }
solana-transaction-error = { workspace = true }
solana-transaction-status-client-types = { workspace = true }
solana-transaction-status-client-types = { workspace = true, features = ["agave-unstable-api"] }
magicblock-magic-program-api = { workspace = true }
spl-token = { workspace = true }
spl-token-2022 = { workspace = true }
Expand Down
24 changes: 24 additions & 0 deletions magicblock-core/src/link/blocks.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use solana_clock::Clock;
use solana_hash::Hash;
use tokio::sync::broadcast;

Expand All @@ -8,3 +9,26 @@ pub type BlockHash = Hash;
/// Typically instantiated as `BlockUpdateRx<LatestBlockInner>` where the payload
/// contains the latest block data (slot, blockhash, timestamp).
pub type BlockUpdateRx<T> = broadcast::Receiver<T>;

#[derive(Default, Clone)]
pub struct LatestBlockInner {
pub slot: u64,
pub blockhash: BlockHash,
pub clock: Clock,
}

impl LatestBlockInner {
pub fn new(slot: u64, blockhash: BlockHash, timestamp: i64) -> Self {
let clock = Clock {
slot: slot + 1,
unix_timestamp: timestamp,
..Default::default()
};

Self {
slot,
blockhash,
clock,
}
}
}
3 changes: 3 additions & 0 deletions magicblock-core/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ use solana_program::instruction::InstructionError;
use solana_pubkey::Pubkey;
use solana_signature::Signature;
use solana_transaction_error::TransactionError;
use tokio::sync::broadcast;

use crate::{
intent::{BaseActionCallback, CommittedAccount},
link::blocks::LatestBlockInner,
Slot,
};

Expand All @@ -28,6 +30,7 @@ pub trait LatestBlockProvider: Send + Sync + Clone + 'static {
fn slot(&self) -> Slot;
fn blockhash(&self) -> Hash;
fn clock(&self) -> Clock;
fn subscribe(&self) -> broadcast::Receiver<LatestBlockInner>;
Comment thread
taco-paco marked this conversation as resolved.
}

/// Interface for service handling callback execution/scheduling
Expand Down
9 changes: 6 additions & 3 deletions magicblock-ledger/src/blockstore_processor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::str::FromStr;

use magicblock_core::link::transactions::{
ReplayPosition, SanitizeableTransaction, TransactionSchedulerHandle,
use magicblock_core::link::{
blocks::LatestBlockInner,
transactions::{
ReplayPosition, SanitizeableTransaction, TransactionSchedulerHandle,
},
};
use num_format::{Locale, ToFormattedString};
use solana_clock::{Slot, UnixTimestamp};
Expand All @@ -12,7 +15,7 @@ use tracing::{Level, *};

use crate::{
errors::{LedgerError, LedgerResult},
LatestBlockInner, Ledger,
Ledger,
};

#[derive(Debug)]
Expand Down
30 changes: 7 additions & 23 deletions magicblock-ledger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ pub use database::{
meta::PerfSample,
options::{LedgerOptions, BLOCKSTORE_DIRECTORY_ROCKS_LEVEL},
};
use magicblock_core::traits::LatestBlockProvider;
use magicblock_core::{
link::blocks::LatestBlockInner, traits::LatestBlockProvider,
};
use solana_clock::Clock;
use solana_hash::Hash;
pub use store::api::{Ledger, SignatureInfosForAddress};
use tokio::sync::broadcast;

#[derive(Default, Clone)]
pub struct LatestBlockInner {
pub slot: u64,
pub blockhash: Hash,
pub clock: Clock,
}

/// Atomically updated, shared, latest block information
/// The instances of this type can be used by various components
/// of the validator to cheaply retrieve the latest block data,
Expand All @@ -35,21 +30,6 @@ pub struct LatestBlock {
notifier: broadcast::Sender<LatestBlockInner>,
}

impl LatestBlockInner {
pub fn new(slot: u64, blockhash: Hash, timestamp: i64) -> Self {
let clock = Clock {
slot: slot + 1,
unix_timestamp: timestamp,
..Default::default()
};
Self {
slot,
blockhash,
clock,
}
}
}

impl Default for LatestBlock {
fn default() -> Self {
let (notifier, _) = broadcast::channel(32);
Expand Down Expand Up @@ -93,6 +73,10 @@ impl LatestBlockProvider for LatestBlock {
fn clock(&self) -> Clock {
self.inner.load().clock.clone()
}

fn subscribe(&self) -> broadcast::Receiver<LatestBlockInner> {
self.subscribe()
}
}

pub mod blockstore_processor;
Expand Down
4 changes: 2 additions & 2 deletions magicblock-ledger/src/store/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
};

use bincode::{deserialize, serialize};
use magicblock_core::link::blocks::BlockHash;
use magicblock_core::link::blocks::{BlockHash, LatestBlockInner};
use magicblock_metrics::metrics::{
start_ledger_disable_compactions_timer, start_ledger_shutdown_timer,
HistogramTimer,
Expand Down Expand Up @@ -42,7 +42,7 @@ use crate::{
errors::{LedgerError, LedgerResult},
metrics::LedgerRpcApiMetrics,
store::utils::adjust_ulimit_nofile,
LatestBlock, LatestBlockInner,
LatestBlock,
};

#[derive(Default, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion magicblock-ledger/tests/get_block.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod common;

use magicblock_ledger::LatestBlockInner;
use magicblock_core::link::blocks::LatestBlockInner;
use solana_hash::Hash;
use test_kit::init_logger;

Expand Down
5 changes: 2 additions & 3 deletions magicblock-ledger/tests/test_ledger_truncator.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
mod common;
use std::{sync::Arc, time::Duration};

use magicblock_ledger::{
ledger_truncator::LedgerTruncator, LatestBlockInner, Ledger,
};
use magicblock_core::link::blocks::LatestBlockInner;
use magicblock_ledger::{ledger_truncator::LedgerTruncator, Ledger};
use solana_hash::Hash;
use solana_signature::Signature;
use test_kit::init_logger;
Expand Down
3 changes: 2 additions & 1 deletion magicblock-processor/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use magicblock_accounts_db::AccountsDb;
use magicblock_core::{
link::{
accounts::AccountUpdateTx,
blocks::LatestBlockInner,
transactions::{
ProcessableTransaction, ScheduledTasksTx,
TransactionProcessingMode, TransactionStatusTx,
},
},
Slot,
};
use magicblock_ledger::{LatestBlock, LatestBlockInner, Ledger};
use magicblock_ledger::{LatestBlock, Ledger};
use solana_feature_set::FeatureSet;
use solana_program::slot_hashes::SlotHashes;
use solana_program_runtime::loaded_programs::{
Expand Down
3 changes: 2 additions & 1 deletion magicblock-processor/src/scheduler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ use locks::{ExecutorId, MAX_SVM_EXECUTORS};
use magicblock_accounts_db::{traits::AccountsBank, AccountsDb};
use magicblock_core::{
link::{
blocks::LatestBlockInner,
replication::{self, Message, SuperBlock},
transactions::{
ProcessableTransaction, SchedulerCommand, SchedulerCommandResult,
Expand All @@ -64,7 +65,7 @@ use magicblock_core::{
},
Slot,
};
use magicblock_ledger::{LatestBlock, LatestBlockInner, Ledger};
use magicblock_ledger::{LatestBlock, Ledger};
use magicblock_metrics::metrics;
use solana_account::{from_account, to_account};
use solana_program::{clock::Clock, hash::Hash, slot_hashes::SlotHashes};
Expand Down
3 changes: 2 additions & 1 deletion test-kit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub use guinea;
use magicblock_accounts_db::{traits::AccountsBank, AccountsDb};
use magicblock_core::{
link::{
blocks::LatestBlockInner,
link,
transactions::{
ReplayPosition, SanitizeableTransaction, SchedulerMode,
Expand All @@ -21,7 +22,7 @@ use magicblock_core::{
},
Slot,
};
use magicblock_ledger::{LatestBlockInner, Ledger};
use magicblock_ledger::Ledger;
use magicblock_processor::{
build_svm_env,
loader::load_upgradeable_programs,
Expand Down
Loading