首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何为基板Aura验证器配置奖励?

如何为基板Aura验证器配置奖励?
EN

Stack Overflow用户
提问于 2022-06-16 06:25:44
回答 1查看 30关注 0票数 -1

现在,PoA与多个Aura验证器一起运行在我的基板-节点模板中。如何为我的Aura验证器配置奖励金额或价值?

EN

回答 1

Stack Overflow用户

发布于 2022-06-21 05:46:33

我让它正常工作,PoA将奖励使用提示作为收费示例值的创建块的验证器,下面是步骤:

安装pallet_authorship的

代码语言:javascript
复制
pallet-authorship = { version = "4.0.0-dev", default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.23" }

  1. 配置托盘以获取块

的当前作者

代码语言:javascript
复制
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 =  ();
}

创建作者和DealWithFees的

  1. OnUnbalanced实现

代码语言:javascript
复制
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);
        }
    }
} 

调用OnChargeTransaction元组

  1. 中的实现

代码语言:javascript
复制
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/06/21/how-to-pay-the-block-author-validator-on-a-proof-of-authority-poa-consensus-in-substrate/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72641374

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档