Search in sources :

Example 1 with BuildInfo

use of org.ethereum.util.BuildInfo in project rskj by rsksmart.

the class MainNetMinerTest method submitBitcoinBlockInvalidBlockDoesntEliminateCache.

/*
     * This test is much more likely to fail than the
     * submitBitcoinBlockProofOfWorkNotGoodEnough test. Even then
     * it should almost never fail.
     */
@Test
public void submitBitcoinBlockInvalidBlockDoesntEliminateCache() {
    // ////////////////////////////////////////////////////////////////////
    // To make this test work we need a special network spec with
    // medium minimum difficulty (this is not the mainnet nor the regnet)
    // //////////////////////////////////////////////////////////////////
    /* We need a low, but not too low, target */
    EthereumImpl ethereumImpl = Mockito.mock(EthereumImpl.class);
    when(ethereumImpl.addNewMinedBlock(Mockito.any())).thenReturn(ImportResult.IMPORTED_BEST);
    MinerClock clock = new MinerClock(true, Clock.systemUTC());
    MinerServer minerServer = new MinerServerImpl(config, ethereumImpl, mainchainView, blockProcessor, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), blockToMineBuilder(), clock, blockFactory, new BuildInfo("cb7f28e", "master"), ConfigUtils.getDefaultMiningConfig());
    try {
        minerServer.start();
        MinerWork work = minerServer.getWork();
        co.rsk.bitcoinj.core.BtcBlock bitcoinMergedMiningBlock = getMergedMiningBlock(work);
        bitcoinMergedMiningBlock.setNonce(1);
        // Try to submit a block with invalid PoW, this should not eliminate the block from the cache
        SubmitBlockResult result1 = minerServer.submitBitcoinBlock(work.getBlockHashForMergedMining(), bitcoinMergedMiningBlock);
        Assert.assertEquals("ERROR", result1.getStatus());
        Assert.assertNull(result1.getBlockInfo());
        Mockito.verify(ethereumImpl, Mockito.times(0)).addNewMinedBlock(Mockito.any());
    // Now try to submit the same block, this should work fine since the block remains in the cache
    // This WON't work in mainnet because difficulty is HIGH
    /*---------------------------------------------------------
        findNonce(work, bitcoinMergedMiningBlock);

        SubmitBlockResult result2 = minerServer.submitBitcoinBlock(work.getBlockHashForMergedMining(), bitcoinMergedMiningBlock);

        Assert.assertEquals("OK", result2.getStatus());
        Assert.assertNotNull(result2.getBlockInfo());
        Mockito.verify(ethereumImpl, Mockito.times(1)).addNewMinedBlock(Mockito.any());

        // Finally, submit the same block again and validate that addNewMinedBlock is called again
        SubmitBlockResult result3 = minerServer.submitBitcoinBlock(work.getBlockHashForMergedMining(), bitcoinMergedMiningBlock);

        Assert.assertEquals("OK", result3.getStatus());
        Assert.assertNotNull(result3.getBlockInfo());
        Mockito.verify(ethereumImpl, Mockito.times(2)).addNewMinedBlock(Mockito.any());
        -------------------------------*/
    } finally {
        minerServer.stop();
    }
}
Also used : BuildInfo(org.ethereum.util.BuildInfo) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test) ActivationConfigsForTest(org.ethereum.config.blockchain.upgrades.ActivationConfigsForTest) BlockChainImplTest(co.rsk.core.bc.BlockChainImplTest)

Example 2 with BuildInfo

use of org.ethereum.util.BuildInfo in project rskj by rsksmart.

the class MinerManagerTest method getMinerServer.

