Exemplo n.º 1
0
 def setUp(self):
     self.simpools = SimPools(pools=ref_pools)
     self.tx_source = SimTxSource(ref_txsample, ref_txrate)
     self.sim = Simul(self.simpools, self.tx_source)
     self.init_entries = deepcopy(init_entries)
     self.feepoints = [0, 1000, 5000, 10000, 20000]
     self.feepoints = filter(
         lambda feerate: feerate >= self.sim.stablefeerate, self.feepoints)
Exemplo n.º 2
0
    def test_degenerate_pools(self):
        degen_pools = {'pool0': SimPool(1, 0, float("inf")),
                       'pool1': SimPool(1, 0, 0)}
        with self.assertRaises(ValueError):
            # No capacity.
            Simul(SimPools(degen_pools), self.tx_source)

        degen_pools.update({'pool2': SimPool(3, 1000000, 1000)})
        degen_pools['pool0'].maxblocksize = 1
        degen_pools['pool1'].maxblocksize = 1
        self.sim = Simul(SimPools(degen_pools), self.tx_source)

        print("Degenerate pools:")
        print("Height\tNumtxs\tSize\tSFR\tMPsize")
        for idx, simblock in enumerate(self.sim.run()):
            if idx >= 50:
                break
            mempoolsize = sum([entry.size for entry in
                               self.sim.mempool.get_entries().values()])
            print("%d\t%d\t%d\t%.0f\t%d" % (idx, len(simblock.txs),
                                            simblock.size, simblock.sfr,
                                            mempoolsize))
Exemplo n.º 3
0
    def update(self):
        pools, tx_source, mempoolstate = self._get_resources()
        sim = Simul(pools, tx_source)
        feepoints = self.calc_feepoints(sim, mempoolstate)
        init_entries = remove_lowfee(mempoolstate.entries, sim.stablefeerate)

        stats = TransientStats()
        feepoints, waittimes = transientsim(sim,
                                            feepoints=feepoints,
                                            init_entries=init_entries,
                                            miniters=self.miniters,
                                            maxiters=self.maxiters,
                                            maxtime=self.update_period,
                                            numprocesses=self.numprocesses,
                                            stopflag=self.get_stop_object())
        stats.record_waittimes(feepoints, waittimes)

        logger.debug("Finished transient sim in %.2fs and %d iterations" %
                     (stats.timespent, stats.numiters))
        # Warn if we reached miniters
        if stats.timespent > 1.1 * self.update_period:
            logger.warning("Transient sim took %.2fs to do %d iters." %
                           (stats.timespent, stats.numiters))
        self.stats = stats
Exemplo n.º 4
0
import cProfile
from feemodel.txmempool import MemBlock
from feemodel.simul.transient import transientsim
from feemodel.simul import Simul
from feemodel.util import DataSample
from feemodel.tests.config import test_memblock_dbfile as dbfile, poolsref, txref

# flake8: noqa

print(poolsref)
init_entries = MemBlock.read(333931, dbfile=dbfile).entries
sim = Simul(poolsref, txref)

print("Starting transientsim.")
cProfile.run("feepoints, waittimes = transientsim("
             "sim, init_entries=init_entries, numprocesses=1)")
print("Completed with {} iters.".format(len(waittimes[0])))

print("Feerate\tMean wait")
for feerate, waitsample in zip(feepoints, waittimes):
    waitdata = DataSample(waitsample)
    waitdata.calc_stats()
    print("{}\t{}".format(feerate, waitdata.mean))
Exemplo n.º 5
0
 def setUp(self):
     pools = PseudoPools()
     tx_source = SimTxSource([SimTx(0, 250)], 1)
     self.sim = Simul(pools, tx_source)
Exemplo n.º 6
0
class CustomMempoolTests(unittest.TestCase):
    # TODO: needs more detailed tests

    def setUp(self):
        pools = PseudoPools()
        tx_source = SimTxSource([SimTx(0, 250)], 1)
        self.sim = Simul(pools, tx_source)

    def test_A(self):
        print("Test A:")
        print("=======")
        init_entries = {
            str(i): SimEntry(100000, 250, depends=['0'])
            for i in range(1, 1000)
        }
        init_entries['0'] = SimEntry(100000, 1000000)
        for simblock in self.sim.run(init_entries=init_entries):
            print(simblock)
            self.assertEqual(len(simblock.txs), 1)
            self.assertEqual(simblock.sfr, 100001)
            self.assertEqual(len(self.sim.mempool.get_entries()), 999)
            break

    def test_B(self):
        print("Test B:")
        print("=======")
        init_entries = {
            str(i): SimEntry(100000, 250, depends=['0'])
            for i in range(1, 1000)
        }
        init_entries['0'] = SimEntry(999, 250)
        for simblock in self.sim.run(init_entries=init_entries):
            print(simblock)
            self.assertEqual(len(simblock.txs), 0)
            self.assertEqual(simblock.sfr, 1000)
            self.assertEqual(len(self.sim.mempool.get_entries()), 1000)
            break

    def test_C(self):
        print("Test C:")
        print("=======")
        init_entries = {
            str(i): SimEntry(100000, 250, depends=['0'])
            for i in range(1, 1000)
        }
        init_entries['0'] = SimEntry(1000, 900000)
        for simblock in self.sim.run(init_entries=init_entries):
            print(simblock)
            self.assertEqual(len(simblock.txs), 401)
            self.assertEqual(simblock.sfr, 1001)
            self.assertEqual(len(self.sim.mempool.get_entries()), 599)
            break

    def test_D(self):
        print("Test D:")
        print("=======")
        # Chain of txs
        init_entries = {
            str(i): SimEntry(10500-i, 2000, depends=[str(i+1)])
            for i in range(1000)
        }
        with self.assertRaises(ValueError):
            # Hanging dependency
            for simblock in self.sim.run(init_entries=init_entries):
                break

        init_entries['1000'] = SimEntry(1001, 2000)
        # init_mempool.append(SimEntry('1000', SimTx(1001, 2000)))
        for idx, simblock in enumerate(
                self.sim.run(init_entries=init_entries)):
            print(simblock)
            if idx == 0:
                self.assertEqual(simblock.sfr, 1002)
                self.assertEqual(max([tx.feerate for tx in simblock.txs]),
                                 9999)
                self.assertEqual(len(simblock.txs), 500)
                self.assertEqual(len(self.sim.mempool.get_entries()), 501)
            elif idx == 1:
                self.assertEqual(simblock.sfr, 10001)
                self.assertEqual(len(simblock.txs), 375)
                self.assertEqual(len(self.sim.mempool.get_entries()), 501-375)
                self.assertEqual(simblock.size, 750000)
            elif idx == 2:
                self.assertEqual(simblock.sfr, 20000)
                self.assertEqual(len(simblock.txs), 0)
                self.assertEqual(len(self.sim.mempool.get_entries()), 501-375)
                self.assertEqual(simblock.size, 0)
            elif idx == 3:
                self.assertEqual(simblock.sfr, 1000)
                self.assertEqual(len(simblock.txs), 501-375)
                self.assertEqual(len(self.sim.mempool.get_entries()), 0)
                self.assertEqual(simblock.size, 2000*(501-375))
            else:
                break
