diff --git a/planetmint/core.py b/planetmint/core.py index 65d6a10..4369e5d 100644 --- a/planetmint/core.py +++ b/planetmint/core.py @@ -9,7 +9,7 @@ with Tendermint. import logging import sys import enum -from tendermint.abci import types_pb2 +from tendermint.abci import types_pb2 from abci.application import BaseApplication from abci.application import OkCode from tendermint.abci.types_pb2 import ( @@ -50,10 +50,6 @@ from planetmint.events import EventTypes, Event CodeTypeError = 1 logger = logging.getLogger(__name__) -class TmVersion(enum.Enum): - """Supported Tendermint versions enum""" - v0_34_11 = 'v0.34.11' - class App(BaseApplication): """Bridge between Planetmint and Tendermint. diff --git a/planetmint/parallel_validation.py b/planetmint/parallel_validation.py index 040a758..239f4d8 100644 --- a/planetmint/parallel_validation.py +++ b/planetmint/parallel_validation.py @@ -6,7 +6,8 @@ import multiprocessing as mp from collections import defaultdict -from planetmint import App, Planetmint +from planetmint import App +from planetmint.lib import Planetmint from planetmint.tendermint_utils import decode_transaction from abci.application import OkCode from tendermint.abci.types_pb2 import ( diff --git a/planetmint/start.py b/planetmint/start.py index e511d1b..018ff2c 100644 --- a/planetmint/start.py +++ b/planetmint/start.py @@ -6,8 +6,6 @@ import logging import setproctitle -#from abci import TmVersion, ABCI - import planetmint from planetmint.lib import Planetmint from planetmint.core import App diff --git a/planetmint/upsert_validator/validator_utils.py b/planetmint/upsert_validator/validator_utils.py index 1485920..1fc0e5a 100644 --- a/planetmint/upsert_validator/validator_utils.py +++ b/planetmint/upsert_validator/validator_utils.py @@ -4,29 +4,15 @@ import codecs import enum import planetmint -from tendermint.abci import types_pb2 as types_v0_34_11 +from tendermint.abci import types_pb2 from tendermint.crypto import keys_pb2 from planetmint.common.exceptions import InvalidPublicKey, BigchainDBError -class TmVersion(enum.Enum): - """Supported Tendermint versions enum""" - v0_34_11 = 'v0.34.11' - def encode_validator(v): ed25519_public_key = v['public_key']['value'] - # NOTE: tendermint expects public to be encoded in go-amino format - try: - version = TmVersion(planetmint.config["tendermint"]["version"]) - except ValueError: - raise BigchainDBError('Invalid tendermint version, ' - 'check Planetmint configuration file') + pub_key = keys_pb2.PublicKey(ed25519=bytes.fromhex(ed25519_public_key)) - validator_update_t, pubkey_t = { - TmVersion.v0_34_11: (types_v0_34_11.ValidatorUpdate, keys_pb2.PublicKey) - }[version] - pub_key = pubkey_t(ed25519=bytes.fromhex(ed25519_public_key)) - - return validator_update_t(pub_key=pub_key, power=v['power']) + return types_pb2.ValidatorUpdate(pub_key=pub_key, power=v['power']) def decode_validator(v): diff --git a/planetmint/web/server.py b/planetmint/web/server.py index e0c4519..1710efe 100644 --- a/planetmint/web/server.py +++ b/planetmint/web/server.py @@ -16,7 +16,8 @@ from flask_cors import CORS import gunicorn.app.base from planetmint import utils -from planetmint import Planetmint +#from planetmint import Planetmint +from planetmint.lib import Planetmint from planetmint.web.routes import add_routes from planetmint.web.strip_content_type_middleware import StripContentTypeMiddleware diff --git a/tests/elections/test_election.py b/tests/elections/test_election.py index 3e51c9a..10c95a2 100644 --- a/tests/elections/test_election.py +++ b/tests/elections/test_election.py @@ -6,7 +6,7 @@ from planetmint.lib import Block from planetmint.elections.election import Election from planetmint.migrations.chain_migration_election import ChainMigrationElection from planetmint.upsert_validator.validator_election import ValidatorElection -from planetmint.core import TmVersion + @pytest.mark.bdb def test_process_block_concludes_all_elections(b): diff --git a/tests/tendermint/test_core.py b/tests/tendermint/test_core.py index 4712791..70a64af 100644 --- a/tests/tendermint/test_core.py +++ b/tests/tendermint/test_core.py @@ -53,7 +53,7 @@ def generate_init_chain_request(chain_id, vals=None): def test_init_chain_successfully_registers_chain(a, b): request = generate_init_chain_request('chain-XYZ') - res = App(a, b).init_chain(request) + res = App(b, a).init_chain(request) assert res == types.ResponseInitChain() chain = query.get_latest_abci_chain(b.connection) assert chain == {'height': 0, 'chain_id': 'chain-XYZ', 'is_synced': True} @@ -67,7 +67,7 @@ def test_init_chain_successfully_registers_chain(a, b): def test_init_chain_ignores_invalid_init_chain_requests(a, b): validators = [generate_validator()] request = generate_init_chain_request('chain-XYZ', validators) - res = App(a, b).init_chain(request) + res = App(b, a).init_chain(request) assert res == types.ResponseInitChain() validator_set = query.get_validator_set(b.connection) @@ -81,7 +81,7 @@ def test_init_chain_ignores_invalid_init_chain_requests(a, b): ] for r in invalid_requests: with pytest.raises(SystemExit): - App(a, b).init_chain(r) + App(b, a).init_chain(r) # assert nothing changed - neither validator set, nor chain ID new_validator_set = query.get_validator_set(b.connection) assert new_validator_set == validator_set @@ -97,7 +97,7 @@ def test_init_chain_ignores_invalid_init_chain_requests(a, b): def test_init_chain_recognizes_new_chain_after_migration(a, b): validators = [generate_validator()] request = generate_init_chain_request('chain-XYZ', validators) - res = App(a, b).init_chain(request) + res = App(b, a).init_chain(request) assert res == types.ResponseInitChain() validator_set = query.get_validator_set(b.connection)['validators'] @@ -116,7 +116,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b): ] for r in invalid_requests: with pytest.raises(SystemExit): - App(a, b).init_chain(r) + App(b, a).init_chain(r) assert query.get_latest_abci_chain(b.connection) == { 'chain_id': 'chain-XYZ-migrated-at-height-1', 'is_synced': False, @@ -129,7 +129,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b): # completes the migration request = generate_init_chain_request('chain-XYZ-migrated-at-height-1', validators) - res = App(a, b).init_chain(request) + res = App(b, a).init_chain(request) assert res == types.ResponseInitChain() assert query.get_latest_abci_chain(b.connection) == { 'chain_id': 'chain-XYZ-migrated-at-height-1', @@ -150,7 +150,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b): ] for r in invalid_requests: with pytest.raises(SystemExit): - App(a, b).init_chain(r) + App(b, a).init_chain(r) assert query.get_latest_abci_chain(b.connection) == { 'chain_id': 'chain-XYZ-migrated-at-height-1', 'is_synced': True, @@ -167,7 +167,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b): def test_info(a, b): r = types.RequestInfo(version=__tm_supported_versions__[0]) - app = App(a, b) + app = App(b, a) res = app.info(r) assert res.last_block_height == 0 @@ -180,7 +180,7 @@ def test_info(a, b): # simulate a migration and assert the height is shifted b.store_abci_chain(2, 'chain-XYZ') - app = App(a, b) + app = App(b, a) b.store_block(Block(app_hash='2', height=2, transactions=[])._asdict()) res = app.info(r) assert res.last_block_height == 0 @@ -193,7 +193,7 @@ def test_info(a, b): # it's always the latest migration that is taken into account b.store_abci_chain(4, 'chain-XYZ-new') - app = App(a, b) + app = App(b, a) b.store_block(Block(app_hash='4', height=4, transactions=[])._asdict()) res = app.info(r) assert res.last_block_height == 0 @@ -212,7 +212,7 @@ def test_check_tx__signed_create_is_ok(a, b): [([bob.public_key], 1)])\ .sign([alice.private_key]) - app = App(a, b) + app = App(b, a) result = app.check_tx(encode_tx_to_bytes(tx)) assert result.code == OkCode @@ -228,7 +228,7 @@ def test_check_tx__unsigned_create_is_error(a, b): tx = Transaction.create([alice.public_key], [([bob.public_key], 1)]) - app = App(a, b) + app = App(b, a) result = app.check_tx(encode_tx_to_bytes(tx)) assert result.code == CodeTypeError @@ -283,7 +283,7 @@ def test_deliver_tx__double_spend_fails(a, b, init_chain_request): [([bob.public_key], 1)])\ .sign([alice.private_key]) - app = App(a, b) + app = App(b, a) app.init_chain(init_chain_request) begin_block = types.RequestBeginBlock() @@ -305,7 +305,7 @@ def test_deliver_transfer_tx__double_spend_fails(a, b, init_chain_request): from planetmint.models import Transaction from planetmint.common.crypto import generate_key_pair - app = App(a, b) + app = App(b, a) app.init_chain(init_chain_request) begin_block = types.RequestBeginBlock() @@ -345,7 +345,7 @@ def test_deliver_transfer_tx__double_spend_fails(a, b, init_chain_request): def test_end_block_return_validator_updates(a, b, init_chain_request): - app = App(a, b) + app = App(b, a) app.init_chain(init_chain_request) begin_block = types.RequestBeginBlock() @@ -389,7 +389,7 @@ def test_store_pre_commit_state_in_end_block(a, b, alice, init_chain_request): asset={'msg': 'live long and prosper'})\ .sign([alice.private_key]) - app = App(a, b) + app = App(b, a) app.init_chain(init_chain_request) begin_block = types.RequestBeginBlock() @@ -410,7 +410,7 @@ def test_store_pre_commit_state_in_end_block(a, b, alice, init_chain_request): # simulate a chain migration and assert the height is shifted b.store_abci_chain(100, 'new-chain') - app = App(a, b) + app = App(b, a) app.begin_block(begin_block) app.deliver_tx(encode_tx_to_bytes(tx)) app.end_block(types.RequestEndBlock(height=1)) @@ -507,39 +507,39 @@ def test_info_aborts_if_chain_is_not_synced(a, b): b.store_abci_chain(0, 'chain-XYZ', False) with pytest.raises(SystemExit): - App(a, b).info(types.RequestInfo()) + App(b, a).info(types.RequestInfo()) def test_check_tx_aborts_if_chain_is_not_synced(a, b): b.store_abci_chain(0, 'chain-XYZ', False) with pytest.raises(SystemExit): - App(a, b).check_tx('some bytes') + App(b, a).check_tx('some bytes') def test_begin_aborts_if_chain_is_not_synced(a, b): b.store_abci_chain(0, 'chain-XYZ', False) with pytest.raises(SystemExit): - App(a, b).info(types.RequestBeginBlock()) + App(b, a).info(types.RequestBeginBlock()) def test_deliver_tx_aborts_if_chain_is_not_synced(a, b): b.store_abci_chain(0, 'chain-XYZ', False) with pytest.raises(SystemExit): - App(a, b).deliver_tx('some bytes') + App(b, a).deliver_tx('some bytes') def test_end_block_aborts_if_chain_is_not_synced(a, b): b.store_abci_chain(0, 'chain-XYZ', False) with pytest.raises(SystemExit): - App(a, b).info(types.RequestEndBlock()) + App(b, a).info(types.RequestEndBlock()) def test_commit_aborts_if_chain_is_not_synced(a, b): b.store_abci_chain(0, 'chain-XYZ', False) with pytest.raises(SystemExit): - App(a, b).commit() + App(b, a).commit() diff --git a/tests/tendermint/test_integration.py b/tests/tendermint/test_integration.py index 17f96df..78511d7 100644 --- a/tests/tendermint/test_integration.py +++ b/tests/tendermint/test_integration.py @@ -25,7 +25,7 @@ def test_app(a, b, init_chain_request): from planetmint.common.crypto import generate_key_pair from planetmint.models import Transaction - app = App(a, b) + app = App(b, a) p = ProtocolHandler(app) data = p.process('info', @@ -150,7 +150,7 @@ def test_post_transaction_responses(tendermint_ws_url, b): def test_exit_when_tm_ver_not_supported(a, b): from planetmint import App - app = App(a, b) + app = App(b, a) p = ProtocolHandler(app) with pytest.raises(SystemExit): diff --git a/tests/test_core.py b/tests/test_core.py index 4cfa779..8e3bf24 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -53,7 +53,7 @@ def generate_init_chain_request(chain_id, vals=None): def test_init_chain_successfully_registers_chain(a, b): request = generate_init_chain_request('chain-XYZ') - res = App(a, b).init_chain(request) + res = App(b, a).init_chain(request) assert res == types.ResponseInitChain() chain = query.get_latest_abci_chain(b.connection) assert chain == {'height': 0, 'chain_id': 'chain-XYZ', 'is_synced': True} @@ -67,7 +67,7 @@ def test_init_chain_successfully_registers_chain(a, b): def test_init_chain_ignores_invalid_init_chain_requests(a, b): validators = [generate_validator()] request = generate_init_chain_request('chain-XYZ', validators) - res = App(a, b).init_chain(request) + res = App(b, a).init_chain(request) assert res == types.ResponseInitChain() validator_set = query.get_validator_set(b.connection) @@ -81,7 +81,7 @@ def test_init_chain_ignores_invalid_init_chain_requests(a, b): ] for r in invalid_requests: with pytest.raises(SystemExit): - App(a, b).init_chain(r) + App(b, a).init_chain(r) # assert nothing changed - neither validator set, nor chain ID new_validator_set = query.get_validator_set(b.connection) assert new_validator_set == validator_set @@ -97,7 +97,7 @@ def test_init_chain_ignores_invalid_init_chain_requests(a, b): def test_init_chain_recognizes_new_chain_after_migration(a, b): validators = [generate_validator()] request = generate_init_chain_request('chain-XYZ', validators) - res = App(a, b).init_chain(request) + res = App(b, a).init_chain(request) assert res == types.ResponseInitChain() validator_set = query.get_validator_set(b.connection)['validators'] @@ -116,7 +116,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b): ] for r in invalid_requests: with pytest.raises(SystemExit): - App(a, b).init_chain(r) + App(b, a).init_chain(r) assert query.get_latest_abci_chain(b.connection) == { 'chain_id': 'chain-XYZ-migrated-at-height-1', 'is_synced': False, @@ -129,7 +129,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b): # completes the migration request = generate_init_chain_request('chain-XYZ-migrated-at-height-1', validators) - res = App(a, b).init_chain(request) + res = App(b, a).init_chain(request) assert res == types.ResponseInitChain() assert query.get_latest_abci_chain(b.connection) == { 'chain_id': 'chain-XYZ-migrated-at-height-1', @@ -150,7 +150,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b): ] for r in invalid_requests: with pytest.raises(SystemExit): - App(a, b).init_chain(r) + App(b, a).init_chain(r) assert query.get_latest_abci_chain(b.connection) == { 'chain_id': 'chain-XYZ-migrated-at-height-1', 'is_synced': True, @@ -167,7 +167,7 @@ def test_init_chain_recognizes_new_chain_after_migration(a, b): def test_info(a, b): r = types.RequestInfo(version=__tm_supported_versions__[0]) - app = App(a, b) + app = App(b, a) res = app.info(r) assert res.last_block_height == 0 @@ -180,7 +180,7 @@ def test_info(a, b): # simulate a migration and assert the height is shifted b.store_abci_chain(2, 'chain-XYZ') - app = App(a, b) + app = App(b, a) b.store_block(Block(app_hash='2', height=2, transactions=[])._asdict()) res = app.info(r) assert res.last_block_height == 0 @@ -193,7 +193,7 @@ def test_info(a, b): # it's always the latest migration that is taken into account b.store_abci_chain(4, 'chain-XYZ-new') - app = App(a, b) + app = App(b, a) b.store_block(Block(app_hash='4', height=4, transactions=[])._asdict()) res = app.info(r) assert res.last_block_height == 0 @@ -212,7 +212,7 @@ def test_check_tx__signed_create_is_ok(a, b): [([bob.public_key], 1)])\ .sign([alice.private_key]) - app = App(a, b) + app = App(b, a) result = app.check_tx(encode_tx_to_bytes(tx)) assert result.code == CodeTypeOk @@ -228,7 +228,7 @@ def test_check_tx__unsigned_create_is_error(a, b): tx = Transaction.create([alice.public_key], [([bob.public_key], 1)]) - app = App(a, b) + app = App(b, a) result = app.check_tx(encode_tx_to_bytes(tx)) assert result.code == CodeTypeError @@ -283,7 +283,7 @@ def test_deliver_tx__double_spend_fails(a, b, init_chain_request): [([bob.public_key], 1)])\ .sign([alice.private_key]) - app = App(a, b) + app = App(b, a) app.init_chain(init_chain_request) begin_block = types.RequestBeginBlock() @@ -305,7 +305,7 @@ def test_deliver_transfer_tx__double_spend_fails(a, b, init_chain_request): from planetmint.models import Transaction from planetmint.common.crypto import generate_key_pair - app = App(a, b) + app = App(b, a) app.init_chain(init_chain_request) begin_block = types.RequestBeginBlock() @@ -345,7 +345,7 @@ def test_deliver_transfer_tx__double_spend_fails(a, b, init_chain_request): def test_end_block_return_validator_updates(a, b, init_chain_request): - app = App(a, b) + app = App(b, a) app.init_chain(init_chain_request) begin_block = types.RequestBeginBlock() @@ -389,7 +389,7 @@ def test_store_pre_commit_state_in_end_block(a, b, alice, init_chain_request): asset={'msg': 'live long and prosper'})\ .sign([alice.private_key]) - app = App(a, b) + app = App(b, a) app.init_chain(init_chain_request) begin_block = types.RequestBeginBlock() @@ -410,7 +410,7 @@ def test_store_pre_commit_state_in_end_block(a, b, alice, init_chain_request): # simulate a chain migration and assert the height is shifted b.store_abci_chain(100, 'new-chain') - app = App(a, b) + app = App(b, a) app.begin_block(begin_block) app.deliver_tx(encode_tx_to_bytes(tx)) app.end_block(types.RequestEndBlock(height=1)) @@ -507,39 +507,39 @@ def test_info_aborts_if_chain_is_not_synced(a, b): b.store_abci_chain(0, 'chain-XYZ', False) with pytest.raises(SystemExit): - App(a, b).info(types.RequestInfo()) + App(b, a).info(types.RequestInfo()) def test_check_tx_aborts_if_chain_is_not_synced(a, b): b.store_abci_chain(0, 'chain-XYZ', False) with pytest.raises(SystemExit): - App(a, b).check_tx('some bytes') + App(b, a).check_tx('some bytes') def test_begin_aborts_if_chain_is_not_synced(a, b): b.store_abci_chain(0, 'chain-XYZ', False) with pytest.raises(SystemExit): - App(a, b).info(types.RequestBeginBlock()) + App(b, a).info(types.RequestBeginBlock()) def test_deliver_tx_aborts_if_chain_is_not_synced(a, b): b.store_abci_chain(0, 'chain-XYZ', False) with pytest.raises(SystemExit): - App(a, b).deliver_tx('some bytes') + App(b, a).deliver_tx('some bytes') def test_end_block_aborts_if_chain_is_not_synced(a, b): b.store_abci_chain(0, 'chain-XYZ', False) with pytest.raises(SystemExit): - App(a, b).info(types.RequestEndBlock()) + App(b, a).info(types.RequestEndBlock()) def test_commit_aborts_if_chain_is_not_synced(a, b): b.store_abci_chain(0, 'chain-XYZ', False) with pytest.raises(SystemExit): - App(a, b).commit() \ No newline at end of file + App(b, a).commit() \ No newline at end of file