From dc689369f808dd82b28a2537cc8676d557d03705 Mon Sep 17 00:00:00 2001 From: langerhans Date: Sat, 18 Oct 2014 20:39:05 +0200 Subject: [PATCH] Step 3: Update the network params --- .../dogecoinj/core/NetworkParameters.java | 53 +++++++++++++----- .../dogecoinj/params/MainNetParams.java | 56 ++++++++++++------- .../dogecoinj/params/TestNet3Params.java | 31 +++++----- 3 files changed, 93 insertions(+), 47 deletions(-) diff --git a/core/src/main/java/com/dogecoin/dogecoinj/core/NetworkParameters.java b/core/src/main/java/com/dogecoin/dogecoinj/core/NetworkParameters.java index e0c4be90..7653a86c 100644 --- a/core/src/main/java/com/dogecoin/dogecoinj/core/NetworkParameters.java +++ b/core/src/main/java/com/dogecoin/dogecoinj/core/NetworkParameters.java @@ -21,6 +21,7 @@ import com.dogecoin.dogecoinj.params.*; import com.dogecoin.dogecoinj.script.Script; import com.dogecoin.dogecoinj.script.ScriptOpCodes; import com.google.common.base.Objects; +import org.spongycastle.util.encoders.Hex; import javax.annotation.Nullable; import java.io.ByteArrayOutputStream; @@ -47,16 +48,16 @@ public abstract class NetworkParameters implements Serializable { /** * The alert signing key originally owned by Satoshi, and now passed on to Gavin along with a few others. */ - public static final byte[] SATOSHI_KEY = Utils.HEX.decode("04fc9702847840aaf195de8442ebecedf5b095cdbb9bc716bda9110971b28a49e0ead8564ff0db22209e0374782c093bb899692d524e9d6a6956e7c5ecbcd68284"); + public static final byte[] SATOSHI_KEY = Hex.decode("04d4da7a5dae4db797d9b0644d57a5cd50e05a70f36091cd62e2fc41c98ded06340be5a43a35e185690cd9cde5d72da8f6d065b499b06f51dcfba14aad859f443a"); /** The string returned by getId() for the main, production network where people trade things. */ - public static final String ID_MAINNET = "org.bitcoin.production"; + public static final String ID_MAINNET = "org.dogecoin.production"; /** The string returned by getId() for the testnet. */ - public static final String ID_TESTNET = "org.bitcoin.test"; + public static final String ID_TESTNET = "org.dogecoin.test"; /** The string returned by getId() for regtest mode. */ - public static final String ID_REGTEST = "org.bitcoin.regtest"; + public static final String ID_REGTEST = "org.dogecoin.regtest"; /** Unit test network. */ - public static final String ID_UNITTESTNET = "org.bitcoinj.unittest"; + public static final String ID_UNITTESTNET = "org.dogecoinj.unittest"; /** The string used by the payment protocol to represent the main net. */ public static final String PAYMENT_PROTOCOL_ID_MAINNET = "main"; @@ -73,7 +74,10 @@ public abstract class NetworkParameters implements Serializable { protected int p2shHeader; protected int dumpedPrivateKeyHeader; protected int interval; + protected int newInterval; protected int targetTimespan; + protected int newTargetTimespan; + protected int diffChangeTarget; protected byte[] alertSigningKey; /** @@ -105,13 +109,13 @@ public abstract class NetworkParameters implements Serializable { // // "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks" byte[] bytes = Utils.HEX.decode - ("04ffff001d0104455468652054696d65732030332f4a616e2f32303039204368616e63656c6c6f72206f6e206272696e6b206f66207365636f6e64206261696c6f757420666f722062616e6b73"); + ("04ffff001d0104084e696e746f6e646f"); t.addInput(new TransactionInput(n, t, bytes)); ByteArrayOutputStream scriptPubKeyBytes = new ByteArrayOutputStream(); Script.writeBytes(scriptPubKeyBytes, Utils.HEX.decode - ("04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f")); + ("040184710fa689ad5023690c80f3a49c8f13f8d45b8c857fbcbc8bc4a8e4d3eb4b10f4d4604fa08dce601aaf0f470216fe1b51850b4acf21b179c45070ac7b03a9")); scriptPubKeyBytes.write(ScriptOpCodes.OP_CHECKSIG); - t.addOutput(new TransactionOutput(n, t, FIFTY_COINS, scriptPubKeyBytes.toByteArray())); + t.addOutput(new TransactionOutput(n, t, COIN.multiply(88), scriptPubKeyBytes.toByteArray())); } catch (Exception e) { // Cannot happen. throw new RuntimeException(e); @@ -120,9 +124,11 @@ public abstract class NetworkParameters implements Serializable { return genesisBlock; } - public static final int TARGET_TIMESPAN = 14 * 24 * 60 * 60; // 2 weeks per difficulty cycle, on average. - public static final int TARGET_SPACING = 10 * 60; // 10 minutes per block. + public static final int TARGET_TIMESPAN = 4 * 60 * 60; // 2 weeks per difficulty cycle, on average. + public static final int TARGET_TIMESPAN_NEW = 60; // 60s per difficulty cycle, on average. Kicks in after block 145k. + public static final int TARGET_SPACING = 1 * 60; // 10 minutes per block. public static final int INTERVAL = TARGET_TIMESPAN / TARGET_SPACING; + public static final int INTERVAL_NEW = TARGET_TIMESPAN_NEW / TARGET_SPACING; /** * Blocks with a timestamp after this should enforce BIP 16, aka "Pay to script hash". This BIP changed the @@ -133,8 +139,10 @@ public abstract class NetworkParameters implements Serializable { /** * The maximum number of coins to be generated + * This is 92bn! We don't expect single transactions or blocks with that value. + * Therefore we can assume this will suffice. */ - public static final long MAX_COINS = 21000000; + public static final long MAX_COINS = Long.MAX_VALUE / Coin.SMALLEST_UNIT_EXPONENT; /** * The maximum money to be generated @@ -304,13 +312,22 @@ public abstract class NetworkParameters implements Serializable { /** * How much time in seconds is supposed to pass between "interval" blocks. If the actual elapsed time is - * significantly different from this value, the network difficulty formula will produce a different value. Both - * test and production Bitcoin networks use 2 weeks (1209600 seconds). + * significantly different from this value, the network difficulty formula will produce a different value. + * Dogecoin before block 145k used 4 hours. */ public int getTargetTimespan() { return targetTimespan; } + /** + * How much time in seconds is supposed to pass between "interval" blocks. If the actual elapsed time is + * significantly different from this value, the network difficulty formula will produce a different value. + * Dogecoin after block 145k uses 60 seconds. + */ + public int getNewTargetTimespan() { + return newTargetTimespan; + } + /** * The version codes that prefix addresses which are acceptable on this network. Although Satoshi intended these to * be used for "versioning", in fact they are today used to discriminate what kind of data is contained in the @@ -332,6 +349,16 @@ public abstract class NetworkParameters implements Serializable { return interval; } + /** How many blocks pass between difficulty adjustment periods. After new diff algo. */ + public int getNewInterval() { + return newInterval; + } + + /** Target for switch to new diff algo */ + public int getDiffChangeTarget() { + return diffChangeTarget; + } + /** Maximum target represents the easiest allowable proof of work. */ public BigInteger getMaxTarget() { return maxTarget; diff --git a/core/src/main/java/com/dogecoin/dogecoinj/params/MainNetParams.java b/core/src/main/java/com/dogecoin/dogecoinj/params/MainNetParams.java index 1b28a758..65bfdec1 100644 --- a/core/src/main/java/com/dogecoin/dogecoinj/params/MainNetParams.java +++ b/core/src/main/java/com/dogecoin/dogecoinj/params/MainNetParams.java @@ -29,40 +29,54 @@ public class MainNetParams extends NetworkParameters { public MainNetParams() { super(); interval = INTERVAL; + newInterval = INTERVAL_NEW; targetTimespan = TARGET_TIMESPAN; - maxTarget = Utils.decodeCompactBits(0x1d00ffffL); - dumpedPrivateKeyHeader = 128; - addressHeader = 0; - p2shHeader = 5; + newTargetTimespan = TARGET_TIMESPAN_NEW; + maxTarget = Utils.decodeCompactBits(0x1e0fffffL); + dumpedPrivateKeyHeader = 158; //This is always addressHeader + 128 + addressHeader = 30; + p2shHeader = 22; acceptableAddressCodes = new int[] { addressHeader, p2shHeader }; - port = 8333; - packetMagic = 0xf9beb4d9L; - genesisBlock.setDifficultyTarget(0x1d00ffffL); - genesisBlock.setTime(1231006505L); - genesisBlock.setNonce(2083236893); + port = 22556; + packetMagic = 0xc0c0c0c0; + genesisBlock.setDifficultyTarget(0x1e0ffff0L); + genesisBlock.setTime(1386325540L); + genesisBlock.setNonce(99943L); id = ID_MAINNET; - subsidyDecreaseBlockCount = 210000; + subsidyDecreaseBlockCount = 100000; spendableCoinbaseDepth = 100; + + diffChangeTarget = 145000; + String genesisHash = genesisBlock.getHashAsString(); - checkState(genesisHash.equals("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"), + checkState(genesisHash.equals("1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691"), genesisHash); // This contains (at a minimum) the blocks which are not BIP30 compliant. BIP30 changed how duplicate // transactions are handled. Duplicated transactions could occur in the case where a coinbase had the same // extraNonce and the same outputs but appeared at different heights, and greatly complicated re-org handling. // Having these here simplifies block connection logic considerably. - checkpoints.put(91722, new Sha256Hash("00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e")); - checkpoints.put(91812, new Sha256Hash("00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f")); - checkpoints.put(91842, new Sha256Hash("00000000000a4d0a398161ffc163c503763b1f4360639393e0e4c8e300e0caec")); - checkpoints.put(91880, new Sha256Hash("00000000000743f190a18c5577a3c2d2a1f610ae9601ac046a38084ccb7cd721")); - checkpoints.put(200000, new Sha256Hash("000000000000034a7dedef4a161fa058a2d67a173a90155f3a2fe6fc132e0ebf")); + checkpoints.put( 0, new Sha256Hash("1a91e3dace36e2be3bf030a65679fe821aa1d6ef92e7c9902eb318182c355691")); + checkpoints.put( 42279, new Sha256Hash("8444c3ef39a46222e87584ef956ad2c9ef401578bd8b51e8e4b9a86ec3134d3a")); + checkpoints.put( 42400, new Sha256Hash("557bb7c17ed9e6d4a6f9361cfddf7c1fc0bdc394af7019167442b41f507252b4")); + checkpoints.put(104679, new Sha256Hash("35eb87ae90d44b98898fec8c39577b76cb1eb08e1261cfc10706c8ce9a1d01cf")); + checkpoints.put(128370, new Sha256Hash("3f9265c94cab7dc3bd6a2ad2fb26c8845cb41cff437e0a75ae006997b4974be6")); + checkpoints.put(145000, new Sha256Hash("cc47cae70d7c5c92828d3214a266331dde59087d4a39071fa76ddfff9b7bde72")); + checkpoints.put(165393, new Sha256Hash("7154efb4009e18c1c6a6a79fc6015f48502bcd0a1edd9c20e44cd7cbbe2eeef1")); + checkpoints.put(186774, new Sha256Hash("3c712c49b34a5f34d4b963750d6ba02b73e8a938d2ee415dcda141d89f5cb23a")); + checkpoints.put(199992, new Sha256Hash("3408ff829b7104eebaf61fd2ba2203ef2a43af38b95b353e992ef48f00ebb190")); + checkpoints.put(225000, new Sha256Hash("be148d9c5eab4a33392a6367198796784479720d06bfdd07bd547fe934eea15a")); + checkpoints.put(250000, new Sha256Hash("0e4bcfe8d970979f7e30e2809ab51908d435677998cf759169407824d4f36460")); + checkpoints.put(270639, new Sha256Hash("c587a36dd4f60725b9dd01d99694799bef111fc584d659f6756ab06d2a90d911")); + checkpoints.put(299742, new Sha256Hash("1cc89c0c8a58046bf0222fe131c099852bd9af25a80e07922918ef5fb39d6742")); + checkpoints.put(323141, new Sha256Hash("60c9f919f9b271add6ef5671e9538bad296d79f7fdc6487ba702bf2ba131d31d")); + checkpoints.put(339202, new Sha256Hash("8c29048df5ae9df38a67ea9470fdd404d281a3a5c6f33080cd5bf14aa496ab03")); dnsSeeds = new String[] { - "seed.bitcoin.sipa.be", // Pieter Wuille - "dnsseed.bluematt.me", // Matt Corallo - "dnsseed.bitcoin.dashjr.org", // Luke Dashjr - "seed.bitcoinstats.com", // Chris Decker - "seed.bitnodes.io", // Addy Yeow + "seed.dogecoin.com", + "seed.mophides.com", + "seed.dglibrary.org", + "seed.dogechain.info", }; } diff --git a/core/src/main/java/com/dogecoin/dogecoinj/params/TestNet3Params.java b/core/src/main/java/com/dogecoin/dogecoinj/params/TestNet3Params.java index b4a2dc0a..a4197791 100644 --- a/core/src/main/java/com/dogecoin/dogecoinj/params/TestNet3Params.java +++ b/core/src/main/java/com/dogecoin/dogecoinj/params/TestNet3Params.java @@ -19,6 +19,7 @@ package com.dogecoin.dogecoinj.params; import com.dogecoin.dogecoinj.core.NetworkParameters; import com.dogecoin.dogecoinj.core.Utils; +import org.spongycastle.util.encoders.Hex; import static com.google.common.base.Preconditions.checkState; @@ -30,24 +31,28 @@ public class TestNet3Params extends NetworkParameters { public TestNet3Params() { super(); id = ID_TESTNET; - // Genesis hash is 000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943 - packetMagic = 0x0b110907; + // Genesis hash is bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e + packetMagic = 0xfcc1b7dc; interval = INTERVAL; + newInterval = INTERVAL_NEW; targetTimespan = TARGET_TIMESPAN; - maxTarget = Utils.decodeCompactBits(0x1d00ffffL); - port = 18333; - addressHeader = 111; + newTargetTimespan = TARGET_TIMESPAN_NEW; + maxTarget = Utils.decodeCompactBits(0x1e0fffffL); + port = 44556; + addressHeader = 113; p2shHeader = 196; acceptableAddressCodes = new int[] { addressHeader, p2shHeader }; - dumpedPrivateKeyHeader = 239; - genesisBlock.setTime(1296688602L); - genesisBlock.setDifficultyTarget(0x1d00ffffL); - genesisBlock.setNonce(414098458); - spendableCoinbaseDepth = 100; - subsidyDecreaseBlockCount = 210000; + dumpedPrivateKeyHeader = 241; + genesisBlock.setTime(1391503289L); + genesisBlock.setDifficultyTarget(0x1e0ffff0L); + genesisBlock.setNonce(997879); + spendableCoinbaseDepth = 30; + subsidyDecreaseBlockCount = 100000; String genesisHash = genesisBlock.getHashAsString(); - checkState(genesisHash.equals("000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943")); - alertSigningKey = Utils.HEX.decode("04302390343f91cc401d56d68b123028bf52e5fca1939df127f63c6467cdf9c8e2c14b61104cf817d0b780da337893ecc4aaff1309e536162dabbdb45200ca2b0a"); + checkState(genesisHash.equals("bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e")); + alertSigningKey = Hex.decode("042756726da3c7ef515d89212ee1705023d14be389e25fe15611585661b9a20021908b2b80a3c7200a0139dd2b26946606aab0eef9aa7689a6dc2c7eee237fa834"); + + diffChangeTarget = 145000; dnsSeeds = new String[] { "testnet-seed.alexykot.me", // Alex Kotenko