Pages:
Author

Topic: Technical questions about blockchain - page 2. (Read 1521 times)

legendary
Activity: 3472
Merit: 4794
October 29, 2017, 04:48:08 PM
#8
Oh thanks a lot, now i understand.

So the "reward" itself is included in the new Block, so for example:

In bitcoin?  Yes, that is how it works.

I launch a new coin, and miners start mining, but no pending transaction are available for a loong time.

So everytime a miner start mining, new blocks are created with only miners reward, in this case how I could handle supply?

That's up to you.  You are designing the coin, you need to decide how you want it to work.

with difficulty?

With Bitcoin, difficulty is used to control what the average time is between solved blocks.  If you want your coin to work the same way, then you need to find a way for all nodes to agree about how fast blocks are being solved, and then to all adjust the difficulty in the same way to speed up or slow down the blocks as needed.

If you don't want your coin to work the same way as Bitcoin, then you get to decide how you want to use difficulty (if any).

In my coin difficulty is measured in this way:

difficulty 2:
Means finding a proof when hashing it with last proof finds a hash with 2 0's at the end of the hash,

Are you talking about the hash as represented in binary?  If so, that's not going to give you much control over difficulty.  For example, if you use SHA256, then you'll only be able to make a MAXIMUM of 256 adjustements, and then you'll run out of zeros.  Also, adding a zero is a DOUBLING of the difficulty.  You won't be able to adjust difficulty by 10% or 5% or anything like that.  You'll only be able to make it DOUBLE as difficult!

At the start it would be very easy to mine blocks, but every 10 Block's I increment difficulty (which means more time). Would this be correct?

So, assuming you are using SHA256 and binary representation, after 2560 blocks you will have used up all your zeros, and have the maximum possible difficulty.  Blocks will be solved once every few trillion years.  After just 720 blocks you will already have higher difficulty than Bitcoin, and after 760 blocks your coin will be more then 10 times more difficult to mine than Bitcoin.

You really might want to think about the mathematics and incentive structures behind your coin if you want it to work, otherwise it will be completely unusable.

And another question:
When new transactions arrives to my node, I check the transaction signature with the public key (to know if the sender of the tx is the owner of the address), then I add this transaction to a "pending transaction pool" this is a pool of valid transactions that have to be mined, would the node forward this valid pending transactions to other nodes too?

This is your coin.  You can make it work however you want.  If that's what you want it to do, then that is what it should do.

If you are asking about how bitcoin handles transactions:

Each node maintains a list of unspent outputs.  When it receives a transaction, it verifies that all of the transaction inputs are in its list of unspent outputs. If there are any inputs that are NOT in that list, then the transaction is invalid.  The node then executes the script formed by concatenating the Txout-script (also called the scriptPubKey) with the Txin-script (also called the scriptSig).  If that script does not execute without error, or does not have a valid result, then the transaction is invalid.

As long as the transaction is valid, then the Bitcoin node adds it to its own mempool (list of unconfirmed transactions) and shares that transaction with all the peers it is connected to which have not yet received it.

Because it can be possible that a miner is not connected to all nodes, and if the miner mine's the block the node would forward the valid block to all nodes.

