Skip to content

Commit cf9082a

Browse files
committed
Merge branch 'master' into thlorenz/subscription-metrics
* master: hotfix: unregistered metric COMMITTOR_INTENT_CU_USAGE (#612) feat: add metrics for intent execution time (#607) fix: don't increment subscription id for dups (#610) chore: broaden dependency range on the magic program api (#609) feat: parallel CI integration tests (#605) Handle uncleaned buffers + generalized tx send retries (#597) fix: support binary opcode (#604) fix: correct log imports (#606)
2 parents fece0cd + c7955c3 commit cf9082a

File tree

26 files changed

+1152
-321
lines changed

26 files changed

+1152
-321
lines changed

.github/workflows/ci-test-integration.yml

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ on:
1111
types: [opened, reopened, synchronize, ready_for_review]
1212

1313
jobs:
14-
run_make_ci_test:
15-
if: github.event.pull_request.draft == false
14+
build:
15+
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
1616
runs-on: extra-large
17+
name: Build Project
1718
steps:
1819
- name: Checkout this magicblock-validator
19-
uses: actions/checkout@v2
20+
uses: actions/checkout@v5
2021
with:
2122
path: magicblock-validator
2223

@@ -29,11 +30,54 @@ jobs:
2930

3031
- uses: ./magicblock-validator/.github/actions/setup-solana
3132

32-
- name: Run integration tests
33+
- name: Build project and test programs
34+
run: |
35+
cargo build --locked
36+
make -C test-integration programs
37+
shell: bash
38+
working-directory: magicblock-validator
39+
40+
run_integration_tests:
41+
needs: build
42+
runs-on: extra-large
43+
strategy:
44+
matrix:
45+
batch_tests:
46+
- "schedulecommit"
47+
- "chainlink"
48+
- "cloning"
49+
- "restore_ledger"
50+
- "magicblock_api"
51+
- "config"
52+
- "table_mania"
53+
- "committor"
54+
- "pubsub"
55+
- "schedule_intents"
56+
- "task-scheduler"
57+
fail-fast: false
58+
name: Integration Tests - ${{ matrix.batch_tests }}
59+
steps:
60+
- name: Checkout this magicblock-validator
61+
uses: actions/checkout@v5
62+
with:
63+
path: magicblock-validator
64+
65+
- uses: ./magicblock-validator/.github/actions/setup-build-env
66+
with:
67+
build_cache_key_name: "magicblock-validator-ci-test-integration-v000"
68+
rust_toolchain_release: "1.84.1"
69+
github_access_token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
70+
github_token: ${{ secrets.GITHUB_TOKEN }}
71+
72+
- uses: ./magicblock-validator/.github/actions/setup-solana
73+
74+
- name: Run integration tests - ${{ matrix.batch_tests }}
3375
run: |
3476
sudo prlimit --pid $$ --nofile=1048576:1048576
3577
sudo sysctl fs.inotify.max_user_instances=1280
3678
sudo sysctl fs.inotify.max_user_watches=655360
3779
make ci-test-integration
3880
shell: bash
3981
working-directory: magicblock-validator
82+
env:
83+
RUN_TESTS: ${{ matrix.batch_tests }}

.github/workflows/publish-packages.yml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish ephemeral validator packages
1+
name: Publish ephemeral validator packages and crates
22

33
concurrency:
44
group: ${{ github.workflow }}-${{ github.ref }}
@@ -213,4 +213,20 @@ jobs:
213213
npm publish --access public
214214
fi
215215
env:
216-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
216+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
217+
218+
- name: cargo publish
219+
working-directory: magicblock-magic-program-api/
220+
run: |
221+
DRY_RUN_FLAG=""
222+
if [ "${DRY_RUN}" = "true" ]; then
223+
DRY_RUN_FLAG="--dry-run"
224+
fi
225+
226+
if [ "${DRY_RUN}" = "true" ]; then
227+
NO_VERIFY_FLAG="--no-verify"
228+
fi
229+
cargo publish $DRY_RUN_FLAG --manifest-path=./Cargo.toml --token $CRATES_TOKEN $NO_VERIFY_FLAG
230+
env:
231+
CRATES_TOKEN: ${{ secrets.CRATES_TOKEN }}
232+
DRY_RUN: ${{ env.DRY_RUN }}

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ ci-test-unit:
5252
RUST_BACKTRACE=1 cargo $(CARGO_TEST_NOCAP)
5353

5454
ci-test-integration:
55-
cargo build --locked && \
56-
$(MAKE) -C $(DIR)/test-integration test
55+
RUN_TESTS=$(RUN_TESTS) $(MAKE) -C $(DIR)/test-integration test
5756

5857
## NOTE: We're getting the following error in github CI when trying to use
5958
# nightly Rust. Until that is fixed we have to use stable to verify format.

magicblock-aperture/src/encoder.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt::Debug;
2+
13
use hyper::body::Bytes;
24
use json::Serialize;
35
use magicblock_core::{
@@ -20,7 +22,7 @@ use crate::{
2022

2123
/// An abstraction trait over types which specialize in turning various
2224
/// websocket notification payload types into sequence of bytes
23-
pub(crate) trait Encoder: Ord + Eq + Clone {
25+
pub(crate) trait Encoder: Ord + Eq + Clone + Debug {
2426
type Data;
2527
fn encode(
2628
&self,
@@ -64,7 +66,7 @@ impl From<UiAccountEncoding> for AccountEncoder {
6466
}
6567

6668
/// A `programSubscribe` payload encoder
67-
#[derive(PartialEq, PartialOrd, Ord, Eq, Clone)]
69+
#[derive(PartialEq, PartialOrd, Ord, Eq, Clone, Debug)]
6870
pub struct ProgramAccountEncoder {
6971
pub encoder: AccountEncoder,
7072
pub filters: ProgramFilters,
@@ -106,7 +108,7 @@ impl Encoder for ProgramAccountEncoder {
106108
}
107109

108110
/// A `signatureSubscribe` payload encoder
109-
#[derive(PartialEq, PartialOrd, Ord, Eq, Clone)]
111+
#[derive(PartialEq, PartialOrd, Ord, Eq, Clone, Debug)]
110112
pub(crate) struct TransactionResultEncoder;
111113

112114
impl Encoder for TransactionResultEncoder {
@@ -130,7 +132,7 @@ impl Encoder for TransactionResultEncoder {
130132
}
131133

132134
/// A `logsSubscribe` payload encoder
133-
#[derive(PartialEq, PartialOrd, Ord, Eq, Clone)]
135+
#[derive(PartialEq, PartialOrd, Ord, Eq, Clone, Debug)]
134136
pub(crate) enum TransactionLogsEncoder {
135137
All,
136138
Mentions(Pubkey),
@@ -172,7 +174,7 @@ impl Encoder for TransactionLogsEncoder {
172174
}
173175

174176
/// A `slotSubscribe` payload encoder
175-
#[derive(PartialEq, PartialOrd, Ord, Eq, Clone)]
177+
#[derive(PartialEq, PartialOrd, Ord, Eq, Clone, Debug)]
176178
pub(crate) struct SlotEncoder;
177179

178180
impl Encoder for SlotEncoder {

magicblock-aperture/src/requests/websocket/account_subscribe.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ impl WsDispatcher {
3232
.subscribe_to_account(pubkey, encoder, self.chan.clone())
3333
.await;
3434

35+
let result = SubResult::SubId(handle.id);
3536
// Store the cleanup handle to manage the subscription's lifecycle.
36-
self.unsubs.insert(handle.id, handle.cleanup);
37-
Ok(SubResult::SubId(handle.id))
37+
self.register_unsub(handle);
38+
39+
Ok(result)
3840
}
3941
}

magicblock-aperture/src/requests/websocket/log_subscribe.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ impl WsDispatcher {
3535
.subscriptions
3636
.subscribe_to_logs(encoder, self.chan.clone());
3737

38-
self.unsubs.insert(handle.id, handle.cleanup);
39-
Ok(SubResult::SubId(handle.id))
38+
let result = SubResult::SubId(handle.id);
39+
// Store the cleanup handle to manage the subscription's lifecycle.
40+
self.register_unsub(handle);
41+
42+
Ok(result)
4043
}
4144
}

magicblock-aperture/src/requests/websocket/program_subscribe.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ impl WsDispatcher {
4343
.subscribe_to_program(pubkey, encoder, self.chan.clone())
4444
.await;
4545

46-
self.unsubs.insert(handle.id, handle.cleanup);
47-
Ok(SubResult::SubId(handle.id))
46+
let result = SubResult::SubId(handle.id);
47+
// Store the cleanup handle to manage the subscription's lifecycle.
48+
self.register_unsub(handle);
49+
50+
Ok(result)
4851
}
4952
}

magicblock-aperture/src/requests/websocket/slot_subscribe.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ impl WsDispatcher {
77
/// each time the validator advances to a new slot.
88
pub(crate) fn slot_subscribe(&mut self) -> RpcResult<SubResult> {
99
let handle = self.subscriptions.subscribe_to_slot(self.chan.clone());
10-
self.unsubs.insert(handle.id, handle.cleanup);
11-
Ok(SubResult::SubId(handle.id))
10+
let result = SubResult::SubId(handle.id);
11+
// Store the cleanup handle to manage the subscription's lifecycle.
12+
self.register_unsub(handle);
13+
14+
Ok(result)
1215
}
1316
}

magicblock-aperture/src/server/websocket/connection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl ConnectionHandler {
112112
// Reschedule the next ping
113113
next_ping.as_mut().reset(Instant::now() + PING_PERIOD);
114114

115-
if frame.opcode != OpCode::Text {
115+
if frame.opcode != OpCode::Text && frame.opcode != OpCode::Binary {
116116
continue;
117117
}
118118

magicblock-aperture/src/server/websocket/dispatch.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use crate::{
1212
requests::{JsonRpcWsMethod, JsonWsRequest},
1313
state::{
1414
signatures::SignaturesExpirer,
15-
subscriptions::{CleanUp, SubscriptionID, SubscriptionsDb},
15+
subscriptions::{
16+
CleanUp, SubscriptionHandle, SubscriptionID, SubscriptionsDb,
17+
},
1618
transactions::TransactionsCache,
1719
},
1820
RpcResult,
@@ -123,6 +125,16 @@ impl WsDispatcher {
123125
let success = self.unsubs.remove(&id).is_some();
124126
Ok(SubResult::Unsub(success))
125127
}
128+
129+
/// Register the unsubscription callback for the new subscription on this connection
130+
pub(crate) fn register_unsub(&mut self, handle: SubscriptionHandle) {
131+
let cleanup = self.unsubs.insert(handle.id, handle.cleanup);
132+
// If we have a duplicate subscription, drop the
133+
// previous cleanup callback to prevent double-cleanup
134+
if let Some(mut callback) = cleanup {
135+
callback.0.take();
136+
}
137+
}
126138
}
127139

128140
/// Bundles a connection's unique ID with its dedicated sender channel.

0 commit comments

Comments
 (0)