Skip to content

Commit

Permalink
Fixed merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
zktony committed Aug 12, 2024
2 parents f46de28 + 071b1f9 commit 1ed005a
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 67 deletions.
32 changes: 10 additions & 22 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ pallet-statement = { git = "https://github.com/paritytech/polkadot-sdk", branch
sp-statement-store = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-asset-conversion = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-asset-conversion-tx-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }

frame-metadata-hash-extension = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
orml-vesting = { git = "https://github.com/Polkadex-Substrate/orml-1.1.0.git", branch = "master", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false}
sp-version = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
sp-staking = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
sp-keyring = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
Expand Down Expand Up @@ -172,7 +172,7 @@ sc-basic-authorship = { git = "https://github.com/paritytech/polkadot-sdk", bran
sc-consensus-babe-rpc = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
sc-authority-discovery = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
sc-finality-grandpa-rpc = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0"}
substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
pallet-nomination-pools = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false }
grandpa-primitives = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0", default-features = false, package = "sp-finality-grandpa" }
Expand Down
17 changes: 9 additions & 8 deletions nodes/mainnet/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polkadex-node"
version = "6.0.0"
version = "6.2.0"
authors = ["Polkadex OÜ <https://polkadex.trade>"]
description = "Polkadex main blockchain"
edition = "2021"
Expand All @@ -13,7 +13,7 @@ repository = "https://github.com/Polkadex-Substrate/Polkadex/"
targets = ["x86_64-unknown-linux-gnu"]

[build-dependencies]
substrate-build-script-utils = { version = "5.0.0" }
substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
structopt = { version = "0.3.8", optional = true }

[dependencies]
Expand All @@ -26,16 +26,18 @@ clap = { version = "4.0.9", features = ["derive"] }
itertools = "0.10.1"
jsonrpsee = { version = "0.16.2", features = ["server"] }
# local dependencies
node-polkadex-runtime = { path = "../../runtimes/mainnet" }
node-polkadex-runtime = { path = "../../runtimes/mainnet"}
rpc-assets = { path = "../../rpc/assets" }
pallet-rewards-rpc = { path = "../../pallets/rewards/rpc" }
pallet-ocex-rpc = { path = "../../pallets/ocex/rpc" }
polkadex-client = { path = "../../client" }

thea = { path = "../../pallets/thea" }
pallet-ocex-lmp = { path = "../../pallets/ocex" }
swap-rpc = { path = "../../rpc/swap" }