Exemplo n.º 7
0
 def setUp(self):
     self.simpools = SimPools(pools=ref_pools)
     self.tx_source = SimTxSource(ref_txsample, ref_txrate)
     self.sim = Simul(self.simpools, self.tx_source)
     self.init_entries = deepcopy(init_entries)
Exemplo n.º 8
0
class BasicSimTests(unittest.TestCase):

    def setUp(self):
        self.simpools = SimPools(pools=ref_pools)
        self.tx_source = SimTxSource(ref_txsample, ref_txrate)
        self.sim = Simul(self.simpools, self.tx_source)
        self.init_entries = deepcopy(init_entries)

    def test_basic(self):
        print("Basic Sim: the stable feerate is %d." % self.sim.stablefeerate)
        print("Height\tNumtxs\tSize\tSFR\tMPsize")
        for idx, simblock in enumerate(self.sim.run()):
            if idx >= 50:
                break
            mempoolsize = sum([entry.size for entry in
                               self.sim.mempool.get_entries().values()])
            print("%d\t%d\t%d\t%.0f\t%d" % (idx, len(simblock.txs),
                                            simblock.size, simblock.sfr,
                                            mempoolsize))

    def test_mempool(self):
        for entry in self.init_entries.values():
            entry.feerate = 100000
            entry.size = 9927
        print("With init mempool:")
        print("Height\tNumtxs\tSize\tSFR\tMPsize")
        for idx, simblock in enumerate(
                self.sim.run(init_entries=self.init_entries)):
            if idx >= 50:
                break
            mempoolsize = sum([entry.size for entry in
                               self.sim.mempool.get_entries().values()])
            self.assertEqual(simblock.size,
                             sum([tx.size for tx in simblock.txs]))
            print("%d\t%d\t%d\t%.0f\t%d" % (idx, len(simblock.txs),
                                            simblock.size, simblock.sfr,
                                            mempoolsize))

    def test_degenerate_pools(self):
        degen_pools = {'pool0': SimPool(1, 0, float("inf")),
                       'pool1': SimPool(1, 0, 0)}
        with self.assertRaises(ValueError):
            # No capacity.
            Simul(SimPools(degen_pools), self.tx_source)

        degen_pools.update({'pool2': SimPool(3, 1000000, 1000)})
        degen_pools['pool0'].maxblocksize = 1
        degen_pools['pool1'].maxblocksize = 1
        self.sim = Simul(SimPools(degen_pools), self.tx_source)

        print("Degenerate pools:")
        print("Height\tNumtxs\tSize\tSFR\tMPsize")
        for idx, simblock in enumerate(self.sim.run()):
            if idx >= 50:
                break
            mempoolsize = sum([entry.size for entry in
                               self.sim.mempool.get_entries().values()])
            print("%d\t%d\t%d\t%.0f\t%d" % (idx, len(simblock.txs),
                                            simblock.size, simblock.sfr,
                                            mempoolsize))

    def test_insane_feerates(self):
        # Test the restriction of feerates to unsigned int.
        for entry in self.init_entries.values():
            entry.feerate = 100000000000000000000000000000000
            entry.size = 9927
        print("Insane feerates:")
        print("Height\tNumtxs\tSize\tSFR\tMPsize")
        for idx, simblock in enumerate(
                self.sim.run(init_entries=self.init_entries)):
            if idx >= 50:
                break
            mempoolsize = sum([entry.size for entry in
                               self.sim.mempool.get_entries().values()])
            self.assertEqual(simblock.size,
                             sum([tx.size for tx in simblock.txs]))
            print("%d\t%d\t%d\t%.0f\t%d" % (idx, len(simblock.txs),
                                            simblock.size, simblock.sfr,
                                            mempoolsize))