Skip to content

Settlement Locking #1818

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

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Conversation

HenriqueNogara
Copy link
Contributor

@HenriqueNogara HenriqueNogara commented Apr 29, 2025

changelog

new features

  • Adds a new workflow for SettleAfterLock instructions;

new external API

  • Added the MaximumLockPeriod associated type to the settlement pallet;
  • Added the following storage to the settlement pallet: LockedTimestamp;
  • Added the following extrinsic to the settlement pallet: lock_instruction;
  • Added the following runtime api: lock_instruction_weight, instruction_asset_count;

new events

  • Added the InstructionLocked variant to the settlement pallet;

other

  • venue_for_management is now called ensure_venue_creator;
  • Improve reject_instruction weight calculation;
  • Improve prune_instruction performance;
  • Add ensure_valid_caller function for removing code duplication;
  • Adds the following errors to the settlement pallet: UnexpectedSettlementType, InvalidInstructionStatusForRejection;
  • Added the following error variants to the settlement pallet: LockTimestampNotFound, ExceededMaximumLockingPeriod, FailedAssetTransferringConditions;

@HenriqueNogara HenriqueNogara requested a review from Copilot April 29, 2025 12:04
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a set of small improvements and refactorings in the settlement module. Key changes include:

  • Renaming of "venue_for_management" to "ensure_venue_creator" and the addition of a new "ensure_valid_caller" function to reduce code duplication.
  • Refinement of weight calculation functions, including new functions (prune_instruction, valid_caller_portfolio, valid_caller_venue, valid_caller_mediator) and updated arithmetic in reject_instruction_common.
  • Updates to error types and benchmarking tests to align error messages and expected outcomes with the new logic.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pallets/weights/src/pallet_settlement.rs Refactored weight functions and removed deprecated reject_instruction.
pallets/settlement/src/benchmarking.rs Added benchmarks for the new caller-validating functions and instruction pruning.
pallets/runtime/tests/src/settlement_test.rs Updated tests to reflect error renaming and changes in behavior.
Comments suppressed due to low confidence (2)

pallets/weights/src/pallet_settlement.rs:1118

  • The write multipliers in reject_instruction_common have been significantly reduced compared to the previous implementation. Please verify that the revised weight increments accurately reflect the intended resource costs.
.saturating_add(DbWeight::get().writes(1))

pallets/runtime/tests/src/settlement_test.rs:2450

  • The error type was updated from Error::Unauthorized to Error::CallerIsNotAParty. Ensure that this change is reflected in the documentation and that all parts of the codebase consistently use the new error code.
error: Error::CallerIsNotAParty.into()

Comment on lines -2638 to +2734
let (caller_did, sk, instruction_details) =
Self::ensure_origin_perm_and_instruction_validity(origin, id, true)?;
let origin_data = pallet_identity::Pallet::<T>::ensure_origin_call_permissions(origin)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a call to ensure_instructino_validity anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have refactored that for improved readability. The same guarantees are achieved by the new match statement added bellow. If the InstructionStatus::Pending only manual instructions that have reached their block can be executed.

@HenriqueNogara HenriqueNogara force-pushed the settlement-small-improvements branch from 302aabd to 6d1de4d Compare May 1, 2025 12:53
…_management

Run benchmarks

Add ensure_valid_cost check back
* Add lock instruction; Allow manual execution for locked instructions; Add simplified transfer

* Add lock_instruction common benchmark

* Improve benchmarks

* Add unit tests

* Add sample weights

* Add rpc calls

* Remove useless test

* Fix benchmarks
@Neopallium Neopallium force-pushed the settlement-small-improvements branch from df5ef0e to 2b42b65 Compare May 6, 2025 11:04
@HenriqueNogara HenriqueNogara changed the title Settlement small improvements Settlement Locking May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants