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

feat(event-streaming): new streams (orders, swaps, eth_fee_estimation) #2172

Open
wants to merge 134 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
7642e69
use a different struct to implement the balance streaming for utxo
mariocynicys Jun 5, 2024
8aee75b
rename UtxoBalanceStreaming -> UtxoBalanceEventStreamer
mariocynicys Jun 17, 2024
94fd9b0
add fixme: reminder to send sse in running swap
mariocynicys Jun 17, 2024
c6ced79
refactor(mm2_event_stream::controller): use less types for easier und…
mariocynicys Jun 27, 2024
fc7e232
add a note about the broadcasting mechanisim
mariocynicys Jun 27, 2024
876226b
Take `event_stream_configuration` out of the `Option<`
mariocynicys Jun 27, 2024
58d436c
don't launch wasm event streamer if there are zero events
mariocynicys Jun 28, 2024
eaca49b
don't error if in native mode while balance streaming enabled
mariocynicys Jul 8, 2024
b893483
generalize event streaming config to be any json config
mariocynicys Jul 8, 2024
737de5b
rework the current events to work with arbitrary input config
mariocynicys Jul 9, 2024
929279f
add always_send parameter to network event config
mariocynicys Jul 10, 2024
4456c74
balance is a better naming, no need for serde_rename now
mariocynicys Jul 10, 2024
1b9aaa5
use a common empty struct for deser-ing empty config
mariocynicys Jul 10, 2024
9504df4
add smart filter object to events
mariocynicys Jul 10, 2024
d113c6f
get rid of `error_event_name`
mariocynicys Jul 12, 2024
209df5f
rename event behavior to event streamer
mariocynicys Jul 12, 2024
4d15a66
new event streaming arch
mariocynicys Jul 15, 2024
009d206
event streamer optimizations and fixmes
mariocynicys Jul 15, 2024
7a6c224
fix not printing streamer id on downcast error
mariocynicys Jul 15, 2024
8fa5950
refuse to add a streamer that is already present
mariocynicys Jul 15, 2024
38e22c3
adapt network and heartbeat streamers to the new interface
mariocynicys Jul 15, 2024
945463f
adapt the rest of the streamers to the new arch
mariocynicys Jul 16, 2024
700e935
abandon CoinFutSpawner & MmFutSpawner in favor of WeakSpawner
mariocynicys Jul 16, 2024
8af7abc
fix compilation issues
mariocynicys Jul 16, 2024
3ade9a2
StreamHandlerInput must be Unpin to call next()
mariocynicys Jul 16, 2024
8972822
PoC: utxo balance streaming using the new streaming manager interface
mariocynicys Jul 16, 2024
bf54981
Revert "PoC: utxo balance streaming using the new streaming manager i…
mariocynicys Jul 16, 2024
cf50389
hide the Controller inside the StreamingManager
mariocynicys Jul 16, 2024
1783c2c
fix wasm compilation
mariocynicys Jul 17, 2024
5655db6
use `fn handle`'s `data_rx` in zcoin balance event streaming
mariocynicys Jul 17, 2024
5a780ed
rename StreamingSendError -> StreamingManagerError
mariocynicys Jul 17, 2024
a736f9b
remove context extraction in eth,zcoin,tendermint,utxo balance events
mariocynicys Jul 17, 2024
eea5e02
no need for error handling macro in zcoin balance streaming
mariocynicys Jul 17, 2024
98f9253
remove ctx from UtxoCoinFields (for now)
mariocynicys Jul 17, 2024
08401d3
clear filtered events in sse_handler
mariocynicys Jul 17, 2024
c089312
try_send: favor broadcasting quickly over delivering messages to slow…
mariocynicys Jul 17, 2024
dc57896
distinguish between SpawnErrors and AddErrors
mariocynicys Jul 17, 2024
a8439ca
remove eventname
mariocynicys Jul 19, 2024
67348ab
keep streamer id for both normal and error events the same
mariocynicys Jul 19, 2024
aab0b1c
let the controller broadcast only to certain clients
mariocynicys Jul 19, 2024
620e35e
convert to sub/pub arch
mariocynicys Jul 19, 2024
571b1a4
move the arc<mutex< from the controller one level up
mariocynicys Jul 19, 2024
0ed45e4
wrap the clients hashmap with a mutex instead of rwlock
mariocynicys Jul 19, 2024
94621f3
ensure atomicity in streaming manager operations
mariocynicys Jul 19, 2024
fb66bf2
fix lint issues
mariocynicys Jul 19, 2024
304c179
adjust only network & core crates to the new changes
mariocynicys Jul 19, 2024
cb1e1c9
abandon the smart Filter object
mariocynicys Jul 19, 2024
4d98d23
rename Event::streamer_id -> Event::event_type
mariocynicys Jul 19, 2024
bc32665
adapt controller tests to the new arch
mariocynicys Jul 22, 2024
2e95af1
fix compilation for the rest of mm2
mariocynicys Jul 22, 2024
7578ddf
fix wasm compilation
mariocynicys Jul 22, 2024
ee32fd1
breaking: change mm2 event_stream_worker_path config parameter
mariocynicys Jul 22, 2024
35e9686
bug: make sure the streamer is up before joining a new client along
mariocynicys Jul 25, 2024
58e5c72
properly timeout in data asker
mariocynicys Jul 22, 2024
e3a4113
move balance network and other streamers to api enabling/disabling
mariocynicys Jul 24, 2024
50978af
Add fee estimation to the streaming API
mariocynicys Jul 25, 2024
8d8d496
remove _streaming postfix from streaming fn names
mariocynicys Jul 25, 2024
0859434
send a non-empty message (success) on successfully rpc call
mariocynicys Jul 25, 2024
eec1f15
stream swap status in real time
mariocynicys Jul 25, 2024
6fad6ab
add order status streaming
mariocynicys Jul 26, 2024
b9d1218
breaking: abandon event_stream_configuration config
mariocynicys Jul 29, 2024
cd831d9
ignore utxo scripthash subscriptions fixme for now
mariocynicys Jul 29, 2024
f54f502
unify all disable streaming endpoints
mariocynicys Jul 29, 2024
481bf5d
remove a fixmes
mariocynicys Jul 29, 2024
a73a0bc
broadcast all from the data asker
mariocynicys Jul 29, 2024
fb4e1ee
use a wrapper around StreamingManager in EventStreamer
mariocynicys Jul 29, 2024
d347e4e
eth balance streaming: attach the address that caused balance fetch e…
mariocynicys Jul 29, 2024
bfb15da
let the manager receive reference through `send`
mariocynicys Jul 29, 2024
4926fff
Revert "let the manager receive reference through `send`"
mariocynicys Jul 29, 2024
3f4484d
using partking lot rwlock to not starve writers
mariocynicys Jul 29, 2024
6c3ce0e
remove eth gas estimator context
mariocynicys Jul 29, 2024
d31ebad
add unit tests for steaming manager
mariocynicys Jul 30, 2024
3b8876d
add `send_fn` to streaming manager to minimize cloning
mariocynicys Aug 1, 2024
8bb36fc
add tx (history) streaming
mariocynicys Aug 1, 2024
5cf1dd7
why use mut & remove?
mariocynicys Aug 1, 2024
fe02050
fail utxo balance streamer initilization if running on top of native rpc
mariocynicys Aug 1, 2024
179b76a
partial impl of zcoin tx history
mariocynicys Aug 2, 2024
3269faa
review: suggestions by sami 1
mariocynicys Aug 13, 2024
1624a3e
streaming_manager: manage streamers & clients & controller from one lock
mariocynicys Aug 13, 2024
a8cd6a6
get rid of the controller
mariocynicys Aug 13, 2024
896636d
explain why tokio is used instead of futures for the channel with cli…
mariocynicys Aug 13, 2024
1b8cab7
impl missing fetch_txs_from_db for zcoin
mariocynicys Aug 8, 2024
a036908
working PoC for zcoin tx (history) streaming
mariocynicys Aug 16, 2024
873c20e
zombie: fix a couple of pitfalls
mariocynicys Aug 16, 2024
746277d
abstract the ugly .0 tuple access
mariocynicys Aug 26, 2024
1d0a75b
fix: actually transfer something for order status events
mariocynicys Aug 28, 2024
c3a99e4
merge with origin/dev
mariocynicys Aug 30, 2024
e5acf6e
merge with origin/dev
mariocynicys Aug 30, 2024
329f152
suggestion from omar: don't nest
mariocynicys Aug 30, 2024
349c5e9
fix wasm compilation
mariocynicys Aug 30, 2024
9f63e6f
fix: test_hd_utxo_tx_history
mariocynicys Sep 5, 2024
bcd4e1c
fix: activate_z_coin_light_with_changing_height
mariocynicys Sep 5, 2024
162ed47
merge with origin/dev
mariocynicys Sep 10, 2024
3f212c4
add `broadcast_to` to send an event to a single client
mariocynicys Sep 11, 2024
2540e83
event streaming for task managed API end points
mariocynicys Sep 11, 2024
12c5b41
stream task status update only to the requesting client
mariocynicys Sep 11, 2024
5d90387
not important; fix test compilation - WithdrawRequest
mariocynicys Sep 11, 2024
5c9dbac
bch standalone activation via task manager
mariocynicys Sep 12, 2024
0ea6367
tendermint coin with-tokens-activation via task manager
mariocynicys Sep 12, 2024
c051400
move tendermint tokens enabler to a todo
mariocynicys Sep 15, 2024
4ca4d69
try_new -> new & let serde do the erroring job
mariocynicys Sep 30, 2024
471c5db
keep balance error wrapped in MmErrro
mariocynicys Sep 30, 2024
f206ce2
merge with origin/dev
mariocynicys Sep 30, 2024
d387d1b
re-introduce get_eth_estimated_fee_per_gas rpc
mariocynicys Oct 2, 2024
f0f6260
remove extra line
mariocynicys Oct 2, 2024
fc133d7
add a fixme: sse endpoint should be authenticated
mariocynicys Oct 2, 2024
bb90b65
re-introduce mm2.json event_streaming_configuration
mariocynicys Oct 6, 2024
41b35e1
setting a default to client_id
mariocynicys Oct 6, 2024
91d98ed
set default cliend_id for rpc tasks
mariocynicys Oct 6, 2024
868ee2c
resolve fixmes
mariocynicys Oct 6, 2024
d2e3734
let event streaming be off by default
mariocynicys Oct 12, 2024
547fc2b
style & code suggestions by onur 1
mariocynicys Oct 12, 2024
3c5b1c6
style & code suggestions by onur 2
mariocynicys Oct 12, 2024
6e7c47d
don't expose the streamer spawn function
mariocynicys Oct 12, 2024
8d1cffd
use future::ready right away in streamer::spawn
mariocynicys Oct 13, 2024
3835964
merge with origin/dev
mariocynicys Oct 13, 2024
c1101c1
stream orderbook reactively
mariocynicys Oct 15, 2024
a1918ec
box orderbook update for enum balancing
mariocynicys Oct 15, 2024
590b2a1
auto subscribe for orderbook topic when orderbook streaming is enabled
mariocynicys Sep 7, 2024
7fe3e53
merge base/rel & rel/base orderbook streamers
mariocynicys Sep 7, 2024
d84bf39
add a todo regarding orderbook streaming in no-login mode
mariocynicys Oct 19, 2024
52af46f
review(dimxy): fix streamer spawner doc comment
mariocynicys Oct 19, 2024
6d6b5a2
merge with origin/dev
mariocynicys Oct 30, 2024
25a27b9
post(1966): enable utxo balance events
mariocynicys Oct 30, 2024
c2f0244
fix: actually (auto) remove the client when they disconnect
mariocynicys Oct 30, 2024
c29cf81
tests(streaming-manager): fix client handle dropped early
mariocynicys Oct 31, 2024
2a5f66c
z_coin wasm tx_history streaming test
mariocynicys Aug 16, 2024
159445b
fix activate_z_coin_*
mariocynicys Nov 1, 2024
853bbf5
add a fixme; check me out
mariocynicys Nov 2, 2024
78cece1
review(onur): cross test event streaming crate
mariocynicys Nov 2, 2024
65bd662
review(onur): don't expose ctx from MmCoin
mariocynicys Nov 6, 2024
e65ace0
review(onur): do the same for tendermint history state machine
mariocynicys Nov 6, 2024
5f775d6
review(sami): code suggestions
mariocynicys Nov 18, 2024
f5dbfdd
review(sami): let event getter return a reference to avoid copying
mariocynicys Nov 18, 2024
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ MM2.json

