mirror of
https://github.com/planetmint/planetmint.git
synced 2025-03-30 15:08:31 +00:00
first structure
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
77ab922eed
commit
4a517f24bd
@ -51,7 +51,7 @@ def test_load_validation_plugin_raises_with_invalid_subclass(monkeypatch):
|
||||
|
||||
monkeypatch.setattr(
|
||||
config_utils, "iter_entry_points", lambda *args: [type("entry_point", (object,), {"load": lambda: object})]
|
||||
)
|
||||
)my_config
|
||||
|
||||
with pytest.raises(TypeError):
|
||||
# Since the function is decorated with `lru_cache`, we need to
|
||||
@ -317,8 +317,8 @@ def test_write_config():
|
||||
def test_database_envs(env_name, env_value, config_key, monkeypatch):
|
||||
monkeypatch.setattr("os.environ", {env_name: env_value})
|
||||
planetmint.config_utils.autoconfigure()
|
||||
|
||||
Config
|
||||
expected_config = Config().get()
|
||||
expected_config["database"][config_key] = env_value
|
||||
|
||||
assert planetmint.config == expected_config
|
||||
assert planetmint.config.Config().get() == expected_config
|
@ -27,7 +27,7 @@ Base class for validation methods (verification of votes, blocks, and transactio
|
||||
|
||||
Entry point for the Planetmint process, after initialization. All subprocesses are started here: processes to handle new blocks, votes, etc.
|
||||
|
||||
### [`config_utils.py`](./config_utils.py)
|
||||
### [`config_utils.py`](config_utils.py)
|
||||
|
||||
Methods for managing the configuration, including loading configuration files, automatically generating the configuration, and keeping the configuration consistent across Planetmint instances.
|
||||
|
||||
|
@ -8,7 +8,7 @@ from transactions.types.elections.validator_election import ValidatorElection #
|
||||
from transactions.types.elections.vote import Vote # noqa
|
||||
from transactions.types.elections.chain_migration_election import ChainMigrationElection
|
||||
from planetmint.lib import Planetmint
|
||||
from planetmint.core import App
|
||||
from planetmint.abci.core import App
|
||||
|
||||
|
||||
Transaction.register_type(Transaction.CREATE, Transaction)
|
||||
|
0
planetmint/abci/__init__.py
Normal file
0
planetmint/abci/__init__.py
Normal file
@ -22,9 +22,9 @@ from tendermint.abci.types_pb2 import (
|
||||
ResponseCommit,
|
||||
)
|
||||
from planetmint import Planetmint
|
||||
from planetmint.tendermint_utils import decode_transaction, calculate_hash, decode_validator
|
||||
from planetmint.abci.tendermint_utils import decode_transaction, calculate_hash, decode_validator
|
||||
from planetmint.lib import Block
|
||||
from planetmint.events import EventTypes, Event
|
||||
from planetmint.ipc.events import EventTypes, Event
|
||||
|
||||
|
||||
CodeTypeError = 1
|
@ -8,7 +8,7 @@ import multiprocessing
|
||||
from collections import defaultdict
|
||||
from planetmint import App
|
||||
from planetmint.lib import Planetmint
|
||||
from planetmint.tendermint_utils import decode_transaction
|
||||
from planetmint.abci.tendermint_utils import decode_transaction
|
||||
from abci.application import OkCode
|
||||
from tendermint.abci.types_pb2 import (
|
||||
ResponseCheckTx,
|
@ -14,7 +14,7 @@ import json
|
||||
import sys
|
||||
import planetmint
|
||||
|
||||
from planetmint.core import rollback
|
||||
from planetmint.abci.core import rollback
|
||||
from planetmint.utils import load_node_key
|
||||
from transactions.common.transaction_mode_types import BROADCAST_TX_COMMIT
|
||||
from transactions.common.exceptions import DatabaseDoesNotExist, ValidationError
|
||||
@ -27,7 +27,7 @@ from planetmint.backend import schema
|
||||
from planetmint.commands import utils
|
||||
from planetmint.commands.utils import configure_planetmint, input_on_stderr
|
||||
from planetmint.log import setup_logging
|
||||
from planetmint.tendermint_utils import public_key_from_base64
|
||||
from planetmint.abci.tendermint_utils import public_key_from_base64
|
||||
from planetmint.commands.election_types import elections
|
||||
from planetmint.version import __tm_supported_versions__
|
||||
from planetmint.config import Config
|
||||
|
@ -25,8 +25,8 @@ import collections.abc
|
||||
from functools import lru_cache
|
||||
from pkg_resources import iter_entry_points, ResolutionError
|
||||
from planetmint.config import Config
|
||||
from transactions.common import exceptions
|
||||
from planetmint.validation import BaseValidationRules
|
||||
from transactions.common import exceptions
|
||||
|
||||
# TODO: move this to a proper configuration file for logging
|
||||
logging.getLogger("requests").setLevel(logging.WARNING)
|
||||
|
0
planetmint/ipc/__init__.py
Normal file
0
planetmint/ipc/__init__.py
Normal file
40
planetmint/ipc/events.py
Normal file
40
planetmint/ipc/events.py
Normal file
@ -0,0 +1,40 @@
|
||||
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||
# Planetmint and IPDB software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
POISON_PILL = "POISON_PILL"
|
||||
|
||||
|
||||
class EventTypes:
|
||||
"""Container class that holds all the possible
|
||||
events Planetmint manages.
|
||||
"""
|
||||
|
||||
# If you add a new Event Type, make sure to add it
|
||||
# to the docs in docs/server/source/event-plugin-api.rst
|
||||
ALL = ~0
|
||||
BLOCK_VALID = 1
|
||||
BLOCK_INVALID = 2
|
||||
# NEW_EVENT = 4
|
||||
# NEW_EVENT = 8
|
||||
# NEW_EVENT = 16...
|
||||
|
||||
|
||||
class Event:
|
||||
"""An Event."""
|
||||
|
||||
def __init__(self, event_type, event_data):
|
||||
"""Creates a new event.
|
||||
|
||||
Args:
|
||||
event_type (int): the type of the event, see
|
||||
:class:`~planetmint.events.EventTypes`
|
||||
event_data (obj): the data of the event.
|
||||
"""
|
||||
|
||||
self.type = event_type
|
||||
self.data = event_data
|
||||
|
||||
|
||||
|
@ -1,46 +1,8 @@
|
||||
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||
# Planetmint and IPDB software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
from queue import Empty
|
||||
from collections import defaultdict
|
||||
import multiprocessing
|
||||
|
||||
|
||||
POISON_PILL = "POISON_PILL"
|
||||
|
||||
|
||||
class EventTypes:
|
||||
"""Container class that holds all the possible
|
||||
events Planetmint manages.
|
||||
"""
|
||||
|
||||
# If you add a new Event Type, make sure to add it
|
||||
# to the docs in docs/server/source/event-plugin-api.rst
|
||||
ALL = ~0
|
||||
BLOCK_VALID = 1
|
||||
BLOCK_INVALID = 2
|
||||
# NEW_EVENT = 4
|
||||
# NEW_EVENT = 8
|
||||
# NEW_EVENT = 16...
|
||||
|
||||
|
||||
class Event:
|
||||
"""An Event."""
|
||||
|
||||
def __init__(self, event_type, event_data):
|
||||
"""Creates a new event.
|
||||
|
||||
Args:
|
||||
event_type (int): the type of the event, see
|
||||
:class:`~planetmint.events.EventTypes`
|
||||
event_data (obj): the data of the event.
|
||||
"""
|
||||
|
||||
self.type = event_type
|
||||
self.data = event_data
|
||||
|
||||
from planetmint.ipc.events import EventTypes, POISON_PILL
|
||||
|
||||
class Exchange:
|
||||
"""Dispatch events to subscribers."""
|
||||
@ -106,4 +68,4 @@ class Exchange:
|
||||
if event == POISON_PILL:
|
||||
return
|
||||
else:
|
||||
self.dispatch(event)
|
||||
self.dispatch(event)
|
@ -50,8 +50,8 @@ from planetmint.backend.tarantool.const import (
|
||||
TARANT_TABLE_TRANSACTION,
|
||||
)
|
||||
from planetmint.config import Config
|
||||
from planetmint import backend, config_utils, fastquery
|
||||
from planetmint.tendermint_utils import (
|
||||
from planetmint import backend, fastquery, config_utils
|
||||
from planetmint.abci.tendermint_utils import (
|
||||
encode_transaction,
|
||||
merkleroot,
|
||||
key_from_base64,
|
||||
|
@ -8,10 +8,11 @@ import setproctitle
|
||||
|
||||
from planetmint.config import Config
|
||||
from planetmint.lib import Planetmint
|
||||
from planetmint.core import App
|
||||
from planetmint.parallel_validation import ParallelValidationApp
|
||||
from planetmint.abci.core import App
|
||||
from planetmint.abci.parallel_validation import ParallelValidationApp
|
||||
from planetmint.web import server, websocket_server
|
||||
from planetmint.events import Exchange, EventTypes
|
||||
from planetmint.ipc.events import EventTypes
|
||||
from planetmint.ipc.exchange import Exchange
|
||||
from planetmint.utils import Process
|
||||
from planetmint.version import __version__
|
||||
|
||||
|
@ -12,7 +12,7 @@ import setproctitle
|
||||
|
||||
from packaging import version
|
||||
from planetmint.version import __tm_supported_versions__
|
||||
from planetmint.tendermint_utils import key_from_base64
|
||||
from planetmint.abci.tendermint_utils import key_from_base64
|
||||
from planetmint.backend.models.output import ConditionDetails
|
||||
from transactions.common.crypto import key_pair_from_ed25519_key
|
||||
|
||||
|
@ -6,8 +6,8 @@
|
||||
|
||||
import json
|
||||
|
||||
from planetmint.events import EventTypes
|
||||
from planetmint.events import POISON_PILL
|
||||
from planetmint.ipc.events import EventTypes
|
||||
from planetmint.ipc.events import POISON_PILL
|
||||
|
||||
|
||||
class Dispatcher:
|
||||
|
@ -24,7 +24,7 @@ from planetmint.backend.connection import Connection
|
||||
from planetmint.backend.tarantool.connection import TarantoolDBConnection
|
||||
from transactions.common import crypto
|
||||
from transactions.common.transaction_mode_types import BROADCAST_TX_COMMIT
|
||||
from planetmint.tendermint_utils import key_from_base64
|
||||
from planetmint.abci.tendermint_utils import key_from_base64
|
||||
from planetmint.backend import schema, query
|
||||
from transactions.common.crypto import key_pair_from_ed25519_key, public_key_from_ed25519_key
|
||||
from planetmint.lib import Block
|
||||
@ -427,7 +427,7 @@ def abci_server():
|
||||
from abci.server import ABCIServer
|
||||
|
||||
# from tendermint.abci import types_pb2 as types_v0_34_11
|
||||
from planetmint.core import App
|
||||
from planetmint.abci.core import App
|
||||
from planetmint.utils import Process
|
||||
|
||||
app = ABCIServer(app=App())
|
||||
|
@ -17,12 +17,11 @@ from transactions.types.assets.create import Create
|
||||
from transactions.types.assets.transfer import Transfer
|
||||
from planetmint import App
|
||||
from planetmint.backend import query
|
||||
from planetmint.core import OkCode, CodeTypeError, rollback
|
||||
from planetmint.abci.core import OkCode, CodeTypeError, rollback
|
||||
from planetmint.lib import Block
|
||||
from planetmint.tendermint_utils import new_validator_set
|
||||
from planetmint.tendermint_utils import public_key_to_base64
|
||||
from planetmint.abci.tendermint_utils import new_validator_set
|
||||
from planetmint.abci.tendermint_utils import public_key_to_base64
|
||||
from planetmint.version import __tm_supported_versions__
|
||||
from planetmint.backend.tarantool.const import TARANT_TABLE_GOVERNANCE
|
||||
from tests.utils import generate_election, generate_validators
|
||||
|
||||
pytestmark = pytest.mark.bdb
|
||||
|
@ -20,7 +20,7 @@ from io import BytesIO
|
||||
@pytest.mark.bdb
|
||||
def test_app(b, eventqueue_fixture, init_chain_request):
|
||||
from planetmint import App
|
||||
from planetmint.tendermint_utils import calculate_hash
|
||||
from planetmint.abci.tendermint_utils import calculate_hash
|
||||
from transactions.common.crypto import generate_key_pair
|
||||
|
||||
app = App(b, eventqueue_fixture)
|
||||
|
@ -10,9 +10,7 @@ import pytest
|
||||
from unittest.mock import patch
|
||||
from transactions.types.assets.create import Create
|
||||
from transactions.types.assets.transfer import Transfer
|
||||
from operator import index
|
||||
from hashlib import sha3_256
|
||||
from pymongo import MongoClient
|
||||
from planetmint import backend
|
||||
from transactions.common.transaction_mode_types import (
|
||||
BROADCAST_TX_COMMIT,
|
||||
@ -101,7 +99,7 @@ def test_validation_error(b):
|
||||
@patch("requests.post")
|
||||
def test_write_and_post_transaction(mock_post, b):
|
||||
from transactions.common.crypto import generate_key_pair
|
||||
from planetmint.tendermint_utils import encode_transaction
|
||||
from planetmint.abci.tendermint_utils import encode_transaction
|
||||
|
||||
alice = generate_key_pair()
|
||||
tx = (
|
||||
|
@ -11,7 +11,7 @@ from hashlib import sha3_256
|
||||
|
||||
|
||||
def test_encode_decode_transaction(b):
|
||||
from planetmint.tendermint_utils import encode_transaction, decode_transaction
|
||||
from planetmint.abci.tendermint_utils import encode_transaction, decode_transaction
|
||||
|
||||
asset = {"value": "key"}
|
||||
|
||||
@ -25,7 +25,7 @@ def test_encode_decode_transaction(b):
|
||||
|
||||
|
||||
def test_calculate_hash_no_key(b):
|
||||
from planetmint.tendermint_utils import calculate_hash
|
||||
from planetmint.abci.tendermint_utils import calculate_hash
|
||||
|
||||
# pass an empty list
|
||||
assert calculate_hash([]) == ""
|
||||
@ -33,7 +33,7 @@ def test_calculate_hash_no_key(b):
|
||||
|
||||
# TODO test for the case of an empty list of hashes, and possibly other cases.
|
||||
def test_merkleroot():
|
||||
from planetmint.tendermint_utils import merkleroot
|
||||
from planetmint.abci.tendermint_utils import merkleroot
|
||||
|
||||
hashes = [sha3_256(i.encode()).digest() for i in "abc"]
|
||||
assert merkleroot(hashes) == ("78c7c394d3158c218916b7ae0ebdea502e0f4e85c08e3b371e3dfd824d389fa3")
|
||||
@ -49,14 +49,14 @@ SAMPLE_PUBLIC_KEY = {
|
||||
reason="ripemd160, the core of pulbic_key64_to_address is no longer supported by hashlib (from python 3.9.13 on)"
|
||||
)
|
||||
def test_convert_base64_public_key_to_address():
|
||||
from planetmint.tendermint_utils import public_key64_to_address
|
||||
from planetmint.abci.tendermint_utils import public_key64_to_address
|
||||
|
||||
address = public_key64_to_address(SAMPLE_PUBLIC_KEY["pub_key"]["value"])
|
||||
assert address == SAMPLE_PUBLIC_KEY["address"]
|
||||
|
||||
|
||||
def test_public_key_encoding_decoding():
|
||||
from planetmint.tendermint_utils import public_key_from_base64, public_key_to_base64
|
||||
from planetmint.abci.tendermint_utils import public_key_from_base64, public_key_to_base64
|
||||
|
||||
public_key = public_key_from_base64(SAMPLE_PUBLIC_KEY["pub_key"]["value"])
|
||||
base64_public_key = public_key_to_base64(public_key)
|
||||
|
@ -5,10 +5,9 @@
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
from planetmint.ipc.events import EventTypes, Event, POISON_PILL
|
||||
from planetmint.ipc.exchange import Exchange
|
||||
def test_event_handler():
|
||||
from planetmint.events import EventTypes, Event, Exchange
|
||||
|
||||
# create and event
|
||||
event_data = {"msg": "some data"}
|
||||
event = Event(EventTypes.BLOCK_VALID, event_data)
|
||||
@ -43,8 +42,6 @@ def test_event_handler():
|
||||
|
||||
|
||||
def test_event_handler_raises_when_called_after_start():
|
||||
from planetmint.events import Exchange, POISON_PILL
|
||||
|
||||
exchange = Exchange()
|
||||
publisher_queue = exchange.get_publisher_queue()
|
||||
publisher_queue.put(POISON_PILL)
|
||||
@ -55,8 +52,6 @@ def test_event_handler_raises_when_called_after_start():
|
||||
|
||||
|
||||
def test_exchange_stops_with_poison_pill():
|
||||
from planetmint.events import EventTypes, Event, Exchange, POISON_PILL
|
||||
|
||||
# create and event
|
||||
event_data = {"msg": "some data"}
|
||||
event = Event(EventTypes.BLOCK_VALID, event_data)
|
||||
|
@ -25,7 +25,7 @@ def generate_create_and_transfer(keypair=None):
|
||||
|
||||
def test_validation_worker_process_multiple_transactions(b):
|
||||
import multiprocessing as mp
|
||||
from planetmint.parallel_validation import ValidationWorker, RESET, EXIT
|
||||
from planetmint.abci.parallel_validation import ValidationWorker, RESET, EXIT
|
||||
|
||||
keypair = generate_key_pair()
|
||||
create_tx, transfer_tx = generate_create_and_transfer(keypair)
|
||||
@ -73,7 +73,7 @@ def test_parallel_validator_routes_transactions_correctly(b, monkeypatch):
|
||||
from collections import defaultdict
|
||||
import multiprocessing as mp
|
||||
from json import dumps
|
||||
from planetmint.parallel_validation import ParallelValidator
|
||||
from planetmint.abci.parallel_validation import ParallelValidator
|
||||
|
||||
# We want to make sure that the load is distributed across all workers.
|
||||
# Since introspection on an object running on a different process is
|
||||
@ -87,7 +87,7 @@ def test_parallel_validator_routes_transactions_correctly(b, monkeypatch):
|
||||
validation_called_by.put((os.getpid(), dict_transaction["id"]))
|
||||
return dict_transaction
|
||||
|
||||
monkeypatch.setattr("planetmint.parallel_validation.ValidationWorker.validate", validate)
|
||||
monkeypatch.setattr("planetmint.abci.parallel_validation.ValidationWorker.validate", validate)
|
||||
|
||||
# Transaction routing uses the `id` of the transaction. This test strips
|
||||
# down a transaction to just its `id`. We have two workers, so even ids
|
||||
|
@ -6,7 +6,7 @@
|
||||
import pytest
|
||||
import codecs
|
||||
|
||||
from planetmint.tendermint_utils import public_key_to_base64
|
||||
from planetmint.abci.tendermint_utils import public_key_to_base64
|
||||
|
||||
from transactions.types.elections.validator_election import ValidatorElection
|
||||
from transactions.common.exceptions import AmountError
|
||||
|
@ -7,7 +7,7 @@ import pytest
|
||||
|
||||
from argparse import Namespace
|
||||
from unittest.mock import patch
|
||||
from planetmint.tendermint_utils import public_key_to_base64
|
||||
from planetmint.abci.tendermint_utils import public_key_to_base64
|
||||
from transactions.types.elections.validator_election import ValidatorElection
|
||||
from transactions.common.exceptions import (
|
||||
DuplicateTransaction,
|
||||
|
@ -16,7 +16,7 @@ from transactions.common.transaction_mode_types import BROADCAST_TX_COMMIT
|
||||
from transactions.types.assets.create import Create
|
||||
from transactions.types.elections.vote import Vote
|
||||
from transactions.types.elections.validator_utils import election_id_to_public_key
|
||||
from planetmint.tendermint_utils import key_to_base64
|
||||
from planetmint.abci.tendermint_utils import key_to_base64
|
||||
|
||||
|
||||
@singledispatch
|
||||
|
@ -13,7 +13,7 @@ import pytest
|
||||
from transactions.types.assets.create import Create
|
||||
from transactions.types.assets.transfer import Transfer
|
||||
from transactions.common import crypto
|
||||
from planetmint import events
|
||||
from planetmint.ipc import events
|
||||
from planetmint.web.websocket_server import init_app, EVENTS_ENDPOINT, EVENTS_ENDPOINT_BLOCKS
|
||||
from ipld import multihash, marshal
|
||||
|
||||
@ -195,7 +195,7 @@ async def test_websocket_transaction_event(aiohttp_client, event_loop):
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_websocket_string_event(aiohttp_client, event_loop):
|
||||
from planetmint.events import POISON_PILL
|
||||
from planetmint.ipc.events import POISON_PILL
|
||||
from planetmint.web.websocket_server import init_app, EVENTS_ENDPOINT
|
||||
|
||||
blk_source = asyncio.Queue(loop=event_loop)
|
||||
|
@ -1,18 +0,0 @@
|
||||
# This is a TOML config file.
|
||||
# For more information, see https://github.com/toml-lang/toml
|
||||
|
||||
proxy_app = "tcp://planetmint:26658"
|
||||
moniker = "anonymous"
|
||||
fast_sync = true
|
||||
db_backend = "leveldb"
|
||||
log_level = "state:debug,*:error"
|
||||
|
||||
[consensus]
|
||||
create_empty_blocks = false
|
||||
|
||||
[rpc]
|
||||
laddr = "tcp://0.0.0.0:26657"
|
||||
|
||||
[p2p]
|
||||
laddr = "tcp://0.0.0.0:26656"
|
||||
seeds = ""
|
Loading…
x
Reference in New Issue
Block a user