Revert "Revert "Revert "self.check_block_data_limit when syncing changes"""
This reverts commit 36a33a8a1f1ed054a539736cc439e76bd2e7f945.
This commit is contained in:
parent
36a33a8a1f
commit
43dd9628e6
@ -742,9 +742,6 @@ impl Web3Connection {
|
|||||||
|
|
||||||
let mut last_hash = H256::zero();
|
let mut last_hash = H256::zero();
|
||||||
|
|
||||||
// TODO: default to true?
|
|
||||||
let mut was_syncing = self.syncing();
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// TODO: what should the max_wait be?
|
// TODO: what should the max_wait be?
|
||||||
match self
|
match self
|
||||||
@ -764,8 +761,6 @@ impl Web3Connection {
|
|||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
warn!("no head block on {}", self);
|
warn!("no head block on {}", self);
|
||||||
|
|
||||||
was_syncing = true;
|
|
||||||
|
|
||||||
self.send_head_block_result(
|
self.send_head_block_result(
|
||||||
Ok(None),
|
Ok(None),
|
||||||
&block_sender,
|
&block_sender,
|
||||||
@ -789,23 +784,6 @@ impl Web3Connection {
|
|||||||
block_map.clone(),
|
block_map.clone(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
if was_syncing {
|
|
||||||
was_syncing = self.syncing();
|
|
||||||
|
|
||||||
if !was_syncing {
|
|
||||||
// we were syncing, but we aren't anymore
|
|
||||||
if let Err(err) = self
|
|
||||||
.check_block_data_limit(&authorization)
|
|
||||||
.await
|
|
||||||
{
|
|
||||||
warn!("unable to check block data limit after syncing ended. {:?}", err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TODO: it wasn't syncing, what if it is now?
|
|
||||||
was_syncing = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@ -816,8 +794,6 @@ impl Web3Connection {
|
|||||||
block_map.clone(),
|
block_map.clone(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
was_syncing = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -831,8 +807,6 @@ impl Web3Connection {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
was_syncing = true;
|
|
||||||
|
|
||||||
// TODO: what should we do? sleep? extra time?
|
// TODO: what should we do? sleep? extra time?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -886,57 +860,25 @@ impl Web3Connection {
|
|||||||
self.send_head_block_result(block, &block_sender, block_map.clone())
|
self.send_head_block_result(block, &block_sender, block_map.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let mut was_syncing = self.syncing();
|
while let Some(new_block) = stream.next().await {
|
||||||
|
// TODO: check the new block's hash to be sure we don't send dupes
|
||||||
|
let new_hash = new_block
|
||||||
|
.hash
|
||||||
|
.expect("blocks should always have a hash here");
|
||||||
|
|
||||||
loop {
|
if new_hash == last_hash {
|
||||||
// TODO: timeout should be based on block time
|
// some rpcs like to give us duplicates. don't waste our time on them
|
||||||
// this timeout is here because
|
continue;
|
||||||
match timeout(Duration::from_secs(60), stream.next()).await {
|
} else {
|
||||||
Ok(Some(new_block)) => {
|
last_hash = new_hash;
|
||||||
// TODO: check the new block's hash to be sure we don't send dupes
|
|
||||||
let new_hash = new_block
|
|
||||||
.hash
|
|
||||||
.expect("blocks should always have a hash here");
|
|
||||||
|
|
||||||
if new_hash == last_hash {
|
|
||||||
// some rpcs like to give us duplicates. don't waste our time on them
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
last_hash = new_hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.send_head_block_result(
|
|
||||||
Ok(Some(Arc::new(new_block))),
|
|
||||||
&block_sender,
|
|
||||||
block_map.clone(),
|
|
||||||
)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
if was_syncing {
|
|
||||||
was_syncing = self.syncing();
|
|
||||||
|
|
||||||
if !was_syncing {
|
|
||||||
// we were syncing, but we aren't anymore
|
|
||||||
if let Err(err) =
|
|
||||||
self.check_block_data_limit(&authorization).await
|
|
||||||
{
|
|
||||||
warn!("unable to check block data limit after syncing ended. {:?}", err);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TODO: it wasn't syncing, what if it is now?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(None) => {
|
|
||||||
warn!("new_heads subscription to {} ended", self);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
warn!("{} timed out waiting for block! {:?}", self, err);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.send_head_block_result(
|
||||||
|
Ok(Some(Arc::new(new_block))),
|
||||||
|
&block_sender,
|
||||||
|
block_map.clone(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear the head block. this might not be needed, but it won't hurt
|
// clear the head block. this might not be needed, but it won't hurt
|
||||||
@ -945,6 +887,7 @@ impl Web3Connection {
|
|||||||
|
|
||||||
// TODO: is this always an error?
|
// TODO: is this always an error?
|
||||||
// TODO: we probably don't want a warn and to return error
|
// TODO: we probably don't want a warn and to return error
|
||||||
|
warn!("new_heads subscription to {} ended", self);
|
||||||
Err(anyhow::anyhow!("new_heads subscription ended"))
|
Err(anyhow::anyhow!("new_heads subscription ended"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user