在以太坊区块链上保存合同数据的更有效方法是哪种?

I am playing with a private Ethereum blockchain, and I am interested in implementing some smart contracts. However, information is very limited since this is a newer implementation of the blockchain.

Just as an example, say I want a contract that holds information about a person. Is it more efficient to create a new contract for each person, or simply hold information about all users in the same contract?

In pseudo-code, the two options look like this.

Option 1 (instantiate a new contract for each person):

contract = // contract code

ethereum.newContract(contract, userInfo);

Option 2 (hold info of all users in one contract):

contract = {
  var users = [];

  // other contract code
}

ethereum.newContract(contract, userInfo);

Here's how we can quantify "efficiency" in this case:

  1. Each time a new contract is instantiated, we have to mine the block for the contract, and then mine any transactions the user makes to the contract. If we only instantiate one contract, however, we only mine the contract deployment once, and then any transactions thereafter, but...
  2. If we go with the option of storing all info for all users in one contract, is only the "diff" of the contract data (the "array" of all users) stored as a block, or is the entire set of data stored in every block? Or...
  3. If we go with the option of "contract per user", does it "waste space" if we're storing the entire contract definition multiple times (and is it worth the possibly redundant mining that needs to take place)?

Hopefully I was clear in my question, but if not, please let me know. I believe this question is one of "trade offs".

(Re: the tags -- I'm using the golang implementation of Ethereum, and a JavaScript API to interact with it.)

  1. Yes. However, each time you want to add a user you will have to send a transaction for adding a new record to the existing contract.

  2. Blocks consist of transactions. Each time you add a user, you will have to create a transaction for the corresponding function call. However, you will only have to do this once and not the data will not be redundantly copied to future blocks.

  3. Yes.

From the way your question is structured, it seems you should read up again on the difference between transactions and blocks.

A single contract for all users should be sufficient, given that your user objects are not too large.

From the code above, suggest using a map which will allow more efficient fetching of user records than an array. Key the records by any string, such as first+last name.

mapping(string => user_struct) public users;