Merge branch 'integration' of github.com:Chia-Network/chia-blockchain into integration

This commit is contained in:
Mariano Sorgente 2020-02-07 23:29:25 -05:00
commit 257e314077
No known key found for this signature in database
GPG Key ID: 0F866338C369278C
22 changed files with 110 additions and 132 deletions

View File

@ -1 +0,0 @@
from .bin_methods import bin_methods # noqa

View File

@ -1,19 +0,0 @@
import io
from typing import Any
class bin_methods:
"""
Create "from_bytes" and "__bytes__" methods in terms of "parse" and "stream" methods.
"""
@classmethod
def from_bytes(cls, blob: bytes) -> Any:
f = io.BytesIO(blob)
return cls.parse(f) # type: ignore # noqa
def __bytes__(self) -> bytes:
f = io.BytesIO()
self.stream(f) # type: ignore # noqa
return f.getvalue()

View File

@ -14,8 +14,8 @@ from src.consensus.pot_iterations import calculate_iterations
from src.consensus.weight_verifier import verify_weight
from src.store import FullNodeStore
from src.protocols import farmer_protocol, peer_protocol, timelord_protocol
from src.farming.farming_tools import best_solution_program
from src.mempool import Mempool
from src.util.bundle_tools import best_solution_program
from src.mempool_manager import MempoolManager
from src.server.outbound_message import Delivery, Message, NodeType, OutboundMessage
from src.server.server import ChiaServer
from src.types.body import Body
@ -23,7 +23,7 @@ from src.types.challenge import Challenge
from src.types.full_block import FullBlock
from src.types.hashable.Coin import Coin
from src.types.hashable.BLSSignature import BLSSignature
from src.types.hashable.Hash import std_hash
from src.util.Hash import std_hash
from src.types.hashable.SpendBundle import SpendBundle
from src.types.hashable.Program import Program
from src.types.header import Header, HeaderData
@ -46,14 +46,14 @@ class FullNode:
store: FullNodeStore,
blockchain: Blockchain,
config: Dict,
mempool: Mempool,
mempool_manager: MempoolManager,
unspent_store: UnspentStore,
name: str = None,
):
self.config: Dict = config
self.store: FullNodeStore = store
self.blockchain: Blockchain = blockchain
self.mempool: Mempool = mempool
self.mempool_manager: MempoolManager = mempool_manager
self._shut_down = False # Set to true to close all infinite loops
self.server: Optional[ChiaServer] = None
self.unspent_store: UnspentStore = unspent_store
@ -759,7 +759,7 @@ class FullNode:
assert target_tip is not None
# Grab best transactions from Mempool for given tip target
spend_bundle: Optional[SpendBundle] = await self.mempool.create_bundle_for_tip(
spend_bundle: Optional[SpendBundle] = await self.mempool_manager.create_bundle_for_tip(
target_tip
)
spend_bundle_fees = 0
@ -1043,15 +1043,15 @@ class FullNode:
@api_request
async def transaction(
self, tx: peer_protocol.Transaction
self, tx: peer_protocol.NewTransaction
) -> OutboundMessageGenerator:
"""
Receives a full transaction from peer.
If tx is added to mempool, send tx_id to others. (maybe_transaction)
"""
added, error = await self.mempool.add_spendbundle(tx.sb)
added, error = await self.mempool_manager.add_spendbundle(tx.transaction)
if added:
maybeTX = peer_protocol.TransactionId(tx.sb.name())
maybeTX = peer_protocol.TransactionId(tx.transaction.name())
yield OutboundMessage(
NodeType.FULL_NODE,
Message("maybe_transaction", maybeTX),
@ -1059,7 +1059,7 @@ class FullNode:
)
else:
self.log.warning(
f"Wasn't able to add transaction with id {tx.sb.name()}, error: {error}"
f"Wasn't able to add transaction with id {tx.transaction.name()}, error: {error}"
)
return
@ -1071,7 +1071,7 @@ class FullNode:
Receives a transaction_id, ignore if we've seen it already.
Request a full transaction if we haven't seen it previously_id:
"""
if self.mempool.seen(tx_id.transaction_id):
if self.mempool_manager.seen(tx_id.transaction_id):
self.log.info(f"tx_id({tx_id.transaction_id}) already seen")
return
else:
@ -1087,11 +1087,11 @@ class FullNode:
self, tx_id: peer_protocol.RequestTransaction
) -> OutboundMessageGenerator:
""" Peer has request a full transaction from us. """
spend_bundle = await self.mempool.get_spendbundle(tx_id.transaction_id)
spend_bundle = await self.mempool_manager.get_spendbundle(tx_id.transaction_id)
if spend_bundle is None:
return
transaction = peer_protocol.Transaction(spend_bundle)
transaction = peer_protocol.NewTransaction(spend_bundle)
yield OutboundMessage(
NodeType.FULL_NODE, Message("transaction", transaction), Delivery.RESPOND,
)
@ -1121,7 +1121,7 @@ class FullNode:
# Tries to add the block to the blockchain
added, replaced = await self.blockchain.receive_block(block.block, val, pos)
if added == ReceiveBlockResult.ADDED_TO_HEAD:
await self.mempool.new_tips(await self.blockchain.get_full_tips())
await self.mempool_manager.new_tips(await self.blockchain.get_full_tips())
if added == ReceiveBlockResult.ALREADY_HAVE_BLOCK:
return

View File

@ -2,14 +2,14 @@ import collections
from typing import Dict, Optional, Tuple, List, Set
from src.consensus.constants import constants as consensus_constants
from src.farming.farming_tools import best_solution_program
from src.util.bundle_tools import best_solution_program
from src.types.full_block import FullBlock
from src.types.hashable.Coin import Coin
from src.types.hashable.SpendBundle import SpendBundle
from src.types.hashable.CoinRecord import CoinRecord
from src.types.header import Header
from src.types.mempool_item import MempoolItem
from src.types.pool import Pool
from src.types.mempool import Mempool
from src.types.sized_bytes import bytes32
from src.unspent_store import UnspentStore
from src.util.ConsensusError import Err
@ -22,7 +22,7 @@ from src.util.ints import uint64, uint32
from sortedcontainers import SortedDict
class Mempool:
class MempoolManager:
def __init__(self, unspent_store: UnspentStore, override_constants: Dict = {}):
# Allow passing in custom overrides
self.constants: Dict = consensus_constants
@ -34,7 +34,7 @@ class Mempool:
# TODO limit the size of seen_bundle_hashes
self.seen_bundle_hashes: Set[bytes32] = set()
# Mempool for each tip
self.mempools: Dict[bytes32, Pool] = {}
self.mempools: Dict[bytes32, Mempool] = {}
# old_mempools will contain transactions that were removed in the last 10 blocks
self.old_mempools: SortedDict[uint32, Dict[bytes32, MempoolItem]] = SortedDict()
@ -55,10 +55,10 @@ class Mempool:
Returns aggregated spendbundle that can be used for creating new block
"""
if header.header_hash in self.mempools:
pool: Pool = self.mempools[header.header_hash]
mempool: Mempool = self.mempools[header.header_hash]
cost_sum = 0
spend_bundles: List[SpendBundle] = []
for dic in pool.sorted_spends.values():
for dic in mempool.sorted_spends.values():
for item in dic.values():
if item.cost + cost_sum <= 6000:
spend_bundles.append(item.spend_bundle)
@ -72,7 +72,7 @@ class Mempool:
return None
async def add_spendbundle(
self, new_spend: SpendBundle, to_pool: Pool = None
self, new_spend: SpendBundle, to_pool: Mempool = None
) -> Tuple[bool, Optional[Err]]:
"""
Tries to add spendbundle to either self.mempools or to_pool if it's specified.
@ -111,7 +111,7 @@ class Mempool:
# Spend might be valid for on pool but not for others
added_count = 0
errors: List[Err] = []
targets: List[Pool]
targets: List[Mempool]
if to_pool:
targets = [to_pool]
@ -207,7 +207,7 @@ class Mempool:
return False, errors[0]
async def check_removals(
self, additions: List[Coin], removals: List[Coin], mempool: Pool
self, additions: List[Coin], removals: List[Coin], mempool: Mempool
) -> Tuple[Optional[Err], Dict[bytes32, CoinRecord], List[Coin]]:
"""
This function checks for double spends, unknown spends and conflicting transactions in mempool.
@ -285,7 +285,7 @@ class Mempool:
Called when new tips are available, we try to recreate a mempool for each of the new tips.
For tip that we already have mempool we don't do anything.
"""
new_pools: Dict[bytes32, Pool] = {}
new_pools: Dict[bytes32, Mempool] = {}
for tip in new_tips:
if tip.header_hash in self.mempools:
# Nothing to change, we already have mempool for this head
@ -293,12 +293,12 @@ class Mempool:
continue
if tip.prev_header_hash in self.mempools:
# Update old mempool
new_pool: Pool = self.mempools[tip.prev_header_hash]
new_pool: Mempool = self.mempools[tip.prev_header_hash]
await self.update_pool(new_pool, tip)
else:
# Create mempool for new head
if len(self.old_mempools) > 0:
new_pool = Pool.create(tip.header, self.mempool_size)
new_pool = Mempool.create(tip.header, self.mempool_size)
# If old spends height is bigger than the new tip height, try adding spends to the pool
for height in self.old_mempools.keys():
@ -310,7 +310,7 @@ class Mempool:
await self.initialize_pool_from_current_pools(new_pool)
else:
new_pool = Pool.create(tip.header, self.mempool_size)
new_pool = Mempool.create(tip.header, self.mempool_size)
await self.initialize_pool_from_current_pools(new_pool)
await self.add_potential_spends_to_pool(new_pool)
@ -318,7 +318,7 @@ class Mempool:
self.mempools = new_pools
async def update_pool(self, pool: Pool, new_tip: FullBlock):
async def update_pool(self, pool: Mempool, new_tip: FullBlock):
"""
Called when new tip extends the tip we had mempool for.
This function removes removals and additions that happened in block from mempool.
@ -366,9 +366,9 @@ class Mempool:
lowest_h = keys[0]
dic_for_height.pop(lowest_h)
async def initialize_pool_from_current_pools(self, pool: Pool):
async def initialize_pool_from_current_pools(self, pool: Mempool):
tried_already: Dict[bytes32, bytes32] = {}
current_pool: Pool
current_pool: Mempool
for current_pool in self.mempools.values():
for item in current_pool.spends.values():
# Don't try to add same mempool item twice
@ -378,11 +378,11 @@ class Mempool:
await self.add_spendbundle(item.spend_bundle, pool)
async def add_old_spends_to_pool(
self, pool: Pool, old_spends: Dict[bytes32, MempoolItem]
self, pool: Mempool, old_spends: Dict[bytes32, MempoolItem]
):
for old in old_spends.values():
await self.add_spendbundle(old.spend_bundle, pool)
async def add_potential_spends_to_pool(self, pool: Pool):
async def add_potential_spends_to_pool(self, pool: Mempool):
for tx in self.potential_txs.values():
await self.add_spendbundle(tx, pool)

View File

@ -2,11 +2,11 @@ from dataclasses import dataclass
from typing import List
from src.types.full_block import FullBlock
from src.types.hashable.SpendBundle import SpendBundle
from src.types.header_block import HeaderBlock
from src.types.peer_info import PeerInfo
from src.types.proof_of_time import ProofOfTime
from src.types.sized_bytes import bytes32
from src.types.transaction import Transaction
from src.util.cbor_message import cbor_message
from src.util.ints import uint32
@ -31,7 +31,7 @@ class RequestTransaction:
@dataclass(frozen=True)
@cbor_message
class NewTransaction:
transaction: Transaction
transaction: SpendBundle
@dataclass(frozen=True)

View File

@ -2,9 +2,9 @@ from dataclasses import dataclass
from typing import List, Tuple
from src.types.body import Body
from src.types.hashable.SpendBundle import SpendBundle
from src.types.header_block import HeaderBlock
from src.types.sized_bytes import bytes32
from src.types.transaction import Transaction
from src.util.cbor_message import cbor_message
from src.util.ints import uint32
@ -17,7 +17,7 @@ Protocol between wallet (SPV node) and full node.
@dataclass(frozen=True)
@cbor_message
class SendTransaction:
transaction: Transaction
transaction: SpendBundle
@dataclass(frozen=True)

View File

@ -16,7 +16,7 @@ from src.consensus.constants import constants
from src.store import FullNodeStore
from src.full_node import FullNode
from src.rpc.rpc_server import start_rpc_server
from src.mempool import Mempool
from src.mempool_manager import MempoolManager
from src.server.server import ChiaServer
from src.server.connection import NodeType
from src.types.full_block import FullBlock
@ -47,10 +47,10 @@ async def main():
log.info("Initializing blockchain from disk")
blockchain = await Blockchain.create(unspent_store, store)
mempool = Mempool(unspent_store)
mempool_manager = MempoolManager(unspent_store)
# await mempool.initialize() TODO uncomment once it's implemented
full_node = FullNode(store, blockchain, config, mempool, unspent_store)
full_node = FullNode(store, blockchain, config, mempool_manager, unspent_store)
# Starts the full node server (which full nodes can connect to)
if config["enable_upnp"]:

View File

@ -12,7 +12,7 @@ ZERO96 = bytes96([0] * 96)
class BLSPublicKey(bytes48):
pass
# TODO Stop using this after BLSLibrary is
@dataclass(frozen=True)
@streamable
class BLSSignature(Streamable):

View File

@ -1,16 +1,16 @@
import io
from typing import Any
from clvm import to_sexp_f
from clvm.serialize import sexp_from_stream, sexp_to_stream
from clvm.subclass_sexp import BaseSExp
from src.types.sized_bytes import bytes32
from .Hash import std_hash
from ...atoms import bin_methods
from src.util.Hash import std_hash
SExp = to_sexp_f(1).__class__
class Program(SExp, bin_methods): # type: ignore # noqa
class Program(SExp): # type: ignore # noqa
"""
A thin wrapper around s-expression data intended to be invoked with "eval".
"""
@ -29,6 +29,16 @@ class Program(SExp, bin_methods): # type: ignore # noqa
def stream(self, f):
sexp_to_stream(self, f)
@classmethod
def from_bytes(cls, blob: bytes) -> Any:
f = io.BytesIO(blob)
return cls.parse(f) # type: ignore # noqa
def __bytes__(self) -> bytes:
f = io.BytesIO()
self.stream(f) # type: ignore # noqa
return f.getvalue()
def __str__(self):
return bytes(self).hex()

View File

@ -9,7 +9,7 @@ from src.util.ints import uint32, uint64
from src.types.header import Header
class Pool:
class Mempool:
header: Header
spends: Dict[bytes32, MempoolItem]
sorted_spends: SortedDict
@ -21,7 +21,7 @@ class Pool:
# if new min fee is added
@staticmethod
def create(tip: Header, size: uint32):
self = Pool()
self = Mempool()
self.header = tip
self.spends = {}
self.additions = {}

View File

@ -1,10 +0,0 @@
from dataclasses import dataclass
from src.types.hashable.SpendBundle import SpendBundle
from src.util.streamable import Streamable, streamable
@dataclass(frozen=True)
@streamable
class Transaction(Streamable):
sb: SpendBundle

View File

@ -4,7 +4,7 @@ from src.types.hashable.Program import Program
from src.types.hashable.SpendBundle import SpendBundle
def best_solution_program(bundle: SpendBundle):
def best_solution_program(bundle: SpendBundle) -> Program:
"""
This could potentially do a lot of clever and complicated compression
optimizations in conjunction with choosing the set of SpendBundles to include.

View File

@ -9,7 +9,7 @@ from src.types.hashable.Program import Program
from src.types.hashable.SpendBundle import SpendBundle
from src.types.hashable.CoinRecord import CoinRecord
from src.types.name_puzzle_condition import NPC
from src.types.pool import Pool
from src.types.mempool import Mempool
from src.types.sized_bytes import bytes32
from src.util.Conditions import ConditionOpcode
from src.util.ConsensusError import Err
@ -17,11 +17,11 @@ from src.util.consensus import conditions_dict_for_solution
import time
from src.util.ints import uint64
from src.util.run_program import run_program
from clvm import run_program
def mempool_assert_coin_consumed(
condition: ConditionVarPair, spend_bundle: SpendBundle, mempool: Pool
condition: ConditionVarPair, spend_bundle: SpendBundle, mempool: Mempool
) -> Optional[Err]:
"""
Checks coin consumed conditions
@ -46,7 +46,7 @@ def mempool_assert_my_coin_id(
def mempool_assert_block_index_exceeds(
condition: ConditionVarPair, unspent: CoinRecord, mempool: Pool
condition: ConditionVarPair, unspent: CoinRecord, mempool: Mempool
) -> Optional[Err]:
"""
Checks if the next block index exceeds the block index from the condition
@ -62,7 +62,7 @@ def mempool_assert_block_index_exceeds(
def mempool_assert_block_age_exceeds(
condition: ConditionVarPair, unspent: CoinRecord, mempool: Pool
condition: ConditionVarPair, unspent: CoinRecord, mempool: Mempool
) -> Optional[Err]:
"""
Checks if the coin age exceeds the age from the condition
@ -139,7 +139,7 @@ def mempool_check_conditions_dict(
unspent: CoinRecord,
spend_bundle: SpendBundle,
conditions_dict: Dict[ConditionOpcode, List[ConditionVarPair]],
mempool: Pool,
mempool: Mempool,
) -> Optional[Err]:
"""
Check all conditions against current state.

View File

@ -1,3 +0,0 @@
import clvm
run_program = clvm.run_program

View File

@ -20,7 +20,7 @@ from src.types.hashable.Program import Program
# contract:
# generate puzzle: (() . puzzle_parameters)
# generate solution: (1 . (puzzle_parameters . solution_parameters))
from src.util.run_program import run_program
from clvm import run_program
def make_contract():

View File

@ -18,7 +18,7 @@ import hashlib
from clvm_tools import binutils
from src.types.hashable.Program import Program
from src.util.run_program import run_program
from clvm import run_program
from .load_clvm import load_clvm

View File

@ -5,7 +5,7 @@ from pathlib import Path
import pytest
from src.blockchain import Blockchain, ReceiveBlockResult
from src.mempool import Mempool
from src.mempool_manager import MempoolManager
from src.store import FullNodeStore
from src.full_node import FullNode
from src.server.connection import NodeType
@ -54,7 +54,7 @@ class TestRpc:
await store._clear_database()
blocks = bt.get_consecutive_blocks(test_constants, 10, [], 10)
unspent_store = await UnspentStore.create("blockchain_test.db")
mempool = Mempool(unspent_store)
mempool_manager = MempoolManager(unspent_store)
b: Blockchain = await Blockchain.create(unspent_store, store, test_constants)
await store.add_block(blocks[0])
@ -65,7 +65,7 @@ class TestRpc:
await store.add_block(blocks[i])
config = load_config("config.yaml", "full_node")
full_node_1 = FullNode(store, b, config, mempool, unspent_store)
full_node_1 = FullNode(store, b, config, mempool_manager, unspent_store)
server_1 = ChiaServer(test_node_1_port, full_node_1, NodeType.FULL_NODE)
_ = await server_1.start_server("127.0.0.1", None)
full_node_1._set_server(server_1)
@ -75,7 +75,8 @@ class TestRpc:
server_1.close_all()
unspent_store2 = await UnspentStore.create("blockchain_test_2.db")
full_node_2 = FullNode(store, b, config, mempool, unspent_store2)
mempool_manager2 = MempoolManager(unspent_store2)
full_node_2 = FullNode(store, b, config, mempool_manager2, unspent_store2)
server_2 = ChiaServer(test_node_2_port, full_node_2, NodeType.FULL_NODE)
full_node_2._set_server(server_2)
@ -101,7 +102,6 @@ class TestRpc:
header = await client.get_header(state["lca"].header_hash)
assert header == blocks[8].header
# TODO implement get pool balances
coins = await client.get_unspent_coins(
blocks[-1].body.coinbase.puzzle_hash, blocks[-1].header_hash
)

View File

@ -3,7 +3,7 @@ from pathlib import Path
import asyncio
from src.blockchain import Blockchain
from src.mempool import Mempool
from src.mempool_manager import MempoolManager
from src.store import FullNodeStore
from src.full_node import FullNode
from src.server.connection import NodeType
@ -51,7 +51,8 @@ async def setup_full_node(db_name, port, introducer_port=None, dic={}):
await store_1._clear_database()
unspent_store_1 = await UnspentStore.create(Path(db_name))
await unspent_store_1._clear_database()
mempool_1 = Mempool(unspent_store_1, dic)
mempool_1 = MempoolManager(unspent_store_1, dic)
b_1: Blockchain = await Blockchain.create(
unspent_store_1, store_1, test_constants_copy
)

View File

@ -2,7 +2,7 @@ import asyncio
from typing import Optional
import pytest
from src.farming.farming_tools import best_solution_program
from src.util.bundle_tools import best_solution_program
from src.server.outbound_message import OutboundMessage
from src.protocols import peer_protocol
from src.types.full_block import FullBlock
@ -53,17 +53,17 @@ class TestBlockchainTransactions:
)
assert spend_bundle is not None
tx: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle)
tx: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle)
async for _ in full_node_1.transaction(tx):
outbound: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
assert outbound.message.function == "maybe_transaction"
sb = await full_node_1.mempool.get_spendbundle(spend_bundle.name())
sb = await full_node_1.mempool_manager.get_spendbundle(spend_bundle.name())
assert sb is spend_bundle
last_block = blocks[10]
next_spendbundle = await full_node_1.mempool.create_bundle_for_tip(
next_spendbundle = await full_node_1.mempool_manager.create_bundle_for_tip(
last_block.header
)
assert next_spendbundle is not None

View File

@ -51,13 +51,13 @@ class TestMempool:
1000, receiver_puzzlehash, block.body.coinbase
)
assert spend_bundle is not None
tx: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle)
tx: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle)
async for _ in full_node_1.transaction(tx):
outbound: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
assert outbound.message.function == "maybe_transaction"
sb = await full_node_1.mempool.get_spendbundle(spend_bundle.name())
sb = await full_node_1.mempool_manager.get_spendbundle(spend_bundle.name())
assert sb is spend_bundle
@pytest.mark.asyncio
@ -81,14 +81,14 @@ class TestMempool:
1000, receiver_puzzlehash, block.body.coinbase
)
assert spend_bundle is not None
tx: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle)
tx: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle)
async for _ in full_node_1.transaction(tx):
outbound: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
assert outbound.message.function != "maybe_transaction"
sb = await full_node_1.mempool.get_spendbundle(spend_bundle.name())
sb = await full_node_1.mempool_manager.get_spendbundle(spend_bundle.name())
assert sb is None
blocks = bt.get_consecutive_blocks(
@ -104,7 +104,7 @@ class TestMempool:
# Maybe transaction means that it's accepted in mempool
assert outbound_2.message.function == "maybe_transaction"
print(blocks[1].body.coinbase.name())
sb = await full_node_1.mempool.get_spendbundle(spend_bundle.name())
sb = await full_node_1.mempool_manager.get_spendbundle(spend_bundle.name())
assert sb is spend_bundle
@pytest.mark.asyncio
@ -129,7 +129,7 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle1)
tx1: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle1)
async for _ in full_node_1.transaction(tx1):
outbound: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
@ -140,12 +140,12 @@ class TestMempool:
1000, other_receiver.get_new_puzzlehash(), block.body.coinbase
)
assert spend_bundle2 is not None
tx2: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle2)
tx2: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle2)
async for _ in full_node_1.transaction(tx2):
pass
sb1 = await full_node_1.mempool.get_spendbundle(spend_bundle1.name())
sb2 = await full_node_1.mempool.get_spendbundle(spend_bundle2.name())
sb1 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
sb2 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle2.name())
assert sb1 == spend_bundle1
assert sb2 is None
@ -171,7 +171,7 @@ class TestMempool:
1000, receiver_puzzlehash, block.body.coinbase
)
assert spend_bundle1 is not None
tx1: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle1)
tx1: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle1)
async for _ in full_node_1.transaction(tx1):
outbound: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
@ -182,12 +182,12 @@ class TestMempool:
)
assert spend_bundle2 is not None
tx2: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle2)
tx2: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle2)
async for _ in full_node_1.transaction(tx2):
pass
sb1 = await full_node_1.mempool.get_spendbundle(spend_bundle1.name())
sb2 = await full_node_1.mempool.get_spendbundle(spend_bundle2.name())
sb1 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
sb2 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle2.name())
assert sb1 is None
assert sb2 == spend_bundle2
@ -221,13 +221,13 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle1)
tx1: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle1)
async for _ in full_node_1.transaction(tx1):
outbound: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
assert outbound.message.function != "maybe_transaction"
sb1 = await full_node_1.mempool.get_spendbundle(spend_bundle1.name())
sb1 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
assert sb1 is None
@ -260,13 +260,13 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle1)
tx1: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle1)
async for _ in full_node_1.transaction(tx1):
outbound: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
assert outbound.message.function == "maybe_transaction"
sb1 = await full_node_1.mempool.get_spendbundle(spend_bundle1.name())
sb1 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
assert sb1 is spend_bundle1
@ -297,13 +297,13 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle1)
tx1: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle1)
async for _ in full_node_1.transaction(tx1):
outbound: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
assert outbound.message.function != "maybe_transaction"
sb1 = await full_node_1.mempool.get_spendbundle(spend_bundle1.name())
sb1 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
assert sb1 is None
@ -336,13 +336,13 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle1)
tx1: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle1)
async for _ in full_node_1.transaction(tx1):
outbound: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
assert outbound.message.function == "maybe_transaction"
sb1 = await full_node_1.mempool.get_spendbundle(spend_bundle1.name())
sb1 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
assert sb1 is spend_bundle1
@ -375,13 +375,13 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle1)
tx1: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle1)
async for _ in full_node_1.transaction(tx1):
outbound: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
assert outbound.message.function == "maybe_transaction"
sb1 = await full_node_1.mempool.get_spendbundle(spend_bundle1.name())
sb1 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
assert sb1 is spend_bundle1
@ -414,13 +414,13 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle1)
tx1: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle1)
async for _ in full_node_1.transaction(tx1):
outbound: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
assert outbound.message.function != "maybe_transaction"
sb1 = await full_node_1.mempool.get_spendbundle(spend_bundle1.name())
sb1 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
assert sb1 is None
@ -455,13 +455,13 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle1)
tx1: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle1)
async for _ in full_node_1.transaction(tx1):
outbound: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
assert outbound.message.function == "maybe_transaction"
sb1 = await full_node_1.mempool.get_spendbundle(spend_bundle1.name())
sb1 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
assert sb1 is spend_bundle1
@ -499,23 +499,23 @@ class TestMempool:
)
assert spend_bundle1 is not None
tx1: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle1)
tx1: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle1)
async for _ in full_node_1.transaction(tx1):
outbound: OutboundMessage = _
assert outbound.message.function != "maybe_transaction"
sb1 = await full_node_1.mempool.get_spendbundle(spend_bundle1.name())
sb1 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
assert sb1 is None
# Sleep so that 3 sec passes
await asyncio.sleep(3)
tx2: peer_protocol.Transaction = peer_protocol.Transaction(spend_bundle1)
tx2: peer_protocol.NewTransaction = peer_protocol.NewTransaction(spend_bundle1)
async for _ in full_node_1.transaction(tx2):
outbound_2: OutboundMessage = _
# Maybe transaction means that it's accepted in mempool
assert outbound_2.message.function == "maybe_transaction"
sb1 = await full_node_1.mempool.get_spendbundle(spend_bundle1.name())
sb1 = await full_node_1.mempool_manager.get_spendbundle(spend_bundle1.name())
assert sb1 is spend_bundle1

View File

@ -1,4 +1,4 @@
from src.types.hashable.Hash import std_hash
from src.util.Hash import std_hash
from src.util.Conditions import conditions_by_opcode
from src.util.consensus import (
conditions_for_solution,