Remove ability to switch from Ethereum devnet to another chain without resetting subscriptions

Assuming migration is over (migration started at 2eb7ec2f64).
This commit is contained in:
silverpill 2023-03-12 15:50:30 +00:00
parent 138c1e915e
commit 0e9879bacb
4 changed files with 8 additions and 20 deletions

View file

@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Removed
- Disabled post tokenization (can be re-enabled with `ethereum-extras` feature).
- Removed ability to switch from Ethereum devnet to another chain without resetting subscriptions.
### Fixed

View file

@ -10,10 +10,7 @@ use web3::{
};
use mitra_config::{EthereumConfig, Instance};
use mitra_utils::{
caip2::ChainId,
currencies::Currency,
};
use mitra_utils::currencies::Currency;
use crate::activitypub::{
builders::{
@ -180,6 +177,10 @@ pub async fn check_ethereum_subscriptions(
&recipient.id,
).await {
Ok(subscription) => {
if subscription.chain_id != config.chain_id {
log::error!("can't switch to another chain");
continue;
};
let current_sender_address =
subscription.sender_address.unwrap_or("''".to_string());
if current_sender_address != sender_address {
@ -193,24 +194,14 @@ pub async fn check_ethereum_subscriptions(
);
continue;
};
if subscription.chain_id != config.chain_id &&
subscription.chain_id != ChainId::ethereum_devnet()
{
// Switching from from devnet is allowed during migration
// because there's no persistent state
log::error!("can't switch to another chain");
continue;
};
if subscription.updated_at >= block_date {
// Event already processed
continue;
};
// Update subscription expiration date
// TODO: disallow automatic chain ID updates after migration
update_subscription(
db_client,
subscription.id,
&config.chain_id,
&expires_at,
&block_date,
).await?;

View file

@ -56,7 +56,6 @@ pub async fn create_subscription(
pub async fn update_subscription(
db_client: &mut impl DatabaseClient,
subscription_id: i32,
chain_id: &ChainId,
expires_at: &DateTime<Utc>,
updated_at: &DateTime<Utc>,
) -> Result<(), DatabaseError> {
@ -65,15 +64,13 @@ pub async fn update_subscription(
"
UPDATE subscription
SET
chain_id = $2,
expires_at = $3,
updated_at = $4
expires_at = $2,
updated_at = $3
WHERE id = $1
RETURNING sender_id, recipient_id
",
&[
&subscription_id,
&DbChainId::new(chain_id),
&expires_at,
&updated_at,
],

View file

@ -174,7 +174,6 @@ pub async fn check_monero_subscriptions(
update_subscription(
db_client,
subscription.id,
subscription.chain_id.inner(),
&expires_at,
&Utc::now(),
).await?;