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 ### Removed
- Disabled post tokenization (can be re-enabled with `ethereum-extras` feature). - 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 ### Fixed

View file

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

View file

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

View file

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