在Substrate运行时包装箱内定义的Log类型在哪里?

时间:2019-05-24 14:04:35

标签: rust substrate

看看this implementation

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的定义?

1 个答案:

答案 0 :(得分: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运行箱时,您应该能够看到结果。