Esempio n. 1
0
 def _send(self, sender, to, value, evmdata='', output=None,
           funid=None, abi=None, profiling=0):
     if funid is not None or abi is not None:
         raise Exception("Send with funid+abi is deprecated. Please use"
                         " the abi_contract mechanism")
     tm, g = time.time(), self.block.gas_used
     sendnonce = self.block.get_nonce(u.privtoaddr(sender))
     tx = t.Transaction(sendnonce, gas_price, gas_limit, to, value, evmdata)
     self.last_tx = tx
     tx.sign(sender)
     recorder = LogRecorder() if profiling > 1 else None
     (s, o) = pb.apply_transaction(self.block, tx)
     if not s:
         raise TransactionFailed()
     out = {"output": o}
     if profiling > 0:
         zero_bytes = tx.data.count(ascii_chr(0))
         non_zero_bytes = len(tx.data) - zero_bytes
         intrinsic_gas_used = opcodes.GTXDATAZERO * zero_bytes + \
             opcodes.GTXDATANONZERO * non_zero_bytes
         ntm, ng = time.time(), self.block.gas_used
         out["time"] = ntm - tm
         out["gas"] = ng - g - intrinsic_gas_used
     if profiling > 1:
         trace = recorder.pop_records()
         ops = [x['op'] for x in trace if x['event'] == 'vm']
         opdict = {}
         for op in ops:
             opdict[op] = opdict.get(op, 0) + 1
         out["ops"] = opdict
     return out
Esempio n. 2
0
    def _get_trace(self, txhash):
        try:  # index
            test_blk, tx, i = self._get_block_before_tx(txhash)
        except (KeyError, TypeError):
            raise Exception('Unknown Transaction  %s' % txhash)

        # collect debug output FIXME set loglevel trace???
        recorder = LogRecorder()
        # apply tx (thread? we don't want logs from other invocations)
        self.app.services.chain.add_transaction_lock.acquire()
        processblock.apply_transaction(test_blk, tx)  # FIXME deactivate tx context switch or lock
        self.app.services.chain.add_transaction_lock.release()
        return dict(tx=txhash, trace=recorder.pop_records())
Esempio n. 3
0
    def _get_trace(self, txhash):
        try:  # index
            test_blk, tx, i = self._get_block_before_tx(txhash)
        except (KeyError, TypeError):
            raise Exception('Unknown Transaction  %s' % txhash)

        # collect debug output FIXME set loglevel trace???
        recorder = LogRecorder()
        # apply tx (thread? we don't want logs from other invocations)
        self.app.services.chain.add_transaction_lock.acquire()
        processblock.apply_transaction(
            test_blk, tx)  # FIXME deactivate tx context switch or lock
        self.app.services.chain.add_transaction_lock.release()
        return dict(tx=txhash, trace=recorder.pop_records())
Esempio n. 4
0
 def _send(self,
           sender,
           to,
           value,
           evmdata='',
           output=None,
           funid=None,
           abi=None,
           profiling=0):
     if funid is not None or abi is not None:
         raise Exception("Send with funid+abi is deprecated. Please use"
                         " the abi_contract mechanism")
     tm, g = time.time(), self.block.gas_used
     sendnonce = self.block.get_nonce(u.privtoaddr(sender))
     tx = t.Transaction(sendnonce, 1, gas_limit, to, value, evmdata)
     self.last_tx = tx
     tx.sign(sender)
     recorder = LogRecorder() if profiling > 1 else None
     (s, o) = pb.apply_transaction(self.block, tx)
     if not s:
         raise Exception("Transaction failed")
     out = {"output": o}
     if profiling > 0:
         zero_bytes = tx.data.count(ascii_chr(0))
         non_zero_bytes = len(tx.data) - zero_bytes
         intrinsic_gas_used = opcodes.GTXDATAZERO * zero_bytes + \
             opcodes.GTXDATANONZERO * non_zero_bytes
         ntm, ng = time.time(), self.block.gas_used
         out["time"] = ntm - tm
         out["gas"] = ng - g - intrinsic_gas_used
     if profiling > 1:
         trace = recorder.pop_records()
         ops = [x['op'] for x in trace if x['event'] == 'vm']
         opdict = {}
         for op in ops:
             opdict[op] = opdict.get(op, 0) + 1
         out["ops"] = opdict
     return out
Esempio n. 5
0
 def trace(self, sender, to, value, data=[]):
     # collect log events (independent of loglevel filters)
     recorder = LogRecorder()
     self.send(sender, to, value, data)
     return recorder.pop_records()
