Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Add darwinia-fee-market pallet #779

Merged
merged 77 commits into from Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
f1e3f09
Add `darwinia-fee-market` pallet framework
boundless-forest Aug 27, 2021
f522d73
Add tests file
boundless-forest Aug 27, 2021
eb5057a
Add pallet storage
boundless-forest Aug 27, 2021
83f105d
Add lowest storage and todos
boundless-forest Aug 27, 2021
a943a76
Update register dispatch call
boundless-forest Aug 27, 2021
4e288de
Use lock from balance module
boundless-forest Aug 30, 2021
1c7cc07
Update test case
boundless-forest Aug 30, 2021
b1c6ef4
Add submit price call
boundless-forest Aug 30, 2021
9d604e5
Add Relay struct
boundless-forest Aug 30, 2021
c3e66aa
Rename & add more test cases
boundless-forest Aug 31, 2021
e1846ba
Refactor storage design
boundless-forest Aug 31, 2021
3479245
Rename submit price
boundless-forest Aug 31, 2021
b0a18ef
Add test cases
boundless-forest Aug 31, 2021
30a1421
Remove useless clone
boundless-forest Aug 31, 2021
1463d4d
Add runtime rpc
boundless-forest Aug 31, 2021
45fccf0
Fix compile issues
boundless-forest Aug 31, 2021
2d49381
Add another two runtime rpc
boundless-forest Aug 31, 2021
3d43912
Lots of better rename
boundless-forest Aug 31, 2021
79a8c61
Change top_relayer return type
boundless-forest Aug 31, 2021
2069b45
Price to fee, include type
boundless-forest Sep 1, 2021
a16b609
Chores
boundless-forest Sep 1, 2021
eb73fa3
Merge branch 'master' into add-ask-price-pallet
boundless-forest Sep 13, 2021
d8907db
Merge master
boundless-forest Sep 13, 2021
4545e70
Merge branch 'master' into add-ask-price-pallet
boundless-forest Sep 15, 2021
7912807
Add FeeMarketPayment
boundless-forest Sep 15, 2021
db419f3
Add PriorRelayer logic
boundless-forest Sep 16, 2021
9eda853
Create order and assgin relayers
boundless-forest Sep 16, 2021
77ae60c
Add reward part
boundless-forest Sep 18, 2021
767696e
Merge branch 'master' into add-ask-price-pallet
boundless-forest Sep 23, 2021
94781ff
Use local parity-bridges-common to dev
boundless-forest Sep 24, 2021
76970ea
Fix test compile issue
boundless-forest Sep 24, 2021
69000e7
Make the whole system compiles
boundless-forest Sep 24, 2021
be5043f
Yes! compatible with upstream now
boundless-forest Sep 25, 2021
fef9bb6
Fix all broken unit test & Add bridges-message pallet in mock test & …
boundless-forest Sep 25, 2021
a38bbb3
Integrate message pallet to order creation test & Fix bug in range ca…
boundless-forest Sep 25, 2021
2a64b71
Abstract reward calculation logic to seperate module & Add unit test …
boundless-forest Sep 26, 2021
efa879f
Abstract the slack trait
boundless-forest Sep 26, 2021
2ba2384
Fix messages-relayers reward bug & add hard unit test about calculati…
boundless-forest Sep 26, 2021
2c7f8dc
Make the whole thing clean and neat
boundless-forest Sep 26, 2021
fa7cce4
Relate slash with assigned_relayers elect & Add more tests about slas…
boundless-forest Sep 27, 2021
1b91866
It's very very close to be ready for review
boundless-forest Sep 27, 2021
e0bb28f
Okay, all issues I can think of is fixed. Code clean and more comment…
boundless-forest Sep 27, 2021
9046e87
Lots of renaming & Update unit tests
boundless-forest Sep 27, 2021
db467e3
Move basic type to primitive
boundless-forest Sep 27, 2021
5ceeed1
Use remote repo link
boundless-forest Sep 27, 2021
e485753
Congrats, the compile change to green,all unit tests passed, addition…
boundless-forest Sep 27, 2021
d481a74
Merge branch 'master' into add-ask-price-pallet
boundless-forest Sep 27, 2021
72b39b6
Format work
boundless-forest Sep 27, 2021
e349b0c
Fix duplicated calculate reward when receive duplicated delivery proof
boundless-forest Sep 28, 2021
399bdb1
Return NONE, If the market unable to give a fee
boundless-forest Sep 28, 2021
13076d0
Merge branch 'master' into add-ask-price-pallet
boundless-forest Sep 28, 2021
d61f093
Merge to the latest step 1
boundless-forest Sep 28, 2021
22e6d4a
Merge branch 'master' into add-ask-price-pallet
boundless-forest Sep 28, 2021
2dbb489
Add json type, I am not sure this is entirely correct, need check later
boundless-forest Sep 28, 2021
0984d3b
Change `BestRelayer` type from `ValueQuery` to `OptionQuery`
boundless-forest Sep 28, 2021
a9e4f43
Remove annoying warning while running tests
boundless-forest Sep 29, 2021
2cedd74
Add benchmark tests
boundless-forest Sep 29, 2021
39ff571
Reduce `BestRelayer` storage item
boundless-forest Oct 9, 2021
389cf0c
Add test: should panic in the case of somebody send message when fee …
boundless-forest Oct 9, 2021
e8674d6
Allow get order return None
boundless-forest Oct 9, 2021
a29195e
Change the slash value for each delay block
boundless-forest Oct 9, 2021
cc45155
Forbid cancel_enrollment when relayer is occupied
boundless-forest Oct 11, 2021
5be8cad
Add runtime api server for application get market fee
boundless-forest Oct 11, 2021
02581ca
Merge branch 'master' into add-ask-price-pallet
boundless-forest Oct 12, 2021
9fd9ef9
Arm pangoro fee market
boundless-forest Oct 12, 2021
8c570e8
Slasher associated type
boundless-forest Oct 12, 2021
b560337
Move callbacks functions into s2s folder, the logic more clear
boundless-forest Oct 12, 2021
e86be1f
Code clean
boundless-forest Oct 12, 2021
ce1868a
Put assign prior relayers to primitives/Change AssignedRelayerStorage…
boundless-forest Oct 13, 2021
2162174
Update type json and test in darwinia apps
boundless-forest Oct 13, 2021
ffbb203
Fix rpc client exit unexpected
boundless-forest Oct 14, 2021
c1d231b
Fix all potential panic
boundless-forest Oct 14, 2021
a965ddf
Fix broken panic test
boundless-forest Oct 14, 2021
d8094ce
Rename, comes from review
boundless-forest Oct 14, 2021
c96fe3d
Remove relayer_fund_account check in payment
boundless-forest Oct 14, 2021
440ffa6
Update test for easy review
boundless-forest Oct 14, 2021
01c5434
Update runtime balance config
boundless-forest Oct 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 66 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Expand Up @@ -38,6 +38,9 @@ members = [
"frame/evm/precompile/contracts/simple",
"frame/evm/precompile/contracts/transfer",
"frame/evm/precompile/contracts/sha3fips",
"frame/fee-market",
"frame/fee-market/rpc",
"frame/fee-market/rpc/runtime-api",
"frame/header-mmr",
"frame/header-mmr/rpc",
"frame/header-mmr/rpc/runtime-api",
Expand All @@ -57,6 +60,7 @@ members = [
"primitives/contract",
"primitives/ethereum",
"primitives/evm",
"primitives/fee-market",
"primitives/merkle-patricia-trie",
"primitives/relay",
"primitives/rpc",
Expand Down
4 changes: 4 additions & 0 deletions docs/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -47,6 +47,9 @@
/frame/elections-phragmen/ @AurevoirXavier
/frame/evm/ @AsceticBear @HackFisher
/frame/evm/precompile/ @AsceticBear @HackFisher @xiaoch05
/frame/fee-market/ @AsceticBear @HackFisher
/frame/fee-market/rpc/ @AsceticBear
/frame/fee-market/rpc/runtime-api/ @AsceticBear
/frame/header-mmr/ @AurevoirXavier @HackFisher
/frame/staking/ @AurevoirXavier @HackFisher
/frame/staking/rpc/ @AurevoirXavier
Expand All @@ -57,6 +60,7 @@
/primitives/consensus/ @AsceticBear
/primitives/ethereum/ @AurevoirXavier @HackFisher
/primitives/evm/ @AsceticBear
/primitives/fee-market/ @AsceticBear
/primitives/merkle-patricia-trie/ @AurevoirXavier @HackFisher
/primitives/relay/ @AurevoirXavier
/primitives/rpc/ @AsceticBear
Expand Down
65 changes: 65 additions & 0 deletions frame/fee-market/Cargo.toml
@@ -0,0 +1,65 @@
[package]
authors = ["Darwinia Network <hello@darwinia.network>"]
description = "Fee Market provides suitable fee for message relaying"
edition = "2018"
homepage = "https://darwinia.network/"
license = "GPL-3.0"
name = "darwinia-fee-market"
readme = "README.md"
repository = "https://github.com/darwinia-network/darwinia-common/"
version = "2.6.6"

[dependencies]
# crates.io
bitvec = { version = "0.20", default-features = false, features = ["alloc"] }
codec = { package = "parity-scale-codec", version = "2.1.1", default-features = false }
log = { version = "0.4.14", default-features = false }
num-traits = { version = "0.2", default-features = false }
# darwinia-network
darwinia-support = { default-features = false, path = "../support" }
dp-fee = { default-features = false, path = "../../primitives/fee-market"}
# paritytech
frame-benchmarking = { optional = true, default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }
frame-support = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }
frame-system = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }
pallet-timestamp = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }
sp-core = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }
sp-runtime = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }
sp-io = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }
sp-std = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }
# parity-bridges-common
bp-messages = { default-features = false, git = "https://github.com/darwinia-network/parity-bridges-common", tag = "darwinia-v0.11.5-rc1" }
bp-runtime = { default-features = false, git = "https://github.com/darwinia-network/parity-bridges-common", tag = "darwinia-v0.11.5-rc1" }
pallet-bridge-messages = { default-features = false, git = "https://github.com/darwinia-network/parity-bridges-common", tag = "darwinia-v0.11.5-rc1" }

