Exemplo n.º 1
0
def non_std_outs_analysis(samples, version):
    """
    Perform the non standard out analysis for a given set of samples.

    :param samples: List of samples that will form the chart.
    :type samples: list
    :param version: Bitcoin core version, used to decide the folder in which to store the data.
    :type version: float
    :return: None
    :rtype: None
    """

    # We can use get_unique_values() to obtain all values for the non_std_type attribute found in the analysed samples:
    # get_unique_values("non_std_type",  fin_name=f_parsed_utxos)

    # Once we know all the possible values, we can create a pie chart, assigning a piece of the pie to the main values
    # and grouping all the rest into an "Other" category. E.g., we create pieces for multisig 1-1, 1-2, 1-3, 2-2, 2-3
    # and 3-3, and put the rest into "Other".

    groups = [[u'multisig-1-3'], [u'multisig-1-2'], [u'multisig-1-1'], [u'multisig-3-3'], [u'multisig-2-2'],
              [u'multisig-2-3'], [False, u'multisig-OP_NOTIF-OP_NOTIF',
                                  u'multisig-<2153484f55544f555420544f2023424954434f494e2d41535345545320202020202020202'
                                  u'0202020202020202020202020202020202020202020202020202020>-1']]
    labels = ['M. 1-3', 'M. 1-2', 'M. 1-1', 'M. 3-3', 'M. 2-2', 'M. 2-3', 'Other']

    out_name = "utxo_non_std_type"

    # ToDo: Fix labels overlapping 

    plot_pie_chart_from_samples(samples=samples, save_fig=out_name, labels=labels, version=version, groups=groups,
                                title="",  colors=["#165873", "#428C5C", "#4EA64B", "#ADD96C", "#B1D781", "#FAD02F",
                                                   "#F69229"], labels_out=True)
Exemplo n.º 2
0
def tx_based_analysis(tx_fin_name):
    """
    Performs a transaction based analysis from a given input file (resulting from a transaction dump of the chainstate)

    :param tx_fin_name: Input file path which contains the chainstate transaction dump.
    :type: str
    :return: None
    :rtype: None
    """

    x_attributes = ['height', 'total_len', 'total_value', 'num_utxos']

    xlabels = [
        'Height', 'Total length (bytes)', 'Total value',
        'Number of UTXOs per tx'
    ]

    out_names = [
        "tx_height", ["tx_total_len", "tx_total_len_logx"],
        "tx_total_value_logx", ["tx_num_utxos", "tx_num_utxos_logx"]
    ]

    log_axis = [False, [False, 'x'], 'x', [False, 'x']]

    x_attr_pie = 'coinbase'
    xlabels_pie = [['Coinbase', 'No-coinbase']]
    out_names_pie = ['tx_coinbase']
    pie_groups = [[[1], [0]]]
    pie_colors = [["#165873", "#428C5C"]]

    samples = get_samples(x_attributes + [x_attr_pie], fin_name=tx_fin_name)
    samples_pie = samples.pop(x_attr_pie)

    for attribute, label, log, out in zip(x_attributes, xlabels, log_axis,
                                          out_names):
        xs, ys = get_cdf(samples[attribute], normalize=True)
        plots_from_samples(xs=xs,
                           ys=ys,
                           xlabel=label,
                           log_axis=log,
                           save_fig=out,
                           ylabel="Number of txs")

    for label, out, groups, colors in (zip(xlabels_pie, out_names_pie,
                                           pie_groups, pie_colors)):
        plot_pie_chart_from_samples(samples=samples_pie,
                                    save_fig=out,
                                    labels=label,
                                    title="",
                                    groups=groups,
                                    colors=colors,
                                    labels_out=True)
Exemplo n.º 3
0
def utxo_based_analysis(utxo_fin_name, version=0.15):
    """
    Performs a utxo based analysis from a given input file (resulting from a utxo dump of the chainstate)

    :param utxo_fin_name: Input file path which contains the chainstate utxo dump.
    :type: str
    :param version: Bitcoin core version, used to decide the folder in which to store the data.
    :type version: float
    :return: None
    :rtype: None
    """

    x_attributes = ['tx_height', 'amount', 'index', 'out_type', 'utxo_data_len']

    xlabels = ['Tx. height', 'Amount', 'UTXO Index', 'Out type', 'UTXO data len.']

    out_names = ["utxo_tx_height", "utxo_amount_logx", ["utxo_index", "utxo_index_logx"],
                 ["utxo_out_type", "utxo_out_type_logx"], ["utxo_data_len", "utxo_data_len_logx"]]

    # Getting register length in case of 0.15 onwards. For previous versions this chart is printed in the tx based
    # analysis, since data is already aggregated.
    if version >= 0.15:
        x_attributes += ['register_len']
        xlabels += ['Register len.']
        out_names += ['utxo_register_len', 'utxo_register_len_logx']

    log_axis = [False, 'x', [False, 'x'], [False, 'x'], [False, 'x'], [False, 'x']]

    x_attributes_pie = ['out_type', 'out_type']
    xlabels_pie = [['C-even', 'C-odd', 'U-even', 'U-odd'], ['P2PKH', 'P2PK', 'P2SH', 'Other']]
    out_names_pie = ["utxo_pk_types", "utxo_types"]
    pie_groups = [[[2], [3], [4], [5]], [[0], [2, 3, 4, 5], [1]]]

    x_attribute_special = 'non_std_type'

    # Since the attributes for the pie chart are already included in the normal chart, we won't pass them to the
    # sampling function.
    samples = get_samples(x_attributes + [x_attribute_special], fin_name=utxo_fin_name)

    for attribute, label, log, out in zip(x_attributes, xlabels, log_axis, out_names):
        plots_from_samples(x_attribute=attribute, samples=samples[attribute], xlabel=label, log_axis=log, save_fig=out,
                           version=str(version), ylabel="Number of UTXOs")

    for attribute, label, out, groups in (zip(x_attributes_pie, xlabels_pie, out_names_pie, pie_groups)):
        plot_pie_chart_from_samples(samples=samples[attribute], save_fig=out, labels=label,
                                    title="", version=version, groups=groups, colors=["#165873", "#428C5C",
                                                                                      "#4EA64B", "#ADD96C"])
    # Special case: non-standard
    non_std_outs_analysis(samples[x_attribute_special], version)
