|
| 1 | +- Feature Name: read_by_prefix |
| 2 | +- Start Date: 2018-12-19 |
| 3 | +- RFC PR: |
| 4 | +- Sawtooth Issue: |
| 5 | + |
| 6 | +# Summary |
| 7 | +[summary]: #summary |
| 8 | + |
| 9 | +This RFC proposes an additional API to transaction context, |
| 10 | +context.listAddresses(address_prefix), which will get address prefix as input |
| 11 | +and return list of all existing addresses that starts with the prefix. |
| 12 | + |
| 13 | +This capability exists when reading state from rest-api but is missing when |
| 14 | +transaction processor reads state. |
| 15 | + |
| 16 | +# Motivation |
| 17 | +[motivation]: #motivation |
| 18 | + |
| 19 | +The motivation came when looking for a way to improve processing transaction |
| 20 | +logic by making better use optimization that comes from using the radix tree. |
| 21 | + |
| 22 | +Since addresses are stored in a radix tree, reading many addresses by |
| 23 | +one prefix is much faster than reading the same amount of addresses one by one. |
| 24 | +Further more, read by prefix doesn't require transaction processor to know |
| 25 | +which addresses exist, removing the need to store list of existing addresses |
| 26 | +in a separate address. |
| 27 | + |
| 28 | +Having this capability allows a better and smarter address mapping this a |
| 29 | +better transaction processor logic. |
| 30 | + |
| 31 | +# Guide-level explanation |
| 32 | +[guide-level-explanation]: #guide-level-explanation |
| 33 | + |
| 34 | +Get state by prefix is a feature available for reading via sawtooth rest-api. |
| 35 | +This RFC adds method to expose this capability of reading address prefix |
| 36 | +to transaction processor. |
| 37 | + |
| 38 | +No change is recommended to the existing methods, so the implementation of this |
| 39 | +RFC should not cause any breakage for pre-existing transaction processors. |
| 40 | + |
| 41 | +# Reference-level explanation |
| 42 | +[reference-level-explanation]: #reference-level-explanation |
| 43 | + |
| 44 | +Example of implementation can be found here: |
| 45 | +Sawtooth-core + Python SDK changes: |
| 46 | +https://github.com/arsulegai/sawtooth-core/tree/jira_1375 |
| 47 | +(commits: 4225dc7 and 2c3a223) |
| 48 | + |
| 49 | +Sawtooth-sdk-cxx changes: |
| 50 | +https://github.com/arsulegai/sawtooth-sdk-cxx/tree/jira_1375 (commit: 23697e8) |
| 51 | + |
| 52 | +In the suggested implementation there are two proto changes: |
| 53 | + |
| 54 | +Addition to state_context.proto: |
| 55 | + |
| 56 | + |
| 57 | + // A request from a handler/tp for list of addresses with valid data |
| 58 | + message TpStateAddressesListRequest { |
| 59 | + // The context id that references a context in the contextmanager |
| 60 | + string context_id = 1; |
| 61 | + repeated string addresses = 2; |
| 62 | + } |
| 63 | + |
| 64 | + // A response from the contextmanager/validator with a series of State |
| 65 | + // entries having valid data |
| 66 | + message TpStateAddressesListResponse { |
| 67 | + enum Status { |
| 68 | + STATUS_UNSET = 0; |
| 69 | + OK = 1; |
| 70 | + AUTHORIZATION_ERROR = 2; |
| 71 | + } |
| 72 | + |
| 73 | + repeated string addresses = 1; |
| 74 | + Status status = 2; |
| 75 | + } |
| 76 | + |
| 77 | +Addition to validator.proto: |
| 78 | + |
| 79 | + // State list request to get all addresses having non empty data |
| 80 | + TP_STATE_LIST_REQUEST = 17; |
| 81 | + // State list response to get all addresses having non empty data |
| 82 | + TP_STATE_LIST_RESPONSE = 18; |
| 83 | + |
| 84 | + |
| 85 | +# Drawbacks |
| 86 | +[drawbacks]: #drawbacks |
| 87 | + |
| 88 | +This will need to be implemented in every sawtooth SDK and will increase |
| 89 | +the complexity of the validator slightly. |
| 90 | + |
| 91 | +# Rationale and alternatives |
| 92 | +[alternatives]: #alternatives |
| 93 | + |
| 94 | +An alternative could be in the transaction processor logic, store an address |
| 95 | +that contains list of existing addresses. When need to manipulate multiple |
| 96 | +addresses transaction processor will first read the special address, then |
| 97 | +read/write/delete each address in the list. |
| 98 | +This has a performance downside that each time transaction processor needs to |
| 99 | +write a new address, it will need to modify the special address containing |
| 100 | +list of all addresses. This address could be huge, when the need to actually |
| 101 | +access all the addresses in the list can be rare. |
| 102 | + |
| 103 | +# Prior art |
| 104 | +[prior-art]: #prior-art |
| 105 | + |
| 106 | +Read state by address prefix is available from sawtooth-rest-api, and is |
| 107 | +one of the key capability that comes from using the radix tree. |
| 108 | + |
| 109 | + |
| 110 | +# Unresolved questions |
| 111 | +[unresolved]: #unresolved-questions |
0 commit comments