Exemple #1
0
from common import node, rpc, email
from mongo import db_height_discrete

if __name__ == '__main__':

    _time = time.strftime('%Y-%m-%d %H:%M:%S',
                          time.localtime(time.time() + 28800))

    n = node.Node()

    b, height = rpc.getblockcount(n.url)
    if b is False:
        email.send_email(
            n.name + '异常报告',
            email.html_table("<tr><td width=" + str(20) +
                             ">时间</td><td width=" + str(200) +
                             ">异常信息</td></tr><tr><td>" + str(_time) +
                             "</td><td>" + str(height) + "</td></tr>"))

    assert b, '[warn_node_height.py] getblockcount error:{}'.format(height)

    obj = db_height_discrete.DetectorMongoDBCont(n.mongo_host, n.mongo_port,
                                                 n.mongo_db)
    ''' detection of block height growth '''
    print('======= detection of block height growth  ========')
    discreteHeight = obj.findOne_discreteHeight()
    print('discreteHeight:{},basicHeight:{}'.format(discreteHeight, height))
    if discreteHeight is None:
        obj.add_discrete_height(height)

    elif discreteHeight['height'] == height:
        mail_text = "<tr><td width=" + str(20) + ">时间</td><td width=" + str(
                                                   height)
        m_sponsor = set()
        for i in range(len(onduty)):
            sponsor = onduty[i].get('_id')
            m_sponsor.add(sponsor)
        print('m_sponsor_1 : ', m_sponsor)

        if node_public_key in m_sponsor:
            assert False, '[normal] First round send the proposal, close the process'

        print('block height :{},{}'.format(gte_height_2, gte_height_1 - 1))
        onduty = obj.condition_find_onduty_sponsor(gte_height_2,
                                                   height - arbiter_num)
        m_sponsor = set()
        for i in range(len(onduty)):
            sponsor = onduty[i].get('_id')
            m_sponsor.add(sponsor)
        print('m_sponsor_2 : ', m_sponsor)

        if node_public_key in m_sponsor:
            assert False, '[normal] Second round send the proposal, close the process'
        ''' 最后的两个集合的sponsor一致,发送邮件 '''
        mail = _onduty_mail(node_public_key, gte_height_2, height)

        mail_vote = _get_vote(obj, node_public_key, gte_height_2, height)

        email.send_email(n.name + '连续不发送提案预警',
                         email.html_table(mail) + email.html_table(mail_vote))

    print('========== Test Finish ==========')
            db_tx = obj.findOne_tx_pool()
            # db count > 3
            if len(db_txs) > 2 and db_tx[interface.height] > height - 1:
                tx_pool = db_txs[0]
                tx_pool_1 = db_txs[1]
                tx_pool_2 = db_txs[2]

                tx_1 = tx_pool.intersection(tx_pool_1)
                tx_2 = tx_1.intersection(tx_pool_2)
                if len(tx_2) == 0:
                    obj.drop_tx_pool()
                else:
                    obj.drop_tx_pool()
                    mail_text = "<tr><td width=" + str(
                        100) + ">区块高度</td><td width=" + str(
                            100) + ">遗留交易数</td></tr>"

                    mail_text = mail_text + "<tr><td>" + str(
                        height - 1) + "</td><td>" + str(
                            len(tx_2)) + "</td></tr>"
                    email.send_email(n.name + '交易池遗留交易预警',
                                     email.html_table(mail_text))
            else:
                obj.add_tx_pool(height - 1, txids)
        else:
            obj.add_tx_pool(height - 1, txids)

    else:
        obj.drop_tx_pool()
    print('========== Test Finish ==========')
# coding-UTF-8

import time

from common import node, rpc, email
'''
检测 mainnet 和 did 区块高度报告
'''

