mirror of
https://github.com/planetmint/planetmint.git
synced 2025-03-30 15:08:31 +00:00
Initial changes with abci
This commit is contained in:
parent
7a451b0c78
commit
e9293a7596
@ -71,7 +71,7 @@ config = {
|
|||||||
'tendermint': {
|
'tendermint': {
|
||||||
'host': 'localhost',
|
'host': 'localhost',
|
||||||
'port': 26657,
|
'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
|
# FIXME: hardcoding to localmongodb for now
|
||||||
'database': _database_map['localmongodb'],
|
'database': _database_map['localmongodb'],
|
||||||
|
@ -10,7 +10,30 @@ import logging
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from abci.application import BaseApplication
|
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 import Planetmint
|
||||||
from planetmint.elections.election import Election
|
from planetmint.elections.election import Election
|
||||||
@ -34,8 +57,8 @@ class App(BaseApplication):
|
|||||||
transaction logic to Tendermint Core.
|
transaction logic to Tendermint Core.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, abci, planetmint=None, events_queue=None,):
|
def __init__(self, planetmint=None, events_queue=None,):
|
||||||
super().__init__(abci)
|
#super().__init__(abci)
|
||||||
self.events_queue = events_queue
|
self.events_queue = events_queue
|
||||||
self.planetmint = planetmint or Planetmint()
|
self.planetmint = planetmint or Planetmint()
|
||||||
self.block_txn_ids = []
|
self.block_txn_ids = []
|
||||||
@ -101,7 +124,7 @@ class App(BaseApplication):
|
|||||||
genesis.chain_id, True)
|
genesis.chain_id, True)
|
||||||
self.chain = {'height': abci_chain_height, 'is_synced': True,
|
self.chain = {'height': abci_chain_height, 'is_synced': True,
|
||||||
'chain_id': genesis.chain_id}
|
'chain_id': genesis.chain_id}
|
||||||
return self.abci.ResponseInitChain()
|
return ResponseInitChain()
|
||||||
|
|
||||||
def info(self, request):
|
def info(self, request):
|
||||||
"""Return height of the latest committed block."""
|
"""Return height of the latest committed block."""
|
||||||
@ -116,7 +139,7 @@ class App(BaseApplication):
|
|||||||
|
|
||||||
logger.info(f"Tendermint version: {request.version}")
|
logger.info(f"Tendermint version: {request.version}")
|
||||||
|
|
||||||
r = self.abci.ResponseInfo()
|
r = ResponseInfo()
|
||||||
block = self.planetmint.get_latest_block()
|
block = self.planetmint.get_latest_block()
|
||||||
if block:
|
if block:
|
||||||
chain_shift = 0 if self.chain is None else self.chain['height']
|
chain_shift = 0 if self.chain is None else self.chain['height']
|
||||||
@ -141,10 +164,10 @@ class App(BaseApplication):
|
|||||||
transaction = decode_transaction(raw_transaction)
|
transaction = decode_transaction(raw_transaction)
|
||||||
if self.planetmint.is_valid_transaction(transaction):
|
if self.planetmint.is_valid_transaction(transaction):
|
||||||
logger.debug('check_tx: VALID')
|
logger.debug('check_tx: VALID')
|
||||||
return self.abci.ResponseCheckTx(code=CodeTypeOk)
|
return ResponseCheckTx(code=CodeTypeOk)
|
||||||
else:
|
else:
|
||||||
logger.debug('check_tx: INVALID')
|
logger.debug('check_tx: INVALID')
|
||||||
return self.abci.ResponseCheckTx(code=CodeTypeError)
|
return ResponseCheckTx(code=CodeTypeError)
|
||||||
|
|
||||||
def begin_block(self, req_begin_block):
|
def begin_block(self, req_begin_block):
|
||||||
"""Initialize list of transaction.
|
"""Initialize list of transaction.
|
||||||
@ -161,7 +184,7 @@ class App(BaseApplication):
|
|||||||
|
|
||||||
self.block_txn_ids = []
|
self.block_txn_ids = []
|
||||||
self.block_transactions = []
|
self.block_transactions = []
|
||||||
return self.abci.ResponseBeginBlock()
|
return ResponseBeginBlock()
|
||||||
|
|
||||||
def deliver_tx(self, raw_transaction):
|
def deliver_tx(self, raw_transaction):
|
||||||
"""Validate the transaction before mutating the state.
|
"""Validate the transaction before mutating the state.
|
||||||
@ -178,12 +201,12 @@ class App(BaseApplication):
|
|||||||
|
|
||||||
if not transaction:
|
if not transaction:
|
||||||
logger.debug('deliver_tx: INVALID')
|
logger.debug('deliver_tx: INVALID')
|
||||||
return self.abci.ResponseDeliverTx(code=CodeTypeError)
|
return ResponseDeliverTx(code=CodeTypeError)
|
||||||
else:
|
else:
|
||||||
logger.debug('storing tx')
|
logger.debug('storing tx')
|
||||||
self.block_txn_ids.append(transaction.id)
|
self.block_txn_ids.append(transaction.id)
|
||||||
self.block_transactions.append(transaction)
|
self.block_transactions.append(transaction)
|
||||||
return self.abci.ResponseDeliverTx(code=CodeTypeOk)
|
return ResponseDeliverTx(code=CodeTypeOk)
|
||||||
|
|
||||||
def end_block(self, request_end_block):
|
def end_block(self, request_end_block):
|
||||||
"""Calculate block hash using transaction ids and previous block
|
"""Calculate block hash using transaction ids and previous block
|
||||||
@ -219,7 +242,7 @@ class App(BaseApplication):
|
|||||||
self.new_height,
|
self.new_height,
|
||||||
self.block_transactions)
|
self.block_transactions)
|
||||||
|
|
||||||
return self.abci.ResponseEndBlock(validator_updates=validator_update)
|
return ResponseEndBlock(validator_updates=validator_update)
|
||||||
|
|
||||||
def commit(self):
|
def commit(self):
|
||||||
"""Store the new height and along with block hash."""
|
"""Store the new height and along with block hash."""
|
||||||
@ -250,7 +273,7 @@ class App(BaseApplication):
|
|||||||
})
|
})
|
||||||
self.events_queue.put(event)
|
self.events_queue.put(event)
|
||||||
|
|
||||||
return self.abci.ResponseCommit(data=data)
|
return ResponseCommit(data=data)
|
||||||
|
|
||||||
|
|
||||||
def rollback(b):
|
def rollback(b):
|
||||||
|
@ -8,21 +8,44 @@ from collections import defaultdict
|
|||||||
|
|
||||||
from planetmint import App, Planetmint
|
from planetmint import App, Planetmint
|
||||||
from planetmint.tendermint_utils import decode_transaction
|
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):
|
class ParallelValidationApp(App):
|
||||||
def __init__(self, planetmint=None, events_queue=None, abci=None):
|
def __init__(self, planetmint=None, events_queue=None):
|
||||||
super().__init__(planetmint, events_queue, abci=abci)
|
super().__init__(planetmint, events_queue)
|
||||||
self.parallel_validator = ParallelValidator()
|
self.parallel_validator = ParallelValidator()
|
||||||
self.parallel_validator.start()
|
self.parallel_validator.start()
|
||||||
|
|
||||||
def check_tx(self, raw_transaction):
|
def check_tx(self, raw_transaction):
|
||||||
return self.abci.ResponseCheckTx(code=CodeTypeOk)
|
return ResponseCheckTx(code=OkCode)
|
||||||
|
|
||||||
def deliver_tx(self, raw_transaction):
|
def deliver_tx(self, raw_transaction):
|
||||||
self.parallel_validator.validate(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):
|
def end_block(self, request_end_block):
|
||||||
result = self.parallel_validator.result(timeout=30)
|
result = self.parallel_validator.result(timeout=30)
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import setproctitle
|
import setproctitle
|
||||||
|
|
||||||
from abci import TmVersion, ABCI
|
#from abci import TmVersion, ABCI
|
||||||
|
|
||||||
import planetmint
|
import planetmint
|
||||||
from planetmint.lib import Planetmint
|
from planetmint.lib import Planetmint
|
||||||
@ -68,18 +68,16 @@ 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(
|
||||||
abci=abci.types,
|
|
||||||
events_queue=exchange.get_publisher_queue(),
|
events_queue=exchange.get_publisher_queue(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
app = ABCIServer(
|
app = ABCIServer(
|
||||||
app=App(
|
app=App(
|
||||||
abci=abci.types,
|
|
||||||
events_queue=exchange.get_publisher_queue(),
|
events_queue=exchange.get_publisher_queue(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -3,7 +3,7 @@ import binascii
|
|||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
import planetmint
|
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
|
from planetmint.common.exceptions import InvalidPublicKey, BigchainDBError
|
||||||
|
|
||||||
|
|
||||||
@ -17,8 +17,7 @@ def encode_validator(v):
|
|||||||
'check Planetmint configuration file')
|
'check Planetmint configuration file')
|
||||||
|
|
||||||
validator_update_t, pubkey_t = {
|
validator_update_t, pubkey_t = {
|
||||||
TmVersion.v0_22_8: (types_v0_22_8.Validator, types_v0_22_8.PubKey),
|
TmVersion.v0_34_11: (types_v0_34_11.ValidatorUpdate, types_v0_34_11.PubKey)
|
||||||
TmVersion.v0_31_5: (types_v0_31_5.ValidatorUpdate, types_v0_31_5.PubKey)
|
|
||||||
}[version]
|
}[version]
|
||||||
pub_key = pubkey_t(type='ed25519', data=bytes.fromhex(ed25519_public_key))
|
pub_key = pubkey_t(type='ed25519', data=bytes.fromhex(ed25519_public_key))
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -73,7 +73,7 @@ tests_require = [
|
|||||||
install_requires = [
|
install_requires = [
|
||||||
'chardet==3.0.4',
|
'chardet==3.0.4',
|
||||||
'aiohttp==3.7.4',
|
'aiohttp==3.7.4',
|
||||||
'bigchaindb-abci==1.0.7',
|
'abci==0.8.3',
|
||||||
'cryptoconditions==0.8.1',
|
'cryptoconditions==0.8.1',
|
||||||
'flask-cors==3.0.10',
|
'flask-cors==3.0.10',
|
||||||
'flask-restful==0.3.9',
|
'flask-restful==0.3.9',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user