Skip to content

Commit

Permalink
Merge pull request openwallet-foundation#2836 from esune/fix/read-onl…
Browse files Browse the repository at this point in the history
…y-ledger-tweaks

Remove requirement for write ledger in read-only mode.
  • Loading branch information
swcurran authored Mar 15, 2024
2 parents 3eb0bf7 + f4fce81 commit 74d12db
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 37 deletions.
20 changes: 10 additions & 10 deletions aries_cloudagent/config/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,6 @@ def add_arguments(self, parser: ArgumentParser):
env_var="ACAPY_PROFILE_ENDPOINT",
help="Specifies the profile endpoint for the (public) DID.",
)
parser.add_argument(
"--read-only-ledger",
action="store_true",
env_var="ACAPY_READ_ONLY_LEDGER",
help="Sets ledger to read-only to prevent updates. Default: false.",
)
parser.add_argument(
"--universal-resolver",
type=str,
Expand Down Expand Up @@ -691,9 +685,6 @@ def get_settings(self, args: Namespace) -> dict:
if args.profile_endpoint:
settings["profile_endpoint"] = args.profile_endpoint

if args.read_only_ledger:
settings["read_only_ledger"] = True

if args.universal_resolver_regex and not args.universal_resolver:
raise ArgsParseError(
"--universal-resolver-regex cannot be used without --universal-resolver"
Expand Down Expand Up @@ -855,6 +846,12 @@ def add_arguments(self, parser: ArgumentParser):
"specified ledger or genesis configurations. Default: false."
),
)
parser.add_argument(
"--read-only-ledger",
action="store_true",
env_var="ACAPY_READ_ONLY_LEDGER",
help="Sets ledger to read-only to prevent updates. Default: false.",
)
parser.add_argument(
"--ledger-keepalive",
default=5,
Expand Down Expand Up @@ -912,6 +909,9 @@ def get_settings(self, args: Namespace) -> dict:
multi_configured = False
update_pool_name = False
write_ledger_specified = False

if args.read_only_ledger:
settings["read_only_ledger"] = True
if args.genesis_url:
settings["ledger.genesis_url"] = args.genesis_url
single_configured = True
Expand Down Expand Up @@ -940,7 +940,7 @@ def get_settings(self, args: Namespace) -> dict:
txn_config["pool_name"] = txn_config["id"]
update_pool_name = True
ledger_config_list.append(txn_config)
if not write_ledger_specified:
if not write_ledger_specified and not args.read_only_ledger:
raise ArgsParseError(
"No write ledger genesis provided in multi-ledger config"
)
Expand Down
12 changes: 8 additions & 4 deletions aries_cloudagent/config/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,14 @@ async def load_multiple_genesis_transactions_from_config(settings: Settings):
if "endorser_did" in config:
config_item["endorser_did"] = config.get("endorser_did")
ledger_txns_list.append(config_item)
if not write_ledger_set and not (
settings.get("ledger.genesis_transactions")
or settings.get("ledger.genesis_file")
or settings.get("ledger.genesis_url")
if (
not write_ledger_set
and not settings.get("ledger.read_only")
and not (
settings.get("ledger.genesis_transactions")
or settings.get("ledger.genesis_file")
or settings.get("ledger.genesis_url")
)
):
raise ConfigError(
"No is_write ledger set and no genesis_url,"
Expand Down
8 changes: 6 additions & 2 deletions aries_cloudagent/utils/multi_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ def get_write_ledger_config_for_profile(settings: BaseSettings) -> dict:
prod_write_ledger_pool = OrderedDict()
non_prod_write_ledger_pool = OrderedDict()
for ledger_config in settings.get("ledger.ledger_config_list"):
if ledger_config.get("is_production") and ledger_config.get("is_write"):
if ledger_config.get("is_production") and (
ledger_config.get("is_write") or settings.get("ledger.read_only")
):
prod_write_ledger_pool[
ledger_config.get("id") or ledger_config.get("pool_name")
] = ledger_config
elif not ledger_config.get("is_production") and ledger_config.get("is_write"):
elif not ledger_config.get("is_production") and (
ledger_config.get("is_write") or settings.get("ledger.read_only")
):
non_prod_write_ledger_pool[
ledger_config.get("id") or ledger_config.get("pool_name")
] = ledger_config
Expand Down
41 changes: 20 additions & 21 deletions docs/features/Multiledger.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,45 +31,45 @@ If `--genesis-transactions-list` is specified, then `--genesis-url, --genesis-fi
```yaml
- id: localVON
is_production: false
genesis_url: 'http://host.docker.internal:9000/genesis'
genesis_url: "http://host.docker.internal:9000/genesis"
- id: bcovrinTest
is_production: true
is_write: true
genesis_url: 'http://test.bcovrin.vonx.io/genesis'
genesis_url: "http://test.bcovrin.vonx.io/genesis"
```
```yaml
- id: localVON
is_production: false
genesis_url: 'http://host.docker.internal:9000/genesis'
genesis_url: "http://host.docker.internal:9000/genesis"
- id: bcovrinTest
is_production: true
is_write: true
genesis_url: 'http://test.bcovrin.vonx.io/genesis'
endorser_did: '9QPa6tHvBHttLg6U4xvviv'
endorser_alias: 'endorser_test'
genesis_url: "http://test.bcovrin.vonx.io/genesis"
endorser_did: "9QPa6tHvBHttLg6U4xvviv"
endorser_alias: "endorser_test"
- id: greenlightDev
is_production: true
is_write: true
genesis_url: 'http://test.bcovrin.vonx.io/genesis'
genesis_url: "http://test.bcovrin.vonx.io/genesis"
```
Note: `is_write` property means that the ledger is write configurable. With reference to the above config example, both `bcovrinTest` and (the no longer available -- in the above its pointing to BCovrin Test as well) `greenlightDev` ledgers are write configurable. By default, on startup `bcovrinTest` will be the write ledger as it is the topmost write configurable production ledger, [more details](#write-requests) regarding the selection rule. Using `PUT /ledger/{ledger_id}/set-write-ledger` endpoint, either `greenlightDev` and `bcovrinTest` can be set as the write ledger.

> Note 2: The `greenlightDev` ledger is no longer available, so both ledger entries in the example above and below
intentionally point to the same ledger URL.
> intentionally point to the same ledger URL.

```yaml
- id: localVON
is_production: false
is_write: true
genesis_url: 'http://host.docker.internal:9000/genesis'
genesis_url: "http://host.docker.internal:9000/genesis"
- id: bcovrinTest
is_production: true
genesis_url: 'http://test.bcovrin.vonx.io/genesis'
genesis_url: "http://test.bcovrin.vonx.io/genesis"
- id: greenlightDev
is_production: true
genesis_url: 'http://test.bcovrin.vonx.io/genesis'
genesis_url: "http://test.bcovrin.vonx.io/genesis"
```

Note: For instance with regards to example config above, `localVON` will be the write ledger, as there are no production ledgers which are configurable it will choose the topmost write configurable non production ledger.
Expand All @@ -80,19 +80,19 @@ For each ledger, the required properties are as following:

- `id`\*: The id (or name) of the ledger, can also be used as the pool name if none provided
- `is_production`\*: Whether the ledger is a production ledger. This is used by the pool selector algorithm to know which ledger to use for certain interactions (i.e. prefer production ledgers over non-production ledgers)

For connecting to ledger, one of the following needs to be specified:

- `genesis_file`: The path to the genesis file to use for connecting to an Indy ledger.
- `genesis_transactions`: String of genesis transactions to use for connecting to an Indy ledger.
- `genesis_url`: The url from which to download the genesis transactions to use for connecting to an Indy ledger.
- `is_write`: Whether this ledger is writable. At least one write ledger must be specified, unless running in read-only mode. Multiple write ledgers can be specified in config.

Optional properties:

- `pool_name`: name of the indy pool to be opened
- `keepalive`: how many seconds to keep the ledger open
- `socks_proxy`
- `is_write`: Whether this ledger is writable. It requires at least one write ledger specified. Multiple write ledgers can be specified in config.
- `endorser_did`: Endorser public DID registered on the ledger, needed for supporting Endorser protocol at multi-ledger level.
- `endorser_alias`: Endorser alias for this ledger, needed for supporting Endorser protocol at multi-ledger level.

Expand All @@ -103,13 +103,13 @@ Note: Both `endorser_did` and `endorser_alias` are part of the endorser info. Wh
Multi-ledger related actions are grouped under the `ledger` topic in the SwaggerUI.

- GET `/ledger/config`:
Returns the multiple ledger configuration currently in use
Returns the multiple ledger configuration currently in use
- GET `/ledger/get-write-ledger`:
Returns the current active/set `write_ledger's` `ledger_id`
Returns the current active/set `write_ledger's` `ledger_id`
- GET `/ledger/get-write-ledgers`:
Returns list of available `write_ledger's` `ledger_id`
Returns list of available `write_ledger's` `ledger_id`
- PUT `/ledger/{ledger_id}/set-write-ledger`:
Set active `write_ledger's` `ledger_id`
Set active `write_ledger's` `ledger_id`

## Ledger Selection

Expand Down Expand Up @@ -162,11 +162,11 @@ When you run in multi-ledger mode, ACA-Py will use the `pool-name` (or `id`) spe
If you are running against a ledger in `write` mode, and the ledger requires you to accept a Transaction Author Agreement (TAA), ACA-Py stores the TAA acceptance
status in the wallet in a non-secrets record, using the ledger's `pool_name` as a key.

This means that if you are upgrading from single-ledger to multi-ledger mode, you will need to *either*:
This means that if you are upgrading from single-ledger to multi-ledger mode, you will need to _either_:

- set the `id` for your writable ledger to `default` (in your `ledgers.yaml` file)

*or*:
_or_:

- re-accept the TAA once you restart your ACA-Py in multi-ledger mode

Expand Down Expand Up @@ -209,7 +209,6 @@ These changes are made here:
- `./aries_cloudagent/resolver/routes.py`
- `./aries_cloudagent/revocation/routes.py`


## Known Issues

* When in multi-ledger mode and switching ledgers (e.g.: the agent is registered on Ledger A and has published its DID there, and now wants to "move" to Ledger B) there is an [issue](https://github.com/hyperledger/aries-cloudagent-python/issues/2473) that will cause the registration to the new ledger to fail.
- When in multi-ledger mode and switching ledgers (e.g.: the agent is registered on Ledger A and has published its DID there, and now wants to "move" to Ledger B) there is an [issue](https://github.com/hyperledger/aries-cloudagent-python/issues/2473) that will cause the registration to the new ledger to fail.

0 comments on commit 74d12db

Please sign in to comment.