laconicd-deprecated/x/registry
Thomas E Lackey 880367d5df 122: Fix attribute index key collision (#123)
Fix #122, where the structure of the index key allowed unintended collisions (see below).

This also adds a test cases which _fails_ under the old scheme, but passes now:

**Before:**

```
--- FAIL: TestKeeperTestSuite (0.31s)
    --- FAIL: TestKeeperTestSuite/TestGrpcGetRecordLists (0.09s)
        grpc_query_test.go:143:
                Error Trace:    /home/telackey/cerc/laconicd/x/registry/keeper/grpc_query_test.go:143
                                                        /home/telackey/cerc/laconicd/x/registry/keeper/suite.go:91
                Error:          Not equal:
                                expected: 0
                                actual  : 1
                Test:           TestKeeperTestSuite/TestGrpcGetRecordLists
        --- FAIL: TestKeeperTestSuite/TestGrpcGetRecordLists/Case_Filter_with_typ_(cerc-io/laconicd#122)_ (0.00s)
            testing.go:1490: test executed panic(nil) or runtime.Goexit: subtest may have called FailNow on a parent test
FAIL
FAIL    github.com/cerc-io/laconicd/x/registry/keeper   0.765s
FAIL
make: *** [Makefile:333: run-tests] Error 1

❯ laconic cns record list --all --typ eWebsiteRegistrationRecord
[
  {
    "id": "bafyreies5he2mxyrjso2quewwlmh6cisekkjnf7yijpd2742wrzxgzuazi",
    "names": null,
    "owners": [
      "FC9B9FB065D70DBB10C8F511348421C16669B37D"
    ],
    "bondId": "a9c7161fc154cf44ee61efc699a59c8a27c804bb23ce4c8a7ffa0a39fcc540b1",
    "createTime": "2023-11-28T19:09:03Z",
    "expiryTime": "2024-11-27T19:09:03Z",
    "attributes": {
      "url": "https://hello-urbit.laconic.com",
      "repo_registration_record_cid": "QmTZQ8ZJS6mALjEM2wY71msFno6zzxFftVCiZELj9xREPx",
      "build_artifact_cid": "~lostex-rabdur-labtul-moltev/hello-urbit",
      "tls_cert_cid": "QmR1acEmQt7Tjmhp9cFtymie2eFcrHURQKt9kGto1TQTW1",
      "type": "WebsiteRegistrationRecord",
      "version": "0.2.4"
    }
  }
...

❯ laconic cns record list --all --type WebsiteRegistrationRecord
[
  {
    "id": "bafyreies5he2mxyrjso2quewwlmh6cisekkjnf7yijpd2742wrzxgzuazi",
    "names": null,
    "owners": [
      "FC9B9FB065D70DBB10C8F511348421C16669B37D"
    ],
    "bondId": "a9c7161fc154cf44ee61efc699a59c8a27c804bb23ce4c8a7ffa0a39fcc540b1",
    "createTime": "2023-11-28T19:09:03Z",
    "expiryTime": "2024-11-27T19:09:03Z",
    "attributes": {
      "url": "https://hello-urbit.laconic.com",
      "repo_registration_record_cid": "QmTZQ8ZJS6mALjEM2wY71msFno6zzxFftVCiZELj9xREPx",
      "build_artifact_cid": "~lostex-rabdur-labtul-moltev/hello-urbit",
      "tls_cert_cid": "QmR1acEmQt7Tjmhp9cFtymie2eFcrHURQKt9kGto1TQTW1",
      "type": "WebsiteRegistrationRecord",
      "version": "0.2.4"
    }
  }
...
```

**After:**

```
ok      github.com/cerc-io/laconicd/x/registry/keeper   1.573s

❯ laconic cns record list --all --typ eWebsiteRegistrationRecord
[]

❯ laconic cns record list --all --type WebsiteRegistrationRecord
[
  {
    "id": "bafyreies5he2mxyrjso2quewwlmh6cisekkjnf7yijpd2742wrzxgzuazi",
    "names": null,
    "owners": [
      "FC9B9FB065D70DBB10C8F511348421C16669B37D"
    ],
    "bondId": "a9c7161fc154cf44ee61efc699a59c8a27c804bb23ce4c8a7ffa0a39fcc540b1",
    "createTime": "2023-11-28T19:09:03Z",
    "expiryTime": "2024-11-27T19:09:03Z",
    "attributes": {
      "url": "https://hello-urbit.laconic.com",
      "repo_registration_record_cid": "QmTZQ8ZJS6mALjEM2wY71msFno6zzxFftVCiZELj9xREPx",
      "build_artifact_cid": "~lostex-rabdur-labtul-moltev/hello-urbit",
      "tls_cert_cid": "QmR1acEmQt7Tjmhp9cFtymie2eFcrHURQKt9kGto1TQTW1",
      "type": "WebsiteRegistrationRecord",
      "version": "0.2.4"
    }
  }
...
```

Reviewed-on: cerc-io/laconicd#123
Co-authored-by: Thomas E Lackey <telackey@bozemanpass.com>
Co-committed-by: Thomas E Lackey <telackey@bozemanpass.com>
2023-11-29 00:05:56 +00:00
..
client Fix lint errors (which are actually bugs in linting dependencies) (#114) 2023-11-21 04:57:52 +00:00
helpers replace CIDFromJSONBytes (#97) 2023-03-14 11:21:23 +05:30
keeper 122: Fix attribute index key collision (#123) 2023-11-29 00:05:56 +00:00
simulation rename nameservie to registry (#54) 2022-12-09 09:47:14 +05:30
types Add new record types ApplicationRecord, WebAppDeploymentRecord, GeneralRecord (#113) 2023-11-20 22:01:03 +00:00
abci.go rename nameservie to registry (#54) 2022-12-09 09:47:14 +05:30
genesis.go rename nameservie to registry (#54) 2022-12-09 09:47:14 +05:30
module.go rename nameservie to registry (#54) 2022-12-09 09:47:14 +05:30
README.md chain id (#73) 2023-01-11 10:52:29 +05:30

Build chain

# it will create binary in build folder with `laconicd`
$ make build

Setup Chain

./build/laconicd keys add root
./build/laconicd init test-moniker --chain-id laconic_9000-1
./build/laconicd add-genesis-account $(./build/laconicd keys show root -a) 1000000000000000000aphoton,1000000000000000000stake
./build/laconicd gentx root 1000000000000000000stake --chain-id laconic_9000-1
./build/laconicd collect-gentxs
./build/laconicd start

Get Params

$ ./build/laconicd q registry params -o json | jq .
{
  "params": {
    "record_rent": {
      "denom": "stake",
      "amount": "1000000"
    },

    "record_rent_duration": "31536000s",
    "authority_rent": {
      "denom": "stake",
      "amount": "1000000"
    },
    "authority_rent_duration": "31536000s",
    "authority_grace_period": "172800s",
    "authority_auction_enabled": false,
    "authority_auction_commits_duration": "86400s",
    "authority_auction_reveals_duration": "86400s",
    "authority_auction_commit_fee": {
      "denom": "stake",
      "amount": "1000000"
    },
    "authority_auction_reveal_fee": {
      "denom": "stake",
      "amount": "1000000"
    },
    "authority_auction_minimum_bid": {
      "denom": "stake",
      "amount": "5000000"
    }
  }

Create (Set) Record

First you have to Create bond

$ ./build/laconicd tx registry set ~/Desktop/examples/records/service_provider_example.yml 95f68b1b862bfd1609b0c9aaf7300287b92fec90ac64027092c3e723af36e83d --from root --chain-id laconic_9000-1 --yes -o json
{
  "height": "0",
  "txhash": "BA44ABE1194724694E7CB290F9F3121DB4E63E1A030D95CB84813EEA132CF95F",
  "codespace": "",
  "code": 0,
  "data": "",
  "raw_log": "[]",
  "logs": [],
  "info": "",
  "gas_wanted": "0",
  "gas_used": "0",
  "tx": null,
  "timestamp": ""
}

Get records list

$ ./build/laconicd q registry list -o json  | jq
[
  {
    "id": "bafyreih7un2ntk235wshncebus5emlozdhdixrrv675my5umb6fgdergae",
    "bondId": "c3f7a78c5042d2003880962ba31ff3b01fcf5942960e0bc3ca331f816346a440",
    "createTime": "2021-10-04T06:50:06.369025861Z",
    "expiryTime": "2022-10-04T06:50:06.369025861Z",
    "attributes": {
      "attr1": "value1",
      "attr2": "value2",
      "link1": {
        "/": "QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D"
      },
      "link2": {
        "/": "QmP8jTG1m9GSDJLCbeWhVSVgEzCPPwXRdCRuJtQ5Tz9Kc9"
      }
    }
  }
]


Get record by id

$ ./build/laconicd q registry get bafyreih7un2ntk235wshncebus5emlozdhdixrrv675my5umb6fgdergae -o json | jq .
{
  "record": {
    "id": "bafyreih7un2ntk235wshncebus5emlozdhdixrrv675my5umb6fgdergae",
    "bond_id": "95f68b1b862bfd1609b0c9aaf7300287b92fec90ac64027092c3e723af36e83d",
    "create_time": "2021-09-27T07:23:25.558111606Z",
    "expiry_time": "2022-09-27T07:23:25.558111606Z",
    "deleted": false,
    "owners": [],
    "attributes": "eyJhdHRyMSI6InZhbHVlMSIsImF0dHIyIjoidmFsdWUyIiwibGluazEiOnsiLyI6IlFtU251V214cHRKWmRMSnBLUmFyeEJNUzJKdTJvQU5WcmdicjJ4V2JpZTliMkQifSwibGluazIiOnsiLyI6IlFtUDhqVEcxbTlHU0RKTENiZVdoVlNWZ0V6Q1BQd1hSZENSdUp0UTVUejlLYzkifX0="
  }
}

Reserve name

 ./build/laconicd tx registry reserve-name hello --from root --chain-id laconic_9000-1 --owner $(./build/laconicd key
s show root -a) -y -o json | jq .
{
  "height": "0",
  "txhash": "7EC19157AC89279DEBE840EA3384FC95D1E2A0931C27746CA42AC23AE285B7ED",
  "codespace": "",
  "code": 0,
  "data": "",
  "raw_log": "[]",
  "logs": [],
  "info": "",
  "gas_wanted": "0",
  "gas_used": "0",
  "tx": null,
  "timestamp": ""
}

Query Whois for name authority

 ./build/laconicd q registry whois hello -o json | jq .
{
  "name_authority": {
    "owner_public_key": "Au3hH1tzL1KgZfXfA71jGYSe5RV9Wg95kwhBWs8V+N+h",
    "owner_address": "ethm1mfdjngh5jvjs9lqtt9a7y2hlgw8v3syh3hsqzk",
    "height": "174",
    "status": "active",
    "auction_id": "",
    "bond_id": "",
    "expiry_time": "2021-09-29T07:34:36.304545965Z"
  }
}

Query the registry module balance

$ ./build/laconicd q registry  balance -o json | jq .
{
  "balances": [
    {
      "account_name": "record_rent",
      "balance": [
        {
          "denom": "stake",
          "amount": "1000000"
        }
      ]
    }
  ]
}

add bond to the authority

$ ./build/laconicd tx registry authority-bond [Authority Name] [Bond ID ]  --from root --chain-id laconic_9000-1  -y -o json | jq .
$ ./build/laconicd tx registry authority-bond hello 95f68b1b862bfd1609b0c9aaf7300287b92fec90ac64027092c3e723af36e83d  --from root --chain-id laconic_9000-1  -y -o json | jq .

Query the records by associate bond id

$ ./build/laconicd q registry query-by-bond 95f68b1b862bfd1609b0c9aaf7300287b92fec90ac64027092c3e723af36e83d -o json | jq .
{
  "records": [
    {
      "id": "bafyreih7un2ntk235wshncebus5emlozdhdixrrv675my5umb6fgdergae",
      "bond_id": "95f68b1b862bfd1609b0c9aaf7300287b92fec90ac64027092c3e723af36e83d",
      "create_time": "2021-09-27T08:25:32.893155609Z",
      "expiry_time": "2022-09-27T08:25:32.893155609Z",
      "deleted": false,
      "owners": [],
      "attributes": "eyJhdHRyMSI6InZhbHVlMSIsImF0dHIyIjoidmFsdWUyIiwibGluazEiOnsiLyI6IlFtU251V214cHRKWmRMSnBLUmFyeEJNUzJKdTJvQU5WcmdicjJ4V2JpZTliMkQifSwibGluazIiOnsiLyI6IlFtUDhqVEcxbTlHU0RKTENiZVdoVlNWZ0V6Q1BQd1hSZENSdUp0UTVUejlLYzkifX0="
    }
  ],
  "pagination": null
}

dissociate bond from record

$ ./build/laconicd tx registry dissociate-bond bafyreih7un2ntk235wshncebus5emlozdhdixrrv675my5umb6fgdergae  --from root --chain-id laconic_9000-1
{"body":{"messages":[{"@type":"/vulcanize.registry.v1beta1.MsgDissociateBond","record_id":"bafyreih7un2ntk235wshncebus5emlozdhdixrrv675my5umb6fgdergae","signer":"ethm1mfdjngh5jvjs9lqtt9a7y2hlgw8v3syh3hsqzk"}],"memo":"","timeout_height":"0","extension_options":[],"non_critical_extension_options":[]},"auth_info":{"signer_infos":[],"fee":{"amount":[],"gas_limit":"200000","payer":"","granter":""}},"signatures":[]}

confirm transaction before signing and broadcasting [y/N]: y
code: 0
codespace: ""
data: ""
gas_used: "0"
gas_wanted: "0"
height: "0"
info: ""
logs: []
raw_log: '[]'
timestamp: ""
tx: null
txhash: 7AFEF524CB0D92D6576FC08601A787786E802449888FD8DDAA7635698CC85060

Associate bond with record

./build/laconicd tx registry associate-bond bafyreih7un2ntk235wshncebus5emlozdhdixrrv675my5umb6fgdergae c3f7a78c5042d2003880962ba31ff3b01fcf5942960e0bc3ca331f816346a440 --from root --chain-id laconic_9000-1  -y -o json | jq .
{
  "height": "0",
  "txhash": "F75C2BF2FE73668AE1332E1237F924AC549E31E822A56394DE5AC17200B199F9",
  "codespace": "",
  "code": 0,
  "data": "",
  "raw_log": "[]",
  "logs": [],
  "info": "",
  "gas_wanted": "0",
  "gas_used": "0",
  "tx": null,
  "timestamp": ""
}

dissociate-records => remove all record from bond

$./build/laconicd tx registry dissociate-records c3f7a78c5042d2003880962ba31ff3b01fcf5942960e0bc3ca331f816346a440 --from root --chain-id laconic_9000-1  -y -o json | jq .
{
  "height": "0",
  "txhash": "0316F503E5DEA47CB108AE6C7C7FFAF3F71CC56BC22F63CB97322E1BE48B33B9",
  "codespace": "",
  "code": 0,
  "data": "",
  "raw_log": "[]",
  "logs": [],
  "info": "",
  "gas_wanted": "0",
  "gas_used": "0",
  "tx": null,
  "timestamp": ""
}

Renew a record

When a record is expires , needs to renew record

$ ./build/laconicd tx registry renew-record bafyreih7un2ntk235wshncebus5emlozdhdixrrv675my5umb6fgdergae --from root --chain-id laconic_9000-1

Set the authority name

$ ./build/laconicd tx registry set-name crn://hello/test test_hello_cid  --from root --chain-id laconic_9000-1 -y -o json | jq .
{
  "height": "0",
  "txhash": "66A63C73B076EEE9A2F7605354448EDEB161F0115D4D03AF68C01BA28DB97486",
  "codespace": "",
  "code": 0,
  "data": "",
  "raw_log": "[]",
  "logs": [],
  "info": "",
  "gas_wanted": "0",
  "gas_used": "0",
  "tx": null,
  "timestamp": ""
}

Delete the name

$./build/laconicd tx registry delete-name crn://hello/test --from root --chain-id laconic_9000-1 -y
code: 0
codespace: ""
data: ""
gas_used: "0"
gas_wanted: "0"
height: "0"
info: ""
logs: []
raw_log: '[]'
timestamp: ""
tx: null
txhash: A3FF4C46BAC7BD6E54BBB743A49830AE8C6F6FE59282384789CBA323C1FE540C

List of Authorities Expire Queue

$ ./build/laconicd q registry authority-expiry  -o json | jq .
{
  "authorities": [],
  "pagination": null
}

List of Records Expire Queue

$  ./build/laconicd q registry record-expiry -o json | jq .
{
  "records": [],
  "pagination": null
}