[dev-dependencies]
darwinia-balances = { default-features = false, path = "../balances" }

[features]
default = ["std"]

std = [
# crates.io
"bitvec/std",
"codec/std",
"log/std",
"num-traits/std",
# darwinia-network
"darwinia-balances/std",
"darwinia-support/std",
"dp-fee/std",
# paritytech
"frame-support/std",
"frame-system/std",
"pallet-timestamp/std",
"sp-core/std",
"sp-io/std",
"sp-std/std",
"sp-runtime/std",
# parity-bridges-common
"bp-messages/std",
"bp-runtime/std",
"pallet-bridge-messages/std",
]

runtime-benchmarks = ["frame-benchmarking"]
File renamed without changes.
23 changes: 23 additions & 0 deletions frame/fee-market/rpc/Cargo.toml
@@ -0,0 +1,23 @@
[package]
authors = ["Darwinia Network <hello@darwinia.network>"]
description = "Node-specific RPC methods for interaction with fee-market"
edition = "2018"
homepage = "https://darwinia.network/"
license = "GPL-3.0"
name = "darwinia-fee-market-rpc"
readme = "README.md"
repository = "https://github.com/darwinia-network/darwinia-common/"
version = "2.6.6"

[dependencies]
# crates.io
codec = { package = "parity-scale-codec", version = "2.1.1" }
jsonrpc-core = { version = "15.1.0" }
jsonrpc-core-client = { version = "15.1.0" }
jsonrpc-derive = { version = "15.1.0" }
# darwinia-network
darwinia-fee-market-rpc-runtime-api = { path = "./runtime-api" }
# paritytech
sp-api = { git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }
sp-blockchain = { git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }
sp-runtime = { git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }
30 changes: 30 additions & 0 deletions frame/fee-market/rpc/runtime-api/Cargo.toml
@@ -0,0 +1,30 @@
[package]
authors = ["Darwinia Network <hello@darwinia.network>"]
description = "Runtime API definition required by fee-market RPC extensions."
edition = "2018"
homepage = "https://darwinia.network/"
license = "GPL-3.0"
name = "darwinia-fee-market-rpc-runtime-api"
readme = "README.md"
repository = "https://github.com/darwinia-network/darwinia-common/"
version = "2.6.6"

