1

I am looking for a data structure kind of like this:

[
  "data": {
    "id": 0,
    "hash" : "5feceb66ffc86f38d952786c6d696c79c2dbc239dd4e91b46729d73a27fb57e9",
    "owner" : 0,
    "status" : "allocated"
  },
  "data": {
    "id": 1,
    "hash" : "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b",
    "owner" : null,
    "status" : "pending"
  },
  "data": {
    "id": 2,
    "hash" : "d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35",
    "owner" : 0
    "status" : "allocated"
  },
  "data": {
    "id": 3,
    "hash" : "4e07408562bedb8b60ce05c1decfe3ad16b72230967de01f640b7e4729b49fce",
    "owner" : 1
    "status" : "allocated"
  },
  "data": {
    "id": 4,
    "hash" : "4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a",
    "owner" : null
    "status" : null
  }

]

My use-case would have a bigint worth of records stored, from 0 to many many quadrillions, recording their owner and status.

Specifically, I'd like access to the following kinds of queries, written in SQL here (but not needing to be, of course, open to learning any other language or package for query logic):

SELECT * FROM dataset WHERE data.owner = 1;

SELECT * FROM dataset WHERE data.id = 4;

UPDATE dataset SET data.status = "pending" WHERE data.id = 4;

UPDATE dataset SET data.status = "allocated", data.owner = 1 WHERE data.id = 4 and data.status = "pending";

I'd like to pre-populate the values for ids once offchain and upload them all at once, but then do computations like the UPDATE statements by contract on-chain.

My very nooby questions are:

  1. Is ETH a good choice for this? If not, is there a more suitable one?
  2. How do I set this kind of thing up when data is immutable?
  3. If you did have to store 10^1000s of records in a distributed fashion, but wanted some kind of application control over metadata like above, as well as query infrastructure for slicing up fields, what's a good way to do that?
  4. What is a good way to handle on-chain v off-chain?

Sidenote, writing out just integers from 0...5500000000 = 55GB, so this an expensive amount of data, likely.

1

You should think of using a smart contract with mapping storage data structure of structs. First, define a struct representing your object

struct Data {
  string hash,
  uint owner,
  string status
} 

Then you may define a mapping that maps the unique data ID to its values, for example:

mapping(uint=>Data) idTodataMapping;
uint[] allIds;

These fields will be replicated by all the nodes and gives you the data distribution that you are looking for. And allIds may be used to store all the keys for the mapping, so you can loop over the mapping later. Note that you can omit this array and replace it with a simple uint count if the Ids are incremental.

Now if you want to manipulate data, there's nothing like SQL queries in solidity so far, but you can achieve what you want by looping over your idTodataMapping. For instance:

for (uint i = 0; i < allIds.length; i++) {
    if (idTodataMapping[i].owner == "1") {
        idTodataMapping[i].status = "allocated";
    }
}
1

Is ETH a good choice for this? If not, is there a more suitable one?

No, storing data in ethereum is expensive. storing one byte of data in ethereum cost 68gas. At the current gas price this is 0.043 USD per Kbyte, that is about 45000 USD per GB.

Saving the data on the blockchain is not an option.

Jaime

  • WOW! That is more than I expected – Mittenchops Nov 13 '18 at 14:26
  • Can I ask how you calculated this? I'm looking here: ethgasstation.info, but what is the rate used to translate the gas price of 4 Gwei into Kbyte storage? – Mittenchops Nov 16 '18 at 19:04
  • The price per byte is 68 gas and 1kbyte is 1024 bytes then 1kbyte_cost = 1024*68*gasprice – Jaime Nov 16 '18 at 20:05
  • 68 gas per byte is just hard coded into the spec, and it's the price of gas that varies? – Mittenchops Nov 16 '18 at 20:17
  • yes, you can find this in the yellow paper Apendix G – Jaime Nov 16 '18 at 21:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.