Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[r2r] refactor p2p message processing flow #1436

Merged
merged 21 commits into from
Aug 15, 2022
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e91189c
refactor p2p message processing flow
onur-ozkan Aug 7, 2022
9588098
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into wo…
onur-ozkan Aug 7, 2022
e3bad18
drop `message` mutability in `process_p2p_message`
onur-ozkan Aug 7, 2022
d1ad936
refactor `fn tx_enum_from_bytes` error type
onur-ozkan Aug 8, 2022
b0284c0
check topics in `lp_topic_list_validation`
onur-ozkan Aug 8, 2022
c852c7d
optimize
onur-ozkan Aug 9, 2022
cc4a0f9
check if there is any byte left in tx deserialization
onur-ozkan Aug 9, 2022
78c6810
add backwards comparison in `fn deserialization`
onur-ozkan Aug 9, 2022
2cf661d
rollback 78c6810
onur-ozkan Aug 9, 2022
396d162
set JEMALLOC_SYS_WITH_MALLOC_CONF on build pipelines
onur-ozkan Aug 9, 2022
68f561a
Update README.md
onur-ozkan Aug 9, 2022
9426a44
add `_` to unused variables
onur-ozkan Aug 9, 2022
2a08b77
refactor `lp_topic_list_validation` as `topic_prefix_and_coin_validat…
onur-ozkan Aug 9, 2022
49d31ab
fix reviews
onur-ozkan Aug 10, 2022
ee14db8
update `tx_enum_from_bytes` and write unit test
onur-ozkan Aug 11, 2022
eb0a249
Merge branch 'dev' of github.com:KomodoPlatform/atomicDEX-API into wo…
onur-ozkan Aug 11, 2022
c0773dd
update `tx_enum_from_bytes` in tendermint
onur-ozkan Aug 11, 2022
e50c347
update error log of `process_p2p_message`
onur-ozkan Aug 12, 2022
4ae28fb
create `TxMarshalingErr`
onur-ozkan Aug 12, 2022
f38a0d5
fix `test_tx_enum_from_bytes`
onur-ozkan Aug 12, 2022
de40e66
fix test compilation
onur-ozkan Aug 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ RUN cd /mm2 && cargo fetch
# Only needed when we're developing or changing something locally.
#COPY . /mm2

# Important for x86_64 builds
ENV JEMALLOC_SYS_WITH_MALLOC_CONF="background_thread:true,narenas:1,tcache:false,dirty_decay_ms:0,muzzy_decay_ms:0,metadata_thp:auto"

# Build MM1 and MM2.
# Increased verbosity here allows us to see the MM1 CMake logs.
RUN cd /mm2 &&\
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ If you want to build from source, the following prerequisites are required:
rustup default nightly-2022-02-01
rustup component add rustfmt-preview
```


**Note for x86_64 UNIX systems**:
To have more efficient memory consumption please execute the following command before building mm2. (It's also good to have before launching mm2.)
```sh
export JEMALLOC_SYS_WITH_MALLOC_CONF="background_thread:true,narenas:1,tcache:false,dirty_decay_ms:0,muzzy_decay_ms:0,metadata_thp:auto"
artemii235 marked this conversation as resolved.
Show resolved Hide resolved
```

To build, run `cargo build` (or `cargo build -vv` to get verbose build output).

For more detailed instructions, please refer to the [Installation Guide](https://developers.komodoplatform.com/basic-docs/atomicdex/atomicdex-setup/get-started-atomicdex.html).
Expand Down
1 change: 1 addition & 0 deletions azure-pipelines-build-stage-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ jobs:
condition: ne ( variables['Build.Reason'], 'PullRequest' )
env:
MANUAL_MM_VERSION: true
JEMALLOC_SYS_WITH_MALLOC_CONF: "background_thread:true,narenas:1,tcache:false,dirty_decay_ms:0,muzzy_decay_ms:0,metadata_thp:auto"
- task: Docker@2
displayName: Build & Push container of dev branch
condition: and( eq( variables['Agent.OS'], 'Linux' ), eq( variables['Build.SourceBranchName'], 'dev' ) )
Expand Down
1 change: 1 addition & 0 deletions azure-pipelines-release-stage-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
condition: eq( variables['DEBUG_UPLOADED'], '' )
env:
MANUAL_MM_VERSION: true
JEMALLOC_SYS_WITH_MALLOC_CONF: "background_thread:true,narenas:1,tcache:false,dirty_decay_ms:0,muzzy_decay_ms:0,metadata_thp:auto"
- bash: |
zip upload/mm2-$(COMMIT_HASH)-$(Agent.OS)-Debug target-xenial/debug/mm2 target-xenial/debug/libmm2.a -j
displayName: 'Prepare debug build upload Linux'
Expand Down
6 changes: 4 additions & 2 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,8 +1376,10 @@ impl MarketCoinOps for EthCoin {
Box::new(fut.boxed().compat())
}

fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, String> {
Ok(try_s!(signed_eth_tx_from_bytes(bytes)).into())
fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
artemii235 marked this conversation as resolved.
Show resolved Hide resolved
signed_eth_tx_from_bytes(bytes)
.map(TransactionEnum::from)
.map_to_mm(TransactionErr::InvalidTx)
}

fn current_block(&self) -> Box<dyn Future<Item = u64, Error = String> + Send> {
Expand Down
12 changes: 8 additions & 4 deletions mm2src/coins/lightning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use crate::utxo::{sat_from_big_decimal, BlockchainNetwork, FeePolicy, GetUtxoLis
use crate::{BalanceFut, CoinBalance, FeeApproxStage, FoundSwapTxSpend, HistorySyncState, MarketCoinOps, MmCoin,
NegotiateSwapContractAddrErr, RawTransactionFut, RawTransactionRequest, SearchForSwapTxSpendInput,
SignatureError, SignatureResult, SwapOps, TradeFee, TradePreimageFut, TradePreimageResult,
TradePreimageValue, TransactionEnum, TransactionFut, UnexpectedDerivationMethod, UtxoStandardCoin,
ValidateAddressResult, ValidatePaymentInput, VerificationError, VerificationResult, WithdrawError,
WithdrawFut, WithdrawRequest};
TradePreimageValue, TransactionEnum, TransactionErr, TransactionFut, UnexpectedDerivationMethod,
UtxoStandardCoin, ValidateAddressResult, ValidatePaymentInput, VerificationError, VerificationResult,
WithdrawError, WithdrawFut, WithdrawRequest};
use async_trait::async_trait;
use bitcoin::hashes::Hash;
use bitcoin_hashes::sha256::Hash as Sha256;
Expand Down Expand Up @@ -482,7 +482,11 @@ impl MarketCoinOps for LightningCoin {
}

// Todo: Implement this when implementing swaps for lightning as it's is used mainly for swaps
fn tx_enum_from_bytes(&self, _bytes: &[u8]) -> Result<TransactionEnum, String> { unimplemented!() }
fn tx_enum_from_bytes(&self, _bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
MmError::err(TransactionErr::Plain(
"tx_enum_from_bytes is not supported for Lightning yet.".to_string(),
))
}

fn current_block(&self) -> Box<dyn Future<Item = u64, Error = String> + Send> { Box::new(futures01::future::ok(0)) }

Expand Down
4 changes: 3 additions & 1 deletion mm2src/coins/lp_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ pub enum TransactionErr {
TxRecoverable(TransactionEnum, String),
/// Simply for plain error messages.
Plain(String),
InvalidTx(String),
sergeyboyko0791 marked this conversation as resolved.
Show resolved Hide resolved
}

impl TransactionErr {
Expand All @@ -395,6 +396,7 @@ impl TransactionErr {
match self {
TransactionErr::TxRecoverable(_, err) => err.to_string(),
TransactionErr::Plain(err) => err.to_string(),
TransactionErr::InvalidTx(err) => err.to_string(),
}
}
}
Expand Down Expand Up @@ -625,7 +627,7 @@ pub trait MarketCoinOps {
swap_contract_address: &Option<BytesJson>,
) -> TransactionFut;

fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, String>;
fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>>;

fn current_block(&self) -> Box<dyn Future<Item = u64, Error = String> + Send>;

Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/qrc20.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ impl MarketCoinOps for Qrc20Coin {
Box::new(fut.boxed().compat())
}

fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, String> {
fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
utxo_common::tx_enum_from_bytes(self.as_ref(), bytes)
}

Expand Down
12 changes: 8 additions & 4 deletions mm2src/coins/solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::solana::solana_common::{lamports_to_sol, PrepareTransferData, Suffici
use crate::solana::spl::SplTokenInfo;
use crate::{BalanceError, BalanceFut, FeeApproxStage, FoundSwapTxSpend, NegotiateSwapContractAddrErr,
RawTransactionFut, RawTransactionRequest, SearchForSwapTxSpendInput, SignatureResult, TradePreimageFut,
TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionFut, TransactionType,
UnexpectedDerivationMethod, ValidateAddressResult, ValidatePaymentInput, VerificationResult,
WithdrawError, WithdrawFut, WithdrawRequest, WithdrawResult};
TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionErr, TransactionFut,
TransactionType, UnexpectedDerivationMethod, ValidateAddressResult, ValidatePaymentInput,
VerificationResult, WithdrawError, WithdrawFut, WithdrawRequest, WithdrawResult};
use async_trait::async_trait;
use base58::ToBase58;
use bincode::{deserialize, serialize};
Expand Down Expand Up @@ -429,7 +429,11 @@ impl MarketCoinOps for SolanaCoin {
unimplemented!()
}

fn tx_enum_from_bytes(&self, _bytes: &[u8]) -> Result<TransactionEnum, String> { unimplemented!() }
fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
MmError::err(TransactionErr::Plain(
"tx_enum_from_bytes is not supported for Solana yet.".to_string(),
sergeyboyko0791 marked this conversation as resolved.
Show resolved Hide resolved
))
}

fn current_block(&self) -> Box<dyn Future<Item = u64, Error = String> + Send> {
let coin = self.clone();
Expand Down
12 changes: 8 additions & 4 deletions mm2src/coins/solana/spl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::solana::solana_common::{ui_amount_to_amount, PrepareTransferData, Suf
use crate::solana::{solana_common, AccountError, SolanaCommonOps, SolanaFeeDetails};
use crate::{BalanceFut, FeeApproxStage, FoundSwapTxSpend, NegotiateSwapContractAddrErr, RawTransactionFut,
RawTransactionRequest, SearchForSwapTxSpendInput, SignatureResult, SolanaCoin, TradePreimageFut,
TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionFut, TransactionType,
UnexpectedDerivationMethod, ValidateAddressResult, ValidatePaymentInput, VerificationResult,
WithdrawError, WithdrawFut, WithdrawRequest, WithdrawResult};
TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionErr, TransactionFut,
TransactionType, UnexpectedDerivationMethod, ValidateAddressResult, ValidatePaymentInput,
VerificationResult, WithdrawError, WithdrawFut, WithdrawRequest, WithdrawResult};
use async_trait::async_trait;
use bincode::serialize;
use common::{async_blocking, now_ms};
Expand Down Expand Up @@ -267,7 +267,11 @@ impl MarketCoinOps for SplToken {
unimplemented!()
}

fn tx_enum_from_bytes(&self, _bytes: &[u8]) -> Result<TransactionEnum, String> { unimplemented!() }
fn tx_enum_from_bytes(&self, _bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
MmError::err(TransactionErr::Plain(
"tx_enum_from_bytes is not supported for Spl yet.".to_string(),
))
}

fn current_block(&self) -> Box<dyn Future<Item = u64, Error = String> + Send> { self.platform_coin.current_block() }

Expand Down
11 changes: 8 additions & 3 deletions mm2src/coins/tendermint/tendermint_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use crate::{big_decimal_from_sat_unsigned, BalanceError, BalanceFut, BigDecimal,
FoundSwapTxSpend, HistorySyncState, MarketCoinOps, MmCoin, NegotiateSwapContractAddrErr,
RawTransactionFut, RawTransactionRequest, SearchForSwapTxSpendInput, SignatureResult, SwapOps, TradeFee,
TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionEnum,
TransactionFut, TransactionType, TxFeeDetails, UnexpectedDerivationMethod, ValidateAddressResult,
ValidatePaymentInput, VerificationResult, WithdrawError, WithdrawFut, WithdrawRequest};
TransactionErr, TransactionFut, TransactionType, TxFeeDetails, UnexpectedDerivationMethod,
ValidateAddressResult, ValidatePaymentInput, VerificationResult, WithdrawError, WithdrawFut,
WithdrawRequest};
use async_trait::async_trait;
use bitcrypto::sha256;
use common::Future01CompatExt;
Expand Down Expand Up @@ -481,7 +482,11 @@ impl MarketCoinOps for TendermintCoin {
todo!()
}

fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, String> { todo!() }
fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
MmError::err(TransactionErr::Plain(
"tx_enum_from_bytes is not supported for Tendermint yet.".to_string(),
))
}

fn current_block(&self) -> Box<dyn Future<Item = u64, Error = String> + Send> {
let coin = self.clone();
Expand Down
10 changes: 7 additions & 3 deletions mm2src/coins/test_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::{CoinBalance, HistorySyncState, MarketCoinOps, MmCoin, RawTransaction
TradeFee, TransactionEnum, TransactionFut};
use crate::{BalanceFut, CanRefundHtlc, FeeApproxStage, FoundSwapTxSpend, NegotiateSwapContractAddrErr,
SearchForSwapTxSpendInput, SignatureResult, TradePreimageFut, TradePreimageResult, TradePreimageValue,
UnexpectedDerivationMethod, ValidateAddressResult, ValidatePaymentInput, VerificationResult, WithdrawFut,
WithdrawRequest};
TransactionErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidatePaymentInput,
VerificationResult, WithdrawFut, WithdrawRequest};
use async_trait::async_trait;
use futures01::Future;
use keys::KeyPair;
Expand Down Expand Up @@ -78,7 +78,11 @@ impl MarketCoinOps for TestCoin {
unimplemented!()
}

fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, String> { unimplemented!() }
fn tx_enum_from_bytes(&self, _bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
MmError::err(TransactionErr::Plain(
"tx_enum_from_bytes is not supported for Test coin yet.".to_string(),
))
}
sergeyboyko0791 marked this conversation as resolved.
Show resolved Hide resolved

fn current_block(&self) -> Box<dyn Future<Item = u64, Error = String> + Send> { unimplemented!() }

Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/bch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,7 @@ impl MarketCoinOps for BchCoin {
)
}

fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, String> {
fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
utxo_common::tx_enum_from_bytes(self.as_ref(), bytes)
}

Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/qtum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ impl MarketCoinOps for QtumCoin {
)
}

fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, String> {
fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
utxo_common::tx_enum_from_bytes(self.as_ref(), bytes)
}

Expand Down
3 changes: 2 additions & 1 deletion mm2src/coins/utxo/slp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ impl MarketCoinOps for SlpToken {
)
}

fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, String> {
fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
self.platform_coin.tx_enum_from_bytes(bytes)
}

Expand Down Expand Up @@ -2016,6 +2016,7 @@ mod slp_tests {
let err = match tx_err.clone() {
TransactionErr::TxRecoverable(_tx, err) => err,
TransactionErr::Plain(err) => err,
TransactionErr::InvalidTx(err) => err,
};

println!("{:?}", err);
Expand Down
9 changes: 7 additions & 2 deletions mm2src/coins/utxo/utxo_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1822,8 +1822,13 @@ pub fn wait_for_output_spend(
Box::new(fut.boxed().compat())
}

pub fn tx_enum_from_bytes(coin: &UtxoCoinFields, bytes: &[u8]) -> Result<TransactionEnum, String> {
let mut transaction: UtxoTx = try_s!(deserialize(bytes).map_err(|err| format!("{:?}", err)));
pub fn tx_enum_from_bytes(coin: &UtxoCoinFields, bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
let mut transaction: UtxoTx = deserialize(bytes).map_to_mm(|e| TransactionErr::InvalidTx(e.to_string()))?;

if bytes.len() != transaction.tx_hex().len() {
return MmError::err(TransactionErr::InvalidTx("Transaction isn't valid.".to_string()));
sergeyboyko0791 marked this conversation as resolved.
Show resolved Hide resolved
}

transaction.tx_hash_algo = coin.tx_hash_algo;
Ok(transaction.into())
}
Expand Down
2 changes: 1 addition & 1 deletion mm2src/coins/utxo/utxo_standard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ impl MarketCoinOps for UtxoStandardCoin {
)
}

fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, String> {
fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
utxo_common::tx_enum_from_bytes(self.as_ref(), bytes)
}

Expand Down
21 changes: 21 additions & 0 deletions mm2src/coins/utxo/utxo_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3994,3 +3994,24 @@ fn test_sign_verify_message_segwit() {
.unwrap();
assert!(is_valid);
}

#[test]
fn test_tx_enum_from_bytes() {
let client = electrum_client_for_test(RICK_ELECTRUM_ADDRS);
let coin = utxo_coin_for_test(client.into(), None, false);

let tx_hex = hex::decode("01000000017b1eabe0209b1fe794124575ef807057c77ada2138ae4fa8d6c4de0398a14f3f00000000494830450221008949f0cb400094ad2b5eb399d59d01c14d73d8fe6e96df1a7150deb388ab8935022079656090d7f6bac4c9a94e0aad311a4268e082a725f8aeae0573fb12ff866a5f01ffffffff01f0ca052a010000001976a914cbc20a7664f2f69e5355aa427045bc15e7c6c77288ac00000000").unwrap();
coin.tx_enum_from_bytes(&tx_hex).unwrap();

let tx_hex = hex::decode("0100000002440f1a2929eb08c350cc8d2385c77c40411560c3b43b65efb5b06f997fc67672020000006b483045022100f82e88af256d2487afe0c30a166c9ecf6b7013e764e1407317c712d47f7731bd0220358a4d7987bfde2271599b5c4376d26f9ce9f1df2e04f5de8f89593352607110012103c6a78589e18b482aea046975e6d0acbdea7bf7dbf04d9d5bd67fda917815e3edfffffffffb9c2fd7a19b55a4ffbda2ce5065d988a4f4efcf1ae567b4ddb6d97529c8fb0c000000006b483045022100dd75291db32dc859657a5eead13b85c340b4d508e57d2450ebfad76484f254130220727fcd65dda046ea62b449ab217da264dbf7c7ca7e63b39c8835973a152752c1012103c6a78589e18b482aea046975e6d0acbdea7bf7dbf04d9d5bd67fda917815e3edffffffff03102700000000000017a9148d0ad41545dea44e914c419d33d422148c35a274870000000000000000166a149c0a919d4e9a23f0234df916a7dd21f9e2fdaa8f931d0000000000001976a9146d9d2b554d768232320587df75c4338ecc8bf37d88acbd8ff160").unwrap();
coin.tx_enum_from_bytes(&tx_hex).unwrap();

let tx_hex = hex::decode("0200000000010192a4497268107d7999e9551be733f5e0eab479be7d995a061a7bbdc43ef0e5ed0000000000feffffff02cd857a00000000001600145cb39bfcd68d520e29cadc990bceb5cd1562c507a0860100000000001600149a85cc05e9a722575feb770a217c73fd6145cf01024730440220030e0fb58889ab939c701f12d950f00b64836a1a33ec0d6697fd3053d469d244022053e33d72ef53b37b86eea8dfebbafffb0f919ef952dcb6ea6058b81576d8dc86012102225de6aed071dc29d0ca10b9f64a4b502e33e55b3c0759eedd8e333834c6a7d07a1f2000").unwrap();
coin.tx_enum_from_bytes(&tx_hex).unwrap();

let err = coin.tx_enum_from_bytes(&vec![0; 1000000]).unwrap_err().into_inner();
assert_eq!(
discriminant(&err),
discriminant(&TransactionErr::InvalidTx(String::new()))
);
}
10 changes: 6 additions & 4 deletions mm2src/coins/z_coin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use crate::{BalanceError, BalanceFut, CoinBalance, FeeApproxStage, FoundSwapTxSp
MmCoin, NegotiateSwapContractAddrErr, NumConversError, PrivKeyActivationPolicy, RawTransactionFut,
RawTransactionRequest, SearchForSwapTxSpendInput, SignatureError, SignatureResult, SwapOps, TradeFee,
TradePreimageFut, TradePreimageResult, TradePreimageValue, TransactionDetails, TransactionEnum,
TransactionFut, TxFeeDetails, UnexpectedDerivationMethod, ValidateAddressResult, ValidatePaymentInput,
VerificationError, VerificationResult, WithdrawFut, WithdrawRequest};
TransactionErr, TransactionFut, TxFeeDetails, UnexpectedDerivationMethod, ValidateAddressResult,
ValidatePaymentInput, VerificationError, VerificationResult, WithdrawFut, WithdrawRequest};
use crate::{Transaction, WithdrawError};
use async_trait::async_trait;
use bitcrypto::{dhash160, dhash256};
Expand Down Expand Up @@ -983,8 +983,10 @@ impl MarketCoinOps for ZCoin {
)
}

fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, String> {
ZTransaction::read(bytes).map(|tx| tx.into()).map_err(|e| e.to_string())
fn tx_enum_from_bytes(&self, bytes: &[u8]) -> Result<TransactionEnum, MmError<TransactionErr>> {
ZTransaction::read(bytes)
.map(TransactionEnum::from)
.map_to_mm(|e| TransactionErr::InvalidTx(e.to_string()))
}

fn current_block(&self) -> Box<dyn Future<Item = u64, Error = String> + Send> {
Expand Down
3 changes: 3 additions & 0 deletions mm2src/mm2_main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ trie-root = "0.16.0"
uuid = { version = "0.7", features = ["serde", "v4"] }
wasm-timer = "0.2.4"

[target.x86_64-unknown-linux-gnu.dependencies]
jemallocator = "0.5.0"

[target.'cfg(target_arch = "wasm32")'.dependencies]
instant = { version = "0.1.12", features = ["wasm-bindgen"] }
js-sys = { version = "0.3.27" }
Expand Down
Loading