if __name__ == '__main__':
    _time = time.strftime('%Y-%m-%d %H:%M:%S',
                          time.localtime(time.time() + 28800))

    n = node.Node()

    b, height = rpc.getblockcount(n.url)
    assert b, 'getblockcount error:{}'.format(height)

    b, neighbors = rpc.getneighbors(n.url)
    assert b, 'getneighbors error:{}'.format(neighbors)

    mailText = "<tr><td width=" + str(80) + ">时间</td><td width=" + str(
        80) + ">区块高度</td><td width=" + str(80) + ">相邻节点数</td></tr>"

    mailText = mailText + "<tr><td>" + _time + "</td><td>" + str(
        height - 1) + "</td><td>" + str(len(neighbors)) + "</td></tr>"

    email.send_email(n.name + '报告信息', email.html_table(mailText))
    print('========== Test Finish ==========')
            v_mail = _viewoffset_mail(view_list)
    return v_mail


if __name__ == '__main__':
    # 发送大于切换视图指定的数量
    number = 2

    n = node.Node()

    obj = db_onduty_info.OndutyMongoDBCont(n.mongo_host, n.mongo_port, n.mongo_db)

    info = obj.findOne_onduty_info()
    viewoffset_height = obj.findOne_onduty_viewoffset_height()
    db_height = ''
    if info is not None:
        db_height = info[interface.height]
    else:
        assert False, '[warn_onduty_viewoffset.py] mongodb not onduty_info'

    if viewoffset_height is not None:
        viewoffset_height = viewoffset_height[interface.height]
    else:
        viewoffset_height = n.public_dpos_height  # 默认主网H2设置高度

    v_mail = onduty_viewoffset(obj, n, viewoffset_height, db_height, number)
    if v_mail != '':
        email.send_email(n.name + '仲裁人切换视图预警', email.html_table(v_mail))
        obj.add_onduty_viewoffset_height(db_height)
    print('========== Test Finish ==========')
Exemple #6
0
if __name__ == '__main__':

    n = node.Node()

    b, height = rpc.getblockcount(n.url)
    assert b, 'getblockcount error:{}'.format(height)

    b, arbiters = rpc.getarbiterpeersinfo(n.url, height - 1)
    assert b, 'getarbiterpeersinfo error:{}'.format(arbiters)

    # print('arbiters :', arbiters)
    mailText = "<tr><td width=" + str(20) + ">序号</td><td width=" + str(
        20) + ">区块高度</td><td width=" + str(
            200) + ">ownerpublickey</td><td width=" + str(
                200) + ">nodepublickey</td><td width=" + str(
                    20) + ">连接状态</td></tr>"

    print('arbiterpeersinfo:', arbiters)
    for i in range(len(arbiters)):
        arbiter = arbiters[i]
        owner_public_key = arbiter['ownerpublickey']
        node_public_key = arbiter['nodepublickey']
        state = arbiter['connstate']

        mailText = mailText + "<tr><td>" + str(i + 1) + "</td><td>" + str(
            height - 1
        ) + "</td><td>" + owner_public_key + "</td><td>" + node_public_key + "</td><td>" + state + "</td></tr>"
        print('teest :', mailText)

    email.send_email(n.name + '仲裁人直连报告', email.html_table(mailText))
Exemple #7
0
        onduty_height = n.public_dpos_height  # 默认主网H2设置高度

    # 区块范围内发送当值仲裁人的信息

    # 当值轮值次数
    onduty_count = obj.condition_find_onduty_count(onduty_height, db_height)
    # 签名次数
    signer_count = obj.condition_find_signer_count(onduty_height, db_height)
    # 切换视图次数
    viewoffset_count = obj.condition_find_viewoffset_count(
        onduty_height, db_height)

    print('onduty_count :  ', onduty_count)
    print('signer_count :  ', signer_count)
    print('viewoffset_count :  ', viewoffset_count)

    # 发送报告

    onduty_map = onduty_report(n, onduty_count, signer_count, viewoffset_count)
    on_mail = onduty_info_mail(onduty_map, onduty_height, db_height)

    v_mail = warn_onduty_viewoffset.onduty_viewoffset(obj, n, onduty_height,
                                                      db_height, number)

    # print("=======send :", send_email.html_table(on_mail) + send_email.html_table(v_mail))
    email.send_email(n.name + '仲裁人报告信息',
                     email.html_table(on_mail) + email.html_table(v_mail))

    obj.add_onduty_height(db_height)
    print('========== Test Finish ==========')