-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use blocks to determine other environment settlements (#3053)
# Description This PR updates how the `settlement::Observer` distinguishes between settlements from staging and production environments. Staging is usually deployed first, resulting in higher auction IDs, while production lags behind. Since both environments share a settlement contract, they must: - Correctly process settlements from their own environment. - Skip processing settlements from the other environment, while still saving the settlement to auction_id relationship in the database. Detecting staging settlements in production is straightforward and handled by the "AuctionNotFound" error, as staging auctions have higher IDs that don't exist in production yet. However, detecting production settlements in staging has been problematic. Previously, we used the "auction_has_settlement" logic, but this wasn’t reliable. For example, if a staging auction is saved to the database but not settled by solvers, production might settle the same auction after 270 days, leading to incorrect detection. This PR introduces a new approach: if a settlement refers to a VERY old auction (in terms of block time), it’s classified as from the other environment. While this may also catch settlements that violated auction block deadline, from the same environment, this issue hasn't occurred in practice. This solution isn’t perfect but is a reasonable improvement for now. # Changes <!-- List of detailed changes (how the change is accomplished) --> - [ ] Use block numbers to detect settlements with very old auction ids ## How to test Will observe the effects on staging.
- Loading branch information
Showing
13 changed files
with
138 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use primitive_types::U256; | ||
|
||
/// A supported Ethereum Chain ID. | ||
#[derive(Clone, Copy, Debug, Eq, PartialEq)] | ||
pub enum Id { | ||
Mainnet = 1, | ||
Gnosis = 100, | ||
Sepolia = 11155111, | ||
ArbitrumOne = 42161, | ||
} | ||
|
||
impl Id { | ||
pub fn new(value: U256) -> Result<Self, UnsupportedChain> { | ||
// Check to avoid panics for large `U256` values, as there is no checked | ||
// conversion API available and we don't support chains with IDs greater | ||
// than `u64::MAX` anyway. | ||
if value > U256::from(u64::MAX) { | ||
return Err(UnsupportedChain); | ||
} | ||
|
||
match value.as_u64() { | ||
1 => Ok(Self::Mainnet), | ||
100 => Ok(Self::Gnosis), | ||
11155111 => Ok(Self::Sepolia), | ||
42161 => Ok(Self::ArbitrumOne), | ||
_ => Err(UnsupportedChain), | ||
} | ||
} | ||
|
||
/// Returns the network ID for the chain. | ||
pub fn network_id(self) -> &'static str { | ||
match self { | ||
Id::Mainnet => "1", | ||
Id::Gnosis => "100", | ||
Id::Sepolia => "11155111", | ||
Id::ArbitrumOne => "42161", | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
#[error("unsupported chain")] | ||
pub struct UnsupportedChain; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.