Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Constrained the minimum unity fork number to 2
Browse files Browse the repository at this point in the history
AionJayT committed Oct 21, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 64881af commit 168188f
Showing 2 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -235,6 +235,11 @@ protected AionBlockchainImpl(
this.forkUtility = new ForkUtility(); // forks are disabled by default
Optional<Long> maybeFork050 = load050ForkNumberFromConfig(CfgAion.inst());
if (maybeFork050.isPresent()) {
if (maybeFork050.get() < 2) { // AKI-419, Constrain the minimum unity fork number
LOG.warn("The unity fork number can not less than 2, set the fork number to 2");
maybeFork050 = Optional.of(2L);
}

this.forkUtility.enableUnityFork(maybeFork050.get());
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.aion.zero.impl.blockchain;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.Properties;
import org.aion.zero.impl.config.CfgAion;
import org.junit.After;
import org.junit.Test;

public class AionBlockchainImplTest {

private StandaloneBlockchain blockchain;

@After
public void tearDown() {

CfgAion cfg = CfgAion.inst();
Properties p = new Properties();
p.put("fork0.5.0", String.valueOf(Long.MAX_VALUE));
cfg.getFork().setProperties(p);
this.blockchain = null;
}

@Test
public void testUnityMininmumNumber() {
CfgAion cfg = CfgAion.inst();
Properties p = new Properties();
p.put("fork0.5.0", "1");
cfg.getFork().setProperties(p);

StandaloneBlockchain.Bundle bundle =
new StandaloneBlockchain.Builder()
.withDefaultAccounts()
.withValidatorConfiguration("simple")
.build();
this.blockchain = bundle.bc;

assertNotNull(blockchain);
//AKI-419 the minimum fork point is 2, therefore, the unity protocol will start from 3
assertFalse(blockchain.forkUtility.isUnityForkActive(2));
assertTrue(blockchain.forkUtility.isUnityForkActive(3));
}

@Test
public void testUnityMininmumNumber2() {
CfgAion cfg = CfgAion.inst();
Properties p = new Properties();
p.put("fork0.5.0", "2");
cfg.getFork().setProperties(p);

StandaloneBlockchain.Bundle bundle =
new StandaloneBlockchain.Builder()
.withDefaultAccounts()
.withValidatorConfiguration("simple")
.build();
this.blockchain = bundle.bc;

assertNotNull(blockchain);
assertFalse(blockchain.forkUtility.isUnityForkActive(2));
assertTrue(blockchain.forkUtility.isUnityForkActive(3));
}
}

0 comments on commit 168188f

Please sign in to comment.