more inlining

This commit is contained in:
AF 2022-07-28 22:46:16 +03:00
parent 280b035ba1
commit e745eb7c54
4 changed files with 41 additions and 29 deletions

View File

@ -1,4 +1,4 @@
from typing import Any, Generic, Iterable, TypeAlias, TypeVar from typing import Any, Generic, Iterable, Optional, TypeAlias, TypeVar
from rainbowadn.atomic import * from rainbowadn.atomic import *
from rainbowadn.collection.comparison import * from rainbowadn.collection.comparison import *
@ -9,6 +9,7 @@ from rainbowadn.core import *
from rainbowadn.flow.core import * from rainbowadn.flow.core import *
from rainbowadn.flow.primitive import * from rainbowadn.flow.primitive import *
from rainbowadn.flow.verification.core import * from rainbowadn.flow.verification.core import *
from rainbowadn.inlining import *
from rainbowadn.nullability import * from rainbowadn.nullability import *
from ._binaryflow import * from ._binaryflow import *
from ._flowtree import * from ._flowtree import *
@ -82,7 +83,7 @@ class FlowStandard(
return await self.protocolized.tree.reference.str(tab) return await self.protocolized.tree.reference.str(tab)
class FlowStandardFactory(RainbowFactory[FlowStandard[KeyT]], Generic[KeyT]): class FlowStandardFactory(Inlining[FlowStandard[KeyT]], Generic[KeyT]):
def __init__( def __init__(
self, self,
factory: RainbowFactory[BinaryTree[KeyMetadata[KeyT, Integer]]], factory: RainbowFactory[BinaryTree[KeyMetadata[KeyT, Integer]]],
@ -90,9 +91,14 @@ class FlowStandardFactory(RainbowFactory[FlowStandard[KeyT]], Generic[KeyT]):
): ):
assert isinstance(factory, RainbowFactory) assert isinstance(factory, RainbowFactory)
assert isinstance(comparator, Comparator) assert isinstance(comparator, Comparator)
self.factory = factory self.factory: Inlining[
NullableReference[BinaryTree[KeyMetadata[KeyT, Integer]]]
] = NullableReferenceFactory(factory).loose()
self.comparator = comparator self.comparator = comparator
def size(self) -> Optional[int]:
return self.factory.size()
@classmethod @classmethod
def of(cls, factory: RainbowFactory[KeyT], comparator: Comparator[KeyT]) -> 'FlowStandardFactory[KeyT]': def of(cls, factory: RainbowFactory[KeyT], comparator: Comparator[KeyT]) -> 'FlowStandardFactory[KeyT]':
assert isinstance(factory, RainbowFactory) assert isinstance(factory, RainbowFactory)
@ -128,6 +134,6 @@ class FlowStandardFactory(RainbowFactory[FlowStandard[KeyT]], Generic[KeyT]):
return FlowStandard( return FlowStandard(
ActiveBinaryTree( ActiveBinaryTree(
self.protocol(self.comparator), self.protocol(self.comparator),
NullableReferenceFactory(self.factory).from_bytes(source, resolver) self.factory.from_bytes(source, resolver)
).protocolized() ).protocolized()
) )

View File

@ -8,7 +8,6 @@ from rainbowadn.collection.keyvalue import *
from rainbowadn.core import * from rainbowadn.core import *
from rainbowadn.flow.core import * from rainbowadn.flow.core import *
from rainbowadn.flow.verification.core import * from rainbowadn.flow.verification.core import *
# from rainbowadn.inlining import *
from rainbowadn.v13 import * from rainbowadn.v13 import *
from ._flowstandard import * from ._flowstandard import *
from ._resolvemapper import * from ._resolvemapper import *
@ -19,14 +18,18 @@ __all__ = ('FlowCoinData', 'FlowCoin', 'FlowTransactionData', 'FlowTransaction',
class FlowCoinData(RecursiveMentionable, StaticMentionable): class FlowCoinData(RecursiveMentionable, StaticMentionable):
def __init__( def __init__(
self, self,
owner: HashPoint[Subject], owner: Subject,
value: HashPoint[Integer] value: HashPoint[Integer]
): ):
assert isinstance(owner, HashPoint) assert isinstance(owner, Subject)
assert isinstance(value, HashPoint) assert isinstance(value, HashPoint)
self.owner = owner self.owner = owner
self.value = value self.value = value
@classmethod
def size(cls) -> int:
return Subject.size() + HashPoint.HASH_LENGTH
async def int_value(self) -> int: async def int_value(self) -> int:
return (await self.value.resolve()).integer return (await self.value.resolve()).integer
@ -34,10 +37,10 @@ class FlowCoinData(RecursiveMentionable, StaticMentionable):
def of(cls, owner: Subject, value: int) -> 'FlowCoinData': def of(cls, owner: Subject, value: int) -> 'FlowCoinData':
assert isinstance(owner, Subject) assert isinstance(owner, Subject)
assert isinstance(value, int) assert isinstance(value, int)
return cls(HashPoint.of(owner), HashPoint.of(Integer(value))) return cls(owner, HashPoint.of(Integer(value)))
def points(self) -> Iterable[HashPoint]: def points(self) -> Iterable[HashPoint]:
return [self.owner, self.value] return [self.value]
def __bytes__(self): def __bytes__(self):
return bytes(self.owner) + bytes(self.value) return bytes(self.owner) + bytes(self.value)
@ -46,21 +49,16 @@ class FlowCoinData(RecursiveMentionable, StaticMentionable):
def from_bytes(cls, source: bytes, resolver: HashResolver) -> 'FlowCoinData': def from_bytes(cls, source: bytes, resolver: HashResolver) -> 'FlowCoinData':
assert isinstance(source, bytes) assert isinstance(source, bytes)
assert isinstance(resolver, HashResolver) assert isinstance(resolver, HashResolver)
separation = Subject.size()
return cls( return cls(
ResolverOrigin(Subject.factory(), source[:HashPoint.HASH_LENGTH], resolver).hash_point(), Subject.from_bytes(source[:separation], resolver),
ResolverOrigin(Integer.factory(), source[HashPoint.HASH_LENGTH:], resolver).hash_point(), ResolverOrigin(Integer.factory(), source[separation:], resolver).hash_point(),
) )
async def str(self, tab: int) -> str: async def str(self, tab: int) -> str:
assert isinstance(tab, int) assert isinstance(tab, int)
owner_str, value_str = await gather( return f'{self.owner}' \
hash_point_format(self.owner, tab), f'{tabulate(tab)}{await hash_point_format(self.value, tab)}'
hash_point_format(self.value, tab),
)
assert isinstance(owner_str, str)
assert isinstance(value_str, str)
return f'{owner_str}' \
f'{tabulate(tab)}{value_str}'
class FlowCoin(RecursiveMentionable, StaticMentionable): class FlowCoin(RecursiveMentionable, StaticMentionable):
@ -109,8 +107,8 @@ class FlowCoin(RecursiveMentionable, StaticMentionable):
async def int_value(self) -> int: async def int_value(self) -> int:
return await (await self.data_resolved()).int_value() return await (await self.data_resolved()).int_value()
async def owner_resolved(self) -> Subject: async def owner(self) -> Subject:
return await (await self.data_resolved()).owner.resolve() return (await self.data_resolved()).owner
class FlowTransactionData(RecursiveMentionable, StaticMentionable): class FlowTransactionData(RecursiveMentionable, StaticMentionable):
@ -151,7 +149,7 @@ class FlowTransactionData(RecursiveMentionable, StaticMentionable):
assert isinstance(signature, Signature) assert isinstance(signature, Signature)
assert_true( assert_true(
signature.verify( signature.verify(
await coin.owner_resolved(), await coin.owner(),
self.hash_point self.hash_point
) )
) )
@ -253,7 +251,7 @@ class CVMapper(Mapper[FlowCoin, bool]):
assert isinstance(element, FlowCoin) assert isinstance(element, FlowCoin)
assert_true( assert_true(
await self.signatures.contains( await self.signatures.contains(
HashPoint.of(await KeyValue.off((await element.data.resolve()).owner, HashPoint.of(Signature.empty()))), HashPoint.of(KeyValue.of(await element.owner(), Signature.empty())),
exact=False exact=False
) )
) )
@ -298,6 +296,10 @@ class FlowTransaction(RecursiveMentionable, StaticMentionable):
self.hash_point = HashPoint.of(self) self.hash_point = HashPoint.of(self)
assert isinstance(self.hash_point, HashPoint) assert isinstance(self.hash_point, HashPoint)
@classmethod
def size(cls) -> int:
return 3 * HashPoint.HASH_LENGTH
def points(self) -> Iterable[HashPoint]: def points(self) -> Iterable[HashPoint]:
return [*self.data.points(), *self.signatures.points()] return [*self.data.points(), *self.signatures.points()]

View File

@ -88,5 +88,5 @@ class NullableReferenceFactory(Inlining[NullableReference[Referenced]], Generic[
ResolverMetaOrigin(resolver).hash_point(self.factory, source) ResolverMetaOrigin(resolver).hash_point(self.factory, source)
) )
def loose(self) -> RainbowFactory[NullableReference[Referenced]]: def loose(self) -> Inlining[NullableReference[Referenced]]:
return self return self

View File

@ -48,7 +48,7 @@ async def _generate_transaction(
break break
coin = await minted.pop().resolve() coin = await minted.pop().resolve()
in_coins.append(coin) in_coins.append(coin)
keys.append(reverse[(await coin.owner_resolved()).verify_key]) keys.append(reverse[(await coin.owner()).verify_key])
transaction = await FlowTransaction.make( transaction = await FlowTransaction.make(
in_coins, in_coins,
[ [
@ -151,8 +151,12 @@ preset_long = dict(blocks=64, subjects=(4, 8), transactions=(8, 16), caching=Tru
preset_short = dict(blocks=16, subjects=(4, 8), transactions=(8, 16), caching=True, delay=.5) preset_short = dict(blocks=16, subjects=(4, 8), transactions=(8, 16), caching=True, delay=.5)
if __name__ == '__main__': if __name__ == '__main__':
asyncio.run( random.seed(659918)
trace( try:
preset_long asyncio.run(
trace(
preset_long
)
) )
) except KeyboardInterrupt:
print('interrupted')