This is your coin, you can design it to work however you want. If you want ALL nodes to have the blocks, then you need to find a way to share that block with everyone.  One possible method (the method that Bitcoin uses) is to forward the blocks (relay them to all connected peers that haven't received it yet)

And another question:
What is the storage system? Just hold it in memory or MySQL for example? or mongodb?

This is your coin.  You can use whatever database you want.  Bitcoin holds some data in memory structures, and other data it stores in levelDB.

And another question:
Everytime someone does a transaction I have to iterate over all blocks and transactions to check if the public address has enough funds?

This is your coin.  You can make it work however you want

If you are asking how Bitcoin does it...

Bitcoin nodes do not keep track of balances at all.  Transactions consists of two lists.  The first list is called "inputs". The "inputs list" provides value to the transaction.  It is a list of some of the outputs that are not currently seen as inputs in any other valid transactions.  The second list is called "outputs".  Each output in the "outputs list" is assigned value from the transaction.  If the sum of the value of the outputs exceeds the sum of the value of the inputs, then the transaction is invalid.  When an output is not yet used as an input it is called an "unspent" output.  When it is used as an input, it is called a "spent" output.  The node only needs to keep track of the unspent outputs.  When it adds a transaction to its memory pool, it removes all the transaction's inputs from its list of unspent outputs (since they would then be considered "Spent".  It also adds all the new outputs to it's list of unspent outputs.
legendary
Activity: 3038
Merit: 4418
Crypto Swap Exchange
October 29, 2017, 11:26:16 AM
#7
So everytime a miner start mining, new blocks are created with only miners reward, in this case how I could handle supply? with difficulty?
Bitcoin handles the total amount through block halving. To ensure that it is distributed over a spread period, the difficulty ensures that blocks are only generated as close as ten minutes as possible. This ensures that about 12.5BTC (right now) gets distributed per 10 minutes.
In my coin difficulty is measured in this way:

difficulty 2:
Means finding a proof when hashing it with last proof finds a hash with 2 0's at the end of the hash,

At the start it would be very easy to mine blocks, but every 10 Block's I increment difficulty (which means more time). Would this be correct?
No! It doesn't make sense at all. If the difficulty doesn't change when the block frequency gets higher or lower, the supply won't be spread out.
When new transactions arrives to my node, I check the transaction signature with the public key (to know if the sender of the tx is the owner of the address), then I add this transaction to a "pending transaction pool" this is a pool of valid transactions that have to be mined, would the node forward this valid pending transactions to other nodes too?

Because it can be possible that a miner is not connected to all nodes, and if the miner mine's the block the node would forward the valid block to all nodes.
When you can check that the transaction is valid and the inputs are in your UTXO, you will relay it to your peers.
And another question:
Everytime someone does a transaction I have to iterate over all blocks and transactions to check if the public address has enough funds?
No. Bitcoin does not work with public key or addresses. When a transaction is seen by the node, they will remove and create new unspent outputs in their UTXO set. When someone intiates a transaction, they are effectively spending an input. For that reason, nodes do not keep track of the balances in addresses.
member
Activity: 142
Merit: 13
October 29, 2017, 11:09:11 AM
#6
Oh thanks a lot, now i understand.

So the "reward" itself is included in the new Block, so for example:

I launch a new coin, and miners start mining, but no pending transaction are available for a loong time.

So everytime a miner start mining, new blocks are created with only miners reward, in this case how I could handle supply? with difficulty?

In my coin difficulty is measured in this way:

difficulty 2:
Means finding a proof when hashing it with last proof finds a hash with 2 0's at the end of the hash,

At the start it would be very easy to mine blocks, but every 10 Block's I increment difficulty (which means more time). Would this be correct?

And another question:
When new transactions arrives to my node, I check the transaction signature with the public key (to know if the sender of the tx is the owner of the address), then I add this transaction to a "pending transaction pool" this is a pool of valid transactions that have to be mined, would the node forward this valid pending transactions to other nodes too?

Because it can be possible that a miner is not connected to all nodes, and if the miner mine's the block the node would forward the valid block to all nodes.

And another question:
What is the storage system? Just hold it in memory or MySQL for example? or mongodb?

And another question:
Everytime someone does a transaction I have to iterate over all blocks and transactions to check if the public address has enough funds?

Sorry for my ignorance, I'm not doing this to launch a new coin, just for learning and to publish it!

Thanks!!
legendary
Activity: 3472
Merit: 4794
October 29, 2017, 09:38:39 AM
#5
But my question is not resolved, what would happen if there aren't any transactions to "mine" would i merge Block Without transactions
to the blockchain? Or not, but if not, how new coins can be supplied?

If you are designing a new coin, then you will need to decide how your coin will work.

If you are asking how bitcoin handles the situation...

Bitcoin requires that every block has AT LEAST 1 TRANSACTION.  There is a special transaction often called the "coinbase transaction" or the "generation transaction" which every block is required to include.  This is the transaction that pays the miner their reward.  If there is more than one transaction in the block, then it is required to be the first transaction in the list. A block without this transaction is considered to be invalid and is rejected by everyone else.

member
Activity: 142
Merit: 13
October 29, 2017, 07:18:49 AM
#4
1. A block have it just one transaction or can it have more transactions?
Blocks will have transactions up to the size limit (ie. 1MB for Bitcoin).
2. Miners: So, just imagine I launch my coin, and there are no transactions yet, so miners have no work, if miners dont can do work, no new coins are supplied, so my questions, even if there are no transactions, can Block's without any transaction merged to the Blockchain? also "Empty Blocks" ?
That is a misconception. Miners are not exactly mining transactions, they are basically hashing the block header until they find a hash that meets the target. The transactions are included in the merkle root of the block header. There must be at least the coinbase transaction in the block.
3. About wallet System, I have no clue how this works, I know that public key is generated from Private key,  but how can the server know that the transaction comes from the wallet owner?

Imagine I have an endpoint in the node, /tx, there you send a json with from, to, and amount:

- With an wallet application it would be easy, you just verify public key with private and send transaction to /tx, but anyway, what would preventing users to send transaction to /tx, the verification must be done in the server, so i have to send public and private key to the server, right?

But that can lead to security issues, what happens if there's an middleman listening to your requests?
Using ECDSA. In a transaction, the user provides the public key and also the signature of the transaction. Using the public key, nodes can use the public key and the signature to verify that it corresponds to the SHA256 of the TXID.

6. Does every node perform mining tasks?
No. Full nodes usually just verify transactions and blocks.

 Hello, thanks for your answer. I don't understand that, could you explain that?, My block structure is simple and i Haven't a
 "Merkle Root" My block structure is the following:

 private index: number;
 private timestamp: number;
 private data: Data;
 private proofOfWork: number;
 private difficulty: number;
 private previousHash: string;
 private hash: string;
 
 Where data is a List of "Transactions", I don't want to replicate Bitcoin, so I think i dont need a merkle Root, I know
 that miners just do some "hard work" that in reality doesn't have relation to the block, actually my mining algorithm does the following:
 
 sha256(lastDifficulty + difficulty) and search for an amount of 0 at the end of the string.
 
 But my question is not resolved, what would happen if there aren't any transactions to "mine" would i merge Block Without transactions
 to the blockchain? Or not, but if not, how new coins can be supplied?
 
 Best Regard
legendary
Activity: 3038
Merit: 4418
Crypto Swap Exchange
October 29, 2017, 07:09:23 AM
#3
1. A block have it just one transaction or can it have more transactions?
Blocks will have transactions up to the size limit (ie. 1MB for Bitcoin).
2. Miners: So, just imagine I launch my coin, and there are no transactions yet, so miners have no work, if miners dont can do work, no new coins are supplied, so my questions, even if there are no transactions, can Block's without any transaction merged to the Blockchain? also "Empty Blocks" ?
That is a misconception. Miners are not exactly mining transactions, they are basically hashing the block header until they find a hash that meets the target. The transactions are included in the merkle root of the block header. There must be at least the coinbase transaction in the block.
3. About wallet System, I have no clue how this works, I know that public key is generated from Private key,  but how can the server know that the transaction comes from the wallet owner?

Imagine I have an endpoint in the node, /tx, there you send a json with from, to, and amount:

- With an wallet application it would be easy, you just verify public key with private and send transaction to /tx, but anyway, what would preventing users to send transaction to /tx, the verification must be done in the server, so i have to send public and private key to the server, right?

But that can lead to security issues, what happens if there's an middleman listening to your requests?
Using ECDSA. In a transaction, the user provides the public key and also the signature of the transaction. Using the public key, nodes can use the public key and the signature to verify that it corresponds to the SHA256 of the TXID.

6. Does every node perform mining tasks?
No. Full nodes usually just verify transactions and blocks.
member
Activity: 142
Merit: 13
October 29, 2017, 07:09:07 AM
#2
Ok, about how to verify i'm the wallet owner, I've read that I have to send a signature with the transaction
 so the server can check the public key against the signature. Can I use RSA for this? I know that bitcoin uses
 RSA and ECDSA, but well I think for my basic coin RSA would be enough, is this correct or would using ony
 RSA incorrect?
member
Activity: 142
Merit: 13
October 29, 2017, 06:27:43 AM
#1
Hello People,

I'm developing an basic blockchain using nodeJS and TypeScript, basically to learn and understand better how a Blockchain/cryptocurrency work, this project uses PoW algorithm, And consensus catch the longest node available.

My Questions:

1. A block have it just one transaction or can it have more transactions?

2. Miners: So, just imagine I launch my coin, and there are no transactions yet, so miners have no work, if miners dont can do work, no new coins are supplied, so my questions, even if there are no transactions, can Block's without any transaction merged to the Blockchain? also "Empty Blocks" ?

3. About wallet System, I have no clue how this works, I know that public key is generated from Private key,  but how can the server know that the transaction comes from the wallet owner?

Imagine I have an endpoint in the node, /tx, there you send a json with from, to, and amount:

- With an wallet application it would be easy, you just verify public key with private and send transaction to /tx, but anyway, what would preventing users to send transaction to /tx, the verification must be done in the server, so i have to send public and private key to the server, right?

But that can lead to security issues, what happens if there's an middleman listening to your requests?

4. Storage
How do other coins store the Blockchain, Plain Files, MySQL, Or in memory? Redis? what is the normal way to store the Blockchain?

5. What would be better, treat every node as an public API that can be consumed with HTTP or use a socket communication (I think this one is the best, fastest, and securest).

6. Does every node perform mining tasks?

I Appreciate a lot your reading, and  I Hope i get some light from you!

Best Regards


Pages:
Jump to: