# Path: feemodel/config.py
# DIFF_RETARGET_INTERVAL = 2016
# PRIORITYTHRESH = 57600000
# EXPECTED_BLOCK_INTERVAL = 600
# MINRELAYTXFEE = 5000
# def read_default_config():
# 
# Path: feemodel/util.py
# class StoppableThread(threading.Thread):
# class WorkerThread(threading.Thread):
# class BlockingProxy(Proxy):
# class CacheProxy(BlockingProxy):
# class BatchProxy(CacheProxy):
# class DataSample(object):
# class Function(object):
# class DiscreteFunction(Function):
# class StepFunction(Function):
# class BlockMetadata(object):
#     def __init__(self):
#     def run(self):
#     def stop(self):
#     def is_stopped(self):
#     def sleep(self, secs):
#     def context_start(self):
#     def get_stop_object(self):
#     def auto_restart(interval):
#         def decorator(fn):
#             def looped_fn(self, *args, **kwargs):
# def logexceptions(fn):
#     def logged_fn(*args, **kwargs):
#     def __init__(self, workfn):
#     def run(self):
#     def put(self, *args):
#     def stop(self):
#     def __init__(self):
#     def _call(self, *args):
#     def close(self):
#     def __init__(self, maxblocks=10, maxhashes=1000):
#     def getcache(self, d, key, maxitems, default_fn):
#     def getblock(self, blockhash):
#     def getblockhash(self, blockheight):
#     def poll_mempool(self):
#     def __init__(self, datapoints=None):
#     def add_datapoints(self, datapoints):
#     def calc_stats(self):
#     def get_percentile(self, p, weights=None):
#     def __len__(self):
#     def __repr__(self):
#     def __init__(self, x, y):
#     def __call__(self, x0, use_upper=False, use_lower=False):
#     def inv(self, y0, use_upper=False, use_lower=False):
#     def addpoint(self, xi, yi):
#     def __getitem__(self, idx):
#     def __str__(self):
#     def __len__(self):
#     def __iter__(self):
#     def __copy__(self):
#     def __call__(self, x0):
#     def inv(self, y0):
#     def __call__(self, x0):
#     def approx(self, percenterror=0.05, percentstep=0.05):
#     def _get_maxerror(self, previdx, curridx, f):
#     def __copy__(self):
#     def __init__(self, height):
#     def get_poolname(self):
#     def __repr__(self):
# def save_obj(obj, filename, protocol=2):
# def load_obj(filename):
# def get_coinbase_info(blockheight):
# def get_hashesperblock(blockheight):
# def get_block_timestamp(blockheight):
# def get_block_size(blockheight):
# def get_block_name(blockheight):
# def get_feerate(rawentry):
# def round_random(f):
# def interpolate(x0, x, y):
# def cumsum_gen(iterable, base=0, mapfn=lambda x: x):
#     STOP = StopIteration()


import os
import threading
import sqlite3
import decimal
import logging
from time import time
from copy import copy
from itertools import groupby
from operator import attrgetter, itemgetter
from bitcoin.core import b2lx
from feemodel.config import config, datadir, MINRELAYTXFEE, PRIORITYTHRESH
from feemodel.util import (proxy, StoppableThread, get_feerate, WorkerThread,
                           cumsum_gen, BlockMetadata, StepFunction)
