public VersionTally(final NetworkParameters params) { versionWindow = new long[params.getMajorityWindow()]; }
public VersionTally(final NetworkParameters params) { versionWindow = new long[params.getMajorityWindow()]; }
public VersionTally(final NetworkParameters params) { versionWindow = new long[params.getMajorityWindow()]; }
public VersionTally(final NetworkParameters params) { versionWindow = new long[params.getMajorityWindow()]; }
/** * Verify that the version tally returns null until it collects enough data. */ @Test public void testNullWhileEmpty() { VersionTally instance = new VersionTally(PARAMS); for (int i = 0; i < PARAMS.getMajorityWindow(); i++) { assertNull(instance.getCountAtOrAbove(1)); instance.add(1); } assertEquals(PARAMS.getMajorityWindow(), instance.getCountAtOrAbove(1).intValue()); }
/** * Verify that version count and substitution works correctly. */ @Test public void testVersionCounts() { VersionTally instance = new VersionTally(PARAMS); // Fill the tally with 1s for (int i = 0; i < PARAMS.getMajorityWindow(); i++) { assertNull(instance.getCountAtOrAbove(1)); instance.add(1); } assertEquals(PARAMS.getMajorityWindow(), instance.getCountAtOrAbove(1).intValue()); // Check the count updates as we replace with 2s for (int i = 0; i < PARAMS.getMajorityWindow(); i++) { assertEquals(i, instance.getCountAtOrAbove(2).intValue()); instance.add(2); } // Inject a rogue 1 instance.add(1); assertEquals(PARAMS.getMajorityWindow() - 1, instance.getCountAtOrAbove(2).intValue()); // Check we accept high values as well instance.add(10); assertEquals(PARAMS.getMajorityWindow() - 1, instance.getCountAtOrAbove(2).intValue()); }
/** * Verify that the size of the version tally matches the network parameters. */ @Test public void testSize() { VersionTally instance = new VersionTally(PARAMS); assertEquals(PARAMS.getMajorityWindow(), instance.size()); }
@Test public void testInitialize() throws BlockStoreException { final BlockStore blockStore = new MemoryBlockStore(PARAMS); final BlockChain chain = new BlockChain(PARAMS, blockStore); // Build a historical chain of version 2 blocks long timeSeconds = 1231006505; StoredBlock chainHead = null; for (int height = 0; height < PARAMS.getMajorityWindow(); height++) { chainHead = FakeTxBuilder.createFakeBlock(blockStore, 2, timeSeconds, height).storedBlock; assertEquals(2, chainHead.getHeader().getVersion()); timeSeconds += 60; } VersionTally instance = new VersionTally(PARAMS); instance.initialize(blockStore, chainHead); assertEquals(PARAMS.getMajorityWindow(), instance.getCountAtOrAbove(2).intValue()); } }
private void testDeprecatedBlockVersion(final long deprecatedVersion, final long newVersion) throws Exception { final BlockStore versionBlockStore = new MemoryBlockStore(PARAMS); final BlockChain versionChain = new BlockChain(PARAMS, versionBlockStore); // Build a historical chain of version 3 blocks long timeSeconds = 1231006505; int height = 0; FakeTxBuilder.BlockPair chainHead = null; // Put in just enough v2 blocks to be a minority for (height = 0; height < (PARAMS.getMajorityWindow() - PARAMS.getMajorityRejectBlockOutdated()); height++) { chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height); versionChain.add(chainHead.block); timeSeconds += 60; } // Fill the rest of the window with v3 blocks for (; height < PARAMS.getMajorityWindow(); height++) { chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, newVersion, timeSeconds, height); versionChain.add(chainHead.block); timeSeconds += 60; } chainHead = FakeTxBuilder.createFakeBlock(versionBlockStore, deprecatedVersion, timeSeconds, height); // Trying to add a new v2 block should result in rejection thrown.expect(VerificationException.BlockVersionOutOfDate.class); try { versionChain.add(chainHead.block); } catch(final VerificationException ex) { throw (Exception) ex.getCause(); } }
for (height = 1; height <= (PARAMS.getMajorityWindow() - PARAMS.getMajorityEnforceBlockUpgrade()); height++) { chainHead = chainHead.createNextBlockWithCoinbase(Block.BLOCK_VERSION_GENESIS, outKey.getPubKey(), height); for (; height < PARAMS.getMajorityWindow(); height++) { chainHead = chainHead.createNextBlockWithCoinbase(Block.BLOCK_VERSION_BIP34, outKey.getPubKey(), height);