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': {
|
||||
'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'],
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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(),
|
||||
)
|
||||
)
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user