Esempio n. 6
0
 def trace(self, sender, to, value, data=[]):
     # collect log events (independent of loglevel filters)
     recorder = LogRecorder()
     self.send(sender, to, value, data)
     return recorder.pop_records()
Esempio n. 7
0
    def _send(
            self,
            sender,
            to,
            value,
            evmdata='',
            funid=None,
            abi=None,  # pylint: disable=too-many-arguments
            profiling=0):
        # pylint: disable=too-many-locals

        if funid is not None or abi is not None:
            raise Exception(
                'Send with funid+abi is deprecated. Please use the abi_contract mechanism'
            )

        start_time = time.time()
        gas_used = self.block.gas_used

        sendnonce = self.block.get_nonce(privtoaddr(sender))
        transaction = transactions.Transaction(sendnonce, gas_price, gas_limit,
                                               to, value, evmdata)
        self.last_tx = transaction
        transaction.sign(sender)
        recorder = None

        if profiling > 1:
            recorder = LogRecorder(
                disable_other_handlers=True,
                log_config=TRACE_LVL_MAP[3],
            )

        try:
            (success,
             output) = processblock.apply_transaction(self.block, transaction)

            if not success:
                raise TransactionFailed()

            out = {
                'output': output,
            }

            if profiling > 0:
                zero_bytes_count = transaction.data.count(ascii_chr(0))
                non_zero_bytes_count = len(transaction.data) - zero_bytes_count

                zero_bytes_cost = opcodes.GTXDATAZERO * zero_bytes_count
                nonzero_bytes_cost = opcodes.GTXDATANONZERO * non_zero_bytes_count

                base_gas_cost = opcodes.GTXCOST
                intrinsic_gas_used = base_gas_cost + zero_bytes_cost + nonzero_bytes_cost

                out['time'] = time.time() - start_time
                out['gas'] = self.block.gas_used - gas_used - intrinsic_gas_used

            if profiling > 1:
                trace = recorder.pop_records()
                vm_operations = [
                    event['op'] for event in trace if event['event'] == 'vm'
                ]
                opdict = {}
                for operation in vm_operations:
                    opdict[operation] = opdict.get(operation, 0) + 1
                out['ops'] = opdict

            return out
        finally:
            # ensure LogRecorder has been disabled
            if recorder:
                recorder.pop_records()
Esempio n. 8
0
    def _send(self, sender, to, value, evmdata='', funid=None, abi=None,  # pylint: disable=too-many-arguments
              profiling=0):
        # pylint: disable=too-many-locals

        if funid is not None or abi is not None:
            raise Exception(
                'Send with funid+abi is deprecated. Please use the abi_contract mechanism'
            )

        start_time = time.time()
        gas_used = self.block.gas_used

        sendnonce = self.block.get_nonce(privtoaddr(sender))
        transaction = transactions.Transaction(sendnonce, gas_price, gas_limit, to, value, evmdata)
        self.last_tx = transaction
        transaction.sign(sender)
        recorder = None

        if profiling > 1:
            recorder = LogRecorder(
                disable_other_handlers=True,
                log_config=TRACE_LVL_MAP[3],
            )

        try:
            (success, output) = processblock.apply_transaction(self.block, transaction)

            if not success:
                raise TransactionFailed()

            out = {
                'output': output,
            }

            if profiling > 0:
                zero_bytes_count = transaction.data.count(ascii_chr(0))
                non_zero_bytes_count = len(transaction.data) - zero_bytes_count

                zero_bytes_cost = opcodes.GTXDATAZERO * zero_bytes_count
                nonzero_bytes_cost = opcodes.GTXDATANONZERO * non_zero_bytes_count

                base_gas_cost = opcodes.GTXCOST
                intrinsic_gas_used = base_gas_cost + zero_bytes_cost + nonzero_bytes_cost

                out['time'] = time.time() - start_time
                out['gas'] = self.block.gas_used - gas_used - intrinsic_gas_used

            if profiling > 1:
                trace = recorder.pop_records()
                vm_operations = [
                    event['op']
                    for event in trace
                    if event['event'] == 'vm'
                ]
                opdict = {}
                for operation in vm_operations:
                    opdict[operation] = opdict.get(operation, 0) + 1
                out['ops'] = opdict

            return out
        finally:
            # ensure LogRecorder has been disabled
            if recorder:
                recorder.pop_records()