ethereum / ethereumj

DEPRECATED! Java implementation of the Ethereum yellowpaper. For JSON-RPC and other client features check Ethereum Harmony
GNU Lesser General Public License v3.0
2.18k stars 1.1k forks source link

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

Closed redskate closed 6 years ago

redskate commented 6 years ago

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 [] ]

zilm13 commented 6 years ago

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 commented 6 years ago

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

redskate commented 6 years ago

Hi Dmitry

thank you so much for responding :) Since the installation has one miner, I thought it must have sync.enabled=false in order to start mining. But of course in my young knowledge, mining only transactions on something (e.g. adding a contract or asking for a balance of an account).

With your hints (sync.enabled = true, mine.minGasPrice=1) The chain started mining again many blocks, and although minGasprice=1 the gas used is 0 … and all is looping (it seems). I removed the headers from the genesis file (had no idea what for they were there, hence I left them untouched) I let reset the DB every time because if not (flag = false) I got an exception … so step by step …

It was my expectance that the blockchain start to mine in order to see the genesis block, which you say, it is not mined. But then, in the genesis block I need to insert some accounts and with each account a balance as in one test genesis file I took.

When in the program I ask repository.getBalance(“823B03a41935………0a941e9d6".getBytes()) - it always return zero instead of the given value in the “alloc” part of the genesis file. (the genesis file is so correctly loaded in the config object - seen by debugger).

So I would like to query an account using getBalance and getting the value (or near that value) specified in the alloc section of the genesis file.

Do you have an idea why this is so?

Even after all those changes the application still reads a zero balance instead of 1000. The onSyncDone() method seems not to fire neither.

I have set now in the conf file peer.privateKey = something … Where is this used again? What private key should I put there? How calculated ? (sorry for the dumb questions, maybe there is a doc describing it, I should read) - should I debug stop and read it from the db or from the stdio log? I did not yet manage to install a kind of etherscan.io http://etherscan.io/ pointing to my ethereumj instance.

I will have to use the debug option … or debug every step...

Thanks Fabio

PS: Now the genesis file and conf are:

{ "config": { "chainId": 313, "eip158Block": 10, "byzantiumBlock": 1700000 },

"nonce": "0x0000000000000042", "timestamp": "0x00", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "extraData": "0x3535353535353535353535353535353535353535353535353535353535353535", "gasLimit": "0x01", "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 (I have to assign a name here, a long one… why? otherwise it crashes) - of course I will change every key after this issue :)

peer.discovery.enabled = false peer.listen.port = 20202 peer.networkId = 888

cache.flush.memory = 0 cache.flush.blocks = 1 sync.enabled = true sync.makeDoneByTimeout=10 mine.start = true mine.minGasPrice = 1 peer.privateKey = f67c4032a7ff79bbfa7a780331b235c4eb681d51a0704cb1a62064fb6c4bced4

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 loop:

05:50.643 INFO [db] Flush started 21:05:50.643 INFO [db] Flush completed in 0 ms 21:05:51.018 INFO [mine] Wow, block mined !!!: f9020bf90206a0e3e511be946dce9742c45202a8926eeec98beb65c090ec9179f319be20a3673fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a015cc445167da1f7daf9075922e6387c20f9c9723523566ae72c9da59881034fea056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000830223f3818e0180845b39263d91457468657265756d4a20706f7765726564a0ffeea79309d9282995ea092f3e65da2092800a67d67a9bb822a1259153c2bd0888b4d3f3a0b05ae52fc0c0 BlockData [ hash=21e71bbbc3ffaeab4e63a0a57d452098931c64b3724908806550df6dd1c10ba8 parentHash=e3e511be946dce9742c45202a8926eeec98beb65c090ec9179f319be20a3673f unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347 coinbase=0000000000000000000000000000000000000000 stateRoot=15cc445167da1f7daf9075922e6387c20f9c9723523566ae72c9da59881034fe txTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 receiptsTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 difficulty=0223f3 number=142 gasLimit=01 gasUsed=0 timestamp=1530471997 (2018.07.01 21:06:37) extraData=457468657265756d4a20706f7765726564 mixHash=ffeea79309d9282995ea092f3e65da2092800a67d67a9bb822a1259153c2bd08 nonce=b4d3f3a0b05ae52f Uncles [] Txs [] ]

On 1 Jul 2018, at 20:22, Dmitry S. notifications@github.com wrote:

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

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. 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 Most common mistakes with tx-es are too low gasPrice (check mine.minGasPrice in config and in tx) or wrong nonce. —

@redskate https://github.com/redskate you could receive such type of messages, especially if you reset DB and don't set peer.privateKey: your unique id is stored in db folder and if you remove it, it's generated again. The peers you've ever connected with know you with the old id and tries to talk using it, so such warning appears. Also this warning appears if there is something wrong with other peer or whatever. It's ok, when you have such events in log from time to time.

You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ethereum/ethereumj/issues/1116#issuecomment-401623814, or mute the thread https://github.com/notifications/unsubscribe-auth/AA7rrZ7E3Syz84S4pnFXQj6U5qf4CTArks5uCRN6gaJpZM4U-Zu1.

zilm13 commented 6 years ago

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 commented 6 years ago

Hi Dmitry - thank you for the Hex hint - in this case the app gets an expected alloc-defined balance for an account :)

So the network is mining and mining even empty blocks after empty blocks and when sporadically a transaction comes, it is mined in a block (thanks a lot for your kind explanation). (Since I am not creating a coin but just using the nice mechanism in order to safely store / retrieve information, I had to ask myself how to prevent all that zealous mining - I know that a blockchain was created / conceived for another target, but just in case: is there a way to reduce mining other than using a high difficulty which would then in turn cost a lot when a real transaction has come ? Can I bring ethereumj to directly start mining instead of after around 10 min - or not to start mining empty blocks ? (thanks a lot)

Regarding onSyncDone(): Yes I have a listener - the method inside a class “EthereumNetwork” writes like that (start segment):

public void onSyncDone() throws Exception { ethereum.addListener(new EthereumListenerAdapter() { // when block arrives look for our included transactions @Override public void onBlock(Block block, List receipts) { EthereumNetwork.this.onBlock(block, receipts); } });

    s2mp.dp("Compiling contract...");

Perfectly compiled, I put breakpoints on each line, none are executed. This method is practically constructed following the samples (thank you). I.e. the app create a “new EthereumNetwork()” and inside the class there is this method onSyncDone() …

On 1 Jul 2018, at 22:22, Dmitry S. notifications@github.com wrote:

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?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ethereum/ethereumj/issues/1116#issuecomment-401630744, or mute the thread https://github.com/notifications/unsubscribe-auth/AA7rrRdy5CN-OoRCqtd_x5zx2tVK4TSYks5uCS-CgaJpZM4U-Zu1.

zilm13 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

PS: Your kind response in https://github.com/ether-camp/ethereum-harmony/issues/102#issuecomment-401726276 answered my question.

redskate commented 6 years ago

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

redskate commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

Using Thread.run()

pschweitz commented 6 years ago

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 commented 6 years ago

Hi Philippe

thank you very much for your hint. I commented out sync.makeDoneByTimeout=10 and I took out the contract creating code and put it into an own method which is directly executed after network creation. Creating this contract (the beta-compiler seems to deliver) stucks then at transaction submission (waiting for the transaction to be mined). This transaction ist not mined at once, nor after 3 minutes … and sometimes the system does not mine it at all and it throws an exception, that that transaction was not in the last 16 blocks … seems it is a bit lazy... ;))))))

Nice to know you have the same target (I am using tomcat for the moment. And I do not bother about the application system for the moment). It seems my miner here be not too “responsive” … ?

Regarding scanner, I would like so much a scanner like harmony or etherscan pointed on my ethereumj instance, but it seems “too” difficult to do that...

Thank you for your hint, anyway.

btw - the compiler should be a beta one and it is suggested NOT to use it in a prod env. But then… what shell be use instead???

On 2 Jul 2018, at 19:02, pschweitz notifications@github.com wrote:

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

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ethereum/ethereumj/issues/1116#issuecomment-401869883, or mute the thread https://github.com/notifications/unsubscribe-auth/AA7rrai-SvRBQCS35FKCuH6aWHOg2Tl_ks5uClItgaJpZM4U-Zu1.

redskate commented 6 years ago

Hi Philippe

I guessed why my transaction is not suddenly locally mined in my ethereumj: because it does not take the right pair (account address / private key) as a parameter… in some way I must give the wrong address / private key.

In my genesis file (alloc section) I defined some accounts addresses with zero nonce each (ok so?).

These addresses were previously obtained using ethereum-harmony-wallet in the mnemonic way, e.g. creating them giving a mnemonic “bla bla bla”, which then gave an address I noted and put into the alloc section of my genesis file and recompiled all ethereumj JAR. So my knowledge is (up to know) that “bla bla bla” is the mnemonic for the password which I obtain in Java using sha3(“bla bla bla”.getBytes())

I am not sure this is the right way to generate accounts and their corresponding private keys to fire transactions in ethereumj.

Are you using another method to create pairs account address / private key and use them inside ethereumj ?

Is there a clear description (doc) on how to create accounts for ethereumj? The samples just user this “cow” example, I need a bit more clarity.

Could you give me here advise please ?

Thank you in advance

Regards

On 2 Jul 2018, at 19:02, pschweitz notifications@github.com wrote:

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

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/ethereum/ethereumj/issues/1116#issuecomment-401869883, or mute the thread https://github.com/notifications/unsubscribe-auth/AA7rrai-SvRBQCS35FKCuH6aWHOg2Tl_ks5uClItgaJpZM4U-Zu1.

pschweitz commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 ...