Skip to content

Commit 5d07e7f

Browse files
bmuddhathlorenzDodecahedr0xtaco-paco
authored
Feat: multi threaded scheduler (#589)
Co-authored-by: Thorsten Lorenz <thlorenz@gmx.de> Co-authored-by: Dodecahedr0x <hexadecifish@gmail.com> Co-authored-by: taco-paco <edwinswatpako@gmail.com>
1 parent d305a60 commit 5d07e7f

File tree

29 files changed

+2058
-239
lines changed

29 files changed

+2058
-239
lines changed

Cargo.lock

Lines changed: 15 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,12 @@ prometheus = "0.13.4"
119119
# Needs to match https://crates.io/crates/solana-storage-bigtable/2.1.13/dependencies
120120
prost = "0.11.9"
121121
protobuf-src = "1.1"
122-
rand = "0.8.5"
122+
rand = "0.9"
123123
reqwest = "0.11"
124124
# bundled sqlite 3.44
125125
rusqlite = { version = "0.37.0", features = ["bundled"] }
126126
rustc_version = "0.4"
127+
rustc-hash = "2.1"
127128
scc = "2.4"
128129
semver = "1.0.22"
129130
serde = "1.0.217"

magicblock-aperture/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ log = { workspace = true }
6363
serde = { workspace = true }
6464

6565
[dev-dependencies]
66-
rand = "0.9"
66+
rand = { workspace = true }
6767
test-kit = { workspace = true }
6868
reqwest = { workspace = true }
6969
solana-rpc-client = { workspace = true }

magicblock-aperture/src/requests/http/get_blocks_with_limit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ impl HttpDispatcher {
2121
.min(MAX_DEFAULT_BLOCKS_LIMIT);
2222
let end_slot = start_slot + limit;
2323
// Calculate the end slot, ensuring it does not exceed the latest block height.
24-
let end_slot = (end_slot).min(self.blocks.block_height());
24+
let end_slot = (end_slot).min(self.blocks.block_height() + 1);
2525

26-
// The range is exclusive of the end slot, so `(start..end)` is correct.
2726
let slots = (start_slot..end_slot).collect::<Vec<Slot>>();
2827

2928
Ok(ResponsePayload::encode_no_context(&request.id, slots))

magicblock-aperture/src/requests/http/get_token_account_balance.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::mem::size_of;
22

33
use solana_account::AccountSharedData;
4-
use solana_account_decoder::parse_token::UiTokenAmount;
4+
use solana_account_decoder::{
5+
parse_account_data::SplTokenAdditionalDataV2,
6+
parse_token::token_amount_to_ui_amount_v3,
7+
};
58

69
use super::{
710
prelude::*, MINT_DECIMALS_OFFSET, SPL_MINT_RANGE, SPL_TOKEN_AMOUNT_RANGE,
@@ -58,13 +61,14 @@ impl HttpDispatcher {
5861
u64::from_le_bytes(buffer)
5962
};
6063

61-
let ui_amount = (token_amount as f64) / 10f64.powi(decimals as i32);
62-
let ui_token_amount = UiTokenAmount {
63-
amount: token_amount.to_string(),
64-
ui_amount: Some(ui_amount),
65-
ui_amount_string: ui_amount.to_string(),
66-
decimals,
67-
};
64+
let ui_token_amount = token_amount_to_ui_amount_v3(
65+
token_amount,
66+
&SplTokenAdditionalDataV2 {
67+
decimals,
68+
interest_bearing_config: None,
69+
scaled_ui_amount_config: None,
70+
},
71+
);
6872

6973
let slot = self.blocks.block_height();
7074
Ok(ResponsePayload::encode(&request.id, ui_token_amount, slot))

magicblock-aperture/src/requests/http/mocked.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl HttpDispatcher {
8888
Ok(ResponsePayload::encode(
8989
&request.id,
9090
Vec::<()>::new(),
91-
self.blocks.get_latest().slot,
91+
self.blocks.block_height(),
9292
))
9393
}
9494

@@ -107,7 +107,7 @@ impl HttpDispatcher {
107107
Ok(ResponsePayload::encode(
108108
&request.id,
109109
supply,
110-
self.blocks.get_latest().slot,
110+
self.blocks.block_height(),
111111
))
112112
}
113113

@@ -124,7 +124,7 @@ impl HttpDispatcher {
124124
Ok(ResponsePayload::encode(
125125
&request.id,
126126
supply,
127-
self.blocks.get_latest().slot,
127+
self.blocks.block_height(),
128128
))
129129
}
130130

magicblock-aperture/src/requests/http/request_airdrop.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ impl HttpDispatcher {
1515
// Airdrops are only supported if a faucet keypair is configured.
1616
// Which is never the case with *ephemeral* running mode of the validator
1717
let Some(ref faucet) = self.context.faucet else {
18-
return Err(RpcError::invalid_request("method is not supported"));
18+
return Err(RpcError::invalid_request(
19+
"free airdrop faucet is disabled",
20+
));
1921
};
2022

2123
let (pubkey, lamports) =
2224
parse_params!(request.params()?, Serde32Bytes, u64);
2325
let pubkey = some_or_err!(pubkey);
2426
let lamports = some_or_err!(lamports);
27+
if lamports == 0 {
28+
return Err(RpcError::invalid_params("lamports must be > 0"));
29+
}
2530

2631
// Build and execute the airdrop transfer transaction.
2732
let txn = solana_system_transaction::transfer(

magicblock-aperture/src/tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ fn chainlink(accounts_db: &Arc<AccountsDb>) -> ChainlinkImpl {
5252
}
5353

5454
mod event_processor {
55+
use magicblock_config::consts::DEFAULT_LEDGER_BLOCK_TIME_MS;
56+
5557
use super::*;
5658
use crate::state::NodeContext;
5759

@@ -62,8 +64,8 @@ mod event_processor {
6264
let env = ExecutionTestEnv::new();
6365
env.advance_slot();
6466
let node_context = NodeContext {
65-
identity: env.payer.pubkey(),
66-
blocktime: 50,
67+
identity: env.get_payer().pubkey,
68+
blocktime: DEFAULT_LEDGER_BLOCK_TIME_MS,
6769
..Default::default()
6870
};
6971
let state = SharedState::new(

magicblock-aperture/tests/mocked.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use setup::RpcTestEnv;
22
use solana_pubkey::Pubkey;
3-
use test_kit::Signer;
43

54
mod setup;
65

@@ -17,7 +16,7 @@ async fn test_get_slot_leaders() {
1716
assert_eq!(leaders.len(), 1, "should return a single leader");
1817
assert_eq!(
1918
leaders[0],
20-
env.execution.payer.pubkey(),
19+
env.execution.get_payer().pubkey,
2120
"leader should be the validator's own identity"
2221
);
2322
}
@@ -196,7 +195,7 @@ async fn test_get_cluster_nodes() {
196195
assert_eq!(nodes.len(), 1, "should be exactly one node in the cluster");
197196
assert_eq!(
198197
nodes[0].pubkey,
199-
env.execution.payer.pubkey().to_string(),
198+
env.execution.get_payer().pubkey.to_string(),
200199
"node pubkey should match validator identity"
201200
);
202201
}

magicblock-aperture/tests/node.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use setup::RpcTestEnv;
2-
use test_kit::Signer;
32

43
mod setup;
54

@@ -35,7 +34,7 @@ async fn test_get_identity() {
3534

3635
assert_eq!(
3736
identity,
38-
env.execution.payer.pubkey(),
37+
env.execution.get_payer().pubkey,
3938
"identity should match the validator's public key"
4039
);
4140
}

0 commit comments

Comments
 (0)