Exemplo n.º 1
0
def total_act_validators_script():
    try:
        print("#" * 30)
        print("Executing Total Active Validators Count")

        db_con = mongo_helper.mongo_conn()
        crawled_data = db_con.latest_block_altona.find_one(
            {}, sort=[('_id', pymongo.DESCENDING)])
        data = beacon.get_participation_rate()
        if data:
            data2 = beacon.get_active_validators_count_head()
            data = beacon.get_participation_rate()
            participation = data.get('participation')
            if crawled_data.get('epoch') == data.get('epoch'):
                raise ('skipping operation')
            insert_data = {
                'eligible_ether': participation.get('eligibleEther'),
                'epoch': int(data.get('epoch')),
                'timestamp':
                time_calculator.get_epoch_time(int(data.get('epoch'))),
                'total_act_validators': data2
            }
            db_con = mongo_helper.mongo_conn()
            db_status = db_con.new_graph_data_altona.insert(insert_data)
            print(db_status)
        else:
            print('No data')
            False

    except Exception as e:
        error = common.get_error_traceback(sys, e)
        print(error)
Exemplo n.º 2
0
def get_latest_block(args):
    '''gives data of latest block from db'''
    try :
        page = int(args.get('page', 1))
        perPage = int(args.get('perPage', 10))
        db_con = mongo_helper.mongo_conn()
        db_data = db_con.latest_block.find({}).sort([('_id',-1)]).limit(perPage)
        if not db_data:
            raise

        return_list = []
        for data in db_data:
            return_dict = {
                
            }
            return_dict['epoch'] = data.get('epoch','NA')
            return_dict['slot'] = data.get('slot','NA')
            if not (data.get('slot') == 'NA'):
                return_dict['time'] = time_calculator.get_slot_time(data.get('slot'))

            return_dict['proposer'] = data.get('proposer','N/A')
            return_dict['attestian_count'] = data.get('attestian_count','NA')
            return_dict['status'] = data.get('status','NA')
            return_list.append(return_dict)
        
        return common.send_sucess_msg({'data': return_list})
    except Exception as e:
        error = common.get_error_traceback(sys,e)
        print (error)
        return False
Exemplo n.º 3
0
def global_participation_history_crawler():
    epoch_no = 170
    while (epoch_no < 1745):
        data = False
        data = beacon.get_participation_rate(epoch=epoch_no)
        if data:
            participation = data.get('participation')
            epoch_timestamp = time_calculator.get_epoch_time(epoch_no)
            timestamp = datetime.datetime.strptime(epoch_timestamp,
                                                   '%Y-%m-%dT%H:%M:%SZ')
            obj_id = ObjectId.from_datetime(timestamp)

            insert_data = {
                '_id':
                obj_id,
                'epoch':
                int(data.get('epoch')),
                'voted_ether':
                participation.get('votedEther'),
                'global_participation':
                participation.get('globalParticipationRate'),
                'eligible_ether':
                participation.get('eligibleEther'),
                'timestamp':
                epoch_timestamp
            }
            db_con = mongo_helper.mongo_conn()
            db_status = db_con.global_participation_new_altona.insert(
                insert_data)

            print('processing epoch {} with data {}'.format(
                epoch_no, str(insert_data)))
        epoch_no = epoch_no + 1
Exemplo n.º 4
0
def new_graph_history_crawler():
    epoch_no = 2357
    while (epoch_no < 2440):
        data = False
        data = beacon.get_participation_rate(epoch=epoch_no)
        if data:
            participation = data.get('participation')
            epoch_timestamp = time_calculator.get_epoch_time(epoch_no)
            timestamp = datetime.datetime.strptime(epoch_timestamp,
                                                   '%Y-%m-%dT%H:%M:%SZ')
            obj_id = ObjectId.from_datetime(timestamp)
            data2 = beacon.get_active_validators_count(epoch=epoch_no)

            insert_data = {
                '_id': obj_id,
                'eligible_ether': participation.get('eligibleEther'),
                'epoch': int(data.get('epoch')),
                'timestamp': epoch_timestamp,
                'total_act_validators': data2
            }
            db_con = mongo_helper.mongo_conn()
            db_status = db_con.new_graph_data_altona.insert(insert_data)

            print('processing epoch {} with data {}'.format(
                epoch_no, str(insert_data)))
        epoch_no = epoch_no + 1
def get_data_for_global_participation_rate():
    try:
        db_con = mongo_helper.mongo_conn()
        db_data = db_con.global_participation.find({}).sort([('_id', -1)
                                                             ]).limit(24)

        timestamp_list = []
        voted_ether_list = []
        global_participation_list = []

        for data in db_data:
            ether = int(data.get('voted_ether')) / 1000000000
            timestamp_list.append(data.get('timestamp'))
            voted_ether_list.append(ether)
            global_participation_list.append(
                round(data.get('global_participation') * 100, 2))

        return_dict = {
            'timestamp': timestamp_list,
            'voted_ether': voted_ether_list,
            'global_participation': global_participation_list
        }
        return common.send_sucess_msg(return_dict)

    except Exception as e:
        print(e)
        pass
Exemplo n.º 6
0
def global_participation_script():
    try:
        print("#" * 30)
        print("Executing global_participation_script")
        data = beacon.get_participation_rate()
        if data:
            participation = data.get('participation')
            insert_data = {
                'epoch':
                data.get('epoch'),
                'voted_ether':
                participation.get('votedEther'),
                'global_participation':
                participation.get('globalParticipationRate'),
                'eligible_ether':
                participation.get('eligibleEther'),
                'timestamp':
                common.get_current_date_time()
            }
            db_con = mongo_helper.mongo_conn()
            db_status = db_con.global_participation.insert(insert_data)
            print(db_status)
        else:
            False

    except Exception as e:
        error = common.get_error_traceback(sys, e)
        print(error)
Exemplo n.º 7
0
def get_epoch_by_slot(slot):
    db = mongo_helper.mongo_conn()
    epoch_data = db.latest_block.find_one({'slot': int(slot)})
    if epoch_data:
        return epoch_data.get('epoch')
    else:
        epoch_data = db.latest_block.find_one({'slot': str(slot)})
        if epoch_data:
            return epoch_data.get('epoch')
        else:
            return 'NA'
Exemplo n.º 8
0
def validator_crawler(epoch=0, pageToken = '0'):
    try:
        for data in  client_beacon_chain.getChainHeadStream():
            list_validators = client_beacon_chain.ListValidators(epoch=epoch, pageToken=pageToken)
            for data in list_validators.validator_list:
                #todo process validator data here
                total_size = list_validators.total_size
                validators = data.validator
                index = data.index
                public_key = validators.public_key
                pkB64 = base64.b64encode(public_key).decode()
                pkHex = common.decode_public_key(pkB64)
                effective_balance = float(validators.effective_balance)/ 1000000000
                exit_epoch = validators.exit_epoch
                withdrawable_epoch = validators.withdrawable_epoch
                #from GetValidator client
                get_validators = client_beacon_chain.GetValidator(index=index)
                activation_epoch = get_validators.activation_epoch
                activation_eligibility_epoch = get_validators.activation_eligibility_epoch
                slashed = get_validators.slashed
                #Get validators Status
                get_validators_status = client_validators.ValidatorStatus(public_key)
                status_key = get_validators_status.status
                status = {0:'UNKNOWN_STATUS', 1:'DEPOSITED', 2:'PENDING', 3: 'ACTIVE', 4:'EXITING', 5:'SLASHING', 6:'EXITED'}
                #GetValidatorsBalance
                get_validators_balance = client_beacon_chain.ListValidatorBalances([public_key])
                balances_data = get_validators_balance.balances[0]
                balance = int(balances_data.balance)/ 1000000000
                #insert in validator table
                db_con = mongo_helper.mongo_conn()
                db_data = db_con.validators_list.insert({
                    'index' : index,
                    'effective_balance' : effective_balance,
                    'balance' : balance,
                    'public_key' : pkHex,
                    'total_size' : total_size,
                    'activation_epoch': activation_epoch,
                    'activation_eligibility_epoch': activation_eligibility_epoch,
                    'slashed' : slashed,
                    'status': status[status_key]


                })

            if not (list_validators.next_page_token == ''):
                validator_crawler(epoch = epoch, pageToken= list_validators.next_page_token)
            return

    except Exception as e:
        error =  common.get_error_traceback(sys, e)
        print (error)
