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.19k stars 1.09k forks source link

Private net and sync Blocks #1048

Open 1jose234 opened 6 years ago

1jose234 commented 6 years ago

I have doubts about how to make a private network and how to make the blocks copied between nodes, can you help me?

mkalinin commented 6 years ago

Read this guide first https://github.com/ether-camp/ethereum-harmony/wiki/Setting-up-a-private-network

1jose234 commented 6 years ago

thanks, I have already run the project in custom network, I am interested in the creation as a developer with ethereumj core, and I review the classes in "org.ethereum.samples", but I have doubts on how to create a Regular Node and how to synchronize the blocks, not I have seen some technical manual.

zilm13 commented 6 years ago

@1jose234 this is the smallest sample I have

import com.typesafe.config.ConfigFactory;
import org.ethereum.config.SystemProperties;
import org.ethereum.crypto.ECKey;
import org.ethereum.facade.EthereumFactory;
import org.ethereum.samples.BasicSample;
import org.springframework.context.annotation.Bean;

import static org.ethereum.crypto.HashUtil.sha3;

public class Start extends BasicSample {
    /**
     * Use that sender key to sign transactions
     */
    protected final byte[] senderPrivateKey = sha3("cow".getBytes());
    // sender address is derived from the private key
    protected final byte[] senderAddress = ECKey.fromPrivate(senderPrivateKey).getAddress();

    protected abstract static class TestNetConfig {
        private final String config =
                // Ropsten revive network configuration
                "peer.discovery.enabled = true \n" +
                        "peer.listen.port = 30303 \n" +
                        "peer.networkId = 3 \n" +
                        // a number of public peers for this network (not all of then may be functioning)
                        "peer.active = [" +
                        "    {url = 'enode://6ce05930c72abc632c58e2e4324f7c7ea478cec0ed4fa2528982cf34483094e9cbc9216e7aa349691242576d552a2a56aaeae426c5303ded677ce455ba1acd9d@13.84.180.240:30303'}," +
                        "    {url = 'enode://20c9ad97c081d63397d7b685a412227a40e23c8bdc6688c6f37e97cfbc22d2b4d1db1510d8f61e6a8866ad7f0e17c02b14182d37ea7c3c8b9c2683aeb6b733a1@52.169.14.227:30303'}" +
                        "] \n" +
                        "sync.enabled = true \n" +
                        // special genesis for this test network
                        "genesis = ropsten.json \n" +
                        "blockchain.config.name = 'ropsten' \n" +
                        "database.dir = testnetSampleDb \n" +
                        "cache.flush.memory = 0";

        public abstract Start sampleBean();

        @Bean
        public SystemProperties systemProperties() {
            SystemProperties props = new SystemProperties();
            props.overrideParams(ConfigFactory.parseString(config.replaceAll("'", "\"")));
            return props;
        }
    }

    @Override
    public void onSyncDone() throws Exception {
        super.onSyncDone();
    }

    public static void main(String[] args) throws Exception {
        sLogger.info("Starting EthereumJ!");

        class SampleConfig extends TestNetConfig {
            @Bean
            public Start sampleBean() {
                return new Start();
            }
        }

        // Based on Config class the BasicSample would be created by Spring
        // and its springInit() method would be called as an entry point
        EthereumFactory.createEthereum(SampleConfig.class);
    }
}

Still you could remove almost everything from it including inheritance of BasicSample but leave the line EthereumFactory.createEthereum(SampleConfig.class) and use different input or no input at all (so it will use default config). It's the command that starts EthereumJ with provided config.

If you could clarify what's exactly not clear in using EthereumJ for you, I could help you further.

1jose234 commented 6 years ago

ok, I'll tell you what I've done Using the PrivateMinerSample class, activate the option record.blocks = true to save the blocks in the folder of each peer (in a .dmp file), I do not know if this is correct or where the blocks are stored?

Now what I need is to create another Node that is not a Miner and that the two contain the same blocks, but I have not managed to do this.

in the example that you share, it connects to two nodes that already exist in ropsten, but I just need to create those two nodes, connect to my Private Net and share the blocks.

Thank you very much for the help sorry for my English

zilm13 commented 6 years ago

For recording blocks enable record.blocks. You will find dump here:

        String dumpDir = config.databaseDir() + "/" + config.dumpDir();
        File dumpFile = new File(dumpDir + "/blocks-rec.dmp");

For loading blockchain from file provide its name with path using following parameter in config or passing via ENV.

# Load the blocks
# from a rlp lines
# file and not for
# the net
blocks.loader=""

Also you could make your own blockLoading. Take a look of our implementation starting from https://github.com/ethereum/ethereumj/blob/develop/ethereumj-core/src/main/java/org/ethereum/Start.java#L55-L57

1jose234 commented 6 years ago

thanks for your fast answer..   A few minutes ago, I did a miner in a LAN machine and successfully copied the miner's blocks to the Regular Peer. I have doubts about the nodes that I must create in a private network, should they only be Miners and only one Regular Peers?

I want say, if now do one Peer this should be one Miner ?

my goal is: Create a private network using the core of EthereumJ (it is important to use the core and not download the jar dede Maven for example) Create a DAPP that stores the transactions using the private network created, is this possible?

by the by, this code repeat the same block Genesis when is writte, is correctly ?

if (bestBlock.isGenesis()) {
                bw.write(Hex.toHexString(bestBlock.getEncoded()));
                bw.write("\n");
            }

            bw.write(Hex.toHexString(block.getEncoded()));
            bw.write("\n");
zilm13 commented 6 years ago

@1jose234 it's ok to have one miner in private network if you are sure that it will be always up.

Create a DAPP that stores the transactions using the private network created, is this possible?

use ethereum.addListener for it, check, for example, EventListenerSample: https://github.com/ethereum/ethereumj/blob/develop/ethereumj-core/src/main/java/org/ethereum/samples/EventListenerSample.java#L289-L295

by the by, this code repeat the same block Genesis when is writte, is correctly ?

Yeah, because when blockchain is initialised with genesis, genesis block is not passed through with logic, so on 1st block both genesis and 1st block are dumped.

1jose234 commented 6 years ago

ok, i did one test I created 3 peers, 2 miners: minerA, minerB and 1 Regular Node.

The 3 peers are in 3 different computers, but when run the connections, the Regular Node get only the blocks of minerA and nothing of minerB, owever minerB is working correctly.

I understand that the 3 peers should have the same Blocks is true? but the Regular Node and minerA have the same while minerB have their own blocks created.

How i should do the configuration to sync the blocks between the 3 peers ?

this is my configuration:

minerA

private final String config =
                // no need for discovery in that small network
                "peer.discovery.enabled = false \n" +
                "peer.listen.port = 30342 \n" +
                 // need to have different nodeId's for the peers
                "peer.privateKey = 6ef8da380c27cea8fdf7448340ea99e8e2268fc2950d79ed47cbf6f85dc977ec \n" +
                // our private net ID
                "peer.networkId = 556 \n" +
                // we have no peers to sync with
                "sync.enabled = true \n" +
                // genesis with a lower initial difficulty and some predefined known funded accounts
                "genesis = sample-genesis.json \n" +
                // two peers need to have separate database dirs
                "database.dir = sampleDB-1 \n" +
                // when more than 1 miner exist on the network extraData helps to identify the block creator
                "mine.extraDataHex = cccccccccccccccccccc \n" +
                "mine.cpuMineThreads = 2 \n" +
                "cache.flush.blocks = 1";

minerB

private final String config =
                // no need for discovery in that small network
                "peer.discovery.enabled = false \n" +
                "peer.listen.port = 30343 \n" +
                 // need to have different nodeId's for the peers
                "peer.privateKey = 6ef8da380c27cea8fdf7448340ea99e8e2268fc2950d79ed47cbf6f85dc977ed \n" +
                // our private net ID
                "peer.networkId = 556 \n" +
                // we have no peers to sync with
                "sync.enabled = true \n" +
                // genesis with a lower initial difficulty and some predefined known funded accounts
                "genesis = sample-genesis.json \n" +
                // two peers need to have separate database dirs
                "database.dir = sampleDB-1 \n" +
                // when more than 1 miner exist on the network extraData helps to identify the block creator
                "mine.extraDataHex = dccccccccccccccccccd \n" +
                "mine.cpuMineThreads = 2 \n" +
                "cache.flush.blocks = 1";

regular Node

private final String config =
                // no discovery: we are connecting directly to the miner peer
                "peer.discovery.enabled = false \n" +
                "peer.listen.port = 30336 \n" +
                "peer.privateKey = 3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c \n" +
                "peer.networkId = 556 \n" +
                // actively connecting to the miner
                "peer.active = [" +
                "    { url = 'enode://26ba1aadaf59d7607ad7f437146927d79e80312f026cfa635c6b2ccf2c5d3521f5812ca2beb3b295b14f97110e6448c1c7ff68f14c5328d43a3c62b44143e9b1@192.168.6.24:30342' }, \n" +
                "    { url = 'enode://9d19b50f730906d544ad97debd31a0486e0dd53fbed4db0a27fba0c06599ce151d270cf4c504a09f5763c9ba1f8039303a6722d22217e6d1ec13e67bc315f0e0@192.168.6.57:30343' }" +
                "] \n" +
                "sync.enabled = true \n" +
                // all peers in the same network need to use the same genesis block
                "genesis = sample-genesis.json \n" +
                // two peers need to have separate database dirs
                "database.dir = sampleDB-2 \n";
mkalinin commented 6 years ago

As I can see from your configs minerA and minerB have no connection between each other. You may fix this by adding miners to each other peer.active section. Also, a question, do you start miner manually in Terminal?

1jose234 commented 6 years ago

Thaks for the help... I made the configuration of miners

The minerB (mine.extraDataHex = dddddddddddddddddddd) get blocks of minerA (mine.extraDataHex = cccccccccccccccccccc), but the minerA have only their own blocks, while Regular Node get only the blocks of minerA.

minerA

private final String config =
                // no need for discovery in that small network
                "peer.discovery.enabled = false \n" +
                "peer.listen.port = 30342 \n" +
                 // need to have different nodeId's for the peers
                "peer.privateKey = 6ef8da380c27cea8fdf7448340ea99e8e2268fc2950d79ed47cbf6f85dc977ec \n" +
                // our private net ID
                "peer.networkId = 556 \n" +
                "peer.active = [" +               
                "    { url = 'enode://9d19b50f730906d544ad97debd31a0486e0dd53fbed4db0a27fba0c06599ce151d270cf4c504a09f5763c9ba1f8039303a6722d22217e6d1ec13e67bc315f0e0@192.168.6.57:30343' }" +
                "] \n" +
                // we have no peers to sync with
                "sync.enabled = true \n" +
                // genesis with a lower initial difficulty and some predefined known funded accounts
                "genesis = sample-genesis.json \n" +
                // two peers need to have separate database dirs
                "database.dir = sampleDB-1 \n" +
                // when more than 1 miner exist on the network extraData helps to identify the block creator
                "mine.extraDataHex = cccccccccccccccccccc \n" +
                "mine.cpuMineThreads = 2 \n" +
                "cache.flush.blocks = 1";

minerB

private final String config =
                // no need for discovery in that small network
                "peer.discovery.enabled = false \n" +
                "peer.listen.port = 30343 \n" +
                 // need to have different nodeId's for the peers
                "peer.privateKey = 6ef8da380c27cea8fdf7448340ea99e8e2268fc2950d79ed47cbf6f85dc977ed \n" +
                // our private net ID
                "peer.networkId = 556 \n" +
         "peer.active = [" +
                "    { url = 'enode://26ba1aadaf59d7607ad7f437146927d79e80312f026cfa635c6b2ccf2c5d3521f5812ca2beb3b295b14f97110e6448c1c7ff68f14c5328d43a3c62b44143e9b1@192.168.6.24:30342' } \n" +
                "] \n" +
                // we have no peers to sync with
                "sync.enabled = true \n" +
                // genesis with a lower initial difficulty and some predefined known funded accounts
                "genesis = sample-genesis.json \n" +
                // two peers need to have separate database dirs
                "database.dir = sampleDB-1 \n" +
                // when more than 1 miner exist on the network extraData helps to identify the block creator
                "mine.extraDataHex = dddddddddddddddddddd \n" +
                "mine.cpuMineThreads = 2 \n" +
                "cache.flush.blocks = 1";

Here we can see two blocks one of dddddddddddddddddddd and one of cccccccccccccccccccc, but the two miners should have the same information. its true ?

BlockData [   hash=7b0c9a022c930f484cf97d23c134b78590e43a2d385819e48584ffbf4e657ed9
  parentHash=d30e2211835f6cb6f361690efafdca9f4956140620536c4fd8dc5853467382af
  unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
  coinbase=0000000000000000000000000000000000000000
  stateRoot=d2b3c935664f8de0528a300fa2abae6e98c3b9b157d797dab6c9b287763bdc8f
  txTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
  receiptsTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
  difficulty=100dff
  number=13
  gasLimit=1000000000
  gasUsed=0
  timestamp=1523640173 (2018.04.13 12:22:53)
  extraData=dddddddddddddddddddd
  mixHash=71d6ab755d61ab7130f2e769aa5a2b738f616c2a84bd003889fcbb61ef500d39
  nonce=de37c7e9aa21dc77
Uncles []
Txs []BlockData [   hash=d30e2211835f6cb6f361690efafdca9f4956140620536c4fd8dc5853467382af
  parentHash=8a458c9e9a4536d2570b1916d67895a1d387bbc2f82fef3b34c02906ee7408fd
  unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
  coinbase=0000000000000000000000000000000000000000
  stateRoot=d517133483245764b755dd1f0240634a0f7aca5d7b48d5c4c75f200bc6d4d610
  txTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
  receiptsTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
  difficulty=100bfe
  number=12
  gasLimit=1000000000
  gasUsed=0
  timestamp=1523640171 (2018.04.13 12:22:51)
  extraData=cccccccccccccccccccc
  mixHash=58260dc660967ddf71f5eaf337e9e0403aaf75d764d71185a4a8dc641b9031a9
  nonce=d2941f0f9f9209d9
Uncles []
Txs []
]

BlockData [   hash=7b0c9a022c930f484cf97d23c134b78590e43a2d385819e48584ffbf4e657ed9
  parentHash=d30e2211835f6cb6f361690efafdca9f4956140620536c4fd8dc5853467382af
  unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
  coinbase=0000000000000000000000000000000000000000
  stateRoot=d2b3c935664f8de0528a300fa2abae6e98c3b9b157d797dab6c9b287763bdc8f
  txTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
  receiptsTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
  difficulty=100dff
  number=13
  gasLimit=1000000000
  gasUsed=0
  timestamp=1523640173 (2018.04.13 12:22:53)
  extraData=dddddddddddddddddddd
  mixHash=71d6ab755d61ab7130f2e769aa5a2b738f616c2a84bd003889fcbb61ef500d39
  nonce=de37c7e9aa21dc77
Uncles []
Txs []

Also, i can't understand what is the uncle[] ?

BlockData [   hash=217ce835c678ac5ba3c2013268b13c35e0896c23d78d83b57ceb425ea26820a2
  parentHash=22c676ca87b75701b9ca3c918b87ca8636b81eea9f1ea3111a2df5644a1fff4d
  unclesHash=cb283515fa142203eb3aa83a835cb9ce552b570aae6faef3514c16eb7e50eb69
  coinbase=0000000000000000000000000000000000000000
  stateRoot=66cd042a43169f73acd9a017763d7b21d23c8c4858f097e147b6c21f07b8a15a
  txTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
  receiptsTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
  difficulty=100bff
  number=8
  gasLimit=1000000000
  gasUsed=0
  timestamp=1523640116 (2018.04.13 12:21:56)
  extraData=dddddddddddddddddddd
  mixHash=c5069047cebc9af30dbd8b1357281f2b3f1ba8fed914f62e1a743893eec0d7fa
  nonce=ee50cec86928626e
Uncles [
  hash=145a8d736199f9b4fa4a9b24083aea401d2fd91b480ddc3a7ef1bf323cac1070
  parentHash=9e2d5825edcb3de588b3c106ac8dcf95aa9ed8c059574359b9ca6b55b326984a
  unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
  coinbase=0000000000000000000000000000000000000000
  stateRoot=76c1944ea751adee6fcbbbef57d836f5b0aca43de6b7d04c74498788ebb6e9d6
  txTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
  receiptsTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
  difficulty=1007fe
  number=6
  gasLimit=1000000000
  gasUsed=0
  timestamp=1523640108 (2018.04.13 12:21:48)
  extraData=cccccccccccccccccccc
  mixHash=f618b957450d124437a6f74103663453aff0769a9e574757c23b23e7b7383b50
  nonce=2f6e1b25fd9b7dd1

]
Txs []
zilm13 commented 6 years ago

@1jose234 1) When all your mining power is 2 peers with almost equal mining power you get a big chance to get long-long forks with the same difficulty. You need more diversity in mining power. It's a very unstable network configuration. I'd recommend one miner in small private network. If you want several miners, you should setup network configuration with variable difficulty (for example "frontier" and difficulty > 0x0801) and you shouldn't expect stability until miners reach balance of difficulty with block time (13 seconds average block time for Frontier), especially when they have equal mining power. 2) You need to have some delay between blocks, so the peers will have time to sync between blocks. If the peer pops out 5 blocks in a second, peers may have difficulties in sync. So set reasonable difficulty. 3) If you are using miner with sync enabled in private network, call ethereum.switchToShortSync() method first.

You can read about uncles here: https://ethereum.stackexchange.com/questions/34/what-is-an-uncle-ommer-block

1jose234 commented 6 years ago

Thank you for answering so quickly...

I'd recommend one miner in small private network.

In short, what would be the architecture of a network block chain that works for my purpose, I need create one private network to connect one DAPP for save the transactions (not more of 100 in day) of approval of budgets, but i dont know how many peers create and the most important... what kind should they be miners or regular nodes ?

this is one POC to for projects of greater complexity, using code source of ethereumj and dApps in java.

You can read about uncles here: https://ethereum.stackexchange.com/questions/34/what-is-an-uncle-ommer-block

thanks just after send the message, i found this link

zilm13 commented 6 years ago

@1jose234 I'd recommend one miner and 2 different regular peers (say, Harmony and Geth) with JSON-RPC and interaction via JSON-RPC so you will be able to switch between them in case of any instability

1jose234 commented 6 years ago

i applicated your recommendations using PrivateMinerSample as a sample First , i changed "difficulty": "0x900000" After, i run the class and the result is:

BlockData [   hash=9a13c92fe615a49a2e8d5f13b98f975a86ec7cefe3788e6f7da3042232bfc9f4
  parentHash=dca9b48bcaf905b4b8eefef295db88482a1c143cfb8386cdb90d1167bf144ae4
  unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
  coinbase=0000000000000000000000000000000000000000
  stateRoot=9c7460dbfd853c07a340e55bab456d4035190400246b731b193ec8c8044f41ae
  txTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
  receiptsTrieHash=56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421
  difficulty=8fee00
  number=1
  gasLimit=1000000000
  gasUsed=0
  timestamp=1524022714 (2018.04.17 22:38:34)
  extraData=cccccccccccccccccccc
  mixHash=2f6fc2351568781199df55dc08f2ec34612df2edab186c5bb284a19a102d382f
  nonce=e80e1fb995d2c832
Uncles []
Txs []
]

BlockData [   hash=fa3ff312b8cb3827299513a370e12ab8eddc2bc0e1f31e5b4ee0f2b80616026b
  parentHash=9a13c92fe615a49a2e8d5f13b98f975a86ec7cefe3788e6f7da3042232bfc9f4
  unclesHash=1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347
  coinbase=0000000000000000000000000000000000000000
  stateRoot=6bf4df61c2bfcc80dde0fbb66abd9775f864013d52f52b3fa4d2de2fe0be3bc9
  txTrieHash=d837ff9c66366cf70542097deb6e37c89d92696c9cb8903824eb97f80d3d0156
  receiptsTrieHash=de64efe2614e6321f23c2f7355861d610a187916b2a9e8a2aa8ab47b20f6978e
  difficulty=8fdc03
  number=2
  gasLimit=1000000000
  gasUsed=21000
  timestamp=1524022757 (2018.04.17 22:39:17)
  extraData=cccccccccccccccccccc
  mixHash=8d65688fdaf5d9e62d2a069f88326dbbe06a334ef348c6db7b3660fed41d6aef
  nonce=ddeedee7a078bc64
Uncles []
Txs [
TransactionData [hash=7a822f895985c684f554531c79d2fa75012b4b7803ab7abc9e46442b8b142a42  nonce=, gasPrice=0ba43b7400, gas=0fffff, receiveAddress=5db10750e8caff27f906b41c71b3471057dd2004, sendAddress=31e2e1ed11951c7091dfba62cd4b7145e947219c, value=4d, data=, signatureV=27, signatureR=4164906d6b5b242c779b50a4737f30ea7da1a760e99b62492ca8073aaddc28c8, signatureS=287b764c6c73595f941f80cc39abd7bd31a981e44ca584e0813c22fd3df0e0b2]
]
]

the regular node send transactions each minute but i can't understand why some Txs[] are empty and other (i think) have the transactions sended from regular node. could you helpe to know what is the reason ?

mkalinin commented 6 years ago

You have mentioned that Txes are sent with a minute delay, but blocks are minted about two time faster as I can see from blocks' timestamps. That must be a reason why some of minted blocks are empty

1jose234 commented 6 years ago

ok... so, if i have blocks empty affect to my Net or is normal that exist ?, the objective of mi network is save transactions sended by one dapp but this could be in variable time, at that time could exist alot of blocks empty.

what i should do ?

mkalinin commented 6 years ago

Empty blocks by itself don't break anything and are ok for the blockchain.

1jose234 commented 6 years ago

i did test with the class CreateContractSample to add the contract in to private net. https://github.com/ethereum/ethereumj/blob/develop/ethereumj-core/src/main/java/org/ethereum/samples/CreateContractSample.java

this is the configuration of the node in the private net:

private final String config =
                // no discovery: we are connecting directly to the miner peer
                "peer.discovery.enabled = false \n" +
                "peer.listen.port = 30336 \n" +
                "peer.privateKey = 3ec771c31cac8c0dba77a69e503765701d3c2bb62435888d4ffa38fed60c445c \n" +
                "peer.networkId = 556 \n" +
                // actively connecting to the miner
                "peer.active = [" +
                "    { url = 'enode://26ba1aadaf59d7607ad7f437146927d79e80312f026cfa635c6b2ccf2c5d3521f5812ca2beb3b295b14f97110e6448c1c7ff68f14c5328d43a3c62b44143e9b1@localhost:30335' }" +
                "] \n" +
                "sync.enabled = true \n" +
                // all peers in the same network need to use the same genesis block
                "genesis = sample-genesis.json \n" +
                // two peers need to have separate database dirs
                "database.dir = confConecionPrivada \n" +
                "cache.flush.memory = 0";

but in the method waitForTx() the object receipt is all time Null, and after 16 blocks throw a RuntimeException.

 ByteArrayWrapper txHashW = new ByteArrayWrapper(txHash);
        txWaiters.put(txHashW, null); //HERE SET NULL ALL TIME
        long startBlock = ethereum.getBlockchain().getBestBlock().getNumber();
        while(true) {
            TransactionReceipt receipt = txWaiters.get(txHashW);
            if (receipt != null) {
                return receipt;
            } else {
                long curBlock = ethereum.getBlockchain().getBestBlock().getNumber();
                if (curBlock > startBlock + 16) {
                    throw new RuntimeException("The transaction was not included during last 16 blocks: " + txHashW.toString().substring(0,8));
                } else {
                    logger.info("Waiting for block with transaction 0x" + txHashW.toString().substring(0,8) +
                            " included (" + (curBlock - startBlock) + " blocks received so far) ...");
                }
            }
            synchronized (this) {
                wait(20000);
            }
        }

could you help me to know what is the reason ?

zilm13 commented 6 years ago

@1jose234 by some reason your transaction is not included in the chain. Most common reasons for it are: 1) Something is not right with tx: sender doesn't have enough money, nonce is incorrect etc. To check this add pendingState listener and check output for your tx. Something like that is done here: https://github.com/ethereum/ethereumj/blob/develop/ethereumj-core/src/main/java/org/ethereum/samples/EventListenerSample.java#L207-L216 2) Your miner doesn't include tx in chain by some reason: low gasPrice in settings or whatever. Check miner logs, search by your tx hash.

1jose234 commented 6 years ago

now, i can send the transaction to miner, and set to block

Txs [
TransactionData [hash=9df9c95c663d38cfb12c6e4c7e48b99dccc6046fd97ab13c8eb7e863d9c3b224  nonce=05, gasPrice=104c533c00, gas=2dc6c0, receiveAddress=5db10750e8caff27f906b41c71b3471057dd2004, sendAddress=31e2e1ed11951c7091dfba62cd4b7145e947219c, value=, data=6060604052341561000f57600080fd5b60c18061001d6000396000f30060606040526004361060485763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663623845d88114604d5780636d4ce63c146062575b600080fd5b3415605757600080fd5b60606004356084565b005b3415606c57600080fd5b6072608f565b60405190815260200160405180910390f35b600080549091019055565b600054905600a165627a7a7230582008f625b33cf072e0f8ccfd63daa659edfeb62d2a925a0db455031f41769fc9120029, signatureV=28, signatureR=9845e7fa6149495d2295d46c3a1a6f1d8ee616ba8ee401db71cb291109b9efee, signatureS=029fd519d2526d9c5249b2d53294f47fa44a7a0f2f77a94425e11b965c03971b]
]

but the property contract address is null

byte[] contractAddress = receipt.getTransaction().getContractAddress(); logger.info("Contract created: " + Hex.toHexString(contractAddress));

i debugged the code, the method "isContractCreation" return false because return true, and getContractAddress() return null

public byte[] getContractAddress() {
        if (!isContractCreation()) return null;
        return HashUtil.calcNewAddr(this.getSender(), this.getNonce());
    }
mkalinin commented 6 years ago

This method calculates address of the contract which will be created by Tx. If no contract is gonna be created in the Tx then there is no address. but, what are you expecting to get?

1jose234 commented 6 years ago

but, what are you expecting to get?

i can see the tx in the block, for this reason i think the address of the contract should be created and not be null

Txs [
TransactionData [hash=9df9c95c663d38cfb12c6e4c7e48b99dccc6046fd97ab13c8eb7e863d9c3b224  nonce=05, gasPrice=104c533c00, gas=2dc6c0, receiveAddress=5db10750e8caff27f906b41c71b3471057dd2004, sendAddress=31e2e1ed11951c7091dfba62cd4b7145e947219c, value=, data=6060604052341561000f57600080fd5b60c18061001d6000396000f30060606040526004361060485763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663623845d88114604d5780636d4ce63c146062575b600080fd5b3415605757600080fd5b60606004356084565b005b3415606c57600080fd5b6072608f565b60405190815260200160405180910390f35b600080549091019055565b600054905600a165627a7a7230582008f625b33cf072e0f8ccfd63daa659edfeb62d2a925a0db455031f41769fc9120029, signatureV=28, signatureR=9845e7fa6149495d2295d46c3a1a6f1d8ee616ba8ee401db71cb291109b9efee, signatureS=029fd519d2526d9c5249b2d53294f47fa44a7a0f2f77a94425e11b965c03971b]
]

this are the classes

mkalinin commented 6 years ago

This Tx looks not like a contract creation Tx

1jose234 commented 6 years ago

i can'nt understand, why is added that Tx? what i should do to create the contract in a private net ?

i used the files of example for my test and study of ethereumj this are the classes

mkalinin commented 6 years ago

To create a contract you should get contract binaries, append encoded constructor args to it. Then make a Tx from this and sign it with your pKey. Then send transaction to the net. You may use solc or another compiler to get binaries. Look in StandaloneBlockchain, it has an example of everything mentioned above.

1jose234 commented 6 years ago

thanks i saw the class but now i am lost... so what example should be follow... with StandaloneBlockchain i can see clear the use of contracts. but, if i need create a dapp to save the transactions is necesary do a regular node. how can conect a node in "StandaloneBlockchain" ?

zilm13 commented 6 years ago

@1jose234 StandaloneBlockchain is only for testing. @mkalinin just pointed you to the block of code which would be almost the same if you want to make this in the real network. For the method mentioned you will need the same logic, but you will need to submit tx to the network, so use ethereum.submitTransaction in the end instead. You could check https://github.com/ethereum/ethereumj/blob/develop/ethereumj-core/src/main/java/org/ethereum/samples/CreateContractSample.java and other samples to get into.

1jose234 commented 6 years ago

@zilm13 thanks again... i used "PrivateMinerSample" to the miner, i made a connection to this miner using "EventListenerSample.java" to test the contract, obtening the result correct.

i can understand that the diference between CreateContractSample and EventListenerSample is that:

EventListenerSample Replays contract events for old blocks and can deploy a contract or replay only if it have the address, its true ?

but in this case how can know the address, should be save in any place ?

to my objective (create dapp) this could be in productive enviroment ?

zilm13 commented 6 years ago

@1jose234 EventListenerSample not only replays, it could listen for fresh events from pending to confirmed.

You should define contract address in some config or say pass it with ABI anytime when application running via some interface(say, JSON API), construct new listener or extend logic of existing etc.

Theoretically, you could listen to all contract creations and compare contract code hashes to yours, but you could find several addresses if your contract code is not private. And I guess you need to listen one specific contract, so it's not a safe solution.

mkalinin commented 6 years ago

guys, any updates on that?

Passion4866 commented 2 years ago

@mkalinin hello Bro. Some one hacked me in token pockef blok chain. Using qr code of code wallet and tron scan. Can u finish