Skip to content

Commit

Permalink
Mesh 2108/settlement improvements (#1536)
Browse files Browse the repository at this point in the history
* Add v2 extrisic for reject_instruction, withdraw_affirmation, affirm_with_receipts and affirm_instruction

* Add rpc call get_input_cost

* Update json schema with new rpc call and types

* Improve docs

* Call the correct weight function for v2 extrinsics

* Add rcv benchmark weights

* Rename InputCost to AffirmationCount; Remove unimplemented calls

* Remove calls to old functions

* Rename v2 extrinsics; Update schema

---------

Co-authored-by: Adam Dossa <[email protected]>
  • Loading branch information
HenriqueNogara and adamdossa authored Oct 6, 2023
1 parent 612bda0 commit 03cd84f
Show file tree
Hide file tree
Showing 14 changed files with 979 additions and 112 deletions.
96 changes: 94 additions & 2 deletions pallets/common/src/traits/settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use frame_support::weights::Weight;
use sp_std::vec::Vec;

use polymesh_primitives::settlement::{
AssetCount, InstructionId, Leg, LegId, ReceiptMetadata, SettlementType, VenueDetails, VenueId,
VenueType,
AffirmationCount, AssetCount, InstructionId, Leg, LegId, ReceiptMetadata, SettlementType,
VenueDetails, VenueId, VenueType,
};
use polymesh_primitives::{IdentityId, Memo, PortfolioId, Ticker};

Expand Down Expand Up @@ -95,6 +95,9 @@ pub trait WeightInfo {
fn execute_instruction_paused(f: u32, n: u32, o: u32) -> Weight;
fn execute_scheduled_instruction(f: u32, n: u32, o: u32) -> Weight;
fn ensure_root_origin() -> Weight;
fn affirm_with_receipts_rcv(f: u32, n: u32, o: u32) -> Weight;
fn affirm_instruction_rcv(f: u32, n: u32) -> Weight;
fn withdraw_affirmation_rcv(f: u32, n: u32, o: u32) -> Weight;

fn add_instruction_legs(legs: &[Leg]) -> Weight {
let (f, n, o) = Self::get_transfer_by_asset(legs);
Expand Down Expand Up @@ -124,4 +127,93 @@ pub trait WeightInfo {
asset_count.off_chain(),
)
}
fn affirm_with_receipts_input(affirmation_count: Option<AffirmationCount>) -> Weight {
match affirmation_count {
Some(affirmation_count) => {
// The weight for the assets being sent
let sender_asset_count = affirmation_count.sender_asset_count();
let sender_side_weight = Self::affirm_with_receipts(
sender_asset_count.fungible(),
sender_asset_count.non_fungible(),
affirmation_count.offchain_count(),
);
// The weight for the assets being received
let receiver_asset_count = affirmation_count.receiver_asset_count();
let receiver_side_weight = Self::affirm_with_receipts_rcv(
receiver_asset_count.fungible(),
receiver_asset_count.non_fungible(),
0,
);
// Common reads/writes are being added twice
let duplicated_weight = Self::affirm_with_receipts_rcv(0, 0, 0);
// The actual weight is the sum of the sender and receiver weights subtracted by the duplicated weight
sender_side_weight
.saturating_add(receiver_side_weight)
.saturating_sub(duplicated_weight)
}
None => Self::affirm_with_receipts(10, 100, 10),
}
}
fn affirm_instruction_input(affirmation_count: Option<AffirmationCount>) -> Weight {
match affirmation_count {
Some(affirmation_count) => {
// The weight for the assets being sent
let sender_asset_count = affirmation_count.sender_asset_count();
let sender_side_weight = Self::affirm_instruction(
sender_asset_count.fungible(),
sender_asset_count.non_fungible(),
);
// The weight for the assets being received
let receiver_asset_count = affirmation_count.receiver_asset_count();
let receiver_side_weight = Self::affirm_instruction_rcv(
receiver_asset_count.fungible(),
receiver_asset_count.non_fungible(),
);
// Common reads/writes are being added twice
let duplicated_weight = Self::affirm_instruction_rcv(0, 0);
// The actual weight is the sum of the sender and receiver weights subtracted by the duplicated weight
sender_side_weight
.saturating_add(receiver_side_weight)
.saturating_sub(duplicated_weight)
}
None => Self::affirm_instruction(10, 100),
}
}
fn withdraw_affirmation_input(affirmation_count: Option<AffirmationCount>) -> Weight {
match affirmation_count {
Some(affirmation_count) => {
// The weight for the assets being sent
let sender_asset_count = affirmation_count.sender_asset_count();
let sender_side_weight = Self::withdraw_affirmation(
sender_asset_count.fungible(),
sender_asset_count.non_fungible(),
affirmation_count.offchain_count(),
);
// The weight for the assets being received
let receiver_asset_count = affirmation_count.receiver_asset_count();
let receiver_side_weight = Self::withdraw_affirmation_rcv(
receiver_asset_count.fungible(),
receiver_asset_count.non_fungible(),
0,
);
// Common reads/writes are being added twice
let duplicated_weight = Self::withdraw_affirmation_rcv(0, 0, 0);
// The actual weight is the sum of the sender and receiver weights subtracted by the duplicated weight
sender_side_weight
.saturating_add(receiver_side_weight)
.saturating_sub(duplicated_weight)
}
None => Self::withdraw_affirmation(10, 100, 10),
}
}
fn reject_instruction_input(asset_count: Option<AssetCount>) -> Weight {
match asset_count {
Some(asset_count) => Self::reject_instruction(
asset_count.fungible(),
asset_count.non_fungible(),
asset_count.off_chain(),
),
None => Self::reject_instruction(10, 100, 10),
}
}
}
10 changes: 9 additions & 1 deletion pallets/runtime/common/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ macro_rules! runtime_apis {
use pallet_pips::{Vote, VoteCount};
use pallet_protocol_fee_rpc_runtime_api::CappedFee;
use polymesh_primitives::asset::GranularCanTransferResult;
use polymesh_primitives::settlement::{InstructionId, ExecuteInstructionInfo};
use polymesh_primitives::settlement::{InstructionId, ExecuteInstructionInfo, AffirmationCount};
use polymesh_primitives::{
asset::CheckpointId, compliance_manager::AssetComplianceResult, IdentityId, Index, NFTs,
PortfolioId, Signatory, Ticker, WeightMeter, IdentityClaim
Expand Down Expand Up @@ -1006,6 +1006,14 @@ macro_rules! runtime_apis {
) -> ExecuteInstructionInfo {
Settlement::execute_instruction_info(instruction_id)
}

#[inline]
fn get_affirmation_count(
instruction_id: InstructionId,
portfolios: Vec<PortfolioId>,
) -> AffirmationCount {
Settlement::affirmation_count(instruction_id, portfolios)
}
}

$($extra)*
Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/develop/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
authoring_version: 1,
// `spec_version: aaa_bbb_ccd` should match node version v`aaa.bbb.cc`
// N.B. `d` is unpinned from the binary version
spec_version: 6_000_003,
spec_version: 6_000_004,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 4,
Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/mainnet/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
authoring_version: 1,
// `spec_version: aaa_bbb_ccd` should match node version v`aaa.bbb.cc`
// N.B. `d` is unpinned from the binary version
spec_version: 6_000_003,
spec_version: 6_000_004,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 4,
Expand Down
2 changes: 1 addition & 1 deletion pallets/runtime/testnet/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
authoring_version: 1,
// `spec_version: aaa_bbb_ccd` should match node version v`aaa.bbb.cc`
// N.B. `d` is unpinned from the binary version
spec_version: 6_000_003,
spec_version: 6_000_004,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 4,
Expand Down
Loading

0 comments on commit 03cd84f

Please sign in to comment.