From e9293a7596229a3b19aa37241a6afdbf2131b28d Mon Sep 17 00:00:00 2001 From: ArpitShukla007 Date: Wed, 26 Jan 2022 19:23:13 +0100 Subject: [PATCH] Initial changes with abci --- planetmint/__init__.py | 2 +- planetmint/core.py | 47 ++++++++++++++----- planetmint/parallel_validation.py | 33 +++++++++++-- planetmint/start.py | 6 +-- .../upsert_validator/validator_utils.py | 5 +- setup.py | 2 +- 6 files changed, 69 insertions(+), 26 deletions(-) diff --git a/planetmint/__init__.py b/planetmint/__init__.py index e211654..47c2643 100644 --- a/planetmint/__init__.py +++ b/planetmint/__init__.py @@ -71,7 +71,7 @@ config = { 'tendermint': { 'host': 'localhost', 'port': 26657, - 'version': 'v0.31.5', # look for __tm_supported_versions__ + 'version': 'v0.34.11', # look for __tm_supported_versions__ }, # FIXME: hardcoding to localmongodb for now 'database': _database_map['localmongodb'], diff --git a/planetmint/core.py b/planetmint/core.py index b87a778..4143858 100644 --- a/planetmint/core.py +++ b/planetmint/core.py @@ -10,7 +10,30 @@ import logging import sys from abci.application import BaseApplication -from abci import CodeTypeOk +from abci.application import OkCode +from tendermint.abci.types_pb2 import ( + RequestInfo, + ResponseInfo, + RequestInitChain, + ResponseInitChain, + ResponseCheckTx, + ResponseDeliverTx, + RequestQuery, + ResponseQuery, + RequestBeginBlock, + ResponseBeginBlock, + RequestEndBlock, + ResponseEndBlock, + ResponseCommit, + RequestLoadSnapshotChunk, + ResponseLoadSnapshotChunk, + RequestListSnapshots, + ResponseListSnapshots, + RequestOfferSnapshot, + ResponseOfferSnapshot, + RequestApplySnapshotChunk, + ResponseApplySnapshotChunk, +) from planetmint import Planetmint from planetmint.elections.election import Election @@ -34,8 +57,8 @@ class App(BaseApplication): transaction logic to Tendermint Core. """ - def __init__(self, abci, planetmint=None, events_queue=None,): - super().__init__(abci) + def __init__(self, planetmint=None, events_queue=None,): + #super().__init__(abci) self.events_queue = events_queue self.planetmint = planetmint or Planetmint() self.block_txn_ids = [] @@ -101,7 +124,7 @@ class App(BaseApplication): genesis.chain_id, True) self.chain = {'height': abci_chain_height, 'is_synced': True, 'chain_id': genesis.chain_id} - return self.abci.ResponseInitChain() + return ResponseInitChain() def info(self, request): """Return height of the latest committed block.""" @@ -116,7 +139,7 @@ class App(BaseApplication): logger.info(f"Tendermint version: {request.version}") - r = self.abci.ResponseInfo() + r = ResponseInfo() block = self.planetmint.get_latest_block() if block: chain_shift = 0 if self.chain is None else self.chain['height'] @@ -141,10 +164,10 @@ class App(BaseApplication): transaction = decode_transaction(raw_transaction) if self.planetmint.is_valid_transaction(transaction): logger.debug('check_tx: VALID') - return self.abci.ResponseCheckTx(code=CodeTypeOk) + return ResponseCheckTx(code=CodeTypeOk) else: logger.debug('check_tx: INVALID') - return self.abci.ResponseCheckTx(code=CodeTypeError) + return ResponseCheckTx(code=CodeTypeError) def begin_block(self, req_begin_block): """Initialize list of transaction. @@ -161,7 +184,7 @@ class App(BaseApplication): self.block_txn_ids = [] self.block_transactions = [] - return self.abci.ResponseBeginBlock() + return ResponseBeginBlock() def deliver_tx(self, raw_transaction): """Validate the transaction before mutating the state. @@ -178,12 +201,12 @@ class App(BaseApplication): if not transaction: logger.debug('deliver_tx: INVALID') - return self.abci.ResponseDeliverTx(code=CodeTypeError) + return ResponseDeliverTx(code=CodeTypeError) else: logger.debug('storing tx') self.block_txn_ids.append(transaction.id) self.block_transactions.append(transaction) - return self.abci.ResponseDeliverTx(code=CodeTypeOk) + return ResponseDeliverTx(code=CodeTypeOk) def end_block(self, request_end_block): """Calculate block hash using transaction ids and previous block @@ -219,7 +242,7 @@ class App(BaseApplication): self.new_height, self.block_transactions) - return self.abci.ResponseEndBlock(validator_updates=validator_update) + return ResponseEndBlock(validator_updates=validator_update) def commit(self): """Store the new height and along with block hash.""" @@ -250,7 +273,7 @@ class App(BaseApplication): }) self.events_queue.put(event) - return self.abci.ResponseCommit(data=data) + return ResponseCommit(data=data) def rollback(b): diff --git a/planetmint/parallel_validation.py b/planetmint/parallel_validation.py index 047bb2c..126fabc 100644 --- a/planetmint/parallel_validation.py +++ b/planetmint/parallel_validation.py @@ -8,21 +8,44 @@ from collections import defaultdict from planetmint import App, Planetmint from planetmint.tendermint_utils import decode_transaction -from abci import CodeTypeOk +from abci.application import OkCode +from tendermint.abci.types_pb2 import ( + RequestInfo, + ResponseInfo, + RequestInitChain, + ResponseInitChain, + #ResponseCheckTx, + #ResponseDeliverTx, + RequestQuery, + ResponseQuery, + RequestBeginBlock, + ResponseBeginBlock, + RequestEndBlock, + ResponseEndBlock, + ResponseCommit, + RequestLoadSnapshotChunk, + ResponseLoadSnapshotChunk, + RequestListSnapshots, + ResponseListSnapshots, + RequestOfferSnapshot, + ResponseOfferSnapshot, + RequestApplySnapshotChunk, + ResponseApplySnapshotChunk, +) class ParallelValidationApp(App): - def __init__(self, planetmint=None, events_queue=None, abci=None): - super().__init__(planetmint, events_queue, abci=abci) + def __init__(self, planetmint=None, events_queue=None): + super().__init__(planetmint, events_queue) self.parallel_validator = ParallelValidator() self.parallel_validator.start() def check_tx(self, raw_transaction): - return self.abci.ResponseCheckTx(code=CodeTypeOk) + return ResponseCheckTx(code=OkCode) def deliver_tx(self, raw_transaction): self.parallel_validator.validate(raw_transaction) - return self.abci.ResponseDeliverTx(code=CodeTypeOk) + return ResponseDeliverTx(code=OkCode) def end_block(self, request_end_block): result = self.parallel_validator.result(timeout=30) diff --git a/planetmint/start.py b/planetmint/start.py index 5e25261..e511d1b 100644 --- a/planetmint/start.py +++ b/planetmint/start.py @@ -6,7 +6,7 @@ import logging import setproctitle -from abci import TmVersion, ABCI +#from abci import TmVersion, ABCI import planetmint from planetmint.lib import Planetmint @@ -68,18 +68,16 @@ def start(args): setproctitle.setproctitle('planetmint') # Start the ABCIServer - abci = ABCI(TmVersion(planetmint.config['tendermint']['version'])) + #abci = ABCI(TmVersion(planetmint.config['tendermint']['version'])) if args.experimental_parallel_validation: app = ABCIServer( app=ParallelValidationApp( - abci=abci.types, events_queue=exchange.get_publisher_queue(), ) ) else: app = ABCIServer( app=App( - abci=abci.types, events_queue=exchange.get_publisher_queue(), ) ) diff --git a/planetmint/upsert_validator/validator_utils.py b/planetmint/upsert_validator/validator_utils.py index ba6a864..89a2a93 100644 --- a/planetmint/upsert_validator/validator_utils.py +++ b/planetmint/upsert_validator/validator_utils.py @@ -3,7 +3,7 @@ import binascii import codecs import planetmint -from abci import types_v0_22_8, types_v0_31_5, TmVersion +from tendermint.abci import types_pb2 as types_v0_34_11 from planetmint.common.exceptions import InvalidPublicKey, BigchainDBError @@ -17,8 +17,7 @@ def encode_validator(v): 'check Planetmint configuration file') validator_update_t, pubkey_t = { - TmVersion.v0_22_8: (types_v0_22_8.Validator, types_v0_22_8.PubKey), - TmVersion.v0_31_5: (types_v0_31_5.ValidatorUpdate, types_v0_31_5.PubKey) + TmVersion.v0_34_11: (types_v0_34_11.ValidatorUpdate, types_v0_34_11.PubKey) }[version] pub_key = pubkey_t(type='ed25519', data=bytes.fromhex(ed25519_public_key)) diff --git a/setup.py b/setup.py index 5e9c5a9..f6f80c1 100644 --- a/setup.py +++ b/setup.py @@ -73,7 +73,7 @@ tests_require = [ install_requires = [ 'chardet==3.0.4', 'aiohttp==3.7.4', - 'bigchaindb-abci==1.0.7', + 'abci==0.8.3', 'cryptoconditions==0.8.1', 'flask-cors==3.0.10', 'flask-restful==0.3.9',