Skip to content

Commit dbc1f9e

Browse files
committed
simplify Executor APIs
Change signatures of methods that don't need to be async or fallible.
1 parent 8bad333 commit dbc1f9e

File tree

7 files changed

+67
-70
lines changed

7 files changed

+67
-70
lines changed

networks/monza/monza-full-node/src/partial.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ impl <T : MonzaExecutor + Send + Sync + Clone>MonzaPartialNode<T> {
4141
}
4242
}
4343

44-
pub async fn bind_transaction_channel(&mut self) -> Result<(), anyhow::Error> {
45-
self.executor.set_tx_channel(self.transaction_sender.clone()).await?;
46-
Ok(())
47-
}
48-
49-
pub async fn bound(executor : T, light_node_client: LightNodeServiceClient<tonic::transport::Channel>) -> Result<Self, anyhow::Error> {
50-
let mut node = Self::new(executor, light_node_client);
51-
node.bind_transaction_channel().await?;
52-
Ok(node)
53-
}
44+
fn bind_transaction_channel(&mut self) {
45+
self.executor.set_tx_channel(self.transaction_sender.clone());
46+
}
47+
48+
pub fn bound(
49+
executor: T,
50+
light_node_client: LightNodeServiceClient<tonic::transport::Channel>,
51+
) -> Result<Self, anyhow::Error> {
52+
let mut node = Self::new(executor, light_node_client);
53+
node.bind_transaction_channel();
54+
Ok(node)
55+
}
5456

5557
pub async fn tick_write_transactions_to_da(&self) -> Result<(), anyhow::Error> {
5658

@@ -225,7 +227,7 @@ impl MonzaPartialNode<MonzaExecutorV1> {
225227
let executor = MonzaExecutorV1::try_from_env(tx).await.context(
226228
"Failed to get executor from environment"
227229
)?;
228-
Self::bound(executor, light_node_client).await
230+
Self::bound(executor, light_node_client)
229231
}
230232

231233
}

networks/suzuka/suzuka-full-node/src/partial.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ impl <T : SuzukaExecutor + Send + Sync + Clone>SuzukaPartialNode<T> {
4141
}
4242
}
4343

44-
pub async fn bind_transaction_channel(&mut self) -> Result<(), anyhow::Error> {
45-
self.executor.set_tx_channel(self.transaction_sender.clone()).await?;
46-
Ok(())
47-
}
48-
49-
pub async fn bound(executor : T, light_node_client: LightNodeServiceClient<tonic::transport::Channel>) -> Result<Self, anyhow::Error> {
50-
let mut node = Self::new(executor, light_node_client);
51-
node.bind_transaction_channel().await?;
52-
Ok(node)
53-
}
44+
fn bind_transaction_channel(&mut self) {
45+
self.executor.set_tx_channel(self.transaction_sender.clone());
46+
}
47+
48+
pub fn bound(
49+
executor: T,
50+
light_node_client: LightNodeServiceClient<tonic::transport::Channel>,
51+
) -> Result<Self, anyhow::Error> {
52+
let mut node = Self::new(executor, light_node_client);
53+
node.bind_transaction_channel();
54+
Ok(node)
55+
}
5456

5557
pub async fn tick_write_transactions_to_da(&self) -> Result<(), anyhow::Error> {
5658

@@ -225,7 +227,7 @@ impl SuzukaPartialNode<SuzukaExecutorV1> {
225227
let executor = SuzukaExecutorV1::try_from_env(tx).await.context(
226228
"Failed to get executor from environment"
227229
)?;
228-
Self::bound(executor, light_node_client).await
230+
Self::bound(executor, light_node_client)
229231
}
230232

231233
}

protocol-units/execution/maptos/opt-executor/src/executor.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,12 @@ impl Executor {
292292
Ok(())
293293
}
294294

