mirror of
https://github.com/planetmint/planetmint.git
synced 2025-07-11 06:52:31 +00:00
Solved linting errors.
This commit is contained in:
parent
32923e80a3
commit
0fdca70c38
@ -8,38 +8,20 @@ with Tendermint.
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import sys
|
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 BaseApplication
|
||||||
from abci.application import OkCode
|
from abci.application import OkCode
|
||||||
from tendermint.abci.types_pb2 import (
|
from tendermint.abci.types_pb2 import (
|
||||||
RequestInfo,
|
|
||||||
ResponseInfo,
|
ResponseInfo,
|
||||||
RequestInitChain,
|
|
||||||
ResponseInitChain,
|
ResponseInitChain,
|
||||||
ResponseCheckTx,
|
ResponseCheckTx,
|
||||||
ResponseDeliverTx,
|
ResponseDeliverTx,
|
||||||
RequestQuery,
|
|
||||||
ResponseQuery,
|
|
||||||
RequestBeginBlock,
|
|
||||||
ResponseBeginBlock,
|
ResponseBeginBlock,
|
||||||
RequestEndBlock,
|
|
||||||
ResponseEndBlock,
|
ResponseEndBlock,
|
||||||
ResponseCommit,
|
ResponseCommit
|
||||||
RequestLoadSnapshotChunk,
|
|
||||||
ResponseLoadSnapshotChunk,
|
|
||||||
RequestListSnapshots,
|
|
||||||
ResponseListSnapshots,
|
|
||||||
RequestOfferSnapshot,
|
|
||||||
ResponseOfferSnapshot,
|
|
||||||
RequestApplySnapshotChunk,
|
|
||||||
ResponseApplySnapshotChunk,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from planetmint import Planetmint
|
from planetmint import Planetmint
|
||||||
from planetmint.elections.election import Election
|
from planetmint.elections.election import Election
|
||||||
from planetmint.version import __tm_supported_versions__
|
|
||||||
from planetmint.utils import tendermint_version_is_compatible
|
|
||||||
from planetmint.tendermint_utils import (decode_transaction,
|
from planetmint.tendermint_utils import (decode_transaction,
|
||||||
calculate_hash)
|
calculate_hash)
|
||||||
from planetmint.lib import Block
|
from planetmint.lib import Block
|
||||||
@ -80,17 +62,14 @@ class App(BaseApplication):
|
|||||||
def abort_if_abci_chain_is_not_synced(self):
|
def abort_if_abci_chain_is_not_synced(self):
|
||||||
if self.chain is None or self.chain['is_synced']:
|
if self.chain is None or self.chain['is_synced']:
|
||||||
return
|
return
|
||||||
|
|
||||||
validators = self.planetmint_node.get_validators()
|
validators = self.planetmint_node.get_validators()
|
||||||
self.log_abci_migration_error(self.chain['chain_id'], validators)
|
self.log_abci_migration_error(self.chain['chain_id'], validators)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def init_chain(self, genesis):
|
def init_chain(self, genesis):
|
||||||
"""Initialize chain upon genesis or a migration"""
|
"""Initialize chain upon genesis or a migration"""
|
||||||
|
|
||||||
app_hash = ''
|
app_hash = ''
|
||||||
height = 0
|
height = 0
|
||||||
|
|
||||||
known_chain = self.planetmint_node.get_latest_abci_chain()
|
known_chain = self.planetmint_node.get_latest_abci_chain()
|
||||||
if known_chain is not None:
|
if known_chain is not None:
|
||||||
chain_id = known_chain['chain_id']
|
chain_id = known_chain['chain_id']
|
||||||
@ -100,26 +79,21 @@ class App(BaseApplication):
|
|||||||
f'the chain {chain_id} is already synced.')
|
f'the chain {chain_id} is already synced.')
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if chain_id != genesis.chain_id:
|
if chain_id != genesis.chain_id:
|
||||||
validators = self.planetmint_node.get_validators()
|
validators = self.planetmint_node.get_validators()
|
||||||
self.log_abci_migration_error(chain_id, validators)
|
self.log_abci_migration_error(chain_id, validators)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# set migration values for app hash and height
|
# set migration values for app hash and height
|
||||||
block = self.planetmint_node.get_latest_block()
|
block = self.planetmint_node.get_latest_block()
|
||||||
app_hash = '' if block is None else block['app_hash']
|
app_hash = '' if block is None else block['app_hash']
|
||||||
height = 0 if block is None else block['height'] + 1
|
height = 0 if block is None else block['height'] + 1
|
||||||
|
|
||||||
known_validators = self.planetmint_node.get_validators()
|
known_validators = self.planetmint_node.get_validators()
|
||||||
validator_set = [vutils.decode_validator(v)
|
validator_set = [vutils.decode_validator(v)
|
||||||
for v in genesis.validators]
|
for v in genesis.validators]
|
||||||
|
|
||||||
if known_validators and known_validators != validator_set:
|
if known_validators and known_validators != validator_set:
|
||||||
self.log_abci_migration_error(known_chain['chain_id'],
|
self.log_abci_migration_error(known_chain['chain_id'],
|
||||||
known_validators)
|
known_validators)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
block = Block(app_hash=app_hash, height=height, transactions=[])
|
block = Block(app_hash=app_hash, height=height, transactions=[])
|
||||||
self.planetmint_node.store_block(block._asdict())
|
self.planetmint_node.store_block(block._asdict())
|
||||||
self.planetmint_node.store_validator_set(height + 1, validator_set)
|
self.planetmint_node.store_validator_set(height + 1, validator_set)
|
||||||
@ -136,12 +110,12 @@ class App(BaseApplication):
|
|||||||
self.abort_if_abci_chain_is_not_synced()
|
self.abort_if_abci_chain_is_not_synced()
|
||||||
|
|
||||||
# Check if Planetmint supports the Tendermint version
|
# Check if Planetmint supports the Tendermint version
|
||||||
#if not (hasattr(request, 'version') and tendermint_version_is_compatible(request.version)):
|
# if not (hasattr(request, 'version') and tendermint_version_is_compatible(request.version)):
|
||||||
# logger.error(f'Unsupported Tendermint version: {getattr(request, "version", "no version")}.'
|
# logger.error(f'Unsupported Tendermint version: {getattr(request, "version", "no version")}.'
|
||||||
# f' Currently, Planetmint only supports {__tm_supported_versions__}. Exiting!')
|
# f' Currently, Planetmint only supports {__tm_supported_versions__}. Exiting!')
|
||||||
# sys.exit(1)
|
# sys.exit(1)
|
||||||
|
|
||||||
#logger.info(f"Tendermint version: {request.version}")
|
# logger.info(f"Tendermint version: {request.version}")
|
||||||
|
|
||||||
r = ResponseInfo()
|
r = ResponseInfo()
|
||||||
block = self.planetmint_node.get_latest_block()
|
block = self.planetmint_node.get_latest_block()
|
||||||
@ -182,7 +156,7 @@ class App(BaseApplication):
|
|||||||
self.abort_if_abci_chain_is_not_synced()
|
self.abort_if_abci_chain_is_not_synced()
|
||||||
|
|
||||||
chain_shift = 0 if self.chain is None else self.chain['height']
|
chain_shift = 0 if self.chain is None else self.chain['height']
|
||||||
#req_begin_block.header.num_txs not found, so removing it.
|
# req_begin_block.header.num_txs not found, so removing it.
|
||||||
logger.debug('BEGIN BLOCK, height:%s',
|
logger.debug('BEGIN BLOCK, height:%s',
|
||||||
req_begin_block.header.height + chain_shift)
|
req_begin_block.header.height + chain_shift)
|
||||||
|
|
||||||
|
@ -11,27 +11,8 @@ from planetmint.lib import Planetmint
|
|||||||
from planetmint.tendermint_utils import decode_transaction
|
from planetmint.tendermint_utils import decode_transaction
|
||||||
from abci.application import OkCode
|
from abci.application import OkCode
|
||||||
from tendermint.abci.types_pb2 import (
|
from tendermint.abci.types_pb2 import (
|
||||||
RequestInfo,
|
ResponseCheckTx,
|
||||||
ResponseInfo,
|
ResponseDeliverTx,
|
||||||
RequestInitChain,
|
|
||||||
ResponseInitChain,
|
|
||||||
#ResponseCheckTx,
|
|
||||||
#ResponseDeliverTx,
|
|
||||||
RequestQuery,
|
|
||||||
ResponseQuery,
|
|
||||||
RequestBeginBlock,
|
|
||||||
ResponseBeginBlock,
|
|
||||||
RequestEndBlock,
|
|
||||||
ResponseEndBlock,
|
|
||||||
ResponseCommit,
|
|
||||||
RequestLoadSnapshotChunk,
|
|
||||||
ResponseLoadSnapshotChunk,
|
|
||||||
RequestListSnapshots,
|
|
||||||
ResponseListSnapshots,
|
|
||||||
RequestOfferSnapshot,
|
|
||||||
ResponseOfferSnapshot,
|
|
||||||
RequestApplySnapshotChunk,
|
|
||||||
ResponseApplySnapshotChunk,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ def start(args):
|
|||||||
setproctitle.setproctitle('planetmint')
|
setproctitle.setproctitle('planetmint')
|
||||||
|
|
||||||
# Start the ABCIServer
|
# Start the ABCIServer
|
||||||
#abci = ABCI(TmVersion(planetmint.config['tendermint']['version']))
|
# abci = ABCI(TmVersion(planetmint.config['tendermint']['version']))
|
||||||
if args.experimental_parallel_validation:
|
if args.experimental_parallel_validation:
|
||||||
app = ABCIServer(
|
app = ABCIServer(
|
||||||
app=ParallelValidationApp(
|
app=ParallelValidationApp(
|
||||||
|
@ -1,12 +1,10 @@
|
|||||||
import base64
|
import base64
|
||||||
import binascii
|
import binascii
|
||||||
import codecs
|
import codecs
|
||||||
import enum
|
|
||||||
|
|
||||||
import planetmint
|
|
||||||
from tendermint.abci import types_pb2
|
from tendermint.abci import types_pb2
|
||||||
from tendermint.crypto import keys_pb2
|
from tendermint.crypto import keys_pb2
|
||||||
from planetmint.common.exceptions import InvalidPublicKey, BigchainDBError
|
from planetmint.common.exceptions import InvalidPublicKey
|
||||||
|
|
||||||
def encode_validator(v):
|
def encode_validator(v):
|
||||||
ed25519_public_key = v['public_key']['value']
|
ed25519_public_key = v['public_key']['value']
|
||||||
|
@ -31,7 +31,7 @@ from planetmint.common.crypto import (key_pair_from_ed25519_key,
|
|||||||
from planetmint.common.exceptions import DatabaseDoesNotExist
|
from planetmint.common.exceptions import DatabaseDoesNotExist
|
||||||
from planetmint.lib import Block
|
from planetmint.lib import Block
|
||||||
from tests.utils import gen_vote
|
from tests.utils import gen_vote
|
||||||
import tests.tendermint.conftest
|
# import tests.tendermint.conftest
|
||||||
|
|
||||||
TEST_DB_NAME = 'planetmint_test'
|
TEST_DB_NAME = 'planetmint_test'
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ def merlin():
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
#def a():
|
# def a():
|
||||||
def abci_fixture():
|
def abci_fixture():
|
||||||
from tendermint.abci import types_pb2
|
from tendermint.abci import types_pb2
|
||||||
return types_pb2
|
return types_pb2
|
||||||
@ -252,12 +252,9 @@ def eventqueue_fixture():
|
|||||||
from multiprocessing import Queue
|
from multiprocessing import Queue
|
||||||
return Queue()
|
return Queue()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def b_mock(b, network_validators):
|
def b_mock(b, network_validators):
|
||||||
b.get_validators = mock_get_validators(network_validators)
|
b.get_validators = mock_get_validators(network_validators)
|
||||||
|
|
||||||
return b
|
return b
|
||||||
|
|
||||||
|
|
||||||
@ -450,7 +447,7 @@ def event_loop():
|
|||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
def abci_server():
|
def abci_server():
|
||||||
from abci.server import ABCIServer
|
from abci.server import ABCIServer
|
||||||
from tendermint.abci import types_pb2 as types_v0_34_11
|
# from tendermint.abci import types_pb2 as types_v0_34_11
|
||||||
from planetmint.core import App
|
from planetmint.core import App
|
||||||
from planetmint.utils import Process
|
from planetmint.utils import Process
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import pytest
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
from tendermint.abci import types_pb2 as types
|
from tendermint.abci import types_pb2 as types
|
||||||
from tendermint.crypto import keys_pb2
|
from tendermint.crypto import keys_pb2
|
||||||
|
|
||||||
from planetmint import App
|
from planetmint import App
|
||||||
from planetmint.backend.localmongodb import query
|
from planetmint.backend.localmongodb import query
|
||||||
@ -248,7 +248,7 @@ def test_deliver_tx__valid_create_updates_db_and_emits_event(b, init_chain_reque
|
|||||||
.sign([alice.private_key])
|
.sign([alice.private_key])
|
||||||
|
|
||||||
app = App(b, events)
|
app = App(b, events)
|
||||||
|
|
||||||
app.init_chain(init_chain_request)
|
app.init_chain(init_chain_request)
|
||||||
|
|
||||||
begin_block = types.RequestBeginBlock()
|
begin_block = types.RequestBeginBlock()
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
from tendermint.abci import types_pb2 as types
|
from tendermint.abci import types_pb2 as types
|
||||||
import json
|
import json
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -543,4 +543,4 @@ def test_commit_aborts_if_chain_is_not_synced(b):
|
|||||||
b.store_abci_chain(0, 'chain-XYZ', False)
|
b.store_abci_chain(0, 'chain-XYZ', False)
|
||||||
|
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
App(b).commit()
|
App(b).commit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user