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: add deposit reclaim extrinsic for delegations #295

Merged
merged 13 commits into from
Nov 8, 2021

Conversation

ntn-x2
Copy link
Member

@ntn-x2 ntn-x2 commented Nov 5, 2021

fixes KILTProtocol/ticket#1628

Adds the reclaim_deposit extrinsic to the delegation pallet, callable only by a signed origin which must be the deposit owner. Added tests and benchmarks, which will have to be re-run after review.

An SDK companion PR will follow.

M

Checklist:

  • Get review
  • Address review comments
  • Run benchmarks
  • Merge

@ntn-x2 ntn-x2 added the 💛 medium priority: medium label Nov 5, 2021
@ntn-x2 ntn-x2 self-assigned this Nov 5, 2021
@ntn-x2 ntn-x2 requested review from weichweich and wischli November 5, 2021 13:07
Copy link
Contributor

@weichweich weichweich left a comment

Choose a reason for hiding this comment

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

LGTM
It's all there, tests, doc, functionality. Love it!
But I'm triggered by reclaiming back and returning back! 🍠

pallets/delegation/Cargo.toml Show resolved Hide resolved
pallets/delegation/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

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

LGTM! Two super minor things you could resolve.

I am wondering whether we should keep fn remove_delegation at all since it is pretty redundant with adding the reclaiming.

pallets/delegation/src/benchmarking.rs Outdated Show resolved Hide resolved
pallets/delegation/src/lib.rs Outdated Show resolved Hide resolved
@ntn-x2
Copy link
Member Author

ntn-x2 commented Nov 8, 2021

@wischli I think we should keep both as each of them gives "power" to a different user type, and if we remove the remove function, the owner of a delegation (or attestation, as it has the same feature) would not be able to remove their stuff.

@ntn-x2
Copy link
Member Author

ntn-x2 commented Nov 8, 2021

/bench runtime spiritnet-runtime delegation

@ggera
Copy link
Member

ggera commented Nov 8, 2021

/bench runtime spiritnet-runtime delegation

@kilt-command-bot
Copy link

kilt-command-bot bot commented Nov 8, 2021

Benchmark Runtime Pallet for branch "aa-delegation-deposit-claiming" with command cargo run --quiet --release -p kilt-parachain --features=runtime-benchmarks -- benchmark --chain=spiritnet-dev --steps=50 --repeat=20 --pallet=delegation --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./runtimes/spiritnet/src/weights/delegation.rs --template=.maintain/runtime-weight-template.hbs

Results
Pallet: "delegation", Extrinsic: "create_hierarchy", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationHierarchies (r:1 w:1)
Storage: Ctype Ctypes (r:1 w:0)
Storage: System Account (r:1 w:1)
Storage: Delegation DelegationNodes (r:0 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    48.31
              µs

Reads = 3
Writes = 3

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~=    48.31
              µs

Reads = 3
Writes = 3

Pallet: "delegation", Extrinsic: "add_delegation", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:2 w:2)
Storage: System Account (r:1 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    59.06
              µs

Reads = 3
Writes = 3

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~=    59.06
              µs

Reads = 3
Writes = 3

Pallet: "delegation", Extrinsic: "revoke_delegation_root_child", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:1 w:1)
Storage: Delegation DelegationHierarchies (r:1 w:0)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    22.65
    + r    19.66
    + c    0.066
              µs

Reads = 1 + (1 * r) + (0 * c)
Writes = 0 + (1 * r) + (0 * c)

Min Squares Analysis
========
-- Extrinsic Time --

Data points distribution:
    r     c   mean µs  sigma µs       %
    1     5     41.36     0.182    0.4%
    2     5     62.85     0.184    0.2%
    3     5     82.42     0.202    0.2%
    4     5     101.5     0.277    0.2%
    5     1     120.6     0.271    0.2%
    5     2     120.7     0.388    0.3%
    5     3     120.8     0.432    0.3%
    5     4     120.6     0.196    0.1%
    5     5     120.9     0.312    0.2%

Quality and confidence:
param     error
r         0.046
c         0.046

Model:
Time ~=    21.96
    + r    19.69
    + c    0.139
              µs

Reads = 1 + (1 * r) + (0 * c)
Writes = 0 + (1 * r) + (0 * c)

Pallet: "delegation", Extrinsic: "revoke_delegation_leaf", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:6 w:1)
Storage: Delegation DelegationHierarchies (r:1 w:0)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    41.16
    + r    0.093
    + c    6.047
              µs

Reads = 2 + (0 * r) + (1 * c)
Writes = 1 + (0 * r) + (0 * c)

Min Squares Analysis
========
-- Extrinsic Time --

Data points distribution:
    r     c   mean µs  sigma µs       %
    1     5     71.62     0.276    0.3%
    2     5      71.6     0.324    0.4%
    3     5     71.47     0.134    0.1%
    4     5     71.78     0.419    0.5%
    5     1     47.29     0.288    0.6%
    5     2     54.18     0.379    0.6%
    5     3     60.06     0.207    0.3%
    5     4     65.87      0.13    0.1%
    5     5     71.88     0.228    0.3%

Quality and confidence:
param     error
r         0.029
c         0.029

Model:
Time ~=    41.13
    + r    0.108
    + c    6.051
              µs

Reads = 2 + (0 * r) + (1 * c)
Writes = 1 + (0 * r) + (0 * c)

Pallet: "delegation", Extrinsic: "remove_delegation", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:2 w:2)
Storage: System Account (r:1 w:1)
Storage: Delegation DelegationHierarchies (r:1 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    62.41
    + r    39.17
              µs

Reads = 2 + (2 * r)
Writes = 2 + (2 * r)

Min Squares Analysis
========
-- Extrinsic Time --

Data points distribution:
    r   mean µs  sigma µs       %
    1       101     0.583    0.5%
    2     141.6     0.753    0.5%
    3     179.8     0.688    0.3%
    4     218.9     0.657    0.3%
    5     258.5     0.905    0.3%

Quality and confidence:
param     error
r         0.087

Model:
Time ~=    62.33
    + r    39.22
              µs

Reads = 2 + (2 * r)
Writes = 2 + (2 * r)

Pallet: "delegation", Extrinsic: "reclaim_deposit", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:2 w:2)
Storage: System Account (r:1 w:1)
Storage: Delegation DelegationHierarchies (r:0 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    53.35
    + r     39.4
              µs

Reads = 1 + (2 * r)
Writes = 2 + (2 * r)

Min Squares Analysis
========
-- Extrinsic Time --

Data points distribution:
    r   mean µs  sigma µs       %
    1     92.76     0.189    0.2%
    2     133.1     1.381    1.0%
    3     170.1      0.45    0.2%
    4     209.6     0.452    0.2%
    5     251.2      0.52    0.2%

Quality and confidence:
param     error
r         0.126

Model:
Time ~=    53.37
    + r    39.34
              µs

Reads = 1 + (2 * r)
Writes = 2 + (2 * r)


…hmarks -- benchmark --chain=spiritnet-dev --steps=50 --repeat=20 --pallet=delegation --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./runtimes/spiritnet/src/weights/delegation.rs --template=.maintain/runtime-weight-template.hbs
@ntn-x2
Copy link
Member Author

ntn-x2 commented Nov 8, 2021

/bench runtime peregrine-runtime delegation

@kilt-command-bot
Copy link

kilt-command-bot bot commented Nov 8, 2021

Error running benchmark: aa-delegation-deposit-claiming

stdoutCaught exception in benchmarkRuntime: TypeError: Cannot read properties of undefined (reading 'benchCommand')

@ntn-x2
Copy link
Member Author

ntn-x2 commented Nov 8, 2021

/bench runtime pallet delegation

@kilt-command-bot
Copy link

kilt-command-bot bot commented Nov 8, 2021

Benchmark Runtime Pallet for branch "aa-delegation-deposit-claiming" with command cargo run --quiet --release -p kilt-parachain --features=runtime-benchmarks -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=delegation --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=pallets/delegation/src/default_weights.rs --template=.maintain/weight-template.hbs

Results
Pallet: "delegation", Extrinsic: "create_hierarchy", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationHierarchies (r:1 w:1)
Storage: Ctype Ctypes (r:1 w:0)
Storage: System Account (r:1 w:1)
Storage: Delegation DelegationNodes (r:0 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    47.41
              µs

Reads = 3
Writes = 3

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~=    47.41
              µs

Reads = 3
Writes = 3

Pallet: "delegation", Extrinsic: "add_delegation", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:2 w:2)
Storage: System Account (r:1 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    57.22
              µs

Reads = 3
Writes = 3

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~=    57.22
              µs

Reads = 3
Writes = 3

Pallet: "delegation", Extrinsic: "revoke_delegation_root_child", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:1 w:1)
Storage: Delegation DelegationHierarchies (r:1 w:0)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    22.72
    + r    18.72
    + c        0
              µs

Reads = 1 + (1 * r) + (0 * c)
Writes = 0 + (1 * r) + (0 * c)

Min Squares Analysis
========
-- Extrinsic Time --

Data points distribution:
    r     c   mean µs  sigma µs       %
    1     5     40.33     0.196    0.4%
    2     5     60.54     0.479    0.7%
    3     5     79.51     0.424    0.5%
    4     5     97.87     0.443    0.4%
    5     1     115.7     0.439    0.3%
    5     2     115.8     0.483    0.4%
    5     3     115.8     0.307    0.2%
    5     4     115.6     0.287    0.2%
    5     5     115.6     0.599    0.5%

Quality and confidence:
param     error
r         0.055
c         0.055

Model:
Time ~=    22.15
    + r    18.68
    + c    0.095
              µs

Reads = 1 + (1 * r) + (0 * c)
Writes = 0 + (1 * r) + (0 * c)

Pallet: "delegation", Extrinsic: "revoke_delegation_leaf", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:6 w:1)
Storage: Delegation DelegationHierarchies (r:1 w:0)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    39.52
    + r    0.068
    + c    5.733
              µs

