mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 20:29:23 +00:00
Have reserialize_chain automatically retry on ConnectionError
Fixes expectations of formatting by expect as well.
This commit is contained in:
@@ -13,26 +13,36 @@ use monero_serai::{
|
|||||||
ringct::RctPrunable,
|
ringct::RctPrunable,
|
||||||
transaction::{Input, Transaction},
|
transaction::{Input, Transaction},
|
||||||
block::Block,
|
block::Block,
|
||||||
rpc::{Rpc, HttpRpc},
|
rpc::{RpcError, Rpc, HttpRpc},
|
||||||
};
|
};
|
||||||
|
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
|
|
||||||
async fn check_block(rpc: Arc<Rpc<HttpRpc>>, block_i: usize) {
|
async fn check_block(rpc: Arc<Rpc<HttpRpc>>, block_i: usize) {
|
||||||
let hash = rpc.get_block_hash(block_i).await.expect("couldn't get block {block_i}'s hash");
|
let hash = loop {
|
||||||
|
match rpc.get_block_hash(block_i).await {
|
||||||
|
Ok(hash) => break hash,
|
||||||
|
Err(RpcError::ConnectionError) => continue,
|
||||||
|
Err(e) => panic!("couldn't get block {block_i}'s hash: {e:?}"),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: Grab the JSON to also check it was deserialized correctly
|
// TODO: Grab the JSON to also check it was deserialized correctly
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
struct BlockResponse {
|
struct BlockResponse {
|
||||||
blob: String,
|
blob: String,
|
||||||
}
|
}
|
||||||
let res: BlockResponse = rpc
|
let res: BlockResponse = loop {
|
||||||
.json_rpc_call("get_block", Some(json!({ "hash": hex::encode(hash) })))
|
match rpc.json_rpc_call("get_block", Some(json!({ "hash": hex::encode(hash) }))).await {
|
||||||
.await
|
Ok(res) => break res,
|
||||||
.expect("couldn't get block {block} via block.hash()");
|
Err(RpcError::ConnectionError) => continue,
|
||||||
|
Err(e) => panic!("couldn't get block {block_i} via block.hash(): {e:?}"),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let blob = hex::decode(res.blob).expect("node returned non-hex block");
|
let blob = hex::decode(res.blob).expect("node returned non-hex block");
|
||||||
let block = Block::read(&mut blob.as_slice()).expect("couldn't deserialize block {block_i}");
|
let block =
|
||||||
|
Block::read(&mut blob.as_slice()).expect(&format!("couldn't deserialize block {block_i}"));
|
||||||
assert_eq!(block.hash(), hash, "hash differs");
|
assert_eq!(block.hash(), hash, "hash differs");
|
||||||
assert_eq!(block.serialize(), blob, "serialization differs");
|
assert_eq!(block.serialize(), blob, "serialization differs");
|
||||||
|
|
||||||
@@ -54,7 +64,8 @@ async fn check_block(rpc: Arc<Rpc<HttpRpc>>, block_i: usize) {
|
|||||||
let mut hashes_hex = block.txs.iter().map(hex::encode).collect::<Vec<_>>();
|
let mut hashes_hex = block.txs.iter().map(hex::encode).collect::<Vec<_>>();
|
||||||
let mut all_txs = vec![];
|
let mut all_txs = vec![];
|
||||||
while !hashes_hex.is_empty() {
|
while !hashes_hex.is_empty() {
|
||||||
let txs: TransactionsResponse = rpc
|
let txs: TransactionsResponse = loop {
|
||||||
|
match rpc
|
||||||
.rpc_call(
|
.rpc_call(
|
||||||
"get_transactions",
|
"get_transactions",
|
||||||
Some(json!({
|
Some(json!({
|
||||||
@@ -62,7 +73,12 @@ async fn check_block(rpc: Arc<Rpc<HttpRpc>>, block_i: usize) {
|
|||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("couldn't call get_transactions");
|
{
|
||||||
|
Ok(txs) => break txs,
|
||||||
|
Err(RpcError::ConnectionError) => continue,
|
||||||
|
Err(e) => panic!("couldn't call get_transactions: {e:?}"),
|
||||||
|
}
|
||||||
|
};
|
||||||
assert!(txs.missed_tx.is_empty());
|
assert!(txs.missed_tx.is_empty());
|
||||||
all_txs.extend(txs.txs);
|
all_txs.extend(txs.txs);
|
||||||
}
|
}
|
||||||
@@ -135,7 +151,8 @@ async fn check_block(rpc: Arc<Rpc<HttpRpc>>, block_i: usize) {
|
|||||||
outs: Vec<Out>,
|
outs: Vec<Out>,
|
||||||
}
|
}
|
||||||
|
|
||||||
let outs: Outs = rpc
|
let outs: Outs = loop {
|
||||||
|
match rpc
|
||||||
.rpc_call(
|
.rpc_call(
|
||||||
"get_outs",
|
"get_outs",
|
||||||
Some(json!({
|
Some(json!({
|
||||||
@@ -147,7 +164,12 @@ async fn check_block(rpc: Arc<Rpc<HttpRpc>>, block_i: usize) {
|
|||||||
})),
|
})),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.expect("couldn't connect to RPC to get outs");
|
{
|
||||||
|
Ok(outs) => break outs,
|
||||||
|
Err(RpcError::ConnectionError) => continue,
|
||||||
|
Err(e) => panic!("couldn't connect to RPC to get outs: {e:?}"),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let rpc_point = |point: &str| {
|
let rpc_point = |point: &str| {
|
||||||
CompressedEdwardsY(
|
CompressedEdwardsY(
|
||||||
|
|||||||
Reference in New Issue
Block a user