Exemplo n.º 9
0
def global_participation_script():
    try:
        print("#" * 30)
        print("Executing global_participation_script")

        db_con = mongo_helper.mongo_conn()
        crawled_data = db_con.latest_block_altona.find_one(
            {}, sort=[('_id', pymongo.DESCENDING)])
        data = beacon.get_participation_rate()

        if data:
            participation = data.get('participation')
            if crawled_data.get('epoch') == data.get('epoch'):
                raise ('skipping operation')

            insert_data = {
                'epoch':
                data.get('epoch'),
                'voted_ether':
                participation.get('votedEther'),
                'global_participation':
                participation.get('globalParticipationRate'),
                'eligible_ether':
                participation.get('eligibleEther'),
                'timestamp':
                time_calculator.get_epoch_time(int(data.get('epoch')))
            }
            db_con = mongo_helper.mongo_conn()
            db_status = db_con.global_participation_new_altona.insert(
                insert_data)
            print(db_status)
        else:
            print('No data')
            False

    except Exception as e:
        error = common.get_error_traceback(sys, e)
        print(error)
Exemplo n.º 10
0
def get_validator_participation():
    try:

        db =  mongo_helper.mongo_conn()
        data = db.graph_data.find({}).limit(10)
        return_data = []
        for d in data :
            return_dict = {}
            return_dict['epoch'] =  d.get('epoch')
            return_dict['ether'] = d.get('ether')
            return_data.append(return_dict)

        return common.send_sucess_msg({'data':return_data})
    except Exception as e:
        error = common.get_error_traceback(sys,e)
        print (error)
        return common.send_error_msg()
Exemplo n.º 11
0
def crawl_chain_head():
    print('Executing Crawler script....')
    try:
        for chain_head_data in client_beacon_chain.getChainHeadStream():
            current_epoch = int(chain_head_data.get('headEpoch'))
            current_slot = int(chain_head_data.get('headSlot'))

            crawled_slot = int(
                redis_helper.hget(hash='chain_head', key='current_slot_'))
            print('crawled slot is {} current slot is {}'.format(
                crawled_slot, current_slot))

            if crawled_slot < current_slot:
                diffrence = current_slot - crawled_slot

                if diffrence > 1:
                    #case of skipped block
                    print('processing skipped block')
                    for i in range(diffrence - 1):
                        crawled_slot = crawled_slot + 1

                        print('processing skipped block: {} '.format(
                            crawled_slot))

                        db_conn = mongo_helper.mongo_conn()

                        db_status = db_conn.latest_block_altona.insert({
                            'epoch':
                            int(current_epoch),
                            'slot':
                            int(crawled_slot),
                            'proposer':
                            'NA',
                            'attestian_count':
                            0,
                            'status':
                            'Skipped'
                        })
                        print(db_status)

                print('processing redis operation.........')
                redis_set_slot = redis_helper.hset(key_hash='chain_head',
                                                   key='current_slot_',
                                                   value=current_slot)

                crawled_epoch = int(
                    redis_helper.hget(hash='chain_head', key='current_epoch_'))

                if crawled_epoch < current_epoch:
                    redis_set_epoch = redis_helper.hset(key_hash='chain_head',
                                                        key='current_epoch_',
                                                        value=current_epoch)
                slot_data = beacon.get_slot_data(current_slot)[0]
                attestian_count = slot_data.get('attestations_count', '0')
                proposer = slot_data.get('proposer', 'NA')

                print('processing_db operation')

                db_conn = mongo_helper.mongo_conn()
                db_status = db_conn.latest_block_altona.insert({
                    'epoch':
                    int(current_epoch),
                    'slot':
                    int(current_slot),
                    'proposer':
                    proposer,
                    'attestian_count':
                    attestian_count,
                    'status':
                    'proposed'
                })
                print(db_status)
                get_current_chain_state_script()
                # process validator crawling
                validator_Crawler.validator_crawler(current_epoch)

            else:
                print('skipping redis operation')
        else:
            print('No Response from Blockchain')
    except Exception as e:
        error = common.get_error_traceback(sys, e)
        print(error)