# Substrate dependencies
frame-metadata-hash-extension = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
frame-benchmarking-cli = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
pallet-im-online = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
Expand Down Expand Up @@ -73,7 +75,6 @@ sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "rel
sc-telemetry = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-keyring = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
#sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-transaction-pool-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-authority-discovery = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
Expand All @@ -82,7 +83,7 @@ sp-statement-store = { git = "https://github.com/paritytech/polkadot-sdk", branc
sc-network-statement = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
pallet-asset-conversion-tx-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
pallet-asset-conversion = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
#Primitives
##Primitives
polkadex-primitives = { path = "../../primitives/polkadex" }
sc-executor = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-cli = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
Expand All @@ -94,12 +95,12 @@ try-runtime-cli = { git = "https://github.com/paritytech/polkadot-sdk.git", bran
[dev-dependencies]
futures = "0.3.9"
tempfile = "3.1.0"
sc-keystore = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-consensus = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-consensus-babe = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-consensus-epochs = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sp-tracing = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-service-test = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-keystore = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0" }
sc-service-test = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.1.0"}

[features]
default = []
Expand Down
1 change: 1 addition & 0 deletions nodes/mainnet/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,7 @@ pub fn get_stakeholder_tokens() -> Vec<(AccountId, Balance)> {
}

#[cfg(test)]
#[allow(dead_code)]
pub(crate) mod tests {
use sp_runtime::BuildStorage;

Expand Down
5 changes: 5 additions & 0 deletions nodes/mainnet/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ pub fn create_extrinsic(
pallet_asset_conversion_tx_payment::ChargeAssetTxPayment::<
node_polkadex_runtime::Runtime,
>::from(tip, None),
frame_metadata_hash_extension::CheckMetadataHash::new(false),
);

let raw_payload = node_polkadex_runtime::SignedPayload::from_raw(
Expand All @@ -121,6 +122,7 @@ pub fn create_extrinsic(
(),
(),
(),
None,
),
);
let signature = raw_payload.using_encoded(|e| sender.sign(e));
Expand Down Expand Up @@ -312,6 +314,7 @@ pub fn new_partial(
}

/// Result of [`new_full_base`].
#[allow(dead_code)]
pub struct NewFullBase {
/// The task manager of the node.
pub task_manager: TaskManager,
Expand Down Expand Up @@ -848,6 +851,7 @@ mod tests {
check_nonce,
check_weight,
tx_payment,
frame_metadata_hash_extension::CheckMetadataHash::new(false),
);
let raw_payload = node_polkadex_runtime::SignedPayload::from_raw(
function.clone(),
Expand All @@ -861,6 +865,7 @@ mod tests {
(),
(),
(),
None,
),
);
let signature = raw_payload.using_encoded(|payload| signer.sign(payload));
Expand Down
17 changes: 15 additions & 2 deletions pallets/ocex/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ impl<T: Config> AggregatorClient<T> {
/// Load signed summary and send it to the aggregator
/// # Parameters
/// * `snapshot_id`: Snapshot id for which signed summary should be loaded and sent
pub fn load_signed_summary_and_send(snapshot_id: u64) {
pub fn load_signed_summary_and_send(
current_set_id: u64,
snapshot_id: u64,
signer: &T::AuthorityId,
auth_index: u16,
) -> Result<(), &'static str> {
let mut key = LAST_PROCESSED_SNAPSHOT.to_vec();
key.append(&mut snapshot_id.encode());

Expand All @@ -56,7 +61,14 @@ impl<T: Config> AggregatorClient<T> {
<<T as Config>::AuthorityId as RuntimeAppPublic>::Signature,
u16,
)>() {
Ok(Some((summary, signature, index))) => {
Ok(Some((mut summary, mut signature, mut index))) => {
// Check if the validator set id is same as the current active, if not, update it and sign again
if summary.validator_set_id != current_set_id {
log::info!(target:"ocex","Signing with new validator set id's keys");
summary.validator_set_id = current_set_id;
signature = signer.sign(&summary.encode()).ok_or("Private key not found")?;
index = auth_index;
}
match serde_json::to_string(&ApprovedSnapshot {
summary: summary.encode(),
index: index.saturated_into(),
Expand All @@ -83,6 +95,7 @@ impl<T: Config> AggregatorClient<T> {
log::error!(target:"ocex","Error loading signed summary for: nonce {:?}, {:?}",snapshot_id,err);
},
}
Ok(())
}

/// Load user action batch from aggregator
Expand Down
10 changes: 3 additions & 7 deletions pallets/ocex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,11 +974,7 @@ pub mod pallet {
claim_safety_period: Option<u32>,
) -> DispatchResult {
T::GovernanceOrigin::ensure_origin(origin)?;
let mut config = if let Some(config) = <ExpectedLMPConfig<T>>::get() {
config
} else {
LMPEpochConfig::default()
};
let mut config = <ExpectedLMPConfig<T>>::get().unwrap_or_default();
let unit: Decimal = Decimal::from(UNIT_BALANCE);
if let Some(total_liquidity_mining_rewards) = total_liquidity_mining_rewards {
config.total_liquidity_mining_rewards =
Expand Down Expand Up @@ -2281,8 +2277,8 @@ impl<T: Config + frame_system::offchain::SendTransactionTypes<Call<T>>> Pallet<T

//Check threshold

const MAJORITY: u8 = 67;
let p = Percent::from_percent(MAJORITY);
const THRESHOLD: u8 = 51;
let p = Percent::from_percent(THRESHOLD);
let threshold = p * authorities.len();

if threshold > signatures.len() {
Expand Down
30 changes: 23 additions & 7 deletions pallets/ocex/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ impl<T: Config> Pallet<T> {
let authorities = Self::validator_set().validators;
let mut available_keys = authorities
.iter()
.enumerate()
.filter_map(move |(_index, authority)| {
.filter_map(move |authority| {
local_keys
.binary_search(authority)
.ok()
Expand Down Expand Up @@ -120,9 +119,8 @@ impl<T: Config> Pallet<T> {
return Err("Last processed snapshot root is not same as on-chain root");
}
info
} else if info.snapshot_id != 0 {
} else if info.snapshot_id != 0 && info.snapshot_id != next_nonce {
log::error!(target:"ocex","Unable to load last processed snapshot summary from on-chain: {:?}",info.snapshot_id);
store_trie_root(H256::zero());
return Err("Unable to load last processed snapshot summary from on-chain");
} else {
info
Expand All @@ -139,8 +137,22 @@ impl<T: Config> Pallet<T> {
// Check if we already processed this snapshot and updated our offchain state.
if last_processed_nonce == next_nonce {
log::debug!(target:"ocex","Submitting last processed snapshot: {:?}",next_nonce);
if !sp_io::offchain::is_validator() {
log::error!(target: "ocex","We have stale signed summary for {:?} but not a validator anymore", last_processed_nonce);
return Ok(true);
}
let current_set_id = Self::validator_set().set_id;
let key = available_keys.first().ok_or("No active keys found")?;
let auth_index = Self::calculate_signer_index(&authorities, key)
.ok_or("Unable to calculate signer index")?;

// resubmit the summary to aggregator
AggregatorClient::<T>::load_signed_summary_and_send(next_nonce);
AggregatorClient::<T>::load_signed_summary_and_send(
current_set_id,
next_nonce,
key,
auth_index as u16,
)?;
return Ok(true);
}
log::info!(target:"ocex","last_processed_nonce: {:?}, next_nonce: {:?}",last_processed_nonce, next_nonce);
Expand Down Expand Up @@ -646,18 +658,22 @@ impl<T: Config> Pallet<T> {
return Err("Invalid egress message for withdraw trading fees");
}
},
IngressMessages::NewLMPEpoch(epoch) => Self::start_new_lmp_epoch(state, epoch)?,
IngressMessages::NewLMPEpoch(_epoch) => {
// Self::start_new_lmp_epoch(state, epoch)?
},
_ => {},
}
}
state_info.last_block = blk.saturated_into();
Ok(verified_egress_messages)
}

#[allow(dead_code)]
/// Reset the offchain state's LMP index and set the epoch
fn start_new_lmp_epoch(state: &mut OffchainState, epoch: u16) -> Result<(), &'static str> {
let mut config = if epoch > 1 {
get_lmp_config(state, epoch)?
get_lmp_config(state, epoch)
.unwrap_or(orderbook_primitives::lmp::LMPConfig { epoch, index: 0 })
} else {
// To Handle the corner case of zero
orderbook_primitives::lmp::LMPConfig { epoch, index: 0 }
Expand Down
Loading

0 comments on commit 1ed005a

Please sign in to comment.