1

看看这个实现

impl consensus::Trait for Runtime {
    type Log = Log;
    type SessionKey = AuthorityId;

    // The Aura module handles offline-reports internally
    // rather than using an explicit report system.
    type InherentOfflineReport = ();
}

如何Log定义?没有use用于导入此符号的子句。

跑步

cargo rustc -- -Z unstable-options --pretty=expanded

不显示任何带有子句的Log条目。type在 0 级扩展宏后,它确实显示了其他宏声明,但我不确定这是否相关。

我尝试使用 Atom IDE,因为它会自动解析文件并让您找到符号的定义,但它没有帮助。

我怎样才能找到如何Log定义?

4

1 回答 1

2

Logconstruct_runtime宏定义。以下是一些相关代码:

construct_runtime宏:

https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/srml/support/src/runtime.rs#L79

macro_rules! construct_runtime {
    (
        pub enum $runtime:ident with Log ($log_internal:ident: DigestItem<$( $log_genarg:ty ),+>)
            where
                Block = $block:ident,
                NodeBlock = $node_block:ty,
                UncheckedExtrinsic = $uncheckedextrinsic:ident
        {
            $( $rest:tt )*
        }
    )

打电话__decl_outer_log

https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/srml/support/src/runtime.rs#L267

    $crate::__decl_outer_log!(
        $runtime;
        $log_internal < $( $log_genarg ),* >;
        {};
        $(
            $name: $module:: $( < $module_instance >:: )? { $( $modules $( ( $( $modules_args )* ) )* )* }
        )*
    );

__decl_outer_log

https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/srml/support/src/runtime.rs#L706

macro_rules! __decl_outer_log {
    (
        $runtime:ident;
        $log_internal:ident <$( $log_genarg:ty ),+>;
        { $( $parsed:tt )* };
        $name:ident: $module:ident:: $(<$module_instance:ident>::)? {
            Log ( $( $args:ident )* ) $( $modules:ident $( ( $( $modules_args:ident )* ) )* )*
        }
        $( $rest:tt )*
    ) => {

打电话impl_outer_log

https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/srml/support/src/runtime.rs#L763

(
    $runtime:ident;
    $log_internal:ident <$( $log_genarg:ty ),+>;
    { $(
        $parsed_modules:ident $(< $parsed_instance:ident >)? ( $( $parsed_args:ident )* )
    )* };
) => {
    $crate::paste::item! {
        $crate::runtime_primitives::impl_outer_log!(
            pub enum Log($log_internal: DigestItem<$( $log_genarg ),*>) for $runtime {
                $( [< $parsed_modules $(_ $parsed_instance)? >] $(< $parsed_modules::$parsed_instance >)? ( $( $parsed_args ),* ) ),*
            }
        );
    }
};

impl_outer_log宏: https ://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/core/sr-primitives/src/lib.rs#L630

macro_rules! impl_outer_log {
    (
        $(#[$attr:meta])*
        pub enum $name:ident ($internal:ident: DigestItem<$( $genarg:ty ),*>) for $trait:ident {
            $( $module:ident $(<$instance:path>)? ( $( $sitem:ident ),* ) ),*
        }
    )

它实际上声明并实现了Log结构

您应该能够cargo expand在运行时 crate 时看到结果。

于 2019-05-28T01:24:07.957 回答