Skip to content

Commit 49b2ea3

Browse files
committed
(fix) Return false, not null, when not syncing.
(feat) Add testing details to README
1 parent cdb7208 commit 49b2ea3

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,4 @@ Of the currently undocumented APIs, the following are partially implemented:
103103

104104
* `eth_getBlockByHash` (issue #79)
105105
* `eth_getBlockByNumber` (issue #79)
106-
* `eth_syncing`
107106
* `net_peerCount`

docs/api/eth/eth_syncing.doc.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ eth,mining
88

99
# Description
1010

11-
Returns if the node is mining. zq2 nodes always return `false`.
11+
Returns if the node is synchronising with the main chain.
1212

1313
# Curl
1414

@@ -23,10 +23,22 @@ Returns if the node is mining. zq2 nodes always return `false`.
2323

2424
# Response
2525

26+
If the node is synchronised,
27+
2628
```
2729
{"jsonrpc":"2.0","result":false,"id":"1"}
2830
```
2931

32+
If the node is not synchronised:
33+
34+
```
35+
{"jsonrpc":"2.0","id":"1","result":{"startingBlock":0,"currentBlock":24,"highestBlock":1781}}
36+
```
37+
38+
This tells you that this node started syncing at 0 (we started at
39+
genesis), has validated and committed block 24 and believes that the
40+
highest block in the chain is somewhere near block 1781.
41+
3042
# Arguments
3143

3244
| Parameter | Type | Required | Description |

z2/docs/README.md

+6
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,9 @@ Each field is a comma-separated list of ranges - eg. `2` or `1,4-5`.
5151
Thus `1,2,3/` means "Create a network of three validators - nodes 1,2,3 and start none of them".
5252

5353
Ranges are inclusive, so `2-3` means "start validators 2 and 3" - beware of this because internally we convert to the standard Rust half-open ranges.
54+
55+
## Running the js tests against z2 networks
56+
57+
You can run the js tests against z2 networks. See `evm_scilla_js_tests/README.z2.md` for details.
58+
59+

zilliqa/src/api/eth.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ use tracing::*;
2929

3030
use super::{
3131
to_hex::ToHex,
32-
types::eth::{self, CallParams, ErrorCode, HashOrTransaction, OneOrMany, SyncingResult},
32+
types::eth::{
33+
self, CallParams, ErrorCode, HashOrTransaction, OneOrMany, SyncingResult, SyncingStruct,
34+
},
3335
};
3436
use crate::{
3537
crypto::Hash,
@@ -852,18 +854,18 @@ fn protocol_version(_: Params, _: &Arc<Mutex<Node>>) -> Result<String> {
852854
Ok("0x41".to_string())
853855
}
854856

855-
fn syncing(params: Params, node: &Arc<Mutex<Node>>) -> Result<Option<SyncingResult>> {
857+
fn syncing(params: Params, node: &Arc<Mutex<Node>>) -> Result<SyncingResult> {
856858
expect_end_of_params(&mut params.sequence(), 0, 0)?;
857859
if let Some((starting_block, current_block, highest_block)) =
858860
node.lock().unwrap().consensus.get_sync_data()?
859861
{
860-
Ok(Some(SyncingResult {
862+
Ok(SyncingResult::Struct(SyncingStruct {
861863
starting_block,
862864
current_block,
863865
highest_block,
864866
}))
865867
} else {
866-
Ok(None)
868+
Ok(SyncingResult::Bool(false))
867869
}
868870
}
869871

zilliqa/src/api/types/eth.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,19 @@ pub struct TxPoolContent {
450450

451451
#[derive(Clone, Serialize)]
452452
#[serde(rename_all = "camelCase")]
453-
pub struct SyncingResult {
453+
pub struct SyncingStruct {
454454
pub starting_block: u64,
455455
pub current_block: u64,
456456
pub highest_block: u64,
457457
}
458458

459+
#[derive(Clone, Serialize)]
460+
#[serde(untagged)]
461+
pub enum SyncingResult {
462+
Bool(bool),
463+
Struct(SyncingStruct),
464+
}
465+
459466
#[cfg(test)]
460467
mod tests {
461468
use alloy::primitives::B256;

zilliqa/tests/it/eth.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -1359,14 +1359,21 @@ async fn test_send_transaction_errors(mut network: Network) {
13591359
}
13601360
}
13611361

1362-
#[derive(Clone, Deserialize, Serialize, Debug)]
1362+
#[derive(Clone, Deserialize, Serialize, Debug, PartialEq, Eq)]
13631363
#[serde(rename_all = "camelCase")]
1364-
pub struct SyncingResult {
1364+
pub struct SyncingStruct {
13651365
pub starting_block: u64,
13661366
pub current_block: u64,
13671367
pub highest_block: u64,
13681368
}
13691369

1370+
#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)]
1371+
#[serde(untagged)]
1372+
pub enum SyncingResult {
1373+
Bool(bool),
1374+
Struct(SyncingStruct),
1375+
}
1376+
13701377
#[zilliqa_macros::test]
13711378
async fn test_eth_syncing(mut network: Network) {
13721379
let client = network.rpc_client(0).await.unwrap();
@@ -1379,8 +1386,8 @@ async fn test_eth_syncing(mut network: Network) {
13791386
.await
13801387
.unwrap();
13811388
let result = client
1382-
.request_optional::<(), Option<SyncingResult>>("eth_syncing", None)
1389+
.request_optional::<(), SyncingResult>("eth_syncing", None)
13831390
.await
13841391
.unwrap();
1385-
assert!(result.is_none())
1392+
assert_eq!(result, SyncingResult::Bool(false))
13861393
}

0 commit comments

Comments
 (0)