Skip to content

Commit a92eab4

Browse files
bowenwang1996chefsale
authored andcommitted
Revert "fix(rpc): do not serve rpc while the node is syncing (#2985)" (#3059)
A node can be in syncing status as long as it is two blocks behind and this might happen just due to some network glitch. We can probably implement some sophisticated strategy for more fine-grained control, but for now it's better to revert it.
1 parent 0cc71d1 commit a92eab4

4 files changed

Lines changed: 32 additions & 70 deletions

File tree

chain/jsonrpc/client/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ jsonrpc_client!(pub struct JsonRpcClient {
183183
pub fn broadcast_tx_commit(&self, tx: String) -> RpcRequest<FinalExecutionOutcomeView>;
184184
pub fn status(&self) -> RpcRequest<StatusResponse>;
185185
#[allow(non_snake_case)]
186+
pub fn EXPERIMENTAL_check_tx(&self, tx: String) -> RpcRequest<serde_json::Value>;
187+
#[allow(non_snake_case)]
186188
pub fn EXPERIMENTAL_genesis_config(&self) -> RpcRequest<serde_json::Value>;
187189
pub fn health(&self) -> RpcRequest<()>;
188190
pub fn tx(&self, hash: String, account_id: String) -> RpcRequest<FinalExecutionOutcomeView>;

chain/jsonrpc/src/lib.rs

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,6 @@ mod metrics;
5151
const JSON_PAYLOAD_MAX_SIZE: usize = 2 * 1024 * 1024;
5252
const QUERY_DATA_MAX_SIZE: usize = 10 * 1024;
5353

54-
/// RPCs that should only be called when the node is synced
55-
const RPC_REQUIRES_SYNC: [&'static str; 15] = [
56-
"broadcast_tx_async",
57-
"EXPERIMENTAL_broadcast_tx_sync",
58-
"broadcast_tx_commit",
59-
"validators",
60-
"query",
61-
"health",
62-
"tx",
63-
"block",
64-
"chunk",
65-
"EXPERIMENTAL_changes",
66-
"EXPERIMENTAL_changes_in_block",
67-
"next_light_client_block",
68-
"EXPERIMENTAL_light_client_proof",
69-
"light_client_proof",
70-
"gas_price",
71-
];
72-
7354
#[derive(Serialize, Deserialize, Clone, Copy, Debug)]
7455
pub struct RpcPollingConfig {
7556
pub polling_interval: Duration,
@@ -150,7 +131,6 @@ pub enum ServerError {
150131
Timeout,
151132
Closed,
152133
InternalError,
153-
IsSyncing,
154134
}
155135

156136
impl Display for ServerError {
@@ -160,7 +140,6 @@ impl Display for ServerError {
160140
ServerError::Timeout => write!(f, "ServerError: Timeout"),
161141
ServerError::Closed => write!(f, "ServerError: Closed"),
162142
ServerError::InternalError => write!(f, "ServerError: Internal Error"),
163-
ServerError::IsSyncing => write!(f, "ServerError: Node is syncing"),
164143
}
165144
}
166145
}
@@ -232,22 +211,11 @@ impl JsonRpcHandler {
232211
}
233212
}
234213

235-
if RPC_REQUIRES_SYNC.iter().find(|&&s| s == &request.method).is_some() {
236-
match self.client_addr.send(Status { is_health_check: false }).await {
237-
Ok(Ok(result)) => {
238-
if result.sync_info.syncing {
239-
return Err(ServerError::IsSyncing.into());
240-
}
241-
}
242-
Ok(Err(err)) => return Err(RpcError::new(-32_001, err, None)),
243-
Err(_) => return Err(RpcError::server_error::<()>(None)),
244-
}
245-
}
246-
247214
match request.method.as_ref() {
248215
"broadcast_tx_async" => self.send_tx_async(request.params).await,
249216
"EXPERIMENTAL_broadcast_tx_sync" => self.send_tx_sync(request.params).await,
250217
"broadcast_tx_commit" => self.send_tx_commit(request.params).await,
218+
"EXPERIMENTAL_check_tx" => self.check_tx(request.params).await,
251219
"validators" => self.validators(request.params).await,
252220
"query" => self.query(request.params).await,
253221
"health" => self.health().await,
@@ -363,6 +331,10 @@ impl JsonRpcHandler {
363331
self.send_or_check_tx(params, false).await
364332
}
365333

334+
async fn check_tx(&self, params: Option<Value>) -> Result<Value, RpcError> {
335+
self.send_or_check_tx(params, true).await
336+
}
337+
366338
async fn send_or_check_tx(
367339
&self,
368340
params: Option<Value>,

chain/jsonrpc/tests/rpc_transactions.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,28 @@ fn test_tx_status_missing_tx() {
201201
}
202202
});
203203
}
204+
205+
#[test]
206+
fn test_check_invalid_tx() {
207+
test_with_client!(test_utils::NodeType::Validator, client, async move {
208+
let signer = InMemorySigner::from_seed("test1", KeyType::ED25519, "test1");
209+
// invalid base hash
210+
let tx = SignedTransaction::send_money(
211+
1,
212+
"test1".to_string(),
213+
"test2".to_string(),
214+
&signer,
215+
100,
216+
hash(&[1]),
217+
);
218+
let bytes = tx.try_to_vec().unwrap();
219+
match client.EXPERIMENTAL_check_tx(to_base64(&bytes)).await {
220+
Err(e) => {
221+
let s = serde_json::to_string(&e.data.unwrap()).unwrap();
222+
println!("{}", s);
223+
assert_eq!(s, "{\"TxExecutionError\":{\"InvalidTxError\":\"Expired\"}}");
224+
}
225+
Ok(_) => panic!("transaction should not succeed"),
226+
}
227+
});
228+
}

pytest/tests/sanity/rpc_sync.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)