private MinerServerImpl getMinerServer() {
    SimpleEthereum ethereum = new SimpleEthereum();
    ethereum.blockchain = blockchain;
    DifficultyCalculator difficultyCalculator = new DifficultyCalculator(config.getActivationConfig(), config.getNetworkConstants());
    MinerClock clock = new MinerClock(true, Clock.systemUTC());
    MiningConfig miningConfig = ConfigUtils.getDefaultMiningConfig();
    return new MinerServerImpl(config, ethereum, miningMainchainView, null, new ProofOfWorkRule(config).setFallbackMiningEnabled(false), new BlockToMineBuilder(config.getActivationConfig(), miningConfig, repositoryLocator, blockStore, transactionPool, difficultyCalculator, new GasLimitCalculator(config.getNetworkConstants()), new ForkDetectionDataCalculator(), new BlockValidationRuleDummy(), clock, blockFactory, blockExecutor, new MinimumGasPriceCalculator(Coin.valueOf(miningConfig.getMinGasPriceTarget())), new MinerUtils()), clock, blockFactory, new BuildInfo("cb7f28e", "master"), miningConfig);
}
Also used : ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) DifficultyCalculator(co.rsk.core.DifficultyCalculator) MiningConfig(co.rsk.config.MiningConfig) BuildInfo(org.ethereum.util.BuildInfo) SimpleEthereum(org.ethereum.rpc.Simples.SimpleEthereum)

Example 3 with BuildInfo

use of org.ethereum.util.BuildInfo in project rskj by rsksmart.

the class RskContext method getBuildInfo.

public synchronized BuildInfo getBuildInfo() {
    checkIfNotClosed();
    if (buildInfo == null) {
        try {
            Properties props = new Properties();
            InputStream buildInfoFile = RskContext.class.getClassLoader().getResourceAsStream("build-info.properties");
            props.load(buildInfoFile);
            buildInfo = new BuildInfo(props.getProperty("build.hash"), props.getProperty("build.branch"));
        } catch (IOException | NullPointerException e) {
            logger.trace("Can't find build info class, using dev configuration", e);
            buildInfo = new BuildInfo("dev", "dev");
        }
    }
    return buildInfo;
}
Also used : BuildInfo(org.ethereum.util.BuildInfo)

Example 4 with BuildInfo

use of org.ethereum.util.BuildInfo in project rskj by rsksmart.

the class MinerServerTest method extraDataWithClientDataMoreThan32Bytes.

@Test
public void extraDataWithClientDataMoreThan32Bytes() {
    MinerServer minerServer = new MinerServerImpl(config, null, null, null, null, null, null, null, new BuildInfo("cb7f28e", "master"), ConfigUtils.getDefaultMiningConfig());
    minerServer.setExtraData("tincho is the king of mining".getBytes());
    byte[] extraData = minerServer.getExtraData();
    assertEquals(32, extraData.length);
    RLPList decodedExtraData = RLP.decodeList(extraData);
    assertEquals(3, decodedExtraData.size());
    byte[] firstItem = decodedExtraData.get(0).getRLPData();
    assertNotNull(firstItem);
    assertEquals(1, (RLP.decodeInt(firstItem, 0)));
    byte[] secondItem = decodedExtraData.get(1).getRLPData();
    assertNotNull(secondItem);
    assertEquals(config.projectVersionModifier().concat("-cb7f28e"), new String(secondItem));
    byte[] thirdItem = decodedExtraData.get(2).getRLPData();
    assertNotNull(thirdItem);
    // The final client extra data may be truncated by the combined size of the other encoded elements
    int extraDataMaxLength = 32;
    int extraDataEncodingOverhead = 3;
    int clientExtraDataSize = extraDataMaxLength - extraDataEncodingOverhead - firstItem.length - secondItem.length;
    assertEquals("tincho is the king of mining".substring(0, clientExtraDataSize), new String(thirdItem));
}
Also used : BuildInfo(org.ethereum.util.BuildInfo) RLPList(org.ethereum.util.RLPList) Test(org.junit.Test)

Example 5 with BuildInfo

use of org.ethereum.util.BuildInfo in project rskj by rsksmart.

the class MinerServerTest method gasUnitInDollarsIsInitializedOkAtConstructor.

@Test
public void gasUnitInDollarsIsInitializedOkAtConstructor() {
    Block block1 = mock(Block.class);
    when(block1.getFeesPaidToMiner()).thenReturn(new Coin(BigInteger.valueOf(10)));
    when(block1.getHashForMergedMining()).thenReturn(TestUtils.randomHash().getBytes());
    when(block1.getHash()).thenReturn(TestUtils.randomHash());
    when(block1.getDifficulty()).thenReturn(BlockDifficulty.ZERO);
    when(block1.getParentHashJsonString()).thenReturn(TestUtils.randomHash().toJsonString());
    Block block2 = mock(Block.class);
    when(block2.getFeesPaidToMiner()).thenReturn(new Coin(BigInteger.valueOf(24)));
    when(block2.getHashForMergedMining()).thenReturn(TestUtils.randomHash().getBytes());
    when(block2.getHash()).thenReturn(TestUtils.randomHash());
    when(block2.getDifficulty()).thenReturn(BlockDifficulty.ZERO);
    when(block2.getParentHashJsonString()).thenReturn(TestUtils.randomHash().toJsonString());
    BlockToMineBuilder builder = mock(BlockToMineBuilder.class);
    BlockResult blockResult = mock(BlockResult.class);
    BlockResult blockResult2 = mock(BlockResult.class);
    when(blockResult.getBlock()).thenReturn(block1);
    when(blockResult2.getBlock()).thenReturn(block2);
    when(builder.build(any(), any())).thenReturn(blockResult).thenReturn(blockResult2);
    MinerClock clock = new MinerClock(true, Clock.systemUTC());
    MinerServer minerServer = new MinerServerImpl(config, mock(EthereumImpl.class), this.blockchain, null, mock(ProofOfWorkRule.class), builder, clock, mock(BlockFactory.class), new BuildInfo("cb7f28e", "master"), ConfigUtils.getDefaultMiningConfig());
    try {
        minerServer.start();
        minerServer.getWork();
        minerServer.buildBlockToMine(false);
        MinerWork work = minerServer.getWork();
        assertTrue(work.getNotify());
    } finally {
        minerServer.stop();
    }
}
Also used : Coin(co.rsk.core.Coin) BlockResult(co.rsk.core.bc.BlockResult) BuildInfo(org.ethereum.util.BuildInfo) EthereumImpl(org.ethereum.facade.EthereumImpl) ProofOfWorkRule(co.rsk.validators.ProofOfWorkRule) Test(org.junit.Test)

Aggregations

BuildInfo (org.ethereum.util.BuildInfo)12 ProofOfWorkRule (co.rsk.validators.ProofOfWorkRule)6 Test (org.junit.Test)6 EthereumImpl (org.ethereum.facade.EthereumImpl)4 MiningConfig (co.rsk.config.MiningConfig)3 BridgeSupportFactory (co.rsk.peg.BridgeSupportFactory)3 ExecutionBlockRetriever (co.rsk.rpc.ExecutionBlockRetriever)3 Web3RskImpl (co.rsk.rpc.Web3RskImpl)3 DebugModule (co.rsk.rpc.modules.debug.DebugModule)3 DebugModuleImpl (co.rsk.rpc.modules.debug.DebugModuleImpl)3 PersonalModuleWalletEnabled (co.rsk.rpc.modules.personal.PersonalModuleWalletEnabled)3 TxPoolModule (co.rsk.rpc.modules.txpool.TxPoolModule)3 TxPoolModuleImpl (co.rsk.rpc.modules.txpool.TxPoolModuleImpl)3 ChannelManager (org.ethereum.net.server.ChannelManager)3 RLPList (org.ethereum.util.RLPList)3 DifficultyCalculator (co.rsk.core.DifficultyCalculator)2 BlockChainImplTest (co.rsk.core.bc.BlockChainImplTest)2 MiningMainchainView (co.rsk.core.bc.MiningMainchainView)2 MinerClient (co.rsk.mine.MinerClient)2 Web3InformationRetriever (co.rsk.rpc.Web3InformationRetriever)2