89 lines
2.4 KiB
Python
89 lines
2.4 KiB
Python
import asyncio
|
|
import random
|
|
|
|
import matplotlib.pyplot as plt
|
|
import numpy as np
|
|
from nacl.signing import SigningKey
|
|
|
|
from rainbowadn.chain import *
|
|
from rainbowadn.core import *
|
|
from rainbowadn.nullability import *
|
|
from rainbowadn.testing.delayedresolver import DelayedResolver
|
|
from rainbowadn.testing.dictresolver import DictResolver
|
|
from rainbowadn.testing.instrumentation import Concurrency
|
|
from rainbowadn.v13 import *
|
|
|
|
plt.rcParams['figure.figsize'] = [12, 6]
|
|
|
|
plt.style.use("dark_background")
|
|
|
|
plt.subplots_adjust(left=0.05, right=0.99, top=0.99, bottom=0.1)
|
|
|
|
|
|
def get_dr() -> ExtendableResolver:
|
|
dr = DictResolver()
|
|
dr = DelayedResolver(dr, lambda: random.uniform(0.200, 0.500))
|
|
return dr
|
|
|
|
|
|
def plot(instrumentation: Concurrency):
|
|
plt.plot(*np.array(instrumentation.logs).transpose())
|
|
|
|
|
|
async def plot_every_minute(instrumentation: Concurrency):
|
|
while True:
|
|
await asyncio.sleep(60)
|
|
plot(instrumentation)
|
|
plt.show()
|
|
plt.clf()
|
|
plt.subplots_adjust(left=0.05, right=0.99, top=0.99, bottom=0.1)
|
|
|
|
|
|
async def main():
|
|
set_gather_asyncio()
|
|
bank: BankChain = BankChain.empty(ReductionChainMetaFactory().loose())
|
|
key_0 = SigningKey.generate()
|
|
transaction_0 = Transaction.make(
|
|
[],
|
|
[CoinData.of(Subject(key_0.verify_key), 100_000)],
|
|
[]
|
|
)
|
|
coin_0, coin_1 = await transaction_0.coins(MINT_CONST, NotNull(HashPoint.of(Subject(key_0.verify_key))))
|
|
bank = await bank.adds(
|
|
[
|
|
transaction_0,
|
|
Transaction.make(
|
|
[coin_1],
|
|
[CoinData.of(Subject(SigningKey.generate().verify_key), 10_000)],
|
|
[key_0]
|
|
),
|
|
]
|
|
)
|
|
for _ in range(16):
|
|
bank = await bank.adds(
|
|
[
|
|
Transaction.make(
|
|
[],
|
|
[CoinData.of(Subject(SigningKey.generate().verify_key), 0)] * 16,
|
|
[]
|
|
)
|
|
for _ in range(16)
|
|
]
|
|
)
|
|
print('built')
|
|
assert_true(await bank.verify())
|
|
bank = BankChain.from_reference(
|
|
ReductionChainMetaFactory(), await get_dr().migrate_resolved(bank.reference)
|
|
)
|
|
print('saved')
|
|
set_gather_asyncio()
|
|
with Concurrency(DelayedResolver, 'sleep') as sleeps:
|
|
# task = asyncio.create_task(plot_every_minute(sleeps))
|
|
assert_true(await bank.verify())
|
|
# task.cancel()
|
|
plot(sleeps)
|
|
plt.show()
|
|
|
|
|
|
asyncio.run(main())
|