295-
pub async fn try_get_context(&self) -> Result<Arc<Context>, anyhow::Error> {
296-
Ok(self.context.clone())
295+
fn context(&self) -> Arc<Context> {
296+
self.context.clone()
297297
}
298298

299-
pub async fn try_get_apis(&self) -> Result<Apis, anyhow::Error> {
300-
let context = self.try_get_context().await?;
301-
Ok(get_apis(context))
299+
pub fn get_apis(&self) -> Apis {
300+
get_apis(self.context())
302301
}
303302

304303
pub async fn run_service(&self) -> Result<(), anyhow::Error> {
@@ -313,9 +312,7 @@ impl Executor {
313312

314313
}
315314

316-
317-
let context = self.try_get_context().await?;
318-
let api_service = get_api_service(context).server(
315+
let api_service = get_api_service(self.context()).server(
319316
format!("http://{:?}", self.aptos_config.aptos_rest_listen_url)
320317
);
321318

@@ -650,7 +647,7 @@ mod tests {
650647
executor.execute_block(block).await?;
651648

652649
// Retrieve the executor's API interface and fetch the transaction by each hash.
653-
let apis = executor.try_get_apis().await?;
650+
let apis = executor.get_apis();
654651
for hash in transaction_hashes {
655652
let _ = apis.transactions.get_transaction_by_hash_inner(
656653
&AcceptType::Bcs,
@@ -743,7 +740,7 @@ mod tests {
743740
Ok(()) as Result<(), anyhow::Error>
744741
});
745742

746-
let api = executor.try_get_apis().await?;
743+
let api = executor.get_apis();
747744
let user_transaction = create_signed_transaction(0, executor.aptos_config.chain_id.clone());
748745
let comparison_user_transaction = user_transaction.clone();
749746
let bcs_user_transaction = bcs::to_bytes(&user_transaction)?;
@@ -774,7 +771,7 @@ mod tests {
774771
Ok(()) as Result<(), anyhow::Error>
775772
});
776773

777-
let api = executor.try_get_apis().await?;
774+
let api = executor.get_apis();
778775
let mut user_transactions = BTreeSet::new();
779776
let mut comparison_user_transactions = BTreeSet::new();
780777
for _ in 0..25 {

protocol-units/execution/monza/executor/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ pub trait MonzaExecutor {
2828
block: ExecutableBlock,
2929
) -> Result<(), anyhow::Error>;
3030

31-
/// Sets the transaction channel.
32-
async fn set_tx_channel(&mut self, tx_channel: Sender<SignedTransaction>) -> Result<(), anyhow::Error>;
33-
34-
/// Gets the dyn API.
35-
async fn get_api(
36-
&self,
37-
mode : &FinalityMode,
38-
) -> Result<Apis, anyhow::Error>;
31+
/// Sets the transaction channel.
32+
fn set_tx_channel(
33+
&mut self,
34+
tx_channel: Sender<SignedTransaction>,
35+
);
36+
37+
/// Gets the dyn API.
38+
fn get_api(&self, mode: FinalityMode) -> Apis;
3939

4040
/// Get block head height.
4141
async fn get_block_head_height(&self) -> Result<u64, anyhow::Error>;

protocol-units/execution/monza/executor/src/v1.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,18 @@ impl MonzaExecutor for MonzaExecutorV1 {
5757
}
5858

5959
/// Sets the transaction channel.
60-
async fn set_tx_channel(
60+
fn set_tx_channel(
6161
&mut self,
6262
tx_channel: Sender<SignedTransaction>,
63-
) -> Result<(), anyhow::Error> {
63+
) {
6464
self.transaction_channel = tx_channel;
65-
Ok(())
6665
}
6766

6867
/// Gets the API.
69-
async fn get_api(&self, _mode: &FinalityMode) -> Result<Apis, anyhow::Error> {
70-
match _mode {
68+
fn get_api(&self, mode: FinalityMode) -> Apis {
69+
match mode {
7170
FinalityMode::Dyn => unimplemented!(),
72-
FinalityMode::Opt => Ok(self.executor.try_get_apis().await?),
71+
FinalityMode::Opt => self.executor.get_apis(),
7372
FinalityMode::Fin => unimplemented!(),
7473
}
7574
}
@@ -166,7 +165,7 @@ mod tests {
166165
let bcs_user_transaction = bcs::to_bytes(&user_transaction)?;
167166

168167
let request = SubmitTransactionPost::Bcs(aptos_api::bcs_payload::Bcs(bcs_user_transaction));
169-
let api = executor.get_api(&FinalityMode::Opt).await?;
168+
let api = executor.get_api(FinalityMode::Opt);
170169
api.transactions.submit_transaction(AcceptType::Bcs, request).await?;
171170

172171
services_handle.abort();
@@ -200,7 +199,7 @@ mod tests {
200199
let bcs_user_transaction = bcs::to_bytes(&user_transaction)?;
201200

202201
let request = SubmitTransactionPost::Bcs(aptos_api::bcs_payload::Bcs(bcs_user_transaction));
203-
let api = executor.get_api(&FinalityMode::Opt).await?;
202+
let api = executor.get_api(FinalityMode::Opt);
204203
api.transactions.submit_transaction(AcceptType::Bcs, request).await?;
205204

206205
let received_transaction = rx.recv().await?;
@@ -261,7 +260,7 @@ mod tests {
261260

262261
let request =
263262
SubmitTransactionPost::Bcs(aptos_api::bcs_payload::Bcs(bcs_user_transaction));
264-
let api = executor.get_api(&FinalityMode::Opt).await?;
263+
let api = executor.get_api(FinalityMode::Opt);
265264
api.transactions.submit_transaction(AcceptType::Bcs, request).await?;
266265

267266
let received_transaction = rx.recv().await?;
@@ -369,7 +368,7 @@ mod tests {
369368
executor.execute_block(block).await?;
370369

371370
// Retrieve the executor's API interface and fetch the transaction by each hash.
372-
let apis = executor.try_get_apis().await?;
371+
let apis = executor.get_apis();
373372
for hash in transaction_hashes {
374373
let _ = apis
375374
.transactions

protocol-units/execution/suzuka/executor/src/lib.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ pub trait SuzukaExecutor {
2828
block: ExecutableBlock,
2929
) -> Result<(), anyhow::Error>;
3030

31-
/// Sets the transaction channel.
32-
async fn set_tx_channel(&mut self, tx_channel: Sender<SignedTransaction>) -> Result<(), anyhow::Error>;
33-
34-
/// Gets the dyn API.
35-
async fn get_api(
36-
&self,
37-
mode : &FinalityMode,
38-
) -> Result<Apis, anyhow::Error>;
31+
/// Sets the transaction channel.
32+
fn set_tx_channel(
33+
&mut self,
34+
tx_channel: Sender<SignedTransaction>,
35+
);
36+
37+
/// Gets the dyn API.
38+
fn get_api(&self, mode: FinalityMode) -> Apis;
3939

4040
/// Get block head height.
4141
async fn get_block_head_height(&self) -> Result<u64, anyhow::Error>;

protocol-units/execution/suzuka/executor/src/v1.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,18 @@ impl SuzukaExecutor for SuzukaExecutorV1 {
6464
}
6565

6666
/// Sets the transaction channel.
67-
async fn set_tx_channel(&mut self, tx_channel: Sender<SignedTransaction>) -> Result<(), anyhow::Error> {
67+
fn set_tx_channel(&mut self, tx_channel: Sender<SignedTransaction>) {
6868
self.transaction_channel = tx_channel;
69-
Ok(())
7069
}
7170

7271
/// Gets the API.
73-
async fn get_api(
72+
fn get_api(
7473
&self,
75-
_mode : &FinalityMode,
76-
) -> Result<Apis, anyhow::Error> {
77-
match _mode {
74+
mode: FinalityMode,
75+
) -> Apis {
76+
match mode {
7877
FinalityMode::Dyn => unimplemented!(),
79-
FinalityMode::Opt => {
80-
Ok(self.executor.try_get_apis().await?)
81-
},
78+
FinalityMode::Opt => self.executor.get_apis(),
8279
FinalityMode::Fin => unimplemented!(),
8380
}
8481
}
@@ -177,7 +174,7 @@ mod opt_tests {
177174
let request = SubmitTransactionPost::Bcs(
178175
aptos_api::bcs_payload::Bcs(bcs_user_transaction)
179176
);
180-
let api = executor.get_api(&FinalityMode::Opt).await?;
177+
let api = executor.get_api(FinalityMode::Opt);
181178
api.transactions.submit_transaction(AcceptType::Bcs, request).await?;
182179

183180
services_handle.abort();
@@ -215,7 +212,7 @@ mod opt_tests {
215212
let request = SubmitTransactionPost::Bcs(
216213
aptos_api::bcs_payload::Bcs(bcs_user_transaction)
217214
);
218-
let api = executor.get_api(&FinalityMode::Opt).await?;
215+
let api = executor.get_api(FinalityMode::Opt);
219216
api.transactions.submit_transaction(AcceptType::Bcs, request).await?;
220217

221218
let received_transaction = rx.recv().await?;

0 commit comments

Comments
 (0)