Skip to content

Commit

Permalink
PoS deltas are now applied to the chain parent, not seal parent
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Oct 16, 2019
1 parent 28752fa commit b6859dc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public class AionBlockchainImpl implements IAionBlockchain {
private final GrandParentBlockHeaderValidator unityGrandParentBlockHeaderValidator;
private final ParentBlockHeaderValidator preUnityParentBlockHeaderValidator;
private final ParentBlockHeaderValidator unityParentBlockHeaderValidator;
private final ParentBlockHeaderValidator sealParentBlockHeaderValidator;
private final StakingContractHelper stakingContractHelper;
public final BeaconHashValidator beaconHashValidator;

Expand Down Expand Up @@ -204,7 +203,6 @@ protected AionBlockchainImpl(
* blockHash and number.
*/
this.chainConfiguration = chainConfig;
sealParentBlockHeaderValidator = chainConfiguration.createSealParentBlockHeaderValidator();
preUnityParentBlockHeaderValidator = chainConfig.createPreUnityParentBlockHeaderValidator();
unityParentBlockHeaderValidator = chainConfig.createUnityParentBlockHeaderValidator();
preUnityGrandParentBlockHeaderValidator = chainConfiguration.createPreUnityGrandParentHeaderValidator();
Expand Down Expand Up @@ -1331,7 +1329,7 @@ private StakingBlock createNewStakingBlock(

newTimestamp =
Long.max(
parentStakingBlockHeader.getTimestamp() + newDelta,
parent.getHeader().getTimestamp() + newDelta,
parent.getHeader().getTimestamp() + 1);
} else {
newTimestamp = System.currentTimeMillis() / THOUSAND_MS;
Expand Down Expand Up @@ -1646,10 +1644,6 @@ public boolean isValid(BlockHeader header) {
return false;
}

if (!unityParentBlockHeaderValidator.validate(header, parent.getHeader(), LOG, null)) {
return false;
}

Block sealParent;
if (parent.getHeader().getSealType() == BlockSealType.SEAL_POW_BLOCK) {
sealParent = getBlockByHash(parent.getAntiparentHash());
Expand All @@ -1674,7 +1668,7 @@ public boolean isValid(BlockHeader header) {
System.exit(SystemExitCodes.FATAL_VM_ERROR);
}

if (!sealParentBlockHeaderValidator.validate(header, sealParent.getHeader(), LOG, stake)) {
if (!unityParentBlockHeaderValidator.validate(header, parent.getHeader(), LOG, stake)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,6 @@ public BlockHeaderValidator createBlockHeaderValidator() {
return new BlockHeaderValidator(unityRules);
}

public ParentBlockHeaderValidator createSealParentBlockHeaderValidator() {
List<DependentBlockHeaderRule> posRules =
Arrays.asList(new StakingSeedRule(), new StakingBlockTimeStampRule());

Map<BlockSealType, List<DependentBlockHeaderRule>> unityRules = new EnumMap<>(BlockSealType.class);
unityRules.put(BlockSealType.SEAL_POS_BLOCK, posRules);

return new ParentBlockHeaderValidator(unityRules);
}

public GrandParentBlockHeaderValidator createPreUnityGrandParentHeaderValidator() {

List<GrandParentDependantBlockHeaderRule> powRules =
Expand Down Expand Up @@ -193,18 +183,28 @@ public ParentBlockHeaderValidator createPreUnityParentBlockHeaderValidator() {
}

public ParentBlockHeaderValidator createUnityParentBlockHeaderValidator() {
List<DependentBlockHeaderRule> rules =
List<DependentBlockHeaderRule> PoWrules =
Arrays.asList(
new BlockNumberRule(),
new ParentOppositeTypeRule(),
new TimeStampRule(),
new EnergyLimitRule(
getConstants().getEnergyDivisorLimitLong(),
getConstants().getEnergyLowerBoundLong()));

List<DependentBlockHeaderRule> PoSrules =
Arrays.asList(
new BlockNumberRule(),
new ParentOppositeTypeRule(),
new StakingBlockTimeStampRule(),
new TimeStampRule(),
new EnergyLimitRule(
getConstants().getEnergyDivisorLimitLong(),
getConstants().getEnergyLowerBoundLong()));

Map<BlockSealType, List<DependentBlockHeaderRule>> unityRules = new EnumMap<>(BlockSealType.class);
unityRules.put(BlockSealType.SEAL_POW_BLOCK, rules);
unityRules.put(BlockSealType.SEAL_POS_BLOCK, rules);
unityRules.put(BlockSealType.SEAL_POW_BLOCK, PoWrules);
unityRules.put(BlockSealType.SEAL_POS_BLOCK, PoSrules);

return new ParentBlockHeaderValidator(unityRules);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ public boolean validate(
BlockHeaderValidatorUtil.addError("Invalid header type", this.getClass(), errors);
return false;
}

if (!(dependency instanceof StakingBlockHeader)) {
BlockHeaderValidatorUtil.addError(
"Invalid parent header type", this.getClass(), errors);

if (dependency instanceof StakingBlockHeader) {
BlockHeaderValidatorUtil.addError("Invalid parent header type", this.getClass(), errors);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion modAionImpl/test/org/aion/zero/impl/UnityHardForkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void setup() throws Exception {
AvmTestConfig.supportOnlyAvmVersion1();

MockitoAnnotations.initMocks(this);
doReturn(BigInteger.ONE).when(stakingContractHelper).getEffectiveStake(any(AionAddress.class), any(AionAddress.class));
doReturn(new BigInteger("10000000000")).when(stakingContractHelper).getEffectiveStake(any(AionAddress.class), any(AionAddress.class));
key =
new ECKeyEd25519()
.fromPrivate(
Expand Down

0 comments on commit b6859dc

Please sign in to comment.