[dependencies]
# crates.io
codec = { package = "parity-scale-codec", version = "2.1.1", default-features = false }
serde = { version = "1.0.127", optional = true, features = ["derive"] }
# paritytech
sp-api = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }
sp-runtime = { default-features = false, git = "https://github.com/darwinia-network/substrate", tag = "darwinia-v0.11.4" }

[features]
default = ["std"]

std = [
# crates.io
"codec/std",
"serde",
# paritytech
"sp-api/std",
"sp-runtime/std",
]
79 changes: 79 additions & 0 deletions frame/fee-market/rpc/runtime-api/src/lib.rs
@@ -0,0 +1,79 @@
// This file is part of Darwinia.
//
// Copyright (C) 2018-2021 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

//! Runtime API definition required by header-mmr RPC extensions.
//!
//! This API should be imported and implemented by the runtime,
//! of a node that wants to use the custom RPC extension
//! adding header-mmr access methods.

#![cfg_attr(not(feature = "std"), no_std)]

// -- core ---
use core::fmt::Debug;
// --- crates.io ---
use codec::{Codec, Decode, Encode};
#[cfg(feature = "std")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
// --- paritytech ---
use sp_api::decl_runtime_apis;
use sp_runtime::traits::{MaybeDisplay, MaybeFromStr};

#[derive(Eq, PartialEq, Encode, Decode, Default)]
#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))]
#[cfg_attr(feature = "std", serde(rename_all = "camelCase"))]
pub struct Fee<Balance> {
#[cfg_attr(
feature = "std",
serde(bound(serialize = "Balance: std::fmt::Display"))
)]
#[cfg_attr(feature = "std", serde(serialize_with = "serialize_as_string"))]
#[cfg_attr(
feature = "std",
serde(bound(deserialize = "Balance: std::str::FromStr"))
)]
#[cfg_attr(feature = "std", serde(deserialize_with = "deserialize_from_string"))]
pub amount: Balance,
}

#[cfg(feature = "std")]
fn serialize_as_string<S: Serializer, T: std::fmt::Display>(
t: &T,
serializer: S,
) -> Result<S::Ok, S::Error> {
serializer.serialize_str(&t.to_string())
}

#[cfg(feature = "std")]
fn deserialize_from_string<'de, D: Deserializer<'de>, T: std::str::FromStr>(
deserializer: D,
) -> Result<T, D::Error> {
let s = String::deserialize(deserializer)?;
s.parse::<T>()
.map_err(|_| serde::de::Error::custom("Parse from string failed"))
}

decl_runtime_apis! {
pub trait FeeMarketApi<Balance>
where
Balance: Codec + MaybeDisplay + MaybeFromStr,
{
fn market_fee(
boundless-forest marked this conversation as resolved.
Show resolved Hide resolved
) -> Option<Fee<Balance>>;
}
}