mirror of
https://github.com/planetmint/planetmint.git
synced 2025-03-30 15:08:31 +00:00
392 abci rpc is not defined for election proposals (#397)
* fixed missing abci_rpc initialization * bumped versions and added changelog * sq fixes Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
b2bca169ec
commit
4c55f576b9
@ -25,6 +25,11 @@ For reference, the possible headings are:
|
||||
* **Known Issues**
|
||||
* **Notes**
|
||||
|
||||
## [2.4.6] - 2023-2-05
|
||||
* **Fixed** Missing ABCI_RPC object initiailization for CLI voting commands.
|
||||
* **Fixed** TypeError in EndBlock procedure that occured rarely within the network.
|
||||
* **Security** moved to a more secure requests version
|
||||
|
||||
## [2.4.5] - 2023-21-04
|
||||
* **Fixed** Integration of DataAccessor Singleton class to reduce potentially multiple DB driver initializations.
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
---
|
||||
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||
# Planetmint and IPDB software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
|
@ -120,11 +120,8 @@ def test_env_config(monkeypatch):
|
||||
assert result == expected
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_autoconfigure_read_both_from_file_and_env(
|
||||
monkeypatch, request
|
||||
): # TODO Disabled until we create a better config format
|
||||
return
|
||||
@pytest.mark.skip(reason="Disabled until we create a better config format")
|
||||
def test_autoconfigure_read_both_from_file_and_env(monkeypatch, request):
|
||||
# constants
|
||||
DATABASE_HOST = "test-host"
|
||||
DATABASE_NAME = "test-dbname"
|
||||
|
@ -1,3 +1,4 @@
|
||||
---
|
||||
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||
# Planetmint and IPDB software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
@ -35,6 +36,3 @@ services:
|
||||
- ./integration/scripts:/scripts
|
||||
- ./integration/cli:/tests
|
||||
- shared:/shared
|
||||
|
||||
volumes:
|
||||
shared:
|
@ -1,3 +1,4 @@
|
||||
---
|
||||
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||
# Planetmint and IPDB software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
|
@ -189,7 +189,6 @@ def main():
|
||||
ctx["public_keys_transfer"] = tx_transfer.outputs[0].public_keys[0]
|
||||
ctx["tx_transfer_id"] = tx_transfer.id
|
||||
|
||||
# privkey_transfer_last = 'sG3jWDtdTXUidBJK53ucSTrosktG616U3tQHBk81eQe'
|
||||
pubkey_transfer_last = "3Af3fhhjU6d9WecEM9Uw5hfom9kNEwE7YuDWdqAUssqm"
|
||||
|
||||
cid = 0
|
||||
|
@ -198,7 +198,6 @@ todo_include_todos = False
|
||||
# a list of builtin themes.
|
||||
#
|
||||
html_theme = "press"
|
||||
# html_theme = 'sphinx_documatt_theme'
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
|
@ -1,3 +1,4 @@
|
||||
---
|
||||
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||
# Planetmint and IPDB software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
|
@ -1,3 +1,4 @@
|
||||
---
|
||||
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||
# Planetmint and IPDB software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
|
@ -1,3 +1,4 @@
|
||||
---
|
||||
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||
# Planetmint and IPDB software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
|
@ -1,3 +1,4 @@
|
||||
---
|
||||
# Copyright © 2020 Interplanetary Database Association e.V.,
|
||||
# Planetmint and IPDB software contributors.
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
|
@ -81,9 +81,7 @@ class ApplicationLogic(BaseApplication):
|
||||
chain_id = known_chain["chain_id"]
|
||||
|
||||
if known_chain["is_synced"]:
|
||||
msg = (
|
||||
f"Got invalid InitChain ABCI request ({genesis}) - " f"the chain {chain_id} is already synced."
|
||||
)
|
||||
msg = f"Got invalid InitChain ABCI request ({genesis}) - the chain {chain_id} is already synced."
|
||||
logger.error(msg)
|
||||
sys.exit(1)
|
||||
if chain_id != genesis.chain_id:
|
||||
@ -238,7 +236,7 @@ class ApplicationLogic(BaseApplication):
|
||||
block_txn_hash = calculate_hash(self.block_txn_ids)
|
||||
block = self.validator.models.get_latest_block()
|
||||
|
||||
logger.debug("BLOCK: ", block)
|
||||
logger.debug(f"BLOCK: {block}")
|
||||
if self.block_txn_ids:
|
||||
self.block_txn_hash = calculate_hash([block["app_hash"], block_txn_hash])
|
||||
else:
|
||||
@ -279,7 +277,7 @@ class ApplicationLogic(BaseApplication):
|
||||
sys.exit(1)
|
||||
|
||||
logger.debug(
|
||||
"Commit-ing new block with hash: apphash=%s ," "height=%s, txn ids=%s",
|
||||
"Commit-ing new block with hash: apphash=%s, height=%s, txn ids=%s",
|
||||
data,
|
||||
self.new_height,
|
||||
self.block_txn_ids,
|
||||
|
@ -79,7 +79,6 @@ def new_validator_set(validators, updates):
|
||||
|
||||
def get_public_key_decoder(pk):
|
||||
encoding = pk["type"]
|
||||
decoder = base64.b64decode
|
||||
|
||||
if encoding == "ed25519-base16":
|
||||
decoder = base64.b16decode
|
||||
|
@ -61,9 +61,7 @@ class Validator:
|
||||
if tx.operation != Transaction.COMPOSE:
|
||||
asset_id = tx.get_asset_id(input_txs)
|
||||
if asset_id != Transaction.read_out_asset_id(tx):
|
||||
raise AssetIdMismatch(
|
||||
("The asset id of the input does not" " match the asset id of the" " transaction")
|
||||
)
|
||||
raise AssetIdMismatch(("The asset id of the input does not match the asset id of the transaction"))
|
||||
else:
|
||||
asset_ids = Transaction.get_asset_ids(input_txs)
|
||||
if Transaction.read_out_asset_id(tx) in asset_ids:
|
||||
@ -105,9 +103,9 @@ class Validator:
|
||||
|
||||
if output_amount != input_amount:
|
||||
raise AmountError(
|
||||
(
|
||||
"The amount used in the inputs `{}`" " needs to be same as the amount used" " in the outputs `{}`"
|
||||
).format(input_amount, output_amount)
|
||||
"The amount used in the inputs `{}` needs to be same as the amount used in the outputs `{}`".format(
|
||||
input_amount, output_amount
|
||||
)
|
||||
)
|
||||
|
||||
return True
|
||||
@ -202,7 +200,7 @@ class Validator:
|
||||
raise InvalidProposer("Public key is not a part of the validator set")
|
||||
|
||||
# NOTE: Check if all validators have been assigned votes equal to their voting power
|
||||
if not self.is_same_topology(current_validators, transaction.outputs):
|
||||
if not Validator.is_same_topology(current_validators, transaction.outputs):
|
||||
raise UnequalValidatorSet("Validator set much be exactly same to the outputs of election")
|
||||
|
||||
if transaction.operation == VALIDATOR_ELECTION:
|
||||
@ -210,7 +208,8 @@ class Validator:
|
||||
|
||||
return transaction
|
||||
|
||||
def is_same_topology(cls, current_topology, election_topology):
|
||||
@staticmethod
|
||||
def is_same_topology(current_topology, election_topology):
|
||||
voters = {}
|
||||
for voter in election_topology:
|
||||
if len(voter.public_keys) > 1:
|
||||
|
@ -73,7 +73,7 @@ class LocalMongoDBConnection(DBConnection):
|
||||
try:
|
||||
return query.run(self.connect())
|
||||
except pymongo.errors.AutoReconnect:
|
||||
logger.warning("Lost connection to the database, " "retrying query.")
|
||||
logger.warning("Lost connection to the database, retrying query.")
|
||||
return query.run(self.connect())
|
||||
except pymongo.errors.AutoReconnect as exc:
|
||||
raise ConnectionError from exc
|
||||
|
@ -68,12 +68,14 @@ class Output:
|
||||
|
||||
@staticmethod
|
||||
def outputs_dict(output: dict, transaction_id: str = "") -> Output:
|
||||
out_dict: Output
|
||||
if output["condition"]["details"].get("subconditions") is None:
|
||||
out_dict = Output.output_with_public_key(output, transaction_id)
|
||||
else:
|
||||
out_dict = Output.output_with_sub_conditions(output, transaction_id)
|
||||
return out_dict
|
||||
return Output(
|
||||
transaction_id=transaction_id,
|
||||
public_keys=output["public_keys"],
|
||||
amount=output["amount"],
|
||||
condition=Condition(
|
||||
uri=output["condition"]["uri"], details=ConditionDetails.from_dict(output["condition"]["details"])
|
||||
),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def from_tuple(output: tuple) -> Output:
|
||||
@ -110,25 +112,3 @@ class Output:
|
||||
@staticmethod
|
||||
def list_to_dict(output_list: list[Output]) -> list[dict]:
|
||||
return [output.to_dict() for output in output_list or []]
|
||||
|
||||
@staticmethod
|
||||
def output_with_public_key(output, transaction_id) -> Output:
|
||||
return Output(
|
||||
transaction_id=transaction_id,
|
||||
public_keys=output["public_keys"],
|
||||
amount=output["amount"],
|
||||
condition=Condition(
|
||||
uri=output["condition"]["uri"], details=ConditionDetails.from_dict(output["condition"]["details"])
|
||||
),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def output_with_sub_conditions(output, transaction_id) -> Output:
|
||||
return Output(
|
||||
transaction_id=transaction_id,
|
||||
public_keys=output["public_keys"],
|
||||
amount=output["amount"],
|
||||
condition=Condition(
|
||||
uri=output["condition"]["uri"], details=ConditionDetails.from_dict(output["condition"]["details"])
|
||||
),
|
||||
)
|
||||
|
@ -29,7 +29,7 @@ from planetmint.backend import schema
|
||||
from planetmint.commands import utils
|
||||
from planetmint.commands.utils import configure_planetmint, input_on_stderr
|
||||
from planetmint.config_utils import setup_logging
|
||||
from planetmint.abci.rpc import MODE_COMMIT, MODE_LIST
|
||||
from planetmint.abci.rpc import ABCI_RPC, MODE_COMMIT, MODE_LIST
|
||||
from planetmint.abci.utils import load_node_key, public_key_from_base64
|
||||
from planetmint.commands.election_types import elections
|
||||
from planetmint.version import __tm_supported_versions__
|
||||
@ -111,14 +111,18 @@ def run_election(args):
|
||||
"""Initiate and manage elections"""
|
||||
|
||||
b = Validator()
|
||||
abci_rpc = ABCI_RPC()
|
||||
|
||||
# Call the function specified by args.action, as defined above
|
||||
globals()[f"run_election_{args.action}"](args, b)
|
||||
if args.action == "show":
|
||||
run_election_show(args, b)
|
||||
else:
|
||||
# Call the function specified by args.action, as defined above
|
||||
globals()[f"run_election_{args.action}"](args, b, abci_rpc)
|
||||
|
||||
|
||||
def run_election_new(args, planet):
|
||||
def run_election_new(args, planet, abci_rpc):
|
||||
election_type = args.election_type.replace("-", "_")
|
||||
globals()[f"run_election_new_{election_type}"](args, planet)
|
||||
globals()[f"run_election_new_{election_type}"](args, planet, abci_rpc)
|
||||
|
||||
|
||||
def create_new_election(sk, planet, election_class, data, abci_rpc):
|
||||
@ -186,7 +190,7 @@ def run_election_new_chain_migration(args, planet, abci_rpc):
|
||||
return create_new_election(args.sk, planet, ChainMigrationElection, [{"data": {}}], abci_rpc)
|
||||
|
||||
|
||||
def run_election_approve(args, validator: Validator, abci_rpc):
|
||||
def run_election_approve(args, validator: Validator, abci_rpc: ABCI_RPC):
|
||||
"""Approve an election
|
||||
|
||||
:param args: dict
|
||||
|
@ -117,8 +117,8 @@ class Config(metaclass=Singleton):
|
||||
def set(self, config):
|
||||
self._private_real_config = config
|
||||
|
||||
def get_db_key_map(sefl, db):
|
||||
return sefl.__private_database_keys_map[db]
|
||||
def get_db_key_map(self, db):
|
||||
return self.__private_database_keys_map[db]
|
||||
|
||||
def get_db_map(sefl, db):
|
||||
return sefl.__private_database_map[db]
|
||||
@ -131,16 +131,12 @@ DEFAULT_LOGGING_CONFIG = {
|
||||
"formatters": {
|
||||
"console": {
|
||||
"class": "logging.Formatter",
|
||||
"format": (
|
||||
"[%(asctime)s] [%(levelname)s] (%(name)s) " "%(message)s (%(processName)-10s - pid: %(process)d)"
|
||||
),
|
||||
"format": ("[%(asctime)s] [%(levelname)s] (%(name)s) %(message)s (%(processName)-10s - pid: %(process)d)"),
|
||||
"datefmt": "%Y-%m-%d %H:%M:%S",
|
||||
},
|
||||
"file": {
|
||||
"class": "logging.Formatter",
|
||||
"format": (
|
||||
"[%(asctime)s] [%(levelname)s] (%(name)s) " "%(message)s (%(processName)-10s - pid: %(process)d)"
|
||||
),
|
||||
"format": ("[%(asctime)s] [%(levelname)s] (%(name)s) %(message)s (%(processName)-10s - pid: %(process)d)"),
|
||||
"datefmt": "%Y-%m-%d %H:%M:%S",
|
||||
},
|
||||
},
|
||||
|
@ -337,7 +337,6 @@ class DataAccessor(metaclass=Singleton):
|
||||
str: Merkle root in hexadecimal form.
|
||||
"""
|
||||
utxoset = backend.query.get_unspent_outputs(self.connection)
|
||||
# TODO Once ready, use the already pre-computed utxo_hash field.
|
||||
# See common/transactions.py for details.
|
||||
|
||||
hashes = [
|
||||
@ -346,5 +345,4 @@ class DataAccessor(metaclass=Singleton):
|
||||
|
||||
print(sorted(hashes))
|
||||
|
||||
# TODO Notice the sorted call!
|
||||
return merkleroot(sorted(hashes))
|
||||
|
@ -3,6 +3,7 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import setproctitle
|
||||
|
||||
@ -94,4 +95,4 @@ def start(args):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
start()
|
||||
start(sys.argv)
|
||||
|
@ -3,7 +3,7 @@
|
||||
# SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0)
|
||||
# Code is Apache-2.0 and docs are CC-BY-4.0
|
||||
|
||||
__version__ = "2.4.5"
|
||||
__version__ = "2.4.6"
|
||||
__short_version__ = "2.4"
|
||||
|
||||
# Supported Tendermint versions
|
||||
|
@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = "planetmint"
|
||||
version = "2.4.5"
|
||||
version = "2.4.6"
|
||||
description = "Planetmint: The Blockchain Database"
|
||||
authors = ["Planetmint contributors"]
|
||||
license = "AGPLv3"
|
||||
|
@ -26,6 +26,9 @@ from planetmint.backend.connection import Connection
|
||||
from tests.utils import generate_election, generate_validators
|
||||
|
||||
|
||||
rpc_write_transaction_string = "planetmint.abci.rpc.ABCI_RPC.write_transaction"
|
||||
|
||||
|
||||
def mock_get_validators(self, height):
|
||||
return [
|
||||
{
|
||||
@ -57,7 +60,7 @@ def test_chain_migration_election_show_shows_inconclusive(b_flushed, test_abci_r
|
||||
b = b_flushed
|
||||
|
||||
validators = generate_validators([1] * 4)
|
||||
output = b.models.store_validator_set(1, [v["storage"] for v in validators])
|
||||
_ = b.models.store_validator_set(1, [v["storage"] for v in validators])
|
||||
|
||||
public_key = validators[0]["public_key"]
|
||||
private_key = validators[0]["private_key"]
|
||||
@ -465,7 +468,7 @@ def test_election_new_upsert_validator_without_tendermint(
|
||||
from planetmint.model.dataaccessor import DataAccessor
|
||||
|
||||
m.setattr(DataAccessor, "get_validators", mock_get_validators)
|
||||
m.setattr("planetmint.abci.rpc.ABCI_RPC.write_transaction", mock_write)
|
||||
m.setattr(rpc_write_transaction_string, mock_write)
|
||||
|
||||
args = Namespace(
|
||||
action="new",
|
||||
@ -505,7 +508,7 @@ def test_election_new_chain_migration_without_tendermint(
|
||||
from planetmint.model.dataaccessor import DataAccessor
|
||||
|
||||
m.setattr(DataAccessor, "get_validators", mock_get_validators)
|
||||
m.setattr("planetmint.abci.rpc.ABCI_RPC.write_transaction", mock_write)
|
||||
m.setattr(rpc_write_transaction_string, mock_write)
|
||||
|
||||
args = Namespace(action="new", election_type="migration", sk=priv_validator_path, config={})
|
||||
|
||||
@ -546,7 +549,7 @@ def test_election_new_upsert_validator_invalid_power(
|
||||
from planetmint.model.dataaccessor import DataAccessor
|
||||
|
||||
m.setattr(DataAccessor, "get_validators", mock_get_validators)
|
||||
m.setattr("planetmint.abci.rpc.ABCI_RPC.write_transaction", mock_write)
|
||||
m.setattr(rpc_write_transaction_string, mock_write)
|
||||
|
||||
args = Namespace(
|
||||
action="new",
|
||||
@ -600,7 +603,7 @@ def test_election_approve_without_tendermint(
|
||||
from planetmint.model.dataaccessor import DataAccessor
|
||||
|
||||
m.setattr(DataAccessor, "get_validators", mock_get_validators)
|
||||
m.setattr("planetmint.abci.rpc.ABCI_RPC.write_transaction", mock_write)
|
||||
m.setattr(rpc_write_transaction_string, mock_write)
|
||||
|
||||
b, election_id = call_election_internal(b, new_validator, node_key)
|
||||
|
||||
@ -674,7 +677,7 @@ def call_election(monkeypatch, b, new_validator, node_key, abci_rpc):
|
||||
from planetmint.model.dataaccessor import DataAccessor
|
||||
|
||||
m.setattr(DataAccessor, "get_validators", mock_get_validators)
|
||||
m.setattr("planetmint.abci.rpc.ABCI_RPC.write_transaction", mock_write)
|
||||
m.setattr(rpc_write_transaction_string, mock_write)
|
||||
b, election_id = call_election_internal(b, new_validator, node_key)
|
||||
m.undo()
|
||||
return b, election_id
|
||||
|
Loading…
x
Reference in New Issue
Block a user