mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Panic when receive inconsistent data in InitChain.
This commit is contained in:
parent
7730719b3c
commit
b5fe2b15ce
@ -6,6 +6,7 @@
|
|||||||
with Tendermint.
|
with Tendermint.
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
from abci.application import BaseApplication
|
from abci.application import BaseApplication
|
||||||
from abci.types_pb2 import (
|
from abci.types_pb2 import (
|
||||||
@ -63,14 +64,14 @@ class App(BaseApplication):
|
|||||||
'the chain {chain_id} is already synced.'
|
'the chain {chain_id} is already synced.'
|
||||||
|
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
return ResponseInitChain()
|
sys.exit(1)
|
||||||
|
|
||||||
if chain_id != genesis.chain_id:
|
if chain_id != genesis.chain_id:
|
||||||
msg = f'Got mismatching chain ID in the InitChain ' + \
|
msg = f'Got mismatching chain ID in the InitChain ' + \
|
||||||
'ABCI request - you need to migrate the ABCI client ' + \
|
'ABCI request - you need to migrate the ABCI client ' + \
|
||||||
'and set new chain ID: {chain_id}.'
|
'and set new chain ID: {chain_id}.'
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
return ResponseInitChain()
|
sys.exit(1)
|
||||||
|
|
||||||
# set migration values for app hash and height
|
# set migration values for app hash and height
|
||||||
block = self.bigchaindb.get_latest_block()
|
block = self.bigchaindb.get_latest_block()
|
||||||
@ -86,7 +87,7 @@ class App(BaseApplication):
|
|||||||
'ABCI request - you need to migrate the ABCI client ' + \
|
'ABCI request - you need to migrate the ABCI client ' + \
|
||||||
'and set new validator set: {known_validators}.'
|
'and set new validator set: {known_validators}.'
|
||||||
logger.error(msg)
|
logger.error(msg)
|
||||||
return ResponseInitChain()
|
sys.exit(1)
|
||||||
|
|
||||||
block = Block(app_hash=app_hash, height=height, transactions=[])
|
block = Block(app_hash=app_hash, height=height, transactions=[])
|
||||||
self.bigchaindb.store_block(block._asdict())
|
self.bigchaindb.store_block(block._asdict())
|
||||||
|
|||||||
@ -81,8 +81,8 @@ def test_init_chain_ignores_invalid_init_chain_requests(b):
|
|||||||
generate_init_chain_request('chain-ABC', validators),
|
generate_init_chain_request('chain-ABC', validators),
|
||||||
]
|
]
|
||||||
for r in invalid_requests:
|
for r in invalid_requests:
|
||||||
res = App(b).init_chain(r)
|
with pytest.raises(SystemExit):
|
||||||
assert res == ResponseInitChain()
|
App(b).init_chain(r)
|
||||||
# assert nothing changed - neither validator set, nor chain ID
|
# assert nothing changed - neither validator set, nor chain ID
|
||||||
new_validator_set = query.get_validator_set(b.connection)
|
new_validator_set = query.get_validator_set(b.connection)
|
||||||
assert new_validator_set == validator_set
|
assert new_validator_set == validator_set
|
||||||
@ -116,8 +116,8 @@ def test_init_chain_recognizes_new_chain_after_migration(b):
|
|||||||
generate_init_chain_request('chain-XYZ-migrated-at-height-1'),
|
generate_init_chain_request('chain-XYZ-migrated-at-height-1'),
|
||||||
]
|
]
|
||||||
for r in invalid_requests:
|
for r in invalid_requests:
|
||||||
res = App(b).init_chain(r)
|
with pytest.raises(SystemExit):
|
||||||
assert res == ResponseInitChain()
|
App(b).init_chain(r)
|
||||||
assert query.get_latest_abci_chain(b.connection) == {
|
assert query.get_latest_abci_chain(b.connection) == {
|
||||||
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
||||||
'is_synced': False,
|
'is_synced': False,
|
||||||
@ -150,8 +150,8 @@ def test_init_chain_recognizes_new_chain_after_migration(b):
|
|||||||
generate_init_chain_request('chain-XYZ-migrated-at-height-1'),
|
generate_init_chain_request('chain-XYZ-migrated-at-height-1'),
|
||||||
]
|
]
|
||||||
for r in invalid_requests:
|
for r in invalid_requests:
|
||||||
res = App(b).init_chain(r)
|
with pytest.raises(SystemExit):
|
||||||
assert res == ResponseInitChain()
|
App(b).init_chain(r)
|
||||||
assert query.get_latest_abci_chain(b.connection) == {
|
assert query.get_latest_abci_chain(b.connection) == {
|
||||||
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
'chain_id': 'chain-XYZ-migrated-at-height-1',
|
||||||
'is_synced': True,
|
'is_synced': True,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user