Skip to content

Commit c4db33b

Browse files
authored
Merge pull request #535 from LayerXcom/feature/feathc
Join_group修正
2 parents c657829 + 8b822f9 commit c4db33b

7 files changed

Lines changed: 60 additions & 13 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!-- Please refer to User's Guide for the explanation of each field -->
2+
<EnclaveConfiguration>
3+
<ProdID>0</ProdID>
4+
<ISVSVN>0</ISVSVN>
5+
<StackMaxSize>0x40000</StackMaxSize>
6+
<HeapMaxSize>0x100000</HeapMaxSize>
7+
<TCSNum>8</TCSNum>
8+
<TCSPolicy>0</TCSPolicy>
9+
<DisableDebug>0</DisableDebug>
10+
<MiscSelect>0</MiscSelect>
11+
<MiscMask>0xFFFFFFFF</MiscMask>
12+
</EnclaveConfiguration>

modules/anonify-eth-driver/src/dispatcher.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,12 @@ impl Dispatcher {
121121
join_group_ecall_cmd: u32,
122122
) -> Result<Self> {
123123
let this = self.clone();
124-
let receipt = self.join_group(signer, gas, join_group_ecall_cmd).await?;
125-
info!("A transaction hash of join_group: {:?}", receipt);
126124

127125
// it spawns a new OS thread, and hosts an event loop.
128126
actix_rt::Arbiter::new().exec_fn(move || {
129127
actix_rt::spawn(async move {
130128
loop {
131-
match self
129+
match this
132130
.fetch_events(fetch_ciphertext_ecall_cmd, fetch_handshake_ecalll_cmd)
133131
.await
134132
{
@@ -140,7 +138,10 @@ impl Dispatcher {
140138
});
141139
});
142140

143-
Ok(this)
141+
let receipt = self.join_group(signer, gas, join_group_ecall_cmd).await?;
142+
info!("A transaction hash of join_group: {:?}", receipt);
143+
144+
Ok(self)
144145
}
145146

146147
pub fn set_healthy(self) -> Self {

modules/anonify-eth-driver/src/eth/connection.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ use super::{event_def::*, event_watcher::Web3Logs};
22
use crate::{
33
cache::EventCache,
44
error::{HostError, Result},
5-
utils::ContractInfo,
5+
utils::{event_fetch_retry_condition, ContractInfo},
66
workflow::*,
77
};
88
use anonify_ecall_types::CommandCiphertext;
99
use anyhow::anyhow;
1010
use ethabi::{Topic, TopicFilter};
11+
use frame_config::{REQUEST_RETRIES, RETRY_DELAY_MILLS};
12+
use frame_retrier::{strategy, Retry};
1113
use std::{env, fs, path::Path};
1214
use web3::{
1315
contract::{Contract, Options},
@@ -189,7 +191,14 @@ impl Web3Contract {
189191
.limit(self.event_limit)
190192
.build();
191193

192-
let logs = self.web3_conn.get_logs(&filter).await?;
194+
let logs = Retry::new(
195+
"fetch_event",
196+
*REQUEST_RETRIES,
197+
strategy::FixedDelay::new(*RETRY_DELAY_MILLS),
198+
)
199+
.set_condition(event_fetch_retry_condition)
200+
.spawn_async(|| async { self.web3_conn.get_logs(&filter).await })
201+
.await?;
193202

194203
Ok(Web3Logs::new(logs, cache))
195204
}

modules/anonify-eth-driver/src/utils.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::{fs, path::Path};
1111
use web3::{
1212
contract::Contract,
1313
transports::Http,
14-
types::{Address, TransactionReceipt, H256},
14+
types::{Address, TransactionReceipt, H256, Log},
1515
};
1616

1717
/// Define a retry condition of deploying contracts.
@@ -66,6 +66,20 @@ pub const fn call_with_conf_retry_condition(res: &Result<TransactionReceipt>) ->
6666
}
6767
}
6868

69+
pub const fn event_fetch_retry_condition(res: &Result<Vec<Log>>) -> bool {
70+
match res {
71+
Ok(_) => false,
72+
Err(err) => match err {
73+
HostError::Web3ContractError(web3_err) => match web3_err {
74+
web3::contract::Error::Abi(_) => false,
75+
_ => true,
76+
},
77+
HostError::EcallOutputNotSet => false,
78+
_ => true,
79+
},
80+
}
81+
}
82+
6983
/// Needed information to handle smart contracts.
7084
#[derive(Debug, Clone)]
7185
pub struct ContractInfo {

nodes/state-runtime/server/src/tests.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ async fn test_join_group_then_handshake() {
533533
)
534534
.await;
535535

536+
env::set_var("MY_ROSTER_IDX", "1");
536537
let enclave2 = EnclaveDir::new()
537538
.init_enclave(true)
538539
.expect("Failed to initialize enclave.");
@@ -580,7 +581,7 @@ async fn test_join_group_then_handshake() {
580581

581582
// Party 2
582583

583-
other_turn();
584+
env::set_var("ACCOUNT_INDEX", "1");
584585

585586
// using the same encryption key because app2 have to sync with bc, but app2's enclave encryption key cannot be set here
586587
// so using app1's key
@@ -606,6 +607,7 @@ async fn test_join_group_then_handshake() {
606607
)
607608
.await;
608609

610+
actix_rt::time::delay_for(time::Duration::from_millis(SYNC_TIME)).await;
609611
let req = test::TestRequest::get()
610612
.uri("/api/v1/state")
611613
.set_json(&balance_of_req(&mut csprng, &enc_key))

scripts/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SGX_SDK ?= /opt/sgxsdk
2020
SGX_MODE ?= HW
2121
SGX_ARCH ?= x64
2222

23-
ifeq ($(TEST), 1)
23+
ifeq ($(TEST), UNIT)
2424
EDL_FILE := Anonify_test.edl
2525
T_H_FILE := Anonify_test_t.h
2626
T_C_FILE := Anonify_test_t.c
@@ -29,6 +29,15 @@ ifeq ($(TEST), 1)
2929
U_C_FILE := Anonify_test_u.c
3030
U_O_FILE := Anonify_test_u.o
3131
Enclave_Config_File_Name := UnitTestEnclave.config.xml
32+
else ifeq ($(TEST), INTEGRATION)
33+
EDL_FILE := Anonify_common.edl
34+
T_H_FILE := Anonify_common_t.h
35+
T_C_FILE := Anonify_common_t.c
36+
T_O_FILE := Anonify_common_t.o
37+
U_H_FILE := Anonify_common_u.h
38+
U_C_FILE := Anonify_common_u.c
39+
U_O_FILE := Anonify_common_u.o
40+
Enclave_Config_File_Name := IntegrationTestEnclave.config.xml
3241
else
3342
EDL_FILE := Anonify_common.edl
3443
T_H_FILE := Anonify_common_t.h

scripts/test.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ echo "Integration testing..."
2121
cd ${ANONIFY_ROOT}/scripts
2222
unset BACKUP
2323
export ENCLAVE_PKG_NAME=key_vault
24-
make DEBUG=1 ENCLAVE_DIR=example/key-vault/enclave
24+
make DEBUG=1 TEST=INTEGRATION ENCLAVE_DIR=example/key-vault/enclave
2525
export BACKUP=disable
2626
export ENCLAVE_PKG_NAME=erc20
27-
make DEBUG=1 ENCLAVE_DIR=example/erc20/enclave
27+
make DEBUG=1 TEST=INTEGRATION ENCLAVE_DIR=example/erc20/enclave
2828

2929
#
3030
# Integration Tests
@@ -67,7 +67,7 @@ exec_sr_node_tests test_health_check \
6767
cd ${ANONIFY_ROOT}/scripts
6868
unset BACKUP
6969
export ENCLAVE_PKG_NAME=erc20
70-
make DEBUG=1 ENCLAVE_DIR=example/erc20/enclave
70+
make DEBUG=1 TEST=INTEGRATION ENCLAVE_DIR=example/erc20/enclave
7171

7272
function exec_kv_node_tests() {
7373
for N in $@
@@ -95,7 +95,7 @@ echo "Unit testing..."
9595
export ENCLAVE_PKG_NAME=units
9696
export BACKUP=disable
9797
cd ${ANONIFY_ROOT}/scripts
98-
make DEBUG=1 TEST=1 ENCLAVE_DIR=tests/units/enclave
98+
make DEBUG=1 TEST=UNIT ENCLAVE_DIR=tests/units/enclave
9999

100100
cd ${ANONIFY_ROOT}
101101
RUST_BACKTRACE=1 RUST_LOG=debug TEST=1 cargo test \

0 commit comments

Comments
 (0)