Example #1
0
 def cleanup(self, epoch):
     try:
         death_row_node = self.db.get(b'deathrow:' + utils.to_string(epoch))
     except BaseException:
         death_row_node = rlp.encode([])
     death_row_nodes = rlp.decode(death_row_node)
     pruned = 0
     for nodekey in death_row_nodes:
         try:
             refcount, val = rlp.decode(self.db.get(b'r:' + nodekey))
             if utils.decode_int(refcount) == DEATH_ROW_OFFSET + epoch:
                 self.db.delete(b'r:' + nodekey)
                 pruned += 1
         except BaseException:
             pass
     sys.stderr.write('%d nodes successfully pruned\n' % pruned)
     # Delete the deathrow after processing it
     try:
         self.db.delete(b'deathrow:' + utils.to_string(epoch))
     except BaseException:
         pass
     # Delete journals that are too old
     try:
         self.db.delete(b'journal:' + utils.to_string(epoch - self.ttl))
     except BaseException:
         pass
Example #2
0
 def get_refcount(self, k):
     try:
         o = utils.decode_int(self.db.get(b'r:' + k))[0]
         if o >= DEATH_ROW_OFFSET:
             return 0
         return o
     except BaseException:
         return 0
Example #3
0
 def dec_refcount(self, k):
     # raise Exception("WHY AM I CHANGING A REFCOUNT?!:?")
     node_object = rlp.decode(self.db.get(b'r:' + k))
     refcount = utils.decode_int(node_object[0])
     if self.logging:
         sys.stderr.write('decreasing %s to: %d\n' %
                          (utils.encode_hex(k), refcount - 1))
     assert refcount > 0
     self.journal.append([node_object[0], k])
     new_refcount = utils.encode_int(refcount - 1)
     self.db.put(b'r:' + k, rlp.encode([new_refcount, node_object[1]]))
     if new_refcount == ZERO_ENCODED:
         self.death_row.append(k)
Example #4
0
def verify_independent_transaction_spv_proof(db, proof):
    _, prevheader, header, index, nodes = rlp.decode(proof)
    index = utils.decode_int(index)
    pb = blocks.Block.deserialize_header(prevheader)
    b = blocks.Block.init_from_header(db, header)
    b.set_proof_mode(blocks.VERIFYING, nodes)
    if index != 0:
        pre_med, pre_gas, _, _ = b.get_receipt(index - 1)
    else:
        pre_med, pre_gas = pb['state_root'], ''
        if utils.sha3(rlp.encode(prevheader)) != b.prevhash:
            return False
    b.state_root = pre_med
    b.gas_used = utils.decode_int(pre_gas)
    tx = b.get_transaction(index)
    post_med, post_gas, bloom, logs = b.get_receipt(index)
    tx = transactions.Transaction.create(tx)
    o = verify_transaction_spv_proof(b, tx, nodes)
    if b.state_root == post_med:
        if b.gas_used == utils.decode_int(post_gas):
            if [x.serialize() for x in b.logs] == logs:
                if b.mk_log_bloom() == bloom:
                    return o
    return False
Example #5
0
 def inc_refcount(self, k, v):
     # raise Exception("WHY AM I CHANGING A REFCOUNT?!:?")
     try:
         node_object = rlp.decode(self.db.get(b'r:' + k))
         refcount = utils.decode_int(node_object[0])
         self.journal.append([node_object[0], k])
         if refcount >= DEATH_ROW_OFFSET:
             refcount = 0
         new_refcount = utils.encode_int(refcount + 1)
         self.db.put(b'r:' + k, rlp.encode([new_refcount, v]))
         if self.logging:
             sys.stderr.write('increasing %s %r to: %d\n' %
                              (utils.encode_hex(k), v, refcount + 1))
     except BaseException:
         self.db.put(b'r:' + k, rlp.encode([ONE_ENCODED, v]))
         self.journal.append([ZERO_ENCODED, k])
         if self.logging:
             sys.stderr.write('increasing %s %r to: %d\n' %
                              (utils.encode_hex(k), v, 1))
Example #6
0
def decode_int_from_hex(x):
    r = utils.decode_int(decode_hex(x).lstrip(b"\x00"))
    return r