Пример #1
0
 def new_tx(data):
     try:
         new_tx = TX(binary=data['tx'])
         new_tx.signature = data['sign']
         check_tx_time(new_tx)
         check_tx(tx=new_tx, include_block=None)
         if new_tx.type in (C.TX_VALIDATOR_EDIT, C.TX_CONCLUDE_CONTRACT) and new_tx.hash in tx_builder.unconfirmed:
             # marge contract signature
             original_tx = tx_builder.unconfirmed[new_tx.hash]
             new_signature = list(set(new_tx.signature) | set(original_tx.signature))
             original_tx.signature = new_signature
             logging.info("Marge contract tx {}".format(new_tx))
         else:
             # normal tx
             tx_builder.put_unconfirmed(new_tx)
             update_mining_staking_all_info()
             logging.info("Accept new tx {}".format(new_tx))
         return True
     except BlockChainError as e:
         error = 'Failed accept new tx "{}"'.format(e)
         logging.error(error)
         return False
     except Exception:
         error = "Failed accept new tx"
         logging.error(error, exc_info=True)
         return False
Пример #2
0
 def new_block(data):
     try:
         new_block = fill_newblock_info(data)
     except BlockChainError as e:
         warning = 'Do not accept block "{}"'.format(e)
         logging.warning(warning)
         return False
     except BaseException:
         error = "error on accept new block"
         logging.error(error, exc_info=True)
         add_failed_mark(error)
         return False
     try:
         if new_insert_block(new_block, time_check=True):
             update_mining_staking_all_info()
             logging.info("Accept new block {}".format(new_block))
             return True
         else:
             return False
     except BlockChainError as e:
         error = 'Failed accept new block "{}"'.format(e)
         logging.error(error, exc_info=True)
         return False
     except BaseException:
         error = "error on accept new block"
         logging.error(error, exc_info=True)
         add_failed_mark(error)
         return False
Пример #3
0
def mined_newblock(que, pc):
    # 新規採掘BlockをP2Pに公開
    while True:
        try:
            new_block = que.get(timeout=1)
            new_block.create_time = int(time.time())
            if P.F_NOW_BOOTING:
                logging.debug("Mined but now booting..")
                continue
            elif new_block.height != builder.best_block.height + 1:
                logging.debug("Mined but its old block...")
                continue
            elif new_insert_block(new_block, time_check=True):
                logging.info("Mined new block {}".format(new_block.getinfo()))
            else:
                update_mining_staking_all_info()
                continue
            proof = new_block.txs[0]
            others = [tx.hash for tx in new_block.txs]
            data = {
                'cmd': BroadcastCmd.NEW_BLOCK,
                'data': {
                    'block': new_block.b,
                    'txs': others,
                    'proof': proof.b,
                    'block_flag': new_block.flag,
                    'sign': proof.signature
                }
            }
            try:
                pc.send_command(cmd=ClientCmd.BROADCAST, data=data)
                logging.info(
                    "Success broadcast new block {}".format(new_block))
                update_mining_staking_all_info()
            except TimeoutError:
                logging.warning(
                    "Failed broadcast new block, other nodes don\'t accept {}".
                    format(new_block.getinfo()))
                P.F_NOW_BOOTING = True
        except queue.Empty:
            if pc.f_stop:
                logging.debug("Mined new block closed.")
                break
        except BlockChainError as e:
            logging.error('Failed mined new block "{}"'.format(e))
        except Exception as e:
            logging.error("mined_newblock()", exc_info=True)
Пример #4
0
 def new_tx(data):
     try:
         new_tx = TX(binary=data['tx'])
         new_tx.signature = data['sign']
         check_tx(tx=new_tx, include_block=None)
         check_tx_time(new_tx)
         tx_builder.put_unconfirmed(new_tx)
         update_mining_staking_all_info()
         logging.info("Accept new tx {}".format(new_tx))
         return True
     except BlockChainError as e:
         error = 'Failed accept new tx "{}"'.format(e)
         logging.error(error)
         add_failed_mark(error)
         return False
     except BaseException:
         error = "Failed accept new tx"
         logging.error(error, exc_info=True)
         add_failed_mark(error)
         return False