Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Commit

Permalink
Merge pull request #45 from input-output-hk/ksaric/CAD-1456
Browse files Browse the repository at this point in the history
[CAD-1456] Implement blacklisting for pool ids.
  • Loading branch information
ksaric authored Aug 11, 2020
2 parents fe349ef + b307f23 commit 341e349
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
39 changes: 35 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ cardano-node --genesis-file genesis.json --socket-path node.socket --config conf

You can then run ``smash`` using e.g:
```
SMASHPGPASSFILE=./config/pgpass stack run smash-exe -- run-app-with-db-sync --config config.yaml --genesis-file genesis.json --socket-path node.socket --schema-dir schema/
SMASHPGPASSFILE=./config/pgpass stack run smash-exe -- run-app-with-db-sync --config config.yaml --socket-path node.socket --schema-dir schema/
```

## How to test this works?
Expand Down Expand Up @@ -184,17 +184,17 @@ If you find some pool hash that has been inserted, like in our example, '93b1333

You can test the delisting by sending a PATCH on the delist endpoint.
```
curl -X PATCH -v http://localhost:3100/api/v1/delist -H 'content-type: application/json' -d '{"poolHash": "93b13334b5edf623fd4c7a716f3cf47be5baf7fb3a431c16ee07aab8ff074873"}'
curl -X PATCH -v http://localhost:3100/api/v1/delist -H 'content-type: application/json' -d '{"poolId": "062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7"}'
```

Or if you have Basic Auth enabled (replace with the username/pass for your DB):
```
curl -u ksaric:cirask -X PATCH -v http://localhost:3100/api/v1/delist -H 'content-type: application/json' -d '{"poolHash": "93b13334b5edf623fd4c7a716f3cf47be5baf7fb3a431c16ee07aab8ff074873"}'
curl -u ksaric:test -X PATCH -v http://localhost:3100/api/v1/delist -H 'content-type: application/json' -d '{"poolId": "062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7"}'
```

Fetching the pool:
```
curl -X GET -v http://localhost:3100/api/v1/metadata/062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7/93b13334b5edf623fd4c7a716f3cf47be5baf7fb3a431c16ee07aab8ff074873 | jq .
curl -X GET -v http://localhost:3100/api/v1/metadata/062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7/cbdfc4f21feb0a414b2b9471fa56b0ebd312825e63db776d68cc3fa0ca1f5a2f | jq .
```

## Basic Auth and DB
Expand Down Expand Up @@ -255,6 +255,37 @@ SMASHPGPASSFILE=config/pgpass stack run smash-exe -- insert-ticker-name --ticker

If somebody adds the ticker name that exists there, it will not be returned, but it will return 404.

## How to test delisting?

The example we used for testing shows that we can delist the pool id.
That pool id is then unable to provide any more pools.

We first insert the `test_pool.json` we have in the provided example:
```
SMASHPGPASSFILE=config/pgpass stack run smash-exe -- insert-pool --metadata test_pool.json --poolId "062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7" --poolhash "cbdfc4f21feb0a414b2b9471fa56b0ebd312825e63db776d68cc3fa0ca1f5a2f"
```

Then we change ticker name of `test_pool.json` from `testy` to `testo`. This changes the pool hash.
You can check the hash using the example in https://github.com/input-output-hk/smash#how-to-figure-out-the-json-hash:
```
SMASHPGPASSFILE=config/pgpass stack run smash-exe -- insert-pool --metadata test_pool.json --poolId "062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7" --poolhash "3b842358a698119a4b0c0f4934d26cff69190552bf47a85f40f5d1d646c82699"
```

We now have two pools from the same pool id. Let's see if we got them in the database:
```
curl -X GET -v http://localhost:3100/api/v1/metadata/062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7/cbdfc4f21feb0a414b2b9471fa56b0ebd312825e63db776d68cc3fa0ca1f5a2f | jq .
curl -X GET -v http://localhost:3100/api/v1/metadata/062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7/3b842358a698119a4b0c0f4934d26cff69190552bf47a85f40f5d1d646c82699 | jq .
```
We can try to delist that pool id and then try fetching both pools to see if delisting works on the level of the pool id:
```
curl -X PATCH -v http://localhost:3100/api/v1/delist -H 'content-type: application/json' -d '{"poolId": "062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7"}'
```

