Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity integration - FixedPoint / BlockHeaderValidators #987

Merged
merged 2 commits into from
Sep 18, 2019
Merged

Conversation

AionJayT
Copy link
Collaborator

Notice

Please submit your PR to the master branch and rebase your code on master before opening the pull request.

Description

Please include a brief summary of the change that this pull request proposes. Include any relevant motivation and context. List any dependencies required for this change.

Fixes Issue # .

Type of change

Insert x into the following checkboxes to confirm (eg. [x]):

  • Bug fix.
  • New feature.
  • Enhancement.
  • Unit test.
  • Breaking change (a fix or feature that causes existing functionality to not work as expected).
  • Requires documentation update.

Testing

Please describe the tests you used to validate this pull request. Provide any relevant details for test configurations as well as any instructions to reproduce these results.

this.value = value;
}

public FixedPoint(BigDecimal value) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package private

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also use the string directly, add comment


public BigDecimal toBigDecimal() {

BigDecimal maxPrecision = new BigDecimal(BigInteger.ONE.shiftLeft(PRECISION));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use MAX_PRECISION directly


// This class can NOT be used for negative values

public class FixedPoint {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final

public static final FixedPoint ZERO = new FixedPoint(BigInteger.ZERO);
public static final FixedPoint ONE = new FixedPoint(BigInteger.ONE.shiftLeft(PRECISION));

private BigInteger value;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final

return multiplyInteger(BigInteger.valueOf(multiplicand));
}

public FixedPoint divideInteger(BigInteger divisor) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

// This test calculates the logs for all integers from 1 to 2^20, and records how many of them
// end up with the same value. That is, it records how many x /= y satisfy log(x) = log(y) using our approximator
@Test
public void testCollisions() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -44,6 +47,7 @@
import org.aion.zero.impl.valid.AionExtraDataRule;
import org.aion.zero.impl.valid.AionHeaderVersionRule;
import org.aion.zero.impl.valid.EnergyConsumedRule;
import org.aion.zero.impl.valid.EquihashSolutionRule;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove it


public void logErrors(final Logger logger, final List<RuleError> errors) {
void logErrors(final Logger logger, final List<RuleError> errors) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call it statically

@@ -3,12 +3,15 @@
import java.util.List;
import org.aion.mcf.blockchain.BlockHeader;

public abstract class GrandParentDependantBlockHeaderRule
extends AbstractValidRule {
public abstract class GrandParentDependantBlockHeaderRule extends AbstractValidRule {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it an interface

arajasek and others added 2 commits September 18, 2019 11:20
- FixedPoint represents non-integral numbers by multiplying them by a large power of 2.
- LogApproximator approximates the natural log of integers using a shift-and-add algorithm. The returned value is a FixedPoint.
@AionJayT AionJayT merged commit 241877e into master Sep 18, 2019
@AionJayT AionJayT added this to the 0.4.2 milestone Oct 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants