Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

How many empty transactions should be local mined until the first block is (when) finished ? #1116

Closed
redskate opened this issue Jul 1, 2018 · 19 comments

Comments

@redskate
Copy link

redskate commented Jul 1, 2018

My application waits for a onSyncDone() event of a test ethereumj network using the genesis file (see bottom here) and a configuration which resets every time the database.

In onSyncDone() a contract is submitted.

ethereumj is starting mining, each transaction locally mines without using gas. The difficulty arises a bit at each one. It mines and mines ... and I am asking myself when the first block will be "completed" (and the onSyncDone() will be fired / executed).

What can I do in order to avoid all that (empty 0-gas-locally-mining)?
What am I doing wrong?

What I would expect:

  1. quickly start mining
  2. genesis block mined in less than 10 minutes
  3. contract mined in less than 10 minutes

Thanks in advance
Regards

=======
the genesis file used:
{
"config": {
"chainId": 313,
"eip158Block": 10,
"byzantiumBlock": 1700000,

"headerValidators": [
  {"number": 10,     "hash": "0xb3074f936815a0425e674890d7db7b5e94f3a06dca5b22d291b55dcd02dde93e"},
  {"number": 585503, "hash": "0xe8d61ae10fd62e639c2e3c9da75f8b0bdb3fa5961dbd3aed1223f92e147595b9"}
]

},

"nonce": "0x0000000000000042",
"timestamp": "0x00",
"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"extraData": "0x3535353535353535353535353535353535353535353535353535353535353535",
"gasLimit": "0xFFFFFFF",
"gasPrice": "0x0F",
"difficulty": "0x01",
"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"coinbase": "0x0000000000000000000000000000000000000000",

"alloc": {

"0000000000000000000000000000000000000013": {
  "balance": "1000"
},
"0000000000000000000000000000000000000014": {
  "balance": "1000"
},
"0000000000000000000000000000000000000015": {
  "balance": "1000"
},
"0000000000000000000000000000000000000016": {
  "balance": "1000"
},
"0000000000000000000000000000000000000017": {
  "balance": "1000"
},
"0000000000000000000000000000000000000018": {
  "balance": "1000"
},
"0000000000000000000000000000000000000019": {
  "balance": "1000"
},
"000000000000000000000000000000000000001a": {
  "balance": "1000"
},
"000000000000000000000000000000000000001b": {
  "balance": "1000"
},
"000000000000000000000000000000000000001c": {
  "balance": "1000"
},
"000000000000000000000000000000000000001d": {
  "balance": "1000"
},
"000000000000000000000000000000000000001e": {
  "balance": "1000"
},
"000000000000000000000000000000000000001f": {
  "balance": "1000"
}

}
}

====== the conf used:
peer.discovery.enabled = false
peer.listen.port = 20202
peer.networkId = 888

cache.flush.memory = 0
cache.flush.blocks = 1
sync.enabled = false
mine.start = true

database.dir = sksDB
database.reset = true

#Key value data source values: [leveldb/redis/mapdb]
keyvalue.datasource=rocksdb

// a number of public peers for this network (not all of then may be functioning)
// need to get Seed/Miner node info and fill it in active peer section of all regular nodes like this:
peer.active =
[
{
ip= 10.0.1.120
port= 20202
nodeName = "sks1"
name = b3ea40366eae0206f7923a38c61ccfd1fcbd1185aa46596cfcba5eb762d484c15f998d6447162905507212742fbbda96507667d834192dd32bdc980e08e16ad3
}
]

// special genesis for this test network

genesis = eth_genesis_sksprivate.json
blockchain.config.name = "sks"
blockchain.config.class = "org.ethereum.config.blockchain.FrontierConfig"

==== the repeating logged transition:
19:31:29.880 INFO [db] DbFlushManager: flushing db due to commits (1) reached threshold (1)
19:31:29.880 INFO [db] Flush started
19:31:29.880 INFO [db] Flush completed in 0 ms
19:31:31.937 INFO [mine] Wow, block mined !!!: f90210f9020ba088dc93d8fe280f0caa9e6ebfefe7424b3475b32f632266c052e47be20e19da50a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a06d22e1476729423e80cd6fefafec8debaf894f3543d1c3a943d5c48c48ae0d72a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830757d3820a79840fffffff80845b390ff391457468657265756d4a20706f7765726564a0faf87dd749faa0b7c8b096b48eae4d75a5e8bdcf64f0d8dea1136162100c6f4788478d36626f84dbedc0c0
BlockData [ hash=1150ee2b3c5b7d5e3a543f67303d1727cbcf0ccd88cb7e5007d604a709eddc8e
parentHash=88dc93d8fe280f0caa9e6ebfefe7424b3475b32f632266c052e47be20e19da50
unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
coinbase=0000000000000000000000000000000000000000
stateRoot=6d22e1476729423e80cd6fefafec8debaf894f3543d1c3a943d5c48c48ae0d72
txTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
receiptsTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
difficulty=0757d3
number=2681
gasLimit=0fffffff
gasUsed=0
timestamp=1530466291 (2018.07.01 19:31:31)
extraData=457468657265756d4a20706f7765726564
mixHash=faf87dd749faa0b7c8b096b48eae4d75a5e8bdcf64f0d8dea1136162100c6f47
nonce=478d36626f84dbed
Uncles []
Txs []
]

@redskate redskate changed the title How many empty transactions should be mined until the first block is (when) finished ? How many empty transactions should be local mined until the first block is (when) finished ? Jul 1, 2018
@zilm13
Copy link
Collaborator

zilm13 commented Jul 1, 2018

What I would expect:

quickly start mining

You've 2681-th block from log, so mining is running for a long already

genesis block mined in less than 10 minutes

Genesis block is not needed to be mined, it's a priori 0 block of the chain

contract mined in less than 10 minutes

  1. Use sync.enabled=true along with sync.makeDoneByTimeout=10 (for example) for private network. You cannot get syncDone in network consisting only one miner from blocks.
  2. Check log, why your transaction is not included in PendingState, you may need to set logger level to debug for pending to see this. Also you could add listener for onPendingTransactionUpdate and check, what's wrong with it
  3. Most common mistakes with tx-es are too low gasPrice (check mine.minGasPrice in config and in tx) or wrong nonce.

@zilm13
Copy link
Collaborator

zilm13 commented Jul 1, 2018

Also remove headerValidators from your genesis, you are starting chain from the genesis

@redskate
Copy link
Author

redskate commented Jul 1, 2018 via email

@zilm13
Copy link
Collaborator

zilm13 commented Jul 1, 2018

The chain started mining again many blocks

It's ok, the only thing that limits your mining power is difficulty. You don't need txs to mine, it's a base of self-balancing in crypto-networks. When txs arrives they are included in blocks. No txs - blocks are still mined.

it is not mined

yeah, genesis is 0 block of your chain, 1-st mined block is the next block etc.

When in the program I ask repository.getBalance(“823B03a41935………0a941e9d6".getBytes())

“823B03a41935………0a941e9d6".getBytes() - you have the string, one byte for every symbol or whatever, depends on encoding and get bytes from this string, however 823B03a41935………0a941e9d6 is hex transcription of bytes in string. To get your adress bytes you need something like Hex.decode("823B03a41935………0a941e9d6"), so you will get 1 byte from every 2 hex symbols, which encodes this byte.

I have set now in the conf file

not necessary, but you should know that it will be changed with every removal of db if it's not set. It's any random 32 bytes, check config for more info

The onSyncDone() method seems not to fire neither

Do you have listener?

@redskate
Copy link
Author

redskate commented Jul 2, 2018 via email

@zilm13
Copy link
Collaborator

zilm13 commented Jul 2, 2018

@redskate you could either set greater difficulty in genesis, so machine will need more time to make a block or use minBlockTimeout feature https://github.com/ethereum/ethereumj/blob/develop/ethereumj-core/src/main/resources/ethereumj.conf#L348-L349 even with small difficulty.

Can I bring ethereumj to directly start mining instead of after around 10 min - or not to start mining empty blocks ?

Not. Of course, you could fork and change something to make it possible, but you couldn't get such behaviour using config. Normally blockchain network have some competitiveness among peers and it's not designed for wait for tx blocks.

Regarding not called listener, you'd better share your repository, so I could point why it's not switched to syncDone.

@redskate
Copy link
Author

redskate commented Jul 2, 2018

So since right now the app AND the network are on the same machine it seems to me an overkill to let all work on one single machine (very sporadic transactions) ... which would spend time mining. So in my case I think the mine work should not be done via a local miner but via another miner on another machine - the question is: who will then mine "my" blocks on this network on 20202 (for example) ? Any outside "reachable" networks ? And if yes, why should they do that (since no coin is mined) ? So I think in this case the miner should be provided by my "church" ...

  1. Install a miner (have to search for one)
  2. point the miner exclusively to my peer

I hope I see it so in the right way ?

@redskate
Copy link
Author

redskate commented Jul 2, 2018

PS: Your kind response in ether-camp/ethereum-harmony#102 (comment) answered my question.

@redskate
Copy link
Author

redskate commented Jul 2, 2018

I will share (here) ? the code of my EthererumNetwork Class ?

@redskate
Copy link
Author

redskate commented Jul 2, 2018

A repository is a java object, how can I share it with you (here?) ?
Pls have a look at https://semlab.ch/downloads/dmitry/EthereumNetwork.java and tell me when done (I will retract it) - thx.

@redskate
Copy link
Author

redskate commented Jul 2, 2018

I suppose where could be "the problem" of non starting onSyncDone():

In the samples the class implements Runnable ... but my class does not ... so probably I have to derive from Runnable and see ...

But then please how should my app start an ethereumj network inside Java in order to access it later in Java ?

@redskate
Copy link
Author

redskate commented Jul 2, 2018

Using Thread.run()

@redskate redskate closed this as completed Jul 2, 2018
@pschweitz
Copy link

Hi

The following sync.makeDoneByTimeout=10 option will release the block miner after sometime, but unfortunately it wont trigger the onSyncDone event for a listener you have provided after Etherum loading. It apparently works only for internal runtime of ethereumJ.

For information, I remarked the onSyncDone is triggered for my own listener only after I submitted a new transaction.

If it can help you. I am also working in the context of a private network, but without Harmony as I do not want have any dependency to Tomcat or whatever fat and slow Java http server side implementation.

Cheers

Philippe

@redskate
Copy link
Author

redskate commented Jul 2, 2018 via email

@redskate
Copy link
Author

redskate commented Jul 2, 2018 via email

@pschweitz
Copy link

pschweitz commented Jul 4, 2018

Hi Redstake,

I was like you sometime ago wondering to mine blocks in a private network context.

Just for let you know, I am not yet using the functionality of smart contract as it is not yet sufficiently mature, either in technicals nor in legal frameworks.

I do use ethereumJ for traceability of data only at the moment (it won't tell I would never use smart contracts in the future anyway, for particular uses cases)

Regarding your mining issue, you must use the sync.makeDoneByTimeout=10 option. it is the only way to let the miner starting in a private network, otherwise the process remains stuck waiting for a never coming new block.
For the rest it would be complicated to clearly answer you for the use case you are describing.

I just can tell you I use a combination of following methods to get a view of the blockchain status during the runtime:

Blockchain initialization with first transactions thanks to following annotation:

    /**
     * The method is called after all EthereumJ instances are created
     */
    @PostConstruct
    private void init() [...]

My custom Listener onBlock method to remain independent of the "onSyncDone", still triggered too late in my humble opinion

    @Override
    public void onBlock(BlockSummary blockSummary) [...]

For the user creation, I use following piece of code:

    ECKey key = new ECKey();

    byte[] addr = key.getAddress();
    byte[] priv = key.getPrivKeyBytes();

    address = Hex.toHexString(addr);
    privateKey = Hex.toHexString(priv);

Regarding the HTTP server, yes you can see it as self-promotion, but I use a light webserver I designed by my own (using simple framework as the underlaying HTTP library):

https://github.com/pschweitz/CheetahWebserver

Finally, I can already tell you that the software I am creating with ethereumJ will have an open source edition as well, release planned in September.

Cheers,
Philippe

@redskate
Copy link
Author

redskate commented Jul 4, 2018

Hi @pschweitz thanks so much (in the meanwhile I could manage to let mine and to submit/use contracts in ethereumj) - so the stuff is now running (at last and after a number of days for me).

My application shuld/could use a private ethereumj instance to securely store documents. I will be happy to share more details with you privately if wished. Is there a way you can contact me privately?

So since I am tryingto use ethereumj as a basis to hold documents, I am not interested in financial stuff (for the moment), not in a coin, just in enough users with enough balance to be able to add / retrieve docs.

So the next question (maybe you already solved that): is that - well - I can provide a starting genesis file containing - say - 1000 accounts with maximal balance (Bigint.max) and offer the users the next nonused account privatekey, but what if the 1001 account is needed? A new genesis file with further accounts will destroy the chain (we do not wish it) - so for me (ignorant at this stage) the only way would be to change some account objects at runtime in ethereumj code... I would not want to do that ... this would open a branch ...

What did/would you do in order to add new accounts (if your app does it) with "enough" balance?

I close this issue, since we are getting out of issue subject :)

Thanks again.

Thank you for your Webserver - I will give a look asap!

@pschweitz
Copy link

I will enter in these platform-wide administrative concerns soon as well.

You must not alter the genesis, otherwise you will break your chain. This file is only intended to initiate the chain and first accounts. What I suggest to do is to transfer some ethers to the new account once created.

In your case apparently it does not matter how many ethers left in the balance of your (let say) admin account. So then adjust the values like the gas and gas price to enable mining. Another way I have not yet explored is to create new ethers (if possible) also by an admin account to transfer them to the new account.

After that you must think on a way of persisting account information like the address and the private key to recover the balance at the next execution of your software.

@redskate
Copy link
Author

redskate commented Jul 4, 2018

Look at your linkedin profile.

Thank you philippe.

Storing pairs address<->pkeys and storing assignement in another ... say db table is not (in my opinion) a valid way, it offers a vulnerability in case the db is cracked ...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants