Skip to content

Commit

Permalink
Staking V3 (#1611)
Browse files Browse the repository at this point in the history
* Staking V3

* Part.2

* Part.3

* Part.4

* Part.5

* Part.6

* Benchmark

* Benchmark

* Update tx pause

* Re-cache

* Fixes

* Bump

* Staking V3 review (#1617)

* Account migration adaptation

Signed-off-by: Xavier Lau <x@acg.box>

* Limit tasks

---------

Signed-off-by: Xavier Lau <x@acg.box>

* Bench

* Add migration

* Fixes

* Correct r/w count

Signed-off-by: Xavier Lau <x@acg.box>

---------

Signed-off-by: Xavier Lau <x@acg.box>
  • Loading branch information
AurevoirXavier authored Nov 12, 2024
1 parent 9d30501 commit e9e1155
Show file tree
Hide file tree
Showing 123 changed files with 2,117 additions and 6,588 deletions.
22 changes: 6 additions & 16 deletions .maintain/zombienet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,18 @@ validator = true
chain = "koi-genesis"
force_decorator = "generic-evm"
id = 2105
[parachains.collator]
[[parachains.collators]]
args = ["--database=paritydb", "--force-authoring", "-lparachain=debug"]
command = "tmp/darwinia"
name = "C1"
name = "c1"
rpc_port = 10000

[[parachains]]
chain = "koi-genesis"
force_decorator = "generic-evm"
id = 2105
[parachains.collator]
[[parachains.collators]]
args = ["--database=paritydb", "--force-authoring", "-lparachain=debug"]
command = "tmp/darwinia"
name = "C2"
name = "c2"
rpc_port = 10001

[[parachains]]
chain = "koi-genesis"
force_decorator = "generic-evm"
id = 2105
[parachains.collator]
[[parachains.collators]]
args = ["--database=paritydb", "--force-authoring", "-lparachain=debug"]
command = "tmp/darwinia"
name = "C3"
name = "c3"
rpc_port = 10002
64 changes: 0 additions & 64 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ members = [
"core/*",
"node",
"pallet/*",
"pallet/*/traits",
"precompile/*",
"runtime/*",
]
Expand Down Expand Up @@ -40,12 +39,9 @@ darwinia-common-runtime = { path = "runtime/common", default-features
darwinia-deposit = { path = "pallet/deposit", default-features = false }
darwinia-ethtx-forwarder = { path = "pallet/ethtx-forwarder", default-features = false }
darwinia-precompile-assets = { path = "precompile/assets", default-features = false }
darwinia-precompile-deposit = { path = "precompile/deposit", default-features = false }
darwinia-precompile-staking = { path = "precompile/staking", default-features = false }
darwinia-precompile-state-storage = { path = "precompile/state-storage", default-features = false }
darwinia-runtime = { path = "runtime/darwinia" }
darwinia-staking = { path = "pallet/staking", default-features = false }
darwinia-staking-traits = { path = "pallet/staking/traits", default-features = false }
dc-inflation = { path = "core/inflation", default-features = false }
dc-primitives = { path = "core/primitives", default-features = false }
dc-types = { path = "core/types" }
Expand Down
10 changes: 5 additions & 5 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[config]
default_to_workspace = false
# skip_core_tasks = true
# skip_git_env_info = true
# skip_rust_env_info = true
# skip_crate_env_info = true
skip_core_tasks = true
skip_git_env_info = true
skip_rust_env_info = true
skip_crate_env_info = true

[env]
CHAIN = "all"
Expand All @@ -19,7 +19,7 @@ args = ["fmt"]
[tasks.clippy]
env = { "SKIP_WASM_BUILD" = "1" }
command = "cargo"
args = ["clippy"]
args = ["clippy", "--all-features"]

[tasks.c]
alias = "clippy"
Expand Down
6 changes: 0 additions & 6 deletions core/inflation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ readme = "README.md"
version.workspace = true

[dependencies]
# crates.io
primitive-types = { version = "0.12", default-features = false }

# darwinia
dc-types = { workspace = true }

Expand All @@ -22,9 +19,6 @@ sp-arithmetic = { workspace = true, features = ["std"] }
[features]
default = ["std"]
std = [
# crates.io
"primitive-types/std",

# github
"substrate-fixed/std",
]
32 changes: 0 additions & 32 deletions core/inflation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#[cfg(test)]
mod test;

// crates.io
use primitive_types::U256;
// darwinia
use dc_types::{Balance, Moment};
// github
Expand Down Expand Up @@ -148,33 +146,3 @@ pub fn issuing_in_period(period: Moment, elapsed: Moment) -> Option<Balance> {

Some(to_issue_per_millisecs.checked_mul(U94F34::checked_from_num(period)?)?.floor().to_num())
}

/// Calculate the reward of a deposit.
///
/// Reference(s):
/// - <https://github.com/evolutionlandorg/bank/blob/master/contracts/GringottsBank.sol#L280>
pub fn deposit_interest(amount: Balance, months: u8) -> Balance {
// The result of `((quot - 1) * precision + rem * precision / d)` is `197` when months is
// `12`.
//
// The default interest is `1_000`.
// So, we directly use `1_970_000` here instead `interest * 197 * 10^7`.
fn f(amount: U256, precision: U256, quot: U256, rem: U256, d: U256) -> Option<Balance> {
Some(
(amount.checked_mul(
precision.checked_mul(quot.checked_sub(1_u8.into())?)? + precision * rem / d,
)? / 1_970_000_u32)
.as_u128(),
)
}

let amount = U256::from(amount);
let months = U256::from(months);
let n = U256::from(67_u8).pow(months);
let d = U256::from(66_u8).pow(months);
let quot = n / d;
let rem = n % d;
let precision = U256::from(1_000_u16);

f(amount, precision, quot, rem, d).unwrap_or_default()
}
20 changes: 0 additions & 20 deletions core/inflation/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,3 @@ fn issuing_map_should_work() {
unissued -= issued;
});
}

#[test]
fn deposit_interest_should_work() {
let precision = 10_000_f64;

for (&expect_interest, months) in [
0.0761_f64, 0.1522, 0.2335, 0.3096, 0.3959, 0.4771, 0.5634, 0.6446, 0.7309, 0.8223, 0.9086,
1.0000, 1.0913, 1.1878, 1.2842, 1.3807, 1.4771, 1.5736, 1.6751, 1.7766, 1.8832, 1.9898,
2.0964, 2.2030, 2.3147, 2.4263, 2.5380, 2.6548, 2.7715, 2.8934, 3.0101, 3.1370, 3.2588,
3.3857, 3.5126, 3.6446,
]
.iter()
.zip(1_u8..)
{
let interest = deposit_interest(10_000_u128 * UNIT, months) as f64 / UNIT as f64;
let interest = (interest * precision).floor() / precision;

assert_eq!(interest, expect_interest);
}
}
8 changes: 2 additions & 6 deletions node/src/chain_spec/crab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ pub fn development_config() -> ChainSpec {
"darwiniaStaking": {
"now": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(),
"elapsedTime": 0,
"rateLimit": 20_000_000 * UNIT,
"collatorCount": collators.len(),
"collators": collators.iter().map(|(a, _)| (a, UNIT)).collect::<Vec<_>>()
"collatorCount": collators.len()
},
"session": {
"keys": collators.into_iter().map(|(a, sks)| (a, a, sks)).collect::<Vec<_>>()
Expand Down Expand Up @@ -222,9 +220,7 @@ pub fn genesis_config() -> ChainSpec {
"darwiniaStaking": {
"now": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(),
"elapsedTime": 0,
"rateLimit": 20_000_000 * UNIT,
"collatorCount": 6,
"collators": collators.iter().map(|(a, _)| (a, 1_000 * UNIT)).collect::<Vec<_>>()
"collatorCount": 6
},
"session": {
"keys": collators.iter().map(|(a, sks)| (a, a, sks)).collect::<Vec<_>>()
Expand Down
8 changes: 2 additions & 6 deletions node/src/chain_spec/darwinia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ pub fn development_config() -> ChainSpec {
"darwiniaStaking": {
"now": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(),
"elapsedTime": 0,
"rateLimit": 20_000_000 * UNIT,
"collatorCount": collators.len(),
"collators": collators.iter().map(|(a, _)| (a, UNIT)).collect::<Vec<_>>()
"collatorCount": collators.len()
},
"session": {
"keys": collators.into_iter().map(|(a, sks)| (a, a, sks)).collect::<Vec<_>>()
Expand Down Expand Up @@ -211,9 +209,7 @@ pub fn genesis_config() -> ChainSpec {
"darwiniaStaking": {
"now": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(),
"elapsedTime": 0,
"rateLimit": 20_000_000 * UNIT,
"collatorCount": 5,
"collators": collators.iter().map(|(a, _)| (a, 1_000 * UNIT)).collect::<Vec<_>>()
"collatorCount": 5
},
"session": {
"keys": collators.iter().map(|(a, sks)| (a, a, sks)).collect::<Vec<_>>()
Expand Down
8 changes: 2 additions & 6 deletions node/src/chain_spec/koi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ pub fn development_config() -> ChainSpec {
"darwiniaStaking": {
"now": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(),
"elapsedTime": 0,
"rateLimit": 20_000_000 * UNIT,
"collatorCount": collators.len(),
"collators": collators.iter().map(|(a, _)| (a, UNIT)).collect::<Vec<_>>()
"collatorCount": collators.len()
},
"session": {
"keys": collators.into_iter().map(|(a, sks)| (a, a, sks)).collect::<Vec<_>>()
Expand Down Expand Up @@ -166,9 +164,7 @@ pub fn genesis_config() -> ChainSpec {
"darwiniaStaking": {
"now": SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis(),
"elapsedTime": 0,
"rateLimit": 20_000_000 * UNIT,
"collatorCount": 3,
"collators": collators.iter().map(|(a, _)| (a, UNIT)).collect::<Vec<_>>()
"collatorCount": 3
},
"session": {
"keys": collators.iter().map(|(a, sks)| (a, a, sks)).collect::<Vec<_>>()
Expand Down
Loading

0 comments on commit e9e1155

Please sign in to comment.