# mergetool
*.orig
# Dumpster (files not inteded for tracking)
hidden

# Ignore containers runtime directories for dockerized tests
# This directory contains temporary data used by Docker containers during tests execution.
# It is recreated from container-state data each time test containers are started,
# and should not be tracked in version control.
.docker/container-runtime/
.docker/container-runtime/
3 changes: 3 additions & 0 deletions Cargo.lock

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

105 changes: 32 additions & 73 deletions mm2src/coins/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,16 @@ use async_trait::async_trait;
use bitcrypto::{dhash160, keccak256, ripemd160, sha256};
use common::custom_futures::repeatable::{Ready, Retry, RetryOnError};
use common::custom_futures::timeout::FutureTimerExt;
use common::executor::{abortable_queue::AbortableQueue, AbortOnDropHandle, AbortSettings, AbortableSystem,
AbortedError, SpawnAbortable, Timer};
use common::executor::{abortable_queue::AbortableQueue, AbortSettings, AbortableSystem, AbortedError, SpawnAbortable,
Timer};
use common::log::{debug, error, info, warn};
use common::number_type_casting::SafeTypeCastingNumbers;
use common::{now_sec, small_rng, DEX_FEE_ADDR_RAW_PUBKEY};
use crypto::privkey::key_pair_from_secret;
use crypto::{Bip44Chain, CryptoCtx, CryptoCtxError, GlobalHDAccountArc, KeyPairPolicy};
use derive_more::Display;
use enum_derives::EnumFromStringify;

use ethabi::{Contract, Function, Token};
use ethcore_transaction::tx_builders::TxBuilderError;
use ethcore_transaction::{Action, TransactionWrapper, TransactionWrapperBuilder as UnSignedEthTxBuilder,
Expand All @@ -77,7 +78,6 @@ use futures01::Future;
use http::Uri;
use instant::Instant;
use mm2_core::mm_ctx::{MmArc, MmWeak};
use mm2_event_stream::behaviour::{EventBehaviour, EventInitStatus};
use mm2_number::bigdecimal_custom::CheckedDivision;
use mm2_number::{BigDecimal, BigUint, MmNumber};
#[cfg(test)] use mocktopus::macros::*;
Expand Down Expand Up @@ -109,30 +109,30 @@ cfg_wasm32! {
}

use super::{coin_conf, lp_coinfind_or_err, AsyncMutex, BalanceError, BalanceFut, CheckIfMyPaymentSentArgs,
CoinBalance, CoinFutSpawner, CoinProtocol, CoinTransportMetrics, CoinsContext, ConfirmPaymentInput,
EthValidateFeeArgs, FeeApproxStage, FoundSwapTxSpend, HistorySyncState, IguanaPrivKey, MakerSwapTakerCoin,
MarketCoinOps, MmCoin, MmCoinEnum, MyAddressError, MyWalletAddress, NegotiateSwapContractAddrErr,
NumConversError, NumConversResult, PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr,
PrivKeyBuildPolicy, PrivKeyPolicyNotAllowed, RawTransactionError, RawTransactionFut,
RawTransactionRequest, RawTransactionRes, RawTransactionResult, RefundError, RefundPaymentArgs,
RefundResult, RewardTarget, RpcClientType, RpcTransportEventHandler, RpcTransportEventHandlerShared,
SearchForSwapTxSpendInput, SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignEthTransactionParams,
SignRawTransactionEnum, SignRawTransactionRequest, SignatureError, SignatureResult, SpendPaymentArgs,
SwapOps, SwapTxFeePolicy, TakerSwapMakerCoin, TradeFee, TradePreimageError, TradePreimageFut,
TradePreimageResult, TradePreimageValue, Transaction, TransactionDetails, TransactionEnum, TransactionErr,
TransactionFut, TransactionType, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult,
ValidateFeeArgs, ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError,
ValidatePaymentFut, ValidatePaymentInput, VerificationError, VerificationResult, WaitForHTLCTxSpendArgs,
WatcherOps, WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput,
WatcherValidatePaymentInput, WatcherValidateTakerFeeInput, WithdrawError, WithdrawFee, WithdrawFut,
WithdrawRequest, WithdrawResult, EARLY_CONFIRMATION_ERR_LOG, INVALID_CONTRACT_ADDRESS_ERR_LOG,
CoinBalance, CoinProtocol, CoinTransportMetrics, CoinsContext, ConfirmPaymentInput, EthValidateFeeArgs,
FeeApproxStage, FoundSwapTxSpend, HistorySyncState, IguanaPrivKey, MakerSwapTakerCoin, MarketCoinOps,
MmCoin, MmCoinEnum, MyAddressError, MyWalletAddress, NegotiateSwapContractAddrErr, NumConversError,
NumConversResult, PaymentInstructionArgs, PaymentInstructions, PaymentInstructionsErr, PrivKeyBuildPolicy,
PrivKeyPolicyNotAllowed, RawTransactionError, RawTransactionFut, RawTransactionRequest, RawTransactionRes,
RawTransactionResult, RefundError, RefundPaymentArgs, RefundResult, RewardTarget, RpcClientType,
RpcTransportEventHandler, RpcTransportEventHandlerShared, SearchForSwapTxSpendInput,
SendMakerPaymentSpendPreimageInput, SendPaymentArgs, SignEthTransactionParams, SignRawTransactionEnum,
SignRawTransactionRequest, SignatureError, SignatureResult, SpendPaymentArgs, SwapOps, SwapTxFeePolicy,
TakerSwapMakerCoin, TradeFee, TradePreimageError, TradePreimageFut, TradePreimageResult,
TradePreimageValue, Transaction, TransactionDetails, TransactionEnum, TransactionErr, TransactionFut,
TransactionType, TxMarshalingErr, UnexpectedDerivationMethod, ValidateAddressResult, ValidateFeeArgs,
ValidateInstructionsErr, ValidateOtherPubKeyErr, ValidatePaymentError, ValidatePaymentFut,
ValidatePaymentInput, VerificationError, VerificationResult, WaitForHTLCTxSpendArgs, WatcherOps,
WatcherReward, WatcherRewardError, WatcherSearchForSwapTxSpendInput, WatcherValidatePaymentInput,
WatcherValidateTakerFeeInput, WeakSpawner, WithdrawError, WithdrawFee, WithdrawFut, WithdrawRequest,
WithdrawResult, EARLY_CONFIRMATION_ERR_LOG, INVALID_CONTRACT_ADDRESS_ERR_LOG,
INVALID_PAYMENT_STATE_ERR_LOG, INVALID_RECEIVER_ERR_LOG, INVALID_SENDER_ERR_LOG, INVALID_SWAP_ID_ERR_LOG};
pub use rlp;
cfg_native! {
use std::path::PathBuf;
}

mod eth_balance_events;
pub mod eth_balance_events;
mod eth_rpc;
#[cfg(test)] mod eth_tests;
#[cfg(target_arch = "wasm32")] mod eth_wasm_tests;
Expand All @@ -153,10 +153,9 @@ use eth_withdraw::{EthWithdraw, InitEthWithdraw, StandardEthWithdraw};
mod nonce;
use nonce::ParityNonce;

mod eip1559_gas_fee;
pub(crate) use eip1559_gas_fee::FeePerGasEstimated;
use eip1559_gas_fee::{BlocknativeGasApiCaller, FeePerGasSimpleEstimator, GasApiConfig, GasApiProvider,
InfuraGasApiCaller};
pub mod fee_estimation;
use fee_estimation::eip1559::{block_native::BlocknativeGasApiCaller, infura::InfuraGasApiCaller,
simple::FeePerGasSimpleEstimator, FeePerGasEstimated, GasApiConfig, GasApiProvider};
pub(crate) mod eth_swap_v2;

/// https://github.com/artemii235/etomic-swap/blob/master/contracts/EtomicSwap.sol
Expand Down Expand Up @@ -380,7 +379,8 @@ impl TryFrom<PayForGasParams> for PayForGasOption {

type GasDetails = (U256, PayForGasOption);

#[derive(Debug, Display, EnumFromStringify)]
#[derive(Debug, Display, EnumFromStringify, Serialize, SerializeErrorType)]
#[serde(tag = "error_type", content = "error_data")]
pub enum Web3RpcError {
#[display(fmt = "Transport: {}", _0)]
Transport(String),
Expand Down Expand Up @@ -614,29 +614,6 @@ impl From<PrivKeyBuildPolicy> for EthPrivKeyBuildPolicy {
}
}

/// Gas fee estimator loop context, runs a loop to estimate max fee and max priority fee per gas according to EIP-1559 for the next block
///
/// This FeeEstimatorContext handles rpc requests which start and stop gas fee estimation loop and handles the loop itself.
/// FeeEstimatorContext keeps the latest estimated gas fees to return them on rpc request
pub(crate) struct FeeEstimatorContext {
/// Latest estimated gas fee values
pub(crate) estimated_fees: Arc<AsyncMutex<FeePerGasEstimated>>,
/// Handler for estimator loop graceful shutdown
pub(crate) abort_handler: AsyncMutex<Option<AbortOnDropHandle>>,
}

/// Gas fee estimator creation state
pub(crate) enum FeeEstimatorState {
/// Gas fee estimation not supported for this coin
CoinNotSupported,
/// Platform coin required to be enabled for gas fee estimation for this coin
PlatformCoinRequired,
/// Fee estimator created, use simple internal estimator
Simple(AsyncMutex<FeeEstimatorContext>),
/// Fee estimator created, use provider or simple internal estimator (if provider fails)
Provider(AsyncMutex<FeeEstimatorContext>),
}

/// pImpl idiom.
pub struct EthCoinImpl {
ticker: String,
Expand Down Expand Up @@ -677,8 +654,6 @@ pub struct EthCoinImpl {
/// consisting of the token address and token ID, separated by a comma. This field is essential for tracking the NFT assets
/// information (chain & contract type, amount etc.), where ownership and amount, in ERC1155 case, might change over time.
pub nfts_infos: Arc<AsyncMutex<HashMap<String, NftInfo>>>,
/// Context for eth fee per gas estimator loop. Created if coin supports fee per gas estimation
pub(crate) platform_fee_estimator_state: Arc<FeeEstimatorState>,
/// Config provided gas limits for swap and send transactions
pub(crate) gas_limit: EthGasLimit,
/// This spawner is used to spawn coin's related futures that should be aborted on coin deactivation
Expand Down Expand Up @@ -5146,14 +5121,14 @@ impl EthCoin {
}

/// Get gas base fee and suggest priority tip fees for the next block (see EIP-1559)
pub async fn get_eip1559_gas_fee(&self) -> Web3RpcResult<FeePerGasEstimated> {
pub async fn get_eip1559_gas_fee(&self, use_simple: bool) -> Web3RpcResult<FeePerGasEstimated> {
dimxy marked this conversation as resolved.
Show resolved Hide resolved
let coin = self.clone();
let history_estimator_fut = FeePerGasSimpleEstimator::estimate_fee_by_history(&coin);
let ctx =
MmArc::from_weak(&coin.ctx).ok_or_else(|| MmError::new(Web3RpcError::Internal("ctx is null".into())))?;

let gas_api_conf = ctx.conf["gas_api"].clone();
if gas_api_conf.is_null() {
debug!("No eth gas api provider config, using only history estimator");
if gas_api_conf.is_null() || use_simple {
return history_estimator_fut
.await
.map_err(|e| MmError::new(Web3RpcError::Internal(e.to_string())));
Expand Down Expand Up @@ -5190,7 +5165,7 @@ impl EthCoin {
Ok(PayForGasOption::Legacy(LegacyGasPrice { gas_price }))
},
SwapTxFeePolicy::Low | SwapTxFeePolicy::Medium | SwapTxFeePolicy::High => {
let fee_per_gas = coin.get_eip1559_gas_fee().await?;
let fee_per_gas = coin.get_eip1559_gas_fee(false).await?;
dimxy marked this conversation as resolved.
Show resolved Hide resolved
let pay_result = match swap_fee_policy {
SwapTxFeePolicy::Low => PayForGasOption::Eip1559(Eip1559FeePerGas {
max_fee_per_gas: fee_per_gas.low.max_fee_per_gas,
Expand Down Expand Up @@ -5346,16 +5321,6 @@ impl EthCoin {
Box::new(fut.boxed().compat())
}

async fn spawn_balance_stream_if_enabled(&self, ctx: &MmArc) -> Result<(), String> {
if let Some(stream_config) = &ctx.event_stream_configuration {
if let EventInitStatus::Failed(err) = EventBehaviour::spawn_if_active(self.clone(), stream_config).await {
return ERR!("Failed spawning balance events. Error: {}", err);
}
}

Ok(())
}

/// Requests the nonce from all available nodes and returns the highest nonce available with the list of nodes that returned the highest nonce.
/// Transactions will be sent using the nodes that returned the highest nonce.
pub fn get_addr_nonce(
Expand Down Expand Up @@ -5482,7 +5447,7 @@ impl EthTxFeeDetails {
impl MmCoin for EthCoin {
fn is_asset_chain(&self) -> bool { false }

fn spawner(&self) -> CoinFutSpawner { CoinFutSpawner::new(&self.abortable_system) }
fn spawner(&self) -> WeakSpawner { self.abortable_system.weak_spawner() }

fn get_raw_transaction(&self, req: RawTransactionRequest) -> RawTransactionFut {
Box::new(get_raw_transaction_impl(self.clone(), req).boxed().compat())
Expand Down Expand Up @@ -6372,7 +6337,6 @@ pub async fn eth_coin_from_conf_and_request(
// all spawned futures related to `ETH` coin will be aborted as well.
let abortable_system = try_s!(ctx.abortable_system.create_subsystem());

let platform_fee_estimator_state = FeeEstimatorState::init_fee_estimator(ctx, conf, &coin_type).await?;
let max_eth_tx_type = get_max_eth_tx_type_conf(ctx, conf, &coin_type).await?;
let gas_limit = extract_gas_limit_from_conf(conf)?;

Expand All @@ -6399,15 +6363,11 @@ pub async fn eth_coin_from_conf_and_request(
address_nonce_locks,
erc20_tokens_infos: Default::default(),
nfts_infos: Default::default(),
platform_fee_estimator_state,
gas_limit,
abortable_system,
};

let coin = EthCoin(Arc::new(coin));
coin.spawn_balance_stream_if_enabled(ctx).await?;

Ok(coin)
Ok(EthCoin(Arc::new(coin)))
}

/// Displays the address in mixed-case checksum form
Expand Down Expand Up @@ -7215,7 +7175,6 @@ impl EthCoin {
address_nonce_locks: Arc::clone(&self.address_nonce_locks),
erc20_tokens_infos: Arc::clone(&self.erc20_tokens_infos),
nfts_infos: Arc::clone(&self.nfts_infos),
platform_fee_estimator_state: Arc::clone(&self.platform_fee_estimator_state),
gas_limit: EthGasLimit::default(),
abortable_system: self.abortable_system.create_subsystem().unwrap(),
};
Expand Down
Loading
Loading