from feemodel.stranding import tx_preprocess, calc_stranding_feerate
from feemodel.simul.simul import SimEntry
        (entry.currentpriority > prioritythresh), however, currentpriority,
        as obtained by RPC, uses the current height, whereas miners in forming
        a new block use the current height + 1, i.e. the height of the new
        block. So currentpriority underestimates the 'true' mining priority.
        (There are other complications, in that currentpriority doesn't take
        into account cases where the entry has mempool dependencies, but
        that's a different problem, which we live with for now.)

        This difference is important because, for the purposes of minfeerate
        policy estimation, we need to properly exclude all high priority
        transactions. Previously in v0.9 of Bitcoin Core, this wasn't such a
        big problem, because low priority transactions below minrelaytxfee
        are still relayed / enter the mempool; there are thus sufficient
        low-fee, low-priority transactions so that the minfeerate threshold
        is still estimatable in a consistent manner.

        With v0.10, however, only high (miners') priority transactions are
        allowed into the mempool if the tx has low fee. If one relies on the
        criteria (entry.currentpriority > prioritythresh), there will be false
        negatives; however because there aren't any more truly low-priority
        transactions with similar feerate, the minfeerate estimation can
        become inconsistent.

        It's not possible, however, to adjust entry.currentpriority to become
        the miners' priority, solely from the information obtained from
        getrawmempool. Therefore, we resort to this hack: the entry is classed
        as high priority if (entry.currentpriority > prioritythresh) or
        (entry.feerate < minrelaytxfee).
        '''
        return (self.currentpriority > PRIORITYTHRESH or

# Path: feemodel/config.py
# DIFF_RETARGET_INTERVAL = 2016
# PRIORITYTHRESH = 57600000
# EXPECTED_BLOCK_INTERVAL = 600
# MINRELAYTXFEE = 5000
# def read_default_config():
# 
# Path: feemodel/util.py
# class StoppableThread(threading.Thread):
# class WorkerThread(threading.Thread):
# class BlockingProxy(Proxy):
# class CacheProxy(BlockingProxy):
# class BatchProxy(CacheProxy):
# class DataSample(object):
# class Function(object):
# class DiscreteFunction(Function):
# class StepFunction(Function):
# class BlockMetadata(object):
#     def __init__(self):
#     def run(self):
#     def stop(self):
#     def is_stopped(self):
#     def sleep(self, secs):
#     def context_start(self):
#     def get_stop_object(self):
#     def auto_restart(interval):
#         def decorator(fn):
#             def looped_fn(self, *args, **kwargs):
# def logexceptions(fn):
#     def logged_fn(*args, **kwargs):
#     def __init__(self, workfn):
#     def run(self):
#     def put(self, *args):
#     def stop(self):
#     def __init__(self):
#     def _call(self, *args):
#     def close(self):
#     def __init__(self, maxblocks=10, maxhashes=1000):
#     def getcache(self, d, key, maxitems, default_fn):
#     def getblock(self, blockhash):
#     def getblockhash(self, blockheight):
#     def poll_mempool(self):
#     def __init__(self, datapoints=None):
#     def add_datapoints(self, datapoints):
#     def calc_stats(self):
#     def get_percentile(self, p, weights=None):
#     def __len__(self):
#     def __repr__(self):
#     def __init__(self, x, y):
#     def __call__(self, x0, use_upper=False, use_lower=False):
#     def inv(self, y0, use_upper=False, use_lower=False):
#     def addpoint(self, xi, yi):
#     def __getitem__(self, idx):
#     def __str__(self):
#     def __len__(self):
#     def __iter__(self):
#     def __copy__(self):
#     def __call__(self, x0):
#     def inv(self, y0):
#     def __call__(self, x0):
#     def approx(self, percenterror=0.05, percentstep=0.05):
#     def _get_maxerror(self, previdx, curridx, f):
#     def __copy__(self):
#     def __init__(self, height):
#     def get_poolname(self):
#     def __repr__(self):
# def save_obj(obj, filename, protocol=2):
# def load_obj(filename):
# def get_coinbase_info(blockheight):
# def get_hashesperblock(blockheight):
# def get_block_timestamp(blockheight):
# def get_block_size(blockheight):
# def get_block_name(blockheight):
# def get_feerate(rawentry):
# def round_random(f):
# def interpolate(x0, x, y):
# def cumsum_gen(iterable, base=0, mapfn=lambda x: x):
#     STOP = StopIteration()


# Path: feemodel/txmempool.py
import os
import threading
import sqlite3
import decimal
import logging
from time import time
from copy import copy
from itertools import groupby
from operator import attrgetter, itemgetter
from bitcoin.core import b2lx
from feemodel.config import config, datadir, MINRELAYTXFEE, PRIORITYTHRESH
from feemodel.util import (proxy, StoppableThread, get_feerate, WorkerThread,
                           cumsum_gen, BlockMetadata, StepFunction)
from feemodel.stranding import tx_preprocess, calc_stranding_feerate
from feemodel.simul.simul import SimEntry

        (entry.currentpriority > prioritythresh), however, currentpriority,
        as obtained by RPC, uses the current height, whereas miners in forming
        a new block use the current height + 1, i.e. the height of the new
        block. So currentpriority underestimates the 'true' mining priority.
        (There are other complications, in that currentpriority doesn't take
        into account cases where the entry has mempool dependencies, but
        that's a different problem, which we live with for now.)

        This difference is important because, for the purposes of minfeerate
        policy estimation, we need to properly exclude all high priority
        transactions. Previously in v0.9 of Bitcoin Core, this wasn't such a
        big problem, because low priority transactions below minrelaytxfee
        are still relayed / enter the mempool; there are thus sufficient
        low-fee, low-priority transactions so that the minfeerate threshold
        is still estimatable in a consistent manner.

        With v0.10, however, only high (miners') priority transactions are
        allowed into the mempool if the tx has low fee. If one relies on the
        criteria (entry.currentpriority > prioritythresh), there will be false
        negatives; however because there aren't any more truly low-priority
        transactions with similar feerate, the minfeerate estimation can
        become inconsistent.

        It's not possible, however, to adjust entry.currentpriority to become
        the miners' priority, solely from the information obtained from
        getrawmempool. Therefore, we resort to this hack: the entry is classed
        as high priority if (entry.currentpriority > prioritythresh) or
        (entry.feerate < minrelaytxfee).
        '''
        return (self.currentpriority > PRIORITYTHRESH or

                self.feerate < MINRELAYTXFEE)