From faca485ebf3180503e4501042cac886cdab0b5cf Mon Sep 17 00:00:00 2001 From: silverpill Date: Sun, 9 Apr 2023 00:23:12 +0000 Subject: [PATCH] Allow multiple configurations in `blockchains` array --- CHANGELOG.md | 1 + contrib/mitra_config.yaml | 2 +- mitra-config/src/config.rs | 18 ++++++++++++++++-- mitra-config/src/loader.rs | 3 +++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70a4493..ecc8ec7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Added emoji count check to profile data validator. - Check mention and link counts when creating post. - Disable transaction monitor tasks if blockchain integration is disabled. +- Allow multiple configurations in `blockchains` array. ## [1.20.0] - 2023-03-07 diff --git a/contrib/mitra_config.yaml b/contrib/mitra_config.yaml index 7b2f19a..554f422 100644 --- a/contrib/mitra_config.yaml +++ b/contrib/mitra_config.yaml @@ -57,7 +57,7 @@ retention: #blocked_instances: [] # Blockchain integrations -# Multiple configuration are currently not allowed. +# Multi-chain setups are currently not supported. # Chain metadata for EVM chains can be found at https://github.com/ethereum-lists/chains # Signing key for ethereum integration can be generated with `mitractl generate-ethereum-address` #blockchains: diff --git a/mitra-config/src/config.rs b/mitra-config/src/config.rs index a4ae919..b1b1fbf 100644 --- a/mitra-config/src/config.rs +++ b/mitra-config/src/config.rs @@ -1,3 +1,4 @@ +use std::collections::HashMap; use std::path::PathBuf; use log::{Level as LogLevel}; @@ -125,8 +126,21 @@ impl Config { if let Some(ref _blockchain_config) = self._blockchain { panic!("'blockchain' setting is not supported anymore, use 'blockchains' instead"); } else { - if self.blockchains.len() > 1 { - panic!("multichain deployments are not supported"); + let is_error = self.blockchains.iter() + .fold(HashMap::new(), |mut map, blockchain_config| { + let key = match blockchain_config { + BlockchainConfig::Ethereum(_) => 1, + BlockchainConfig::Monero(_) => 2, + }; + map.entry(key) + .and_modify(|count| *count += 1) + .or_insert(1); + map + }) + .into_values() + .any(|count| count > 1); + if is_error { + panic!("'blockchains' array contains more than one chain of the same kind"); }; &self.blockchains } diff --git a/mitra-config/src/loader.rs b/mitra-config/src/loader.rs index 3f07046..7e24570 100644 --- a/mitra-config/src/loader.rs +++ b/mitra-config/src/loader.rs @@ -102,6 +102,9 @@ pub fn parse_config() -> (Config, Vec<&'static str>) { }; check_directory_owner(&config.storage_dir); config.try_instance_url().expect("invalid instance URI"); + if config.blockchains().len() > 1 { + warnings.push("multichain deployments are not recommended"); + }; if let Some(ethereum_config) = config.ethereum_config() { ethereum_config.try_ethereum_chain_id().unwrap(); if !ethereum_config.contract_dir.exists() {