-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AKI-407: utility for managing unity fork point
- Loading branch information
1 parent
305a3da
commit 64881af
Showing
13 changed files
with
196 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.aion.zero.impl.forks; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.base.Preconditions; | ||
|
||
/** Utility for managing the fork checks. Currently implements only Unity fork functionality. */ | ||
public class ForkUtility { | ||
|
||
// variables used by the Unity fork | ||
private boolean unityForkEnabled = false; | ||
private long unityForkBlockHeight = Long.MAX_VALUE; | ||
|
||
/** | ||
* Enables the Unity fork after the given block number. | ||
* | ||
* @param unityForkBlockHeight the height of the block after which Unity behaviour is applied | ||
*/ | ||
public void enableUnityFork(long unityForkBlockHeight) { | ||
Preconditions.checkArgument(unityForkBlockHeight >= 2, "Invalid fork0.5.0 (Unity) block number: must be >= 2"); | ||
this.unityForkBlockHeight = unityForkBlockHeight; | ||
this.unityForkEnabled = true; | ||
} | ||
|
||
/** Disables the Unity fork. */ | ||
@VisibleForTesting | ||
public void disableUnityFork() { | ||
this.unityForkBlockHeight = Long.MAX_VALUE; | ||
this.unityForkEnabled = false; | ||
} | ||
|
||
/** | ||
* Returns a boolean value indicating if the Unity fork is active for the given context (block | ||
* number). We want the fork block itself to be a PoW block subject to the old pre-Unity rules, | ||
* so we use a strict greater than comparison. | ||
* | ||
* @return {@code true} if the unity fork is active for the given context (block number), {@code | ||
* false} otherwise | ||
*/ | ||
public boolean isUnityForkActive(long contextBlockNumber) { | ||
return unityForkEnabled && (contextBlockNumber > unityForkBlockHeight); | ||
} | ||
|
||
public boolean isUnityForkBlock(long contextBlockNumber) { | ||
return unityForkEnabled && (contextBlockNumber == unityForkBlockHeight); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.