def commit_state
      return if @journal.empty?

      changes = []
      addresses = @caches[:all].keys.sort

      addresses.each do |addr|
        acct = get_account addr

        %i(balance nonce code storage).each do |field|
          if v = @caches[field][addr]
            changes.push [field, addr, v]
            acct.send :"#{field}=", v
          end
        end

        t = SecureTrie.new PruningTrie.new(db, acct.storage)
        @caches.fetch("storage:#{addr}", {}).each do |k, v|
          enckey = Utils.zpad Utils.coerce_to_bytes(k), 32
          val = RLP.encode v
          changes.push ['storage', addr, k, v]

          v.true? ? t.set(enckey, val) : t.delete(enckey)
        end

        acct.storage = t.root_hash
        @state[addr] = RLP.encode(acct)
      end
      logger.debug "delta changes=#{changes}"

      reset_cache
      db.put_temporarily "validated:#{full_hash}", '1'
    end
def commit_state
      return if @journal.empty?

      changes = []
      addresses = @caches[:all].keys.sort

      addresses.each do |addr|
        acct = get_account addr

        %i(balance nonce code storage).each do |field|
          if v = @caches[field][addr]
            changes.push [field, addr, v]
            acct.send :"#{field}=", v
          end
        end

        t = SecureTrie.new PruningTrie.new(db, acct.storage)
        @caches.fetch("storage:#{addr}", {}).each do |k, v|
          enckey = Utils.zpad Utils.coerce_to_bytes(k), 32
          val = RLP.encode v
          changes.push ['storage', addr, k, v]

          v.true? ? t.set(enckey, val) : t.delete(enckey)
        end

        acct.storage = t.root_hash
        @state[addr] = RLP.encode(acct)
      end
      logger.debug "delta changes=#{changes}"

      reset_cache
      db.put_temporarily "validated:#{full_hash}", '1'
    end
Commit account caches. Write the account caches on the corresponding
 tries.