@Override public Block getGenesisBlock() { synchronized (RegTestParams.class) { if (genesis == null) { genesis = super.getGenesisBlock(); genesis.setNonce(2); genesis.setDifficultyTarget(0x207fFFFFL); genesis.setTime(1296688602L); checkState(genesis.getHashAsString().toLowerCase().equals("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")); } return genesis; } }
@Override public Block getGenesisBlock() { synchronized (RegTestParams.class) { if (genesis == null) { genesis = super.getGenesisBlock(); genesis.setNonce(2); genesis.setDifficultyTarget(0x207fFFFFL); genesis.setTime(1296688602L); checkState(genesis.getHashAsString().toLowerCase().equals("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")); } return genesis; } }
/** * <p>Finds a value of nonce that makes the blocks hash lower than the difficulty target. This is called mining, but * solve() is far too slow to do real mining with. It exists only for unit testing purposes. * * <p>This can loop forever if a solution cannot be found solely by incrementing nonce. It doesn't change * extraNonce.</p> */ public void solve() { while (true) { try { // Is our proof of work valid yet? if (checkProofOfWork(false)) return; // No, so increment the nonce and try again. setNonce(getNonce() + 1); } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } } }
/** * <p>Finds a value of nonce that makes the blocks hash lower than the difficulty target. This is called mining, but * solve() is far too slow to do real mining with. It exists only for unit testing purposes. * * <p>This can loop forever if a solution cannot be found solely by incrementing nonce. It doesn't change * extraNonce.</p> */ public void solve() { while (true) { try { // Is our proof of work valid yet? if (checkProofOfWork(false)) return; // No, so increment the nonce and try again. setNonce(getNonce() + 1); } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } } }
/** * <p>Finds a value of nonce that makes the blocks hash lower than the difficulty target. This is called mining, but * solve() is far too slow to do real mining with. It exists only for unit testing purposes. * * <p>This can loop forever if a solution cannot be found solely by incrementing nonce. It doesn't change * extraNonce.</p> */ public void solve() { while (true) { try { // Is our proof of work valid yet? if (checkProofOfWork(false)) return; // No, so increment the nonce and try again. setNonce(getNonce() + 1); } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } } }
@Override public Block getGenesisBlock() { synchronized (RegTestParams.class) { if (genesis == null) { genesis = super.getGenesisBlock(); genesis.setNonce(2); genesis.setDifficultyTarget(0x207fFFFFL); genesis.setTime(1296688602L); checkState(genesis.getHashAsString().toLowerCase().equals("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")); } return genesis; } }
/** * <p>Finds a value of nonce that makes the blocks hash lower than the difficulty target. This is called mining, but * solve() is far too slow to do real mining with. It exists only for unit testing purposes. * * <p>This can loop forever if a solution cannot be found solely by incrementing nonce. It doesn't change * extraNonce.</p> */ public void solve() { while (true) { try { // Is our proof of work valid yet? if (checkProofOfWork(false)) return; // No, so increment the nonce and try again. setNonce(getNonce() + 1); } catch (VerificationException e) { throw new RuntimeException(e); // Cannot happen. } } }
@Override public Block getGenesisBlock() { synchronized (RegTestParams.class) { if (genesis == null) { genesis = super.getGenesisBlock(); genesis.setNonce(2); genesis.setDifficultyTarget(0x207fFFFFL); genesis.setTime(1296688602L); //checkState(genesis.getHashAsString().toLowerCase().equals("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206")); } return genesis; } }
genesisBlock.setNonce(CoinDefinition.testnetGenesisBlockNonce); spendableCoinbaseDepth = CoinDefinition.spendableCoinbaseDepth; subsidyDecreaseBlockCount = CoinDefinition.subsidyDecreaseBlockCount;
/** * Extract from Litecoin source code, definition of regtest params. * https://github.com/litecoin-project/litecoin/blob/edc66b374ea68107c721062152dd95e6aa037d53/src/chainparams.cpp */ @Override public Block getGenesisBlock() { synchronized (LitecoinRegTestParams.class) { if (genesis == null) { genesis = super.getGenesisBlock(); genesis.setNonce(0); genesis.setDifficultyTarget(0x207fffffL); genesis.setTime(1296688602L); checkState(genesis.getVersion() == 1); checkState(genesis.getMerkleRoot().toString().equals("97ddfbbae6be97fd6cdf3e7ca13232a3afff2353e29badfab7f73011edd4ced9")); checkState(genesis.getHashAsString().toLowerCase().equals("530827f38f93b43ed12af0b3ad25a288dc02ed74d6d7857862df51fc56c416f9")); genesis.verifyHeader(); } return genesis; } }
genesisBlock.setTime(1296688602L); genesisBlock.setDifficultyTarget(0x1d00ffffL); genesisBlock.setNonce(414098458); spendableCoinbaseDepth = 100; subsidyDecreaseBlockCount = 210000;
public TestNet2Params() { super(); id = ID_TESTNET; packetMagic = 0xfabfb5daL; port = 18333; addressHeader = 111; p2shHeader = 196; acceptableAddressCodes = new int[] { addressHeader, p2shHeader }; interval = INTERVAL; targetTimespan = TARGET_TIMESPAN; maxTarget = Utils.decodeCompactBits(0x1d0fffffL); dumpedPrivateKeyHeader = 239; genesisBlock.setTime(1296688602L); genesisBlock.setDifficultyTarget(0x1d07fff8L); genesisBlock.setNonce(384568319); spendableCoinbaseDepth = 100; subsidyDecreaseBlockCount = 210000; String genesisHash = genesisBlock.getHashAsString(); checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008")); dnsSeeds = null; addrSeeds = null; bip32HeaderPub = 0x043587CF; bip32HeaderPriv = 0x04358394; majorityEnforceBlockUpgrade = TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE; majorityRejectBlockOutdated = TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED; majorityWindow = TESTNET_MAJORITY_WINDOW; }
public TestNet2Params() { super(); id = ID_TESTNET; packetMagic = 0xdab5bffaL; port = 18333; addressHeader = 111; p2shHeader = 196; acceptableAddressCodes = new int[] { addressHeader, p2shHeader }; interval = INTERVAL; targetTimespan = TARGET_TIMESPAN; maxTarget = Utils.decodeCompactBits(0x1d0fffffL); dumpedPrivateKeyHeader = 239; genesisBlock.setTime(1296688602L); genesisBlock.setDifficultyTarget(0x1d07fff8L); genesisBlock.setNonce(384568319); spendableCoinbaseDepth = 100; subsidyDecreaseBlockCount = 210000; String genesisHash = genesisBlock.getHashAsString(); checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008")); dnsSeeds = null; addrSeeds = null; bip32HeaderPub = 0x043587CF; bip32HeaderPriv = 0x04358394; majorityEnforceBlockUpgrade = TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE; majorityRejectBlockOutdated = TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED; majorityWindow = TESTNET_MAJORITY_WINDOW; /** Activation time at which the cash HF kicks in. */ cashHardForkActivationTime = 1510600000; daaHeight = 1188697; }
public TestNet2Params() { super(); id = ID_TESTNET; packetMagic = 0xfabfb5daL; port = 18333; addressHeader = 111; p2shHeader = 196; acceptableAddressCodes = new int[] { addressHeader, p2shHeader }; interval = INTERVAL; targetTimespan = TARGET_TIMESPAN; maxTarget = Utils.decodeCompactBits(0x1d0fffffL); dumpedPrivateKeyHeader = 239; genesisBlock.setTime(1296688602L); genesisBlock.setDifficultyTarget(0x1d07fff8L); genesisBlock.setNonce(384568319); spendableCoinbaseDepth = 100; subsidyDecreaseBlockCount = 210000; String genesisHash = genesisBlock.getHashAsString(); checkState(genesisHash.equals("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008")); dnsSeeds = null; addrSeeds = null; bip32HeaderPub = 0x043587CF; bip32HeaderPriv = 0x04358394; majorityEnforceBlockUpgrade = TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE; majorityRejectBlockOutdated = TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED; majorityWindow = TESTNET_MAJORITY_WINDOW; }
public DogecoinTestNet3Params() { super(DIFFICULTY_CHANGE_TARGET); id = ID_DOGE_TESTNET; packetMagic = 0xfcc1b7dc; maxTarget = Utils.decodeCompactBits(0x1e0fffffL); port = 44556; addressHeader = 113; p2shHeader = 196; acceptableAddressCodes = new int[] { addressHeader, p2shHeader }; dumpedPrivateKeyHeader = 241; genesisBlock.setTime(1391503289L); genesisBlock.setDifficultyTarget(0x1e0ffff0L); genesisBlock.setNonce(997879); spendableCoinbaseDepth = 30; subsidyDecreaseBlockCount = 100000; String genesisHash = genesisBlock.getHashAsString(); checkState(genesisHash.equals("bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e")); alertSigningKey = Hex.decode("042756726da3c7ef515d89212ee1705023d14be389e25fe15611585661b9a20021908b2b80a3c7200a0139dd2b26946606aab0eef9aa7689a6dc2c7eee237fa834"); majorityEnforceBlockUpgrade = TESTNET_MAJORITY_ENFORCE_BLOCK_UPGRADE; majorityRejectBlockOutdated = TESTNET_MAJORITY_REJECT_BLOCK_OUTDATED; majorityWindow = TESTNET_MAJORITY_WINDOW; dnsSeeds = new String[] { "testseed.jrn.me.uk" }; // Note this is the same as the BIP32 testnet, as BIP44 makes HD wallets // chain agnostic. Dogecoin mainnet has its own headers for legacy reasons. bip32HeaderPub = 0x043587CF; bip32HeaderPriv = 0x04358394; }
@Test public void testProofOfWork() throws Exception { // This params accepts any difficulty target. NetworkParameters params = UnitTestParams.get(); Block block = params.getDefaultSerializer().makeBlock(blockBytes); block.setNonce(12346); try { block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class)); fail(); } catch (VerificationException e) { // Expected. } // Blocks contain their own difficulty target. The BlockChain verification mechanism is what stops real blocks // from containing artificially weak difficulties. block.setDifficultyTarget(Block.EASIEST_DIFFICULTY_TARGET); // Now it should pass. block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class)); // Break the nonce again at the lower difficulty level so we can try solving for it. block.setNonce(1); try { block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class)); fail(); } catch (VerificationException e) { // Expected to fail as the nonce is no longer correct. } // Should find an acceptable nonce. block.solve(); block.verify(Block.BLOCK_HEIGHT_GENESIS, EnumSet.noneOf(Block.VerifyFlag.class)); assertEquals(block.getNonce(), 2); }
private static Block getBlock2() throws Exception { Block b2 = new Block(testNet, Block.BLOCK_VERSION_GENESIS); b2.setMerkleRoot(Sha256Hash.wrap("addc858a17e21e68350f968ccd384d6439b64aafa6c193c8b9dd66320470838b")); b2.setNonce(2642058077L); b2.setTime(1296734343L); b2.setPrevBlockHash(Sha256Hash.wrap("000000033cc282bc1fa9dcae7a533263fd7fe66490f550d80076433340831604")); assertEquals("000000037b21cac5d30fc6fda2581cf7b2612908aed2abbcc429c45b0557a15f", b2.getHashAsString()); b2.verifyHeader(); return b2; }
private static Block getBlock1() throws Exception { Block b1 = new Block(testNet, Block.BLOCK_VERSION_GENESIS); b1.setMerkleRoot(Sha256Hash.wrap("0e8e58ecdacaa7b3c6304a35ae4ffff964816d2b80b62b58558866ce4e648c10")); b1.setNonce(236038445); b1.setTime(1296734340); b1.setPrevBlockHash(Sha256Hash.wrap("00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008")); assertEquals("000000033cc282bc1fa9dcae7a533263fd7fe66490f550d80076433340831604", b1.getHashAsString()); b1.verifyHeader(); return b1; }
@Test public void testBasicChaining() throws Exception { // Check that we can plug a few blocks together and the futures work. ListenableFuture<StoredBlock> future = testNetChain.getHeightFuture(2); // Block 1 from the testnet. Block b1 = getBlock1(); assertTrue(testNetChain.add(b1)); assertFalse(future.isDone()); // Block 2 from the testnet. Block b2 = getBlock2(); // Let's try adding an invalid block. long n = b2.getNonce(); try { b2.setNonce(12345); testNetChain.add(b2); fail(); } catch (VerificationException e) { b2.setNonce(n); } // Now it works because we reset the nonce. assertTrue(testNetChain.add(b2)); assertTrue(future.isDone()); assertEquals(2, future.get().getHeight()); }
bad.setNonce(140548933); bad.setTime(1279242649); bad.setPrevBlockHash(b2.getHash());