From a74431f9d934f313e3a35635cd765eeae444013b Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Tue, 22 Nov 2022 11:18:56 -0800 Subject: [PATCH 01/10] Multi-ledger issues WIP Signed-off-by: Ian Costanzo --- aries_cloudagent/admin/server.py | 1 + demo/multi_ledger_config.yml | 8 ++++++-- demo/runners/agent_container.py | 4 +++- demo/runners/support/agent.py | 9 ++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/aries_cloudagent/admin/server.py b/aries_cloudagent/admin/server.py index 6d84de327d..c7ab79334d 100644 --- a/aries_cloudagent/admin/server.py +++ b/aries_cloudagent/admin/server.py @@ -370,6 +370,7 @@ async def check_multitenant_authorization(request: web.Request, handler): and not is_server_path and not is_unprotected_path(path) and not base_limited_access_path + and not (request.method == "OPTIONS") # CORS fix ): raise web.HTTPUnauthorized() diff --git a/demo/multi_ledger_config.yml b/demo/multi_ledger_config.yml index 3290f50d5e..88694188c9 100644 --- a/demo/multi_ledger_config.yml +++ b/demo/multi_ledger_config.yml @@ -1,6 +1,10 @@ -- id: bcorvinTest +- id: local is_production: true - genesis_url: 'http://test.bcovrin.vonx.io/genesis' + is_write: true + genesis_url: 'http://$LEDGER_HOST:9000/genesis' +#- id: bcorvinTest +# is_production: true +# genesis_url: 'http://dev.bcovrin.vonx.io/genesis' - id: greenlightTest is_production: true genesis_url: 'http://dev.greenlight.bcovrin.vonx.io/genesis' diff --git a/demo/runners/agent_container.py b/demo/runners/agent_container.py index a7ee7745ab..87b9ac203c 100644 --- a/demo/runners/agent_container.py +++ b/demo/runners/agent_container.py @@ -1274,9 +1274,11 @@ async def create_agent_with_args(args, ident: str = None): ) multi_ledger_config_path = None + genesis = None if "multi_ledger" in args and args.multi_ledger: multi_ledger_config_path = "./demo/multi_ledger_config.yml" - genesis = await default_genesis_txns() + else: + genesis = await default_genesis_txns() if not genesis and not multi_ledger_config_path: print("Error retrieving ledger genesis transactions") sys.exit(1) diff --git a/demo/runners/support/agent.py b/demo/runners/support/agent.py index 8398df1279..fb923a3028 100644 --- a/demo/runners/support/agent.py +++ b/demo/runners/support/agent.py @@ -213,6 +213,7 @@ def __init__( self.agency_wallet_did = self.did self.agency_wallet_key = self.wallet_key + self.multi_write_ledger_url = None if self.genesis_txn_list: updated_config_list = [] with open(self.genesis_txn_list, "r") as stream: @@ -225,6 +226,8 @@ def __init__( "$LEDGER_HOST", str(self.external_host) ) updated_config_list.append(config) + if "is_write" in config and config["is_write"]: + self.multi_write_ledger_url = config["genesis_url"].replace("/genesis", "") with open(self.genesis_txn_list, "w") as file: documents = yaml.dump(updated_config_list, file) @@ -479,7 +482,10 @@ async def register_did( # if registering a did for issuing indy credentials, publish the did on the ledger self.log(f"Registering {self.ident} ...") if not ledger_url: - ledger_url = LEDGER_URL + if self.multi_write_ledger_url: + ledger_url = self.multi_write_ledger_url + else: + ledger_url = LEDGER_URL if not ledger_url: ledger_url = f"http://{self.external_host}:9000" data = {"alias": alias or self.ident} @@ -501,6 +507,7 @@ async def register_did( await asyncio.sleep(3.0) nym_info = data else: + log_msg("using ledger: " + ledger_url + "/register") resp = await self.client_session.post( ledger_url + "/register", json=data ) From 6a627a2bfc1d2d4e74b2a28e127401a811578552 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Tue, 22 Nov 2022 15:53:33 -0800 Subject: [PATCH 02/10] Use write_ledger info globally in multi-ledger mode Signed-off-by: Ian Costanzo --- aries_cloudagent/config/argparse.py | 26 ++++++++++++++++++++------ aries_cloudagent/core/conductor.py | 4 ++-- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/aries_cloudagent/config/argparse.py b/aries_cloudagent/config/argparse.py index 6822f72c2f..260dc9a70b 100644 --- a/aries_cloudagent/config/argparse.py +++ b/aries_cloudagent/config/argparse.py @@ -872,31 +872,45 @@ def get_settings(self, args: Namespace) -> dict: if args.no_ledger: settings["ledger.disabled"] = True else: - configured = False + single_configured = False + multi_configured = False if args.genesis_url: settings["ledger.genesis_url"] = args.genesis_url - configured = True + single_configured = True elif args.genesis_file: settings["ledger.genesis_file"] = args.genesis_file - configured = True + single_configured = True elif args.genesis_transactions: settings["ledger.genesis_transactions"] = args.genesis_transactions - configured = True + single_configured = True if args.genesis_transactions_list: with open(args.genesis_transactions_list, "r") as stream: txn_config_list = yaml.safe_load(stream) ledger_config_list = [] for txn_config in txn_config_list: ledger_config_list.append(txn_config) + if "is_write" in txn_config and txn_config["is_write"]: + if "genesis_url" in txn_config: + settings["ledger.genesis_url"] = txn_config["genesis_url"] + elif "genesis_file" in txn_config: + settings["ledger.genesis_file"] = txn_config["genesis_file"] + elif "genesis_transactions" in txn_config: + settings["ledger.genesis_transactions"] = txn_config["genesis_transactions"] + else: + raise ArgsParseError("No genesis information provided for write ledger") settings["ledger.ledger_config_list"] = ledger_config_list - configured = True - if not configured: + multi_configured = True + if not (single_configured or multi_configured): raise ArgsParseError( "One of --genesis-url --genesis-file, --genesis-transactions " "or --genesis-transactions-list must be specified (unless " "--no-ledger is specified to explicitly configure aca-py to" " run with no ledger)." ) + if single_configured and multi_configured: + raise ArgsParseError( + "Cannot configure both single- and multi-ledger." + ) if args.ledger_pool_name: settings["ledger.pool_name"] = args.ledger_pool_name if args.ledger_keepalive: diff --git a/aries_cloudagent/core/conductor.py b/aries_cloudagent/core/conductor.py index c24862a4e9..edf881f84f 100644 --- a/aries_cloudagent/core/conductor.py +++ b/aries_cloudagent/core/conductor.py @@ -144,7 +144,7 @@ async def setup(self): self.root_profile.BACKEND_NAME == "askar" and ledger.BACKEND_NAME == "indy-vdr" ): - context.injector.bind_instance(BaseLedger, ledger) + # context.injector.bind_instance(BaseLedger, ledger) context.injector.bind_provider( IndyVerifier, ClassProvider( @@ -156,7 +156,7 @@ async def setup(self): self.root_profile.BACKEND_NAME == "indy" and ledger.BACKEND_NAME == "indy" ): - context.injector.bind_instance(BaseLedger, ledger) + # context.injector.bind_instance(BaseLedger, ledger) context.injector.bind_provider( IndyVerifier, ClassProvider( From 5f1c539d6b01a54fe5f85a84c8c713fe4a20ae05 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Tue, 22 Nov 2022 16:10:19 -0800 Subject: [PATCH 03/10] Formatting Signed-off-by: Ian Costanzo --- aries_cloudagent/config/argparse.py | 20 +++++++++++++------- aries_cloudagent/core/conductor.py | 2 +- demo/runners/support/agent.py | 4 +++- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/aries_cloudagent/config/argparse.py b/aries_cloudagent/config/argparse.py index 260dc9a70b..678028dcb7 100644 --- a/aries_cloudagent/config/argparse.py +++ b/aries_cloudagent/config/argparse.py @@ -891,13 +891,21 @@ def get_settings(self, args: Namespace) -> dict: ledger_config_list.append(txn_config) if "is_write" in txn_config and txn_config["is_write"]: if "genesis_url" in txn_config: - settings["ledger.genesis_url"] = txn_config["genesis_url"] + settings["ledger.genesis_url"] = txn_config[ + "genesis_url" + ] elif "genesis_file" in txn_config: - settings["ledger.genesis_file"] = txn_config["genesis_file"] + settings["ledger.genesis_file"] = txn_config[ + "genesis_file" + ] elif "genesis_transactions" in txn_config: - settings["ledger.genesis_transactions"] = txn_config["genesis_transactions"] + settings["ledger.genesis_transactions"] = txn_config[ + "genesis_transactions" + ] else: - raise ArgsParseError("No genesis information provided for write ledger") + raise ArgsParseError( + "No genesis information provided for write ledger" + ) settings["ledger.ledger_config_list"] = ledger_config_list multi_configured = True if not (single_configured or multi_configured): @@ -908,9 +916,7 @@ def get_settings(self, args: Namespace) -> dict: " run with no ledger)." ) if single_configured and multi_configured: - raise ArgsParseError( - "Cannot configure both single- and multi-ledger." - ) + raise ArgsParseError("Cannot configure both single- and multi-ledger.") if args.ledger_pool_name: settings["ledger.pool_name"] = args.ledger_pool_name if args.ledger_keepalive: diff --git a/aries_cloudagent/core/conductor.py b/aries_cloudagent/core/conductor.py index edf881f84f..d65133981b 100644 --- a/aries_cloudagent/core/conductor.py +++ b/aries_cloudagent/core/conductor.py @@ -28,7 +28,7 @@ from ..config.wallet import wallet_config from ..core.profile import Profile from ..indy.verifier import IndyVerifier -from ..ledger.base import BaseLedger +# from ..ledger.base import BaseLedger from ..ledger.error import LedgerConfigError, LedgerTransactionError from ..ledger.multiple_ledger.base_manager import ( BaseMultipleLedgerManager, diff --git a/demo/runners/support/agent.py b/demo/runners/support/agent.py index fb923a3028..1ec42565dc 100644 --- a/demo/runners/support/agent.py +++ b/demo/runners/support/agent.py @@ -227,7 +227,9 @@ def __init__( ) updated_config_list.append(config) if "is_write" in config and config["is_write"]: - self.multi_write_ledger_url = config["genesis_url"].replace("/genesis", "") + self.multi_write_ledger_url = config["genesis_url"].replace( + "/genesis", "" + ) with open(self.genesis_txn_list, "w") as file: documents = yaml.dump(updated_config_list, file) From 26875d4c1f96f94eee3897a16dbdf10650b33ec1 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Tue, 22 Nov 2022 17:06:57 -0800 Subject: [PATCH 04/10] Add multi/multi integration test Signed-off-by: Ian Costanzo --- demo/features/0586-sign-transaction.feature | 1 + demo/multi_ledger_config.yml | 10 +++++----- docker/Dockerfile.bdd | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/demo/features/0586-sign-transaction.feature b/demo/features/0586-sign-transaction.feature index 1a66ef69ab..261800926d 100644 --- a/demo/features/0586-sign-transaction.feature +++ b/demo/features/0586-sign-transaction.feature @@ -25,6 +25,7 @@ Feature: RFC 0586 Aries sign (endorse) transactions functions | --mediation | --mediation | driverslicense | | --multitenant | --multitenant | driverslicense | | --mediation --multitenant | --mediation --multitenant | driverslicense | + | --multitenant --multi-ledger | --multitenant --multi-ledger | driverslicense | @T001.1-RFC0586 @GHA diff --git a/demo/multi_ledger_config.yml b/demo/multi_ledger_config.yml index 88694188c9..c3d19f1cc9 100644 --- a/demo/multi_ledger_config.yml +++ b/demo/multi_ledger_config.yml @@ -1,10 +1,10 @@ -- id: local +#- id: local +# is_production: true +# genesis_url: 'http://$LEDGER_HOST:9000/genesis' +- id: bcorvinTest is_production: true is_write: true - genesis_url: 'http://$LEDGER_HOST:9000/genesis' -#- id: bcorvinTest -# is_production: true -# genesis_url: 'http://dev.bcovrin.vonx.io/genesis' + genesis_url: 'http://dev.bcovrin.vonx.io/genesis' - id: greenlightTest is_production: true genesis_url: 'http://dev.greenlight.bcovrin.vonx.io/genesis' diff --git a/docker/Dockerfile.bdd b/docker/Dockerfile.bdd index cacf38b6aa..f821d813ec 100644 --- a/docker/Dockerfile.bdd +++ b/docker/Dockerfile.bdd @@ -4,5 +4,6 @@ FROM faber-alice-demo RUN pip3 install --no-cache-dir -r demo/requirements.behave.txt WORKDIR ./demo +ADD demo ./demo RUN chmod a+w . ENTRYPOINT ["behave"] From 3e8802c53539aae8954f58ceaa8e6c67339f0cec Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Tue, 22 Nov 2022 17:19:23 -0800 Subject: [PATCH 05/10] Fix multi-leg config Signed-off-by: Ian Costanzo --- demo/multi_ledger_config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/multi_ledger_config.yml b/demo/multi_ledger_config.yml index c3d19f1cc9..b4b07d1c64 100644 --- a/demo/multi_ledger_config.yml +++ b/demo/multi_ledger_config.yml @@ -4,7 +4,7 @@ - id: bcorvinTest is_production: true is_write: true - genesis_url: 'http://dev.bcovrin.vonx.io/genesis' + genesis_url: 'http://test.bcovrin.vonx.io/genesis' - id: greenlightTest is_production: true - genesis_url: 'http://dev.greenlight.bcovrin.vonx.io/genesis' + genesis_url: 'http://test.greenlight.bcovrin.vonx.io/genesis' From 24c9fb3cd5eeb1cc3f24fdd7d820b0f36cb1aa33 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Tue, 22 Nov 2022 17:20:14 -0800 Subject: [PATCH 06/10] Fix multi-leg config Signed-off-by: Ian Costanzo --- demo/multi_ledger_config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/multi_ledger_config.yml b/demo/multi_ledger_config.yml index b4b07d1c64..2c423b8d51 100644 --- a/demo/multi_ledger_config.yml +++ b/demo/multi_ledger_config.yml @@ -7,4 +7,4 @@ genesis_url: 'http://test.bcovrin.vonx.io/genesis' - id: greenlightTest is_production: true - genesis_url: 'http://test.greenlight.bcovrin.vonx.io/genesis' + genesis_url: 'http://dev.greenlight.bcovrin.vonx.io/genesis' From 80049e7e8ffac75b63b69970cb5c4e4c1031bc46 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Wed, 23 Nov 2022 06:27:38 -0800 Subject: [PATCH 07/10] Formatting Signed-off-by: Ian Costanzo --- aries_cloudagent/core/conductor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aries_cloudagent/core/conductor.py b/aries_cloudagent/core/conductor.py index d65133981b..9f03e8baf1 100644 --- a/aries_cloudagent/core/conductor.py +++ b/aries_cloudagent/core/conductor.py @@ -28,6 +28,7 @@ from ..config.wallet import wallet_config from ..core.profile import Profile from ..indy.verifier import IndyVerifier + # from ..ledger.base import BaseLedger from ..ledger.error import LedgerConfigError, LedgerTransactionError from ..ledger.multiple_ledger.base_manager import ( From f9867fdda5bc2662e999b9a32d54876a50cff9fb Mon Sep 17 00:00:00 2001 From: shaangill025 Date: Wed, 23 Nov 2022 10:50:37 -0800 Subject: [PATCH 08/10] fix for ledger.pool_name Signed-off-by: shaangill025 --- aries_cloudagent/config/argparse.py | 41 ++++++++++++++++++++++------- aries_cloudagent/core/conductor.py | 3 --- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/aries_cloudagent/config/argparse.py b/aries_cloudagent/config/argparse.py index 6822f72c2f..b372bb56ce 100644 --- a/aries_cloudagent/config/argparse.py +++ b/aries_cloudagent/config/argparse.py @@ -75,10 +75,8 @@ def create_argument_parser(*, prog: str = None): def load_argument_groups(parser: ArgumentParser, *groups: Type[ArgumentGroup]): """Log a set of argument groups into a parser. - Returns: A callable to convert loaded arguments into a settings dictionary - """ group_inst = [] for group in groups: @@ -872,32 +870,56 @@ def get_settings(self, args: Namespace) -> dict: if args.no_ledger: settings["ledger.disabled"] = True else: - configured = False + single_configured = False + multi_configured = False + update_pool_name = False if args.genesis_url: settings["ledger.genesis_url"] = args.genesis_url - configured = True + single_configured = True elif args.genesis_file: settings["ledger.genesis_file"] = args.genesis_file - configured = True + single_configured = True elif args.genesis_transactions: settings["ledger.genesis_transactions"] = args.genesis_transactions - configured = True + single_configured = True if args.genesis_transactions_list: with open(args.genesis_transactions_list, "r") as stream: txn_config_list = yaml.safe_load(stream) ledger_config_list = [] for txn_config in txn_config_list: ledger_config_list.append(txn_config) + if "is_write" in txn_config and txn_config["is_write"]: + if "genesis_url" in txn_config: + settings["ledger.genesis_url"] = txn_config[ + "genesis_url" + ] + elif "genesis_file" in txn_config: + settings["ledger.genesis_file"] = txn_config[ + "genesis_file" + ] + elif "genesis_transactions" in txn_config: + settings["ledger.genesis_transactions"] = txn_config[ + "genesis_transactions" + ] + else: + raise ArgsParseError( + "No genesis information provided for write ledger" + ) + if "id" in txn_config: + settings["ledger.pool_name"] = txn_config["id"] + update_pool_name = True settings["ledger.ledger_config_list"] = ledger_config_list - configured = True - if not configured: + multi_configured = True + if not (single_configured or multi_configured): raise ArgsParseError( "One of --genesis-url --genesis-file, --genesis-transactions " "or --genesis-transactions-list must be specified (unless " "--no-ledger is specified to explicitly configure aca-py to" " run with no ledger)." ) - if args.ledger_pool_name: + if single_configured and multi_configured: + raise ArgsParseError("Cannot configure both single- and multi-ledger.") + if args.ledger_pool_name and not update_pool_name: settings["ledger.pool_name"] = args.ledger_pool_name if args.ledger_keepalive: settings["ledger.keepalive"] = args.ledger_keepalive @@ -1327,7 +1349,6 @@ def get_settings(self, args: Namespace): class MediationInviteGroup(ArgumentGroup): """ Mediation invitation settings. - These can be provided at provision- and start-time. """ diff --git a/aries_cloudagent/core/conductor.py b/aries_cloudagent/core/conductor.py index c24862a4e9..eb79c819a2 100644 --- a/aries_cloudagent/core/conductor.py +++ b/aries_cloudagent/core/conductor.py @@ -28,7 +28,6 @@ from ..config.wallet import wallet_config from ..core.profile import Profile from ..indy.verifier import IndyVerifier -from ..ledger.base import BaseLedger from ..ledger.error import LedgerConfigError, LedgerTransactionError from ..ledger.multiple_ledger.base_manager import ( BaseMultipleLedgerManager, @@ -144,7 +143,6 @@ async def setup(self): self.root_profile.BACKEND_NAME == "askar" and ledger.BACKEND_NAME == "indy-vdr" ): - context.injector.bind_instance(BaseLedger, ledger) context.injector.bind_provider( IndyVerifier, ClassProvider( @@ -156,7 +154,6 @@ async def setup(self): self.root_profile.BACKEND_NAME == "indy" and ledger.BACKEND_NAME == "indy" ): - context.injector.bind_instance(BaseLedger, ledger) context.injector.bind_provider( IndyVerifier, ClassProvider( From 53b413b451aa12b3b18ea81a577fa1e9e035ba00 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Wed, 23 Nov 2022 13:30:38 -0800 Subject: [PATCH 09/10] Comment formatting: Signed-off-by: Ian Costanzo --- aries_cloudagent/config/argparse.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/aries_cloudagent/config/argparse.py b/aries_cloudagent/config/argparse.py index b372bb56ce..d19bff39c6 100644 --- a/aries_cloudagent/config/argparse.py +++ b/aries_cloudagent/config/argparse.py @@ -74,9 +74,12 @@ def create_argument_parser(*, prog: str = None): def load_argument_groups(parser: ArgumentParser, *groups: Type[ArgumentGroup]): - """Log a set of argument groups into a parser. + """ + Log a set of argument groups into a parser. + Returns: A callable to convert loaded arguments into a settings dictionary + """ group_inst = [] for group in groups: @@ -1349,6 +1352,7 @@ def get_settings(self, args: Namespace): class MediationInviteGroup(ArgumentGroup): """ Mediation invitation settings. + These can be provided at provision- and start-time. """ From 724aceb529ee1dfce437fbfe54dc371fcb0b1fd4 Mon Sep 17 00:00:00 2001 From: Ian Costanzo Date: Wed, 23 Nov 2022 13:58:40 -0800 Subject: [PATCH 10/10] Integration test for the multi/multi scenario Signed-off-by: Ian Costanzo --- demo/features/taa-txn-author-acceptance.feature | 2 ++ demo/multi_ledger_config_bdd.yml | 11 +++++++++++ docker/Dockerfile.bdd | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 demo/multi_ledger_config_bdd.yml diff --git a/demo/features/taa-txn-author-acceptance.feature b/demo/features/taa-txn-author-acceptance.feature index 55d5790227..ac8274c1ec 100644 --- a/demo/features/taa-txn-author-acceptance.feature +++ b/demo/features/taa-txn-author-acceptance.feature @@ -17,6 +17,8 @@ Feature: TAA Transaction Author Agreement related tests | --taa-accept | driverslicense | | --taa-accept --multitenant | driverslicense | | --taa-accept --revocation | driverslicense | + | --taa-accept --multi-ledger | driverslicense | + | --taa-accept --multitenant --multi-ledger | driverslicense | @T001a-TAA @taa_required Scenario Outline: accept the ledger TAA and write to the ledger via endorser diff --git a/demo/multi_ledger_config_bdd.yml b/demo/multi_ledger_config_bdd.yml new file mode 100644 index 0000000000..14f7919fe1 --- /dev/null +++ b/demo/multi_ledger_config_bdd.yml @@ -0,0 +1,11 @@ +- id: local + is_production: true + is_write: true + genesis_url: 'http://$LEDGER_HOST:9000/genesis' +- id: bcorvinTest + is_production: true +# is_write: true + genesis_url: 'http://test.bcovrin.vonx.io/genesis' +- id: greenlightTest + is_production: true + genesis_url: 'http://dev.greenlight.bcovrin.vonx.io/genesis' diff --git a/docker/Dockerfile.bdd b/docker/Dockerfile.bdd index f821d813ec..d2e6c2098a 100644 --- a/docker/Dockerfile.bdd +++ b/docker/Dockerfile.bdd @@ -4,6 +4,6 @@ FROM faber-alice-demo RUN pip3 install --no-cache-dir -r demo/requirements.behave.txt WORKDIR ./demo -ADD demo ./demo +ADD demo/multi_ledger_config_bdd.yml ./demo/multi_ledger_config.yml RUN chmod a+w . ENTRYPOINT ["behave"]