Exemplo n.º 4
0
def tx_based_analysis(tx_fin_name, version=0.15):
    """
    Performs a transaction based analysis from a given input file (resulting from a transaction dump of the chainstate)

    :param tx_fin_name: Input file path which contains the chainstate transaction dump.
    :type: str
    :param version: Bitcoin core version, used to decide the folder in which to store the data.
    :type version: float
    :return: None
    :rtype: None
    """

    x_attributes = ['height', 'total_len', 'version', 'total_value', 'num_utxos']

    xlabels = ['Height', 'Total length (bytes)', 'Version', 'Total value', 'Number of UTXOs per tx']

    out_names = ["tx_height", ["tx_total_len", "tx_total_len_logx"], 'tx_version', "tx_total_value_logx",
                 ["tx_num_utxos", "tx_num_utxos_logx"]]

    log_axis = [False, [False, 'x'], False, 'x', [False, 'x']]

    x_attr_pie = ['coinbase']
    xlabels_pie = [['Coinbase', 'No-coinbase']]
    out_names_pie = ['tx_coinbase']
    pie_groups = [[[1], [0]]]
    pie_colors = [["#165873", "#428C5C"]]

    # Version has been dropped of in version 0.15, so there is no need of parsing Null data for 0.15 onwards.
    if version >= 0.15:
        i = x_attributes.index('version')
        x_attributes.pop(i)
        xlabels.pop(i)
        out_names.pop(i)
        log_axis.pop(i)

    samples = get_samples(x_attributes + x_attr_pie,  fin_name=tx_fin_name)

    for attribute, label, log, out in zip(x_attributes, xlabels, log_axis, out_names):
        plots_from_samples(x_attribute=attribute, samples=samples[attribute], xlabel=label, log_axis=log, save_fig=out,
                           version=str(version), ylabel="Number of txs")

    for attribute, label, out, groups, colors in (zip(x_attr_pie, xlabels_pie, out_names_pie, pie_groups, pie_colors)):
        plot_pie_chart_from_samples(samples=samples[attribute], save_fig=out, labels=label,
                                    title="", version=version, groups=groups, colors=colors)
Exemplo n.º 5
0
def utxo_based_analysis(utxo_fin_name):
    """
    Performs a utxo based analysis from a given input file (resulting from a utxo dump of the chainstate)

    :param utxo_fin_name: Input file path which contains the chainstate utxo dump.
    :type: str
    :return: None
    :rtype: None
    """

    x_attributes = [
        'tx_height', 'amount', 'index', 'out_type', 'utxo_data_len',
        'register_len'
    ]

    xlabels = [
        'Tx. height', 'Amount', 'UTXO index', 'Out type', 'UTXO data length',
        'Register length'
    ]

    out_names = [
        "utxo_tx_height", "utxo_amount_logx",
        ["utxo_index", "utxo_index_logx"],
        ["utxo_out_type", "utxo_out_type_logx"],
        ["utxo_data_len", "utxo_data_len_logx"],
        ['utxo_register_len', 'utxo_register_len_logx']
    ]

    log_axis = [
        False, 'x', [False, 'x'], [False, 'x'], [False, 'x'], [False, 'x']
    ]

    x_attributes_pie = ['out_type', 'out_type']
    xlabels_pie = [['C-even', 'C-odd', 'U-even', 'U-odd'],
                   ['P2PKH', 'P2PK', 'P2SH', 'Other']]
    out_names_pie = ["utxo_pk_types", "utxo_types"]
    pie_groups = [[[2], [3], [4], [5]], [[0], [2, 3, 4, 5], [1]]]

    x_attribute_special = 'non_std_type'

    # Since the attributes for the pie chart are already included in the normal chart, we won't pass them to the
    # sampling function.
    samples = get_samples(x_attributes + [x_attribute_special],
                          fin_name=utxo_fin_name)
    samples_special = samples.pop(x_attribute_special)

    for attribute, label, log, out in zip(x_attributes, xlabels, log_axis,
                                          out_names):
        xs, ys = get_cdf(samples[attribute], normalize=True)
        plots_from_samples(xs=xs,
                           ys=ys,
                           xlabel=label,
                           log_axis=log,
                           save_fig=out,
                           ylabel="Number of UTXOs")

    for attribute, label, out, groups in (zip(x_attributes_pie, xlabels_pie,
                                              out_names_pie, pie_groups)):
        plot_pie_chart_from_samples(
            samples=samples[attribute],
            save_fig=out,
            labels=label,
            title="",
            groups=groups,
            colors=["#165873", "#428C5C", "#4EA64B", "#ADD96C"],
            labels_out=True)
    # Special case: non-standard
    non_std_outs_analysis(samples_special)