Exemplo n.º 1
0
    def _set_root_node(self, root_node):
        validate_is_node(root_node)
        if self.is_pruning:
            old_root_hash = self.root_hash
            if old_root_hash != BLANK_NODE_HASH and old_root_hash in self.db:
                self._prune_key(old_root_hash)

        self.root_hash = self._set_raw_node(root_node)
Exemplo n.º 2
0
    def _node_to_db_mapping(node):
        validate_is_node(node)
        if is_blank_node(node):
            return BLANK_NODE, None
        encoded_node = encode_raw(node)
        if len(encoded_node) < 32:
            return node, None

        encoded_node_hash = keccak(encoded_node)
        return encoded_node_hash, encoded_node
Exemplo n.º 3
0
    def _persist_node(self, node):
        validate_is_node(node)
        if is_blank_node(node):
            return BLANK_NODE
        encoded_node = rlp.encode(node)
        if len(encoded_node) < 32:
            return node

        encoded_node_hash = keccak(encoded_node)
        self.db[encoded_node_hash] = encoded_node
        return encoded_node_hash
Exemplo n.º 4
0
    def _set_root_node(self, root_node):
        validate_is_node(root_node)
        if self.is_pruning:
            old_root_hash = self.root_hash
            if old_root_hash != BLANK_NODE_HASH and old_root_hash in self.db:
                del self.db[old_root_hash]

        if is_blank_node(root_node):
            self.root_hash = BLANK_NODE_HASH
        else:
            encoded_root_node = encode_raw(root_node)
            new_root_hash = keccak(encoded_root_node)
            self.db[new_root_hash] = encoded_root_node
            self.root_hash = new_root_hash
Exemplo n.º 5
0
    def _set_root_node(self, root_node):
        validate_is_node(root_node)

        if self.is_pruning:
            # Root nodes are special: they are always hashed, which is a surprise to the rest of
            #   the pruning logic. We have to catch if the root node is small and prune it here.
            old_root_hash = self.root_hash
            if old_root_hash != BLANK_NODE_HASH:
                try:
                    old_root_node = self.get_node(old_root_hash)
                except KeyError:
                    # The old root node is missing from the database, but the only
                    #   reason we were retrieving it is to potentially prune it away.
                    # So just ignore the pruning if the old node is already missing
                    pass
                else:
                    prune_key, node_body = self._node_to_db_mapping(
                        old_root_node)
                    if node_body is None and old_root_hash in self.db:
                        self._pending_prune_keys[old_root_hash] += 1

        self.root_hash = self._set_raw_node(root_node)
Exemplo n.º 6
0
 def _set_root_node(self, root_node):
     validate_is_node(root_node)
     encoded_root_node = rlp.encode(root_node)
     self.root_hash = keccak(encoded_root_node)
     self.db[self.root_hash] = encoded_root_node