我如何配置基材Aura验证器的奖励?

发布于 2025-02-08 00:48:11 字数 225 浏览 2 评论 0原文

现在,POA正在我的基板节​​点模板中使用多个AURA验证器运行。我如何为我的光环验证器配置该奖励金额或价值?

Now that the PoA is running with multiple Aura validators in my substrate-node-template. How could I configure that reward amount or value for my Aura validators?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

油饼 2025-02-15 00:48:11

我让它起作用,POA将奖励使用提示作为费用的示例值创建块的验证者,以下是:

  1. 安装pallet_authorship
pallet-authorship = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.23" }
  1. 配置托盘,以使块的当前作者
pub struct AuraAccountAdapter;
impl frame_support::traits::FindAuthor<AccountId> for AuraAccountAdapter {
    fn find_author<'a, I>(digests: I) -> Option<AccountId>
        where I: 'a + IntoIterator<Item=(frame_support::ConsensusEngineId, &'a [u8])>
    {
        pallet_aura::AuraAuthorId::<Runtime>::find_author(digests).and_then(|k| {
            AccountId::try_from(k.as_ref()).ok()
        })
    }
}
impl pallet_authorship::Config for Runtime {
    type FindAuthor = AuraAccountAdapter;
    type UncleGenerations = ();
    type FilterUncle = ();
    type EventHandler =  ();
}
  1. 创建了作者和作者和作者和DealWithFees
use crate::{Authorship, Balances};
use frame_support::traits::{Imbalance, OnUnbalanced};
use crate::sp_api_hidden_includes_construct_runtime::hidden_include::traits::Currency;
use crate::AccountId;

type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;

pub struct Author;
impl OnUnbalanced<NegativeImbalance> for Author {
    fn on_nonzero_unbalanced(amount: NegativeImbalance) {
        if let Some(author) = Authorship::author() {
            Balances::resolve_creating(&author, amount);
        }
    }
}

pub struct DealWithFees;
impl OnUnbalanced<NegativeImbalance> for DealWithFees {
    fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {
        if let Some(fees) = fees_then_tips.next() {
            let mut split = fees.ration(80, 20);
            if let Some(tips) = fees_then_tips.next() {
                // for tips, if any, 80% to treasury, 20% to block author (though this can be anything)
                tips.ration_merge_into(80, 20, &mut split);
            }
            //Treasury::on_unbalanced(split.0);
            Author::on_unbalanced(split.1);
        }
    }
} 
  1. 在我的博客中添加了Pallet_transaction_payment tuple tuple tuple tuple tuple the
impl pallet_transaction_payment::Config for Runtime {
    type OnChargeTransaction = CurrencyAdapter<Balances, crate::impls::DealWithFees>;
    type OperationalFeeMultiplier = ConstU8<5>;
    type WeightToFee = IdentityFee<Balance>;
    type LengthToFee = IdentityFee<Balance>;
    type FeeMultiplierUpdate = ();
}

https://hgminerva.wordpress.com/2022/2022/06/21/how-to-pay-to-pay-pay-pay-theblock-auctor-validator--validator--validator--validator---validator--validator----授权授权的poa-consensus-in-substrate/“ rel =” nofollow noreferrer“> https://hgminerva.wordpress.com/2022/2022/06/21/how-to-poy-to-pay-poy-to-pay-pay-pay-the-pay-the----the-----the------------------------------------------------------------------------------------------------已经一下平一下。实体录音机在范围内的po poa-poa-consensus in-substrate/

I got it working, PoA will reward the validator who created the block using the tip as the sample value for the fees, here are the steps:

  1. Install the pallet_authorship
pallet-authorship = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.23" }
  1. Configure the pallet to get the current author of the block
pub struct AuraAccountAdapter;
impl frame_support::traits::FindAuthor<AccountId> for AuraAccountAdapter {
    fn find_author<'a, I>(digests: I) -> Option<AccountId>
        where I: 'a + IntoIterator<Item=(frame_support::ConsensusEngineId, &'a [u8])>
    {
        pallet_aura::AuraAuthorId::<Runtime>::find_author(digests).and_then(|k| {
            AccountId::try_from(k.as_ref()).ok()
        })
    }
}
impl pallet_authorship::Config for Runtime {
    type FindAuthor = AuraAccountAdapter;
    type UncleGenerations = ();
    type FilterUncle = ();
    type EventHandler =  ();
}
  1. Create OnUnbalanced implementation of Author and DealWithFees
use crate::{Authorship, Balances};
use frame_support::traits::{Imbalance, OnUnbalanced};
use crate::sp_api_hidden_includes_construct_runtime::hidden_include::traits::Currency;
use crate::AccountId;

type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;