Reads = 2 + (0 * r) + (1 * c)
Writes = 1 + (0 * r) + (0 * c)

Min Squares Analysis
========
-- Extrinsic Time --

Data points distribution:
    r     c   mean µs  sigma µs       %
    1     5     68.14     0.152    0.2%
    2     5     68.48     0.237    0.3%
    3     5     68.19     0.267    0.3%
    4     5     68.41      0.33    0.4%
    5     1     45.08      0.25    0.5%
    5     2     52.03     0.295    0.5%
    5     3     57.58      0.17    0.2%
    5     4     63.19     0.237    0.3%
    5     5     68.58     0.301    0.4%

Quality and confidence:
param     error
r         0.034
c         0.034

Model:
Time ~=    39.25
    + r    0.147
    + c    5.748
              µs

Reads = 2 + (0 * r) + (1 * c)
Writes = 1 + (0 * r) + (0 * c)

Pallet: "delegation", Extrinsic: "remove_delegation", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:2 w:2)
Storage: System Account (r:1 w:1)
Storage: Delegation DelegationHierarchies (r:1 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    61.23
    + r    37.92
              µs

Reads = 2 + (2 * r)
Writes = 2 + (2 * r)

Min Squares Analysis
========
-- Extrinsic Time --

Data points distribution:
    r   mean µs  sigma µs       %
    1     99.06     0.397    0.4%
    2     137.7     0.655    0.4%
    3     173.8     0.668    0.3%
    4     213.5     1.139    0.5%
    5     250.9     0.524    0.2%

Quality and confidence:
param     error
r         0.099

Model:
Time ~=    61.17
    + r    37.94
              µs

Reads = 2 + (2 * r)
Writes = 2 + (2 * r)

Pallet: "delegation", Extrinsic: "reclaim_deposit", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:2 w:2)
Storage: System Account (r:1 w:1)
Storage: Delegation DelegationHierarchies (r:0 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=     50.1
    + r    38.38
              µs

Reads = 1 + (2 * r)
Writes = 2 + (2 * r)

Min Squares Analysis
========
-- Extrinsic Time --

Data points distribution:
    r   mean µs  sigma µs       %
    1     87.87     0.239    0.2%
    2     127.3     0.377    0.2%
    3       165     0.697    0.4%
    4     203.3     0.538    0.2%
    5     241.9     0.602    0.2%

Quality and confidence:
param     error
r         0.064

Model:
Time ~=    49.88
    + r    38.41
              µs

Reads = 1 + (2 * r)
Writes = 2 + (2 * r)


@ntn-x2
Copy link
Member Author

ntn-x2 commented Nov 8, 2021

/bench runtime peregrine delegation

…hmarks -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=delegation --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=pallets/delegation/src/default_weights.rs --template=.maintain/weight-template.hbs
@kilt-command-bot
Copy link

kilt-command-bot bot commented Nov 8, 2021

Benchmark Runtime Substrate Pallet for branch "aa-delegation-deposit-claiming" with command cargo run --quiet --release -p kilt-parachain --features=runtime-benchmarks -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=delegation --extrinsic="*" --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./runtimes/peregrine/src/weights/delegation.rs --template=.maintain/runtime-weight-template.hbs

Results
Pallet: "delegation", Extrinsic: "create_hierarchy", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationHierarchies (r:1 w:1)
Storage: Ctype Ctypes (r:1 w:0)
Storage: System Account (r:1 w:1)
Storage: Delegation DelegationNodes (r:0 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    48.47
              µs

Reads = 3
Writes = 3

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~=    48.47
              µs

Reads = 3
Writes = 3

Pallet: "delegation", Extrinsic: "add_delegation", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:2 w:2)
Storage: System Account (r:1 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    59.82
              µs

Reads = 3
Writes = 3

Min Squares Analysis
========
-- Extrinsic Time --

Model:
Time ~=    59.82
              µs

Reads = 3
Writes = 3

Pallet: "delegation", Extrinsic: "revoke_delegation_root_child", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:1 w:1)
Storage: Delegation DelegationHierarchies (r:1 w:0)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=       24
    + r    19.07
    + c    0.001
              µs

Reads = 1 + (1 * r) + (0 * c)
Writes = 0 + (1 * r) + (0 * c)

Min Squares Analysis
========
-- Extrinsic Time --

Data points distribution:
    r     c   mean µs  sigma µs       %
    1     5     41.97     0.172    0.4%
    2     5     63.17      0.56    0.8%
    3     5     81.74     0.304    0.3%
    4     5       100     0.358    0.3%
    5     1     119.3     0.305    0.2%
    5     2       119     0.252    0.2%
    5     3     119.1     0.207    0.1%
    5     4     118.7     0.314    0.2%
    5     5     119.2     0.302    0.2%

Quality and confidence:
param     error
r         0.052
c         0.052

Model:
Time ~=    23.76
    + r    19.06
    + c    0.043
              µs

Reads = 1 + (1 * r) + (0 * c)
Writes = 0 + (1 * r) + (0 * c)

Pallet: "delegation", Extrinsic: "revoke_delegation_leaf", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:6 w:1)
Storage: Delegation DelegationHierarchies (r:1 w:0)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    41.27
    + r    0.039
    + c    5.728
              µs

Reads = 2 + (0 * r) + (1 * c)
Writes = 1 + (0 * r) + (0 * c)

Min Squares Analysis
========
-- Extrinsic Time --

Data points distribution:
    r     c   mean µs  sigma µs       %
    1     5     69.76     0.158    0.2%
    2     5        70     0.355    0.5%
    3     5     70.29     0.254    0.3%
    4     5     70.04     0.206    0.2%
    5     1     46.84      0.49    1.0%
    5     2     53.18     0.331    0.6%
    5     3     58.48     0.132    0.2%
    5     4     64.28     0.092    0.1%
    5     5     70.01     0.252    0.3%

Quality and confidence:
param     error
r         0.027
c         0.027

Model:
Time ~=    41.09
    + r    0.041
    + c    5.758
              µs

Reads = 2 + (0 * r) + (1 * c)
Writes = 1 + (0 * r) + (0 * c)

Pallet: "delegation", Extrinsic: "remove_delegation", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:2 w:2)
Storage: System Account (r:1 w:1)
Storage: Delegation DelegationHierarchies (r:1 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    63.32
    + r    38.98
              µs

Reads = 2 + (2 * r)
Writes = 2 + (2 * r)

Min Squares Analysis
========
-- Extrinsic Time --

Data points distribution:
    r   mean µs  sigma µs       %
    1     102.4     0.742    0.7%
    2     141.5     0.982    0.6%
    3       180     0.782    0.4%
    4     218.8     0.525    0.2%
    5     258.6       0.7    0.2%

Quality and confidence:
param     error
r         0.083

Model:
Time ~=    63.36
    + r    38.97
              µs

Reads = 2 + (2 * r)
Writes = 2 + (2 * r)

Pallet: "delegation", Extrinsic: "reclaim_deposit", Lowest values: [], Highest values: [], Steps: 50, Repeat: 20
Raw Storage Info
========
Storage: Delegation DelegationNodes (r:2 w:2)
Storage: System Account (r:1 w:1)
Storage: Delegation DelegationHierarchies (r:0 w:1)

Median Slopes Analysis
========
-- Extrinsic Time --

Model:
Time ~=    53.09
    + r    39.06
              µs

Reads = 1 + (2 * r)
Writes = 2 + (2 * r)

Min Squares Analysis
========
-- Extrinsic Time --

Data points distribution:
    r   mean µs  sigma µs       %
    1     92.23     0.789    0.8%
    2     131.6     0.465    0.3%
    3     169.5     0.578    0.3%
    4     208.8     0.622    0.2%
    5     248.8     0.394    0.1%

Quality and confidence:
param     error
r         0.075

Model:
Time ~=    53.09
    + r    39.04
              µs

Reads = 1 + (2 * r)
Writes = 2 + (2 * r)


…hmarks -- benchmark --chain=dev --steps=50 --repeat=20 --pallet=delegation --extrinsic=* --execution=wasm --wasm-execution=compiled --heap-pages=4096 --output=./runtimes/peregrine/src/weights/delegation.rs --template=.maintain/runtime-weight-template.hbs
@ntn-x2 ntn-x2 enabled auto-merge (squash) November 8, 2021 09:19
@ntn-x2 ntn-x2 merged commit fc56483 into develop Nov 8, 2021
@ntn-x2 ntn-x2 deleted the aa-delegation-deposit-claiming branch November 8, 2021 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💛 medium priority: medium
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants