Skip to content

Commit

Permalink
remove minimum block delay check
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronKutch committed Jun 19, 2023
1 parent d80b332 commit ff589fe
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 44 deletions.
8 changes: 2 additions & 6 deletions orchestrator/gbt/src/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use gravity_utils::{
wait_for_cosmos_node_ready,
},
error::GravityError,
get_block_delay, get_expected_block_delay,
get_block_delay,
get_with_retry::get_net_version_with_retry,
types::{BatchRequestMode, GravityBridgeToolsConfig},
TEST_ETH_CHAIN_ID, USE_FINALIZATION,
Expand Down Expand Up @@ -63,16 +63,12 @@ pub async fn orchestrator(
// so we can double check in the logs that there is no configuration problem
let net_version = get_net_version_with_retry(&web3).await;
let block_delay = get_block_delay(&web3).await;
let expected_block_delay = get_expected_block_delay(&web3).await;
info!("Chain ID is {}", net_version);
if net_version == TEST_ETH_CHAIN_ID {
warn!("Chain ID is equal to TEST_ETH_CHAIN_ID, assuming this is a local test net");
}
if USE_FINALIZATION {
info!(
"Using finalization with expected minimum block delay {}",
expected_block_delay
);
info!("Using finalization for block delays",);
} else {
info!(
"Using probabilistic finality with block delay {}",
Expand Down
15 changes: 0 additions & 15 deletions orchestrator/gravity_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ pub const BLOCK_DELAY: Uint256 = u256!(35);
pub const TEST_BLOCK_DELAY: Uint256 = u256!(0);

pub const USE_FINALIZATION: bool = false;
pub const EXPECTED_MIN_BLOCK_DELAY: Uint256 = u256!(0);
pub const TEST_EXPECTED_MIN_BLOCK_DELAY: Uint256 = u256!(0);

/// Only for tests, some chains are quiescent and need dummy transactions to keep block
/// production going and not softlock tests.
Expand All @@ -62,16 +60,3 @@ pub async fn get_block_delay(web3: &Web3) -> Uint256 {
_ => BLOCK_DELAY,
}
}

/// For chains with deterministic finality (`USE_FINALIZATION == true`), they sometimes
/// have a minimum number of blocks that must be created before finalization. We should
/// be extra paranoid and check that the finalized block is at least the expected
/// minimum number of blocks behind the latest block
pub async fn get_expected_block_delay(web3: &Web3) -> Uint256 {
let net_version = get_net_version_with_retry(web3).await;

match net_version {
TEST_ETH_CHAIN_ID => TEST_EXPECTED_MIN_BLOCK_DELAY,
_ => EXPECTED_MIN_BLOCK_DELAY,
}
}
18 changes: 1 addition & 17 deletions orchestrator/orchestrator/src/ethereum_event_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use gravity_utils::{
clarity::{utils::bytes_to_hex_str, Address as EthAddress, Uint256},
deep_space::{coin::Coin, private_key::PrivateKey as CosmosPrivateKey, Contact},
error::GravityError,
get_block_delay, get_expected_block_delay,
get_block_delay,
get_with_retry::{get_finalized_block_number_with_retry, get_latest_block_number_with_retry},
types::{
event_signatures::*, Erc20DeployedEvent, LogicCallExecutedEvent, SendToCosmosEvent,
Expand Down Expand Up @@ -38,23 +38,7 @@ pub async fn check_for_events(
let our_cosmos_address = our_private_key.to_address(&contact.get_prefix()).unwrap();

let ending_block = if USE_FINALIZATION {
// get this first in case inbetween the calls is a block boundary
// don't accidentally use this variable elswhere
let unsafe_latest_block = get_latest_block_number_with_retry(web3).await;

// NOTE: the delay can only be omitted if we are using the `finalized` version on a PoS network
let finalized_block = get_finalized_block_number_with_retry(web3).await;

let expected_delay = get_expected_block_delay(web3).await;

// do this even if `expected_delay` is zero, be extra paranoid
if finalized_block.checked_add(expected_delay).unwrap() > unsafe_latest_block {
return Err(GravityError::UnrecoverableError(format!(
"the finalized block number ({finalized_block:?}) does not have the expected minimum delay \
({expected_delay:?}) over the latest block number ({unsafe_latest_block:?})"
)));
}

finalized_block
} else {
let latest_block = get_latest_block_number_with_retry(web3).await;
Expand Down
8 changes: 2 additions & 6 deletions orchestrator/test_runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use gravity_proto::gravity::query_client::QueryClient as GravityQueryClient;
use gravity_utils::{
clarity::{u256, Address as EthAddress, PrivateKey as EthPrivateKey, Uint256},
deep_space::{coin::Coin, Contact},
get_block_delay, get_expected_block_delay,
get_block_delay,
get_with_retry::get_net_version_with_retry,
u64_array_bigints, DEFAULT_ADDRESS_PREFIX, GRAVITY_DENOM_PREFIX,
TEST_DEFAULT_ETH_NODE_ENDPOINT, TEST_DEFAULT_MINER_KEY, TEST_ETH_CHAIN_ID, TEST_GAS_LIMIT,
Expand Down Expand Up @@ -168,7 +168,6 @@ pub async fn main() {

let net_version = get_net_version_with_retry(&web30).await;
let block_delay = get_block_delay(&web30).await;
let expected_block_delay = get_expected_block_delay(&web30).await;
info!(
"Eth chain ID is {}, Cosmos prefix is {}, denom prefix is {}",
net_version, *ADDRESS_PREFIX, GRAVITY_DENOM_PREFIX
Expand All @@ -177,10 +176,7 @@ pub async fn main() {
warn!("Chain ID is not equal to TEST_ETH_CHAIN_ID");
}
if USE_FINALIZATION {
info!(
"Using finalization with expected minimum block delay {}",
expected_block_delay
);
info!("Using finalization for block delays");
} else {
info!(
"Using probabilistic finality with block delay {}",
Expand Down

0 comments on commit ff589fe

Please sign in to comment.