0

Could somebody help me out please? I'm really stuck creating a Private Ethereum Network and undestadning what the nodes are mining.

SO : Windows

Ethereum Client : Go-Ethereum

Here is my genesis.json:

{
"config": {
    "chainId": 9354,
    "homesteadBlock": 0,
    "eip155Block": 0,
    "eip158Block": 0
},
"alloc": {
    "8ef3b17dfd837ba9db963cb4aec03385cb58d366" : {"balance" : "1000000000000000000"}
},
"difficulty" : "0x20000",
"gasLimit"   : "0x8880000"}

I initialized the blockchain with following command in a terminal (T1):

geth --datadir pblkchain init genesis.json

Then started geth :

geth --port 3000 --networkid 9354 --nodiscover --datadir=./pblkchain --maxpeers=0 --unlock 8ef3b17dfd837ba9db963cb4aec03385cb58d366 --rpc --rpcport 8543 --rpcaddr 127.0.0.1 --rpccorsdomain "*" --rpcapi "eth,net,web3,personal,miner"

After that, I open a new terminal (T2) and attached via rpc :

geth attach http://127.0.0.1:8543

Finally I deployed my Truffle project to that private network in third terminal (T3) :

    truffle compile 
    truffle migrate --reset

With all that steps the smart contracts are deployed at the private network, but actually there is nobody mining. So in T2, we'll init a miner:

miner.start()

After init the miner, the smart contracts are really introduced into the blockchain.

At the terminal it's able to see the smart contract address which are being deployed. After the smart contract is deployed, in my terminal appear messages that keep importing blocks, but I'm not generating more transactions, what is it?.

PS C:\Users\xmaltas\Desktop\PrivateNetwork\network> geth --port 3000 --networkid 9354 --nodiscover --datadir=./pblkchain --maxpeers=0 --rpc --rpcport 8543 --rpcaddr 127.0.0.1 --rpccorsdomain "*" --rpcapi "eth,net,web3,personal,miner" --unlock 8ef3b17dfd837ba9db963cb4aec03385cb58d366
INFO [03-08|13:16:41.833] Maximum peer count ETH=0 LES=0 total=0
INFO [03-08|13:16:41.905] Starting peer-to-peer node instance=Geth/v1.8.21-stable-9dc5d1a9/windows-amd64/go1.11.4
INFO [03-08|13:16:41.911] Allocated cache and file handles database=C:\\Users\\xmaltas\\Desktop\\PrivateNetwork\\network\\pblkchain\\geth\\chaindata cache=512 handles=8192
INFO [03-08|13:16:41.986] Initialised chain configuration config="{ChainID: 143 Homestead: 0 DAO: <nil> DAOSupport: false EIP150: <nil> EIP155: 0 EIP158: 0 Byzantium: <nil> Constantinople: <nil> Engine: unknown}"
INFO [03-08|13:16:41.995] Disk storage enabled for ethash caches dir=C:\\Users\\xmaltas\\Desktop\\PrivateNetwork\\network\\pblkchain\\geth\\ethash count=3
INFO [03-08|13:16:42.002] Disk storage enabled for ethash DAGs dir=C:\\Users\\xmaltas\\AppData\\Ethash count=2
INFO [03-08|13:16:42.012] Initialising Ethereum protocol versions="[63 62]" network=9354
INFO [03-08|13:16:42.109] Loaded most recent local header number=562 hash=d2e805…b5590e td=84636417 age=1h15m58s
INFO [03-08|13:16:42.115] Loaded most recent local full block number=562 hash=d2e805…b5590e td=84636417 age=1h15m58s
INFO [03-08|13:16:42.120] Loaded most recent local fast block number=562 hash=d2e805…b5590e td=84636417 age=1h15m58s
INFO [03-08|13:16:42.129] Loaded local transaction journal transactions=4 dropped=4
INFO [03-08|13:16:42.135] Regenerated local transaction journal transactions=0 accounts=0
WARN [03-08|13:16:42.140] Blockchain not empty, fast sync disabled
INFO [03-08|13:16:42.191] New local node record

enter image description here

marked as duplicate by Richard Horrocks, Nicolas Massart, Achala Dissanayake, shane, Ismael Mar 9 at 3:48

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Hi there. Miners will create blocks even when there are no transactions being broadcast. This is by design, and expected. If you want to change your system to only mine when transactions have been broadcast, see this thread: ethereum.stackexchange.com/questions/3151/… – Richard Horrocks Mar 8 at 12:41
1

A miner will continue to mine even if there are not pending transactions. On your private geth network, if you want to stop nodes to mine empty blocks, you could either preload a javascript files on launch like this one:

var mining_threads = 1

function checkWork() {
    if (eth.getBlock("pending").transactions.length > 0) {
        if (eth.mining) return;
        console.log("== Pending transactions! Mining...");
        miner.start(mining_threads);
    } else {
        miner.stop(0);  // This param means nothing
        console.log("== No transactions! Mining stopped.");
    }
}

eth.filter("latest", function(err, block) { checkWork(); });
eth.filter("pending", function(err, block) { checkWork(); });

checkWork();

or either fork geth and edit the sealer.go file at line 62 this way

//if no pending transactions, stop
    if len(block.Transactions()) == 0 {
            log.Info("Sealing paused, waiting for transactions")
            return nil
    }

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