rebuild nonce and swqos strategy
This commit is contained in:
@@ -33,45 +33,26 @@ impl GasFeeStrategy {
|
||||
/// 设置全局费率策略
|
||||
/// Set global fee strategy
|
||||
pub fn set_global_fee_strategy(cu_limit: u32, cu_price: u64, buy_tip: f64, sell_tip: f64) {
|
||||
GasFeeStrategy::add_normal_fee_strategies(
|
||||
&SwqosType::values()
|
||||
.into_iter()
|
||||
.filter(|swqos_type| !swqos_type.eq(&SwqosType::Default))
|
||||
.collect::<Vec<SwqosType>>(),
|
||||
TradeType::Buy,
|
||||
cu_limit,
|
||||
cu_price,
|
||||
buy_tip,
|
||||
);
|
||||
GasFeeStrategy::add_normal_fee_strategies(
|
||||
&SwqosType::values()
|
||||
.into_iter()
|
||||
.filter(|swqos_type| !swqos_type.eq(&SwqosType::Default))
|
||||
.collect::<Vec<SwqosType>>(),
|
||||
TradeType::Sell,
|
||||
cu_limit,
|
||||
cu_price,
|
||||
sell_tip,
|
||||
);
|
||||
GasFeeStrategy::add_normal_fee_strategy(
|
||||
for swqos_type in SwqosType::values() {
|
||||
if swqos_type.eq(&SwqosType::Default) {
|
||||
continue;
|
||||
}
|
||||
GasFeeStrategy::set(swqos_type, TradeType::Buy, cu_limit, cu_price, buy_tip);
|
||||
GasFeeStrategy::set(swqos_type, TradeType::Sell, cu_limit, cu_price, sell_tip);
|
||||
}
|
||||
|
||||
GasFeeStrategy::set_normal_fee_strategy(
|
||||
SwqosType::Default,
|
||||
TradeType::Buy,
|
||||
cu_limit,
|
||||
cu_price,
|
||||
0.0,
|
||||
);
|
||||
GasFeeStrategy::add_normal_fee_strategy(
|
||||
SwqosType::Default,
|
||||
TradeType::Sell,
|
||||
cu_limit,
|
||||
cu_price,
|
||||
0.0,
|
||||
);
|
||||
}
|
||||
|
||||
/// 为多个服务类型添加高低费率策略,会移除(SwqosType,TradeType)的默认策略。
|
||||
/// Add high-low fee strategies for multiple service types, Will remove the default strategy of (SwqosType,TradeType)
|
||||
pub fn add_high_low_fee_strategies(
|
||||
pub fn set_high_low_fee_strategies(
|
||||
swqos_types: &[SwqosType],
|
||||
trade_type: TradeType,
|
||||
cu_limit: u32,
|
||||
@@ -81,30 +62,15 @@ impl GasFeeStrategy {
|
||||
high_tip: f64,
|
||||
) {
|
||||
for swqos_type in swqos_types {
|
||||
GasFeeStrategy::remove_strategy(*swqos_type, trade_type);
|
||||
GasFeeStrategy::del(*swqos_type, trade_type);
|
||||
GasFeeStrategy::set(*swqos_type, trade_type, cu_limit, high_cu_price, low_tip);
|
||||
GasFeeStrategy::set(*swqos_type, trade_type, cu_limit, low_cu_price, high_tip);
|
||||
}
|
||||
STRATEGIES.rcu(|current_map| {
|
||||
let mut new_map = (**current_map).clone();
|
||||
for swqos_type in swqos_types {
|
||||
if swqos_type.eq(&SwqosType::Default) {
|
||||
continue;
|
||||
}
|
||||
new_map.insert(
|
||||
(*swqos_type, trade_type, GasFeeStrategyType::LowTipHighCuPrice),
|
||||
GasFeeStrategyValue { cu_limit, cu_price: high_cu_price, tip: low_tip },
|
||||
);
|
||||
new_map.insert(
|
||||
(*swqos_type, trade_type, GasFeeStrategyType::HighTipLowCuPrice),
|
||||
GasFeeStrategyValue { cu_limit, cu_price: low_cu_price, tip: high_tip },
|
||||
);
|
||||
}
|
||||
Arc::new(new_map)
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/// 为单个服务类型添加高低费率策略,会移除(SwqosType,TradeType)的默认策略。
|
||||
/// Add high-low fee strategy for a single service type, Will remove the default strategy of (SwqosType,TradeType)
|
||||
pub fn add_high_low_fee_strategy(
|
||||
pub fn set_high_low_fee_strategy(
|
||||
swqos_type: SwqosType,
|
||||
trade_type: TradeType,
|
||||
cu_limit: u32,
|
||||
@@ -116,24 +82,14 @@ impl GasFeeStrategy {
|
||||
if swqos_type.eq(&SwqosType::Default) {
|
||||
return;
|
||||
}
|
||||
GasFeeStrategy::remove_strategy(swqos_type, trade_type);
|
||||
STRATEGIES.rcu(|current_map| {
|
||||
let mut new_map = (**current_map).clone();
|
||||
new_map.insert(
|
||||
(swqos_type, trade_type, GasFeeStrategyType::LowTipHighCuPrice),
|
||||
GasFeeStrategyValue { cu_limit, cu_price: high_cu_price, tip: low_tip },
|
||||
);
|
||||
new_map.insert(
|
||||
(swqos_type, trade_type, GasFeeStrategyType::HighTipLowCuPrice),
|
||||
GasFeeStrategyValue { cu_limit, cu_price: low_cu_price, tip: high_tip },
|
||||
);
|
||||
Arc::new(new_map)
|
||||
});
|
||||
GasFeeStrategy::del(swqos_type, trade_type);
|
||||
GasFeeStrategy::set(swqos_type, trade_type, cu_limit, high_cu_price, low_tip);
|
||||
GasFeeStrategy::set(swqos_type, trade_type, cu_limit, low_cu_price, high_tip);
|
||||
}
|
||||
|
||||
/// 为多个服务类型添加标准费率策略,会移除(SwqosType,TradeType)的高低价策略。
|
||||
/// Add normal fee strategies for multiple service types, Will remove the high-low strategies of (SwqosType,TradeType)
|
||||
pub fn add_normal_fee_strategies(
|
||||
pub fn set_normal_fee_strategies(
|
||||
swqos_types: &[SwqosType],
|
||||
trade_type: TradeType,
|
||||
cu_limit: u32,
|
||||
@@ -141,30 +97,30 @@ impl GasFeeStrategy {
|
||||
tip: f64,
|
||||
) {
|
||||
for swqos_type in swqos_types {
|
||||
GasFeeStrategy::remove_strategy(*swqos_type, trade_type);
|
||||
GasFeeStrategy::del(*swqos_type, trade_type);
|
||||
GasFeeStrategy::set(*swqos_type, trade_type, cu_limit, cu_price, tip);
|
||||
}
|
||||
STRATEGIES.rcu(|current_map| {
|
||||
let mut new_map = (**current_map).clone();
|
||||
for swqos_type in swqos_types {
|
||||
new_map.insert(
|
||||
(*swqos_type, trade_type, GasFeeStrategyType::Normal),
|
||||
GasFeeStrategyValue { cu_limit, cu_price, tip },
|
||||
);
|
||||
}
|
||||
Arc::new(new_map)
|
||||
});
|
||||
}
|
||||
|
||||
/// 为单个服务类型添加标准费率策略,会移除(SwqosType,TradeType)的高低价策略。
|
||||
/// Add normal fee strategy for a single service type, Will remove the high-low strategies of (SwqosType,TradeType)
|
||||
pub fn add_normal_fee_strategy(
|
||||
pub fn set_normal_fee_strategy(
|
||||
swqos_type: SwqosType,
|
||||
cu_limit: u32,
|
||||
cu_price: u64,
|
||||
buy_tip: f64,
|
||||
sell_tip: f64,
|
||||
) {
|
||||
GasFeeStrategy::set(swqos_type, TradeType::Buy, cu_limit, cu_price, buy_tip);
|
||||
GasFeeStrategy::set(swqos_type, TradeType::Sell, cu_limit, cu_price, sell_tip);
|
||||
}
|
||||
|
||||
fn set(
|
||||
swqos_type: SwqosType,
|
||||
trade_type: TradeType,
|
||||
cu_limit: u32,
|
||||
cu_price: u64,
|
||||
tip: f64,
|
||||
) {
|
||||
GasFeeStrategy::remove_strategy(swqos_type, trade_type);
|
||||
GasFeeStrategy::del(swqos_type, trade_type);
|
||||
STRATEGIES.rcu(|current_map| {
|
||||
let mut new_map = (**current_map).clone();
|
||||
new_map.insert(
|
||||
@@ -177,7 +133,7 @@ impl GasFeeStrategy {
|
||||
|
||||
/// 移除指定(SwqosType,TradeType)的策略。
|
||||
/// Remove strategy for specified (SwqosType,TradeType)
|
||||
pub fn remove_strategy(swqos_type: SwqosType, trade_type: TradeType) {
|
||||
fn del(swqos_type: SwqosType, trade_type: TradeType) {
|
||||
STRATEGIES.rcu(|current_map| {
|
||||
let mut new_map = (**current_map).clone();
|
||||
new_map.remove(&(swqos_type, trade_type, GasFeeStrategyType::Normal));
|
||||
|
||||
@@ -19,6 +19,15 @@ pub struct NonceInfo {
|
||||
pub used: bool,
|
||||
}
|
||||
|
||||
/// DurableNonceInfo structure to store durable nonce-related information
|
||||
#[derive(Clone)]
|
||||
pub struct DurableNonceInfo {
|
||||
/// Nonce account address
|
||||
pub nonce_account: Option<Pubkey>,
|
||||
/// Current nonce value
|
||||
pub current_nonce: Option<Hash>,
|
||||
}
|
||||
|
||||
/// NonceInfoStore singleton for storing and managing NonceInfo
|
||||
pub struct NonceCache {
|
||||
/// Internally stored NonceInfo data
|
||||
@@ -50,8 +59,8 @@ impl NonceCache {
|
||||
self.update_nonce_info_partial(nonce_account, None, Some(false));
|
||||
}
|
||||
|
||||
/// Get a copy of NonceInfo
|
||||
pub fn get_nonce_info(&self) -> NonceInfo {
|
||||
/// Get a copy of NonceInfo
|
||||
pub fn get_nonce_info(&self) -> NonceInfo {
|
||||
let nonce_info = self.nonce_info.lock();
|
||||
NonceInfo {
|
||||
nonce_account: nonce_info.nonce_account,
|
||||
@@ -60,6 +69,20 @@ impl NonceCache {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_durable_nonce_info() -> DurableNonceInfo {
|
||||
let nonce_info = Self::get_instance().get_nonce_info();
|
||||
let nonce_account = nonce_info.nonce_account;
|
||||
let current_nonce = if nonce_account.is_some() && nonce_info.current_nonce != Hash::default() {
|
||||
Some(nonce_info.current_nonce)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
DurableNonceInfo {
|
||||
nonce_account,
|
||||
current_nonce,
|
||||
}
|
||||
}
|
||||
|
||||
/// Partially update NonceInfo, only update the passed fields
|
||||
pub fn update_nonce_info_partial(
|
||||
&self,
|
||||
|
||||
Reference in New Issue
Block a user