pub struct Author;
impl OnUnbalanced<NegativeImbalance> for Author {
    fn on_nonzero_unbalanced(amount: NegativeImbalance) {
        if let Some(author) = Authorship::author() {
            Balances::resolve_creating(&author, amount);
        }
    }
}

pub struct DealWithFees;
impl OnUnbalanced<NegativeImbalance> for DealWithFees {
    fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item = NegativeImbalance>) {
        if let Some(fees) = fees_then_tips.next() {
            let mut split = fees.ration(80, 20);
            if let Some(tips) = fees_then_tips.next() {
                // for tips, if any, 80% to treasury, 20% to block author (though this can be anything)
                tips.ration_merge_into(80, 20, &mut split);
            }
            //Treasury::on_unbalanced(split.0);
            Author::on_unbalanced(split.1);
        }
    }
} 
  1. Call the implementation in the pallet_transaction_payment tuple OnChargeTransaction
impl pallet_transaction_payment::Config for Runtime {
    type OnChargeTransaction = CurrencyAdapter<Balances, crate::impls::DealWithFees>;
    type OperationalFeeMultiplier = ConstU8<5>;
    type WeightToFee = IdentityFee<Balance>;
    type LengthToFee = IdentityFee<Balance>;
    type FeeMultiplierUpdate = ();
}

Also added in my blog: https://hgminerva.wordpress.com/2022/06/21/how-to-pay-the-block-author-validator-on-a-proof-of-authority-poa-consensus-in-substrate/

悲念泪 2025-02-15 00:48:11

我能够使用此代码使它起作用。

// Substrate and Polkadot dependencies
use frame_support::{
    derive_impl, parameter_types, ord_parameter_types,
    traits::{
        fungible::{Balanced, Credit},
    OnUnbalanced,
    },
};



/// Logic for the author to get a portion of fees.
pub struct ToAuthor<R>(core::marker::PhantomData<R>);
impl<R> OnUnbalanced<Credit<R::AccountId, pallet_balances::Pallet<R>>> for ToAuthor<R>
where
    R: pallet_balances::Config + pallet_authorship::Config,
    <R as frame_system::Config>::AccountId: From<AccountId>,
    <R as frame_system::Config>::AccountId: Into<AccountId>,
{
    fn on_nonzero_unbalanced(
        amount: Credit<<R as frame_system::Config>::AccountId, pallet_balances::Pallet<R>>,
    ) {
        if let Some(author) = <pallet_authorship::Pallet<R>>::author() {
            let _ = <pallet_balances::Pallet<R>>::resolve(&author, amount);
        }
    }
}

parameter_types! {
    pub FeeMultiplier: Multiplier = Multiplier::one();
}

impl pallet_transaction_payment::Config for Runtime {
    type RuntimeEvent = RuntimeEvent;
    type OnChargeTransaction = FungibleAdapter<Balances, ToAuthor<Runtime>>;
    type OperationalFeeMultiplier = ConstU8<100>;
    type WeightToFee = IdentityFee<Balance>;
    type LengthToFee = IdentityFee<Balance>;
    type FeeMultiplierUpdate = ConstFeeMultiplier<FeeMultiplier>;
}



pub struct AuraAccountAdapter;
impl frame_support::traits::FindAuthor<AccountId> for AuraAccountAdapter {
    fn find_author<'a, I>(digests: I) -> Option<AccountId>
        where I: 'a + IntoIterator<Item=(frame_support::ConsensusEngineId, &'a [u8])>
    {
        pallet_aura::AuraAuthorId::<Runtime>::find_author(digests).and_then(|k| {
            AccountId::try_from(k.as_ref()).ok()
        })
    }
}

impl pallet_authorship::Config for Runtime {
    type FindAuthor = AuraAccountAdapter;
    type EventHandler = ();
}


I was able to make it work using this code.

// Substrate and Polkadot dependencies
use frame_support::{
    derive_impl, parameter_types, ord_parameter_types,
    traits::{
        fungible::{Balanced, Credit},
    OnUnbalanced,
    },
};



/// Logic for the author to get a portion of fees.
pub struct ToAuthor<R>(core::marker::PhantomData<R>);
impl<R> OnUnbalanced<Credit<R::AccountId, pallet_balances::Pallet<R>>> for ToAuthor<R>
where
    R: pallet_balances::Config + pallet_authorship::Config,
    <R as frame_system::Config>::AccountId: From<AccountId>,
    <R as frame_system::Config>::AccountId: Into<AccountId>,
{
    fn on_nonzero_unbalanced(
        amount: Credit<<R as frame_system::Config>::AccountId, pallet_balances::Pallet<R>>,
    ) {
        if let Some(author) = <pallet_authorship::Pallet<R>>::author() {
            let _ = <pallet_balances::Pallet<R>>::resolve(&author, amount);
        }
    }
}

parameter_types! {
    pub FeeMultiplier: Multiplier = Multiplier::one();
}

impl pallet_transaction_payment::Config for Runtime {
    type RuntimeEvent = RuntimeEvent;
    type OnChargeTransaction = FungibleAdapter<Balances, ToAuthor<Runtime>>;
    type OperationalFeeMultiplier = ConstU8<100>;
    type WeightToFee = IdentityFee<Balance>;
    type LengthToFee = IdentityFee<Balance>;
    type FeeMultiplierUpdate = ConstFeeMultiplier<FeeMultiplier>;
}



pub struct AuraAccountAdapter;
impl frame_support::traits::FindAuthor<AccountId> for AuraAccountAdapter {
    fn find_author<'a, I>(digests: I) -> Option<AccountId>
        where I: 'a + IntoIterator<Item=(frame_support::ConsensusEngineId, &'a [u8])>
    {
        pallet_aura::AuraAuthorId::<Runtime>::find_author(digests).and_then(|k| {
            AccountId::try_from(k.as_ref()).ok()
        })
    }
}

impl pallet_authorship::Config for Runtime {
    type FindAuthor = AuraAccountAdapter;
    type EventHandler = ();
}


心的憧憬 2025-02-15 00:48:11

基于上述答案,我们可以将其扩展到包括财政部和作者之间的分配。非常感谢@alpha游戏街机。

pub struct DealWithFees<R>(core::marker::PhantomData<R>);
impl<R> OnUnbalanced<Credit<R::AccountId, pallet_balances::Pallet<R>>> for DealWithFees<R>
where
    R: pallet_balances::Config + pallet_authorship::Config + pallet_treasury::Config,
    <R as frame_system::Config>::AccountId: From<AccountId>,
    <R as frame_system::Config>::AccountId: Into<AccountId>,
{
    fn on_unbalanceds(
        mut fees_then_tips: impl Iterator<Item = Credit<R::AccountId, pallet_balances::Pallet<R>>>,
    ) {
        if let Some(fees) = fees_then_tips.next() {
            let mut split = fees.ration(80, 20);
            if let Some(tips) = fees_then_tips.next() {
                tips.merge_into(&mut split.1);
            }
            ResolveTo::<pallet_treasury::TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(split.0);
            <ToAuthor<R> as OnUnbalanced<_>>::on_unbalanced(split.1);
        }
    }
}

只需替换:

type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>;

对于查找作者,我们依靠Pallet_authorship中的默认设置,该设置使用Session和aura:

impl pallet_authorship::Config for Runtime {
    type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
    type EventHandler = (CollatorSelection,);
}

您可以在此处找到完整的代码: https://github.com/xode-dao/xode-blockchain

但我不确定我们在做帕拉奇因以来就处于相同的情况。

Based on the above answer, we can expand it to include the split between the treasury and the author. Thank you so much @Alpha Gaming Arcade.

pub struct DealWithFees<R>(core::marker::PhantomData<R>);
impl<R> OnUnbalanced<Credit<R::AccountId, pallet_balances::Pallet<R>>> for DealWithFees<R>
where
    R: pallet_balances::Config + pallet_authorship::Config + pallet_treasury::Config,
    <R as frame_system::Config>::AccountId: From<AccountId>,
    <R as frame_system::Config>::AccountId: Into<AccountId>,
{
    fn on_unbalanceds(
        mut fees_then_tips: impl Iterator<Item = Credit<R::AccountId, pallet_balances::Pallet<R>>>,
    ) {
        if let Some(fees) = fees_then_tips.next() {
            let mut split = fees.ration(80, 20);
            if let Some(tips) = fees_then_tips.next() {
                tips.merge_into(&mut split.1);
            }
            ResolveTo::<pallet_treasury::TreasuryAccountId<R>, pallet_balances::Pallet<R>>::on_unbalanced(split.0);
            <ToAuthor<R> as OnUnbalanced<_>>::on_unbalanced(split.1);
        }
    }
}

Just replace:

type OnChargeTransaction = pallet_transaction_payment::FungibleAdapter<Balances, DealWithFees<Runtime>>;

For the finding the author we rely on the default settings in the pallet_authorship which uses session and Aura:

impl pallet_authorship::Config for Runtime {
    type FindAuthor = pallet_session::FindAccountFromAuthorIndex<Self, Aura>;
    type EventHandler = (CollatorSelection,);
}

You can find the complete code here: https://github.com/Xode-DAO/xode-blockchain

But I am not sure that we are of the same circumstances since we are doing a Parachain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文