Fetching them again should result in 403:
```
curl -X GET -v http://localhost:3100/api/v1/metadata/062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7/cbdfc4f21feb0a414b2b9471fa56b0ebd312825e63db776d68cc3fa0ca1f5a2f | jq .
curl -X GET -v http://localhost:3100/api/v1/metadata/062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7/3b842358a698119a4b0c0f4934d26cff69190552bf47a85f40f5d1d646c82699 | jq .
```

6 changes: 3 additions & 3 deletions doc/getting-started/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ For example, after seeing that a pool has be registered, you can try to get it's
curl -X GET -v http://localhost:3100/api/v1/metadata/062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7/93b13334b5edf623fd4c7a716f3cf47be5baf7fb3a431c16ee07aab8ff074873
```

You can test the delisting by sending a PATCH on the delist endpoint.
You can test the delisting by sending a PATCH on the delist endpoint (using the pool id from the example, `062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7`).
```
curl -X PATCH -v http://localhost:3100/api/v1/delist -H 'content-type: application/json' -d '{"poolHash": "93b13334b5edf623fd4c7a716f3cf47be5baf7fb3a431c16ee07aab8ff074873"}'
curl -X PATCH -v http://localhost:3100/api/v1/delist -H 'content-type: application/json' -d '{"poolId": "062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7"}'
```

Or if you have Basic Auth enabled (replace with you username/pass you have in your DB):
```
curl -u ksaric:cirask -X PATCH -v http://localhost:3100/api/v1/delist -H 'content-type: application/json' -d '{"poolHash": "93b13334b5edf623fd4c7a716f3cf47be5baf7fb3a431c16ee07aab8ff074873"}'
curl -u ksaric:cirask -X PATCH -v http://localhost:3100/api/v1/delist -H 'content-type: application/json' -d '{"poolId": "062693863e0bcf9f619238f020741381d4d3748aae6faf1c012e80e7"}'
```

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ BEGIN
ALTER TABLE "block" ADD CONSTRAINT "unique_block" UNIQUE("hash");
CREATe TABLE "meta"("id" SERIAL8 PRIMARY KEY UNIQUE,"protocol_const" INT8 NOT NULL,"slot_duration" INT8 NOT NULL,"start_time" timestamp NOT NULL,"slots_per_epoch" INT8 NOT NULL,"network_name" VARCHAR NULL);
ALTER TABLE "meta" ADD CONSTRAINT "unique_meta" UNIQUE("start_time");
CREATe TABLE "delisted_pool"("id" SERIAL8 PRIMARY KEY UNIQUE,"pool_id" hash28type NOT NULL);
CREATe TABLE "delisted_pool"("id" SERIAL8 PRIMARY KEY UNIQUE,"pool_id" text NOT NULL);
ALTER TABLE "delisted_pool" ADD CONSTRAINT "unique_blacklisted_pool" UNIQUE("pool_id");
CREATe TABLE "reserved_ticker"("id" SERIAL8 PRIMARY KEY UNIQUE,"name" text NOT NULL,"pool_hash" base16type NOT NULL);
ALTER TABLE "reserved_ticker" ADD CONSTRAINT "unique_reserved_ticker" UNIQUE("name");
Expand Down
2 changes: 1 addition & 1 deletion src/Cardano/Db/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ share

-- A table containing a list of delisted pools.
DelistedPool
poolId Types.PoolId sqltype=hash28type
poolId Types.PoolId sqltype=text
UniqueBlacklistedPool poolId

-- A table containing a managed list of reserved ticker names.
Expand Down

0 comments on commit 341e349

Please sign in to comment.