Skip to content

Commit

Permalink
Merge branch 'master-pre-merge' into db-journal-prune
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandraRoatis authored Jun 1, 2018
2 parents ab40ed4 + 4b5e4f7 commit 46fccd6
Show file tree
Hide file tree
Showing 48 changed files with 8,132 additions and 3,807 deletions.
12 changes: 12 additions & 0 deletions .github/issue_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
_Before filing a new issue, please **provide the following information**._

> I'm running:
>
> - **Which Aion version?**: 0.2.x.{git-revision}
> - **Which operating system?**: Linux
> - **Which distributor and version?**: Ubuntu 16.04
> - **How installed?**: via binaries / from source
> - **Are you fully synchronized?**: no / yes
> - **Did you try to restart the node?**: no / yes
_Your issue description goes here below. Try to include **actual** vs. **expected behavior** and **steps to reproduce** the issue._
35 changes: 35 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Notice

It is not allowed to submit your PR to the master branch directly, please submit your PR to the master-pre-merge branch.

## 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.
- [ ] 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.

-

## Verification

Insert **x** into the following checkboxes to confirm (eg. [x]):
- [ ] I have self-reviewed my own code and conformed to the style guidelines of this project.
- [ ] New and existing tests pass locally with my changes.
- [ ] I have added tests for my fix or feature.
- [ ] I have made appropriate changes to the corresponding documentation.
- [ ] My code generates no new warnings.
- [ ] Any dependent changes have been made.
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Contributing Guidelines

## Do you have a question?

Check out our [Aion Owner's Manual](https://github.com/aionnetwork/aion/wiki/Aion-Owner's-Manual), [Installation and Cofiguration](https://github.com/aionnetwork/aion/wiki/Installation), [FAQ](https://github.com/aionnetwork/aion/wiki/Aion-Owner's-Manual#faqs), and articles on our [wiki](https://github.com/aionnetwork/aion/wiki)!

For further questions and discussions see our [Aion Forum](https://forum.aion.network/).

## Report bugs!

Do **not** open an issue on Github if you think your discovered bug could be a **security-relevant vulnerability**. Instead, either private message us on [gitter](https://gitter.im/aionnetwork) or send an email to [email protected].


Otherwise, just create a [new issue](https://github.com/aionnetwork/aion/issues/new) in our repository and state:

- What's your aion version?
- What's your operating system and version?
- How did you install aion?
- Is your node fully synchronized?
- Did you try turning it off and on again?

Also, try to include **steps to reproduce** the issue and expand on the **actual versus expected behavior**.

## Contribute!

If you would like to contribute to Aion, please **fork it**, fix bugs or implement features, and [propose a pull request](https://github.com/aionnetwork/aion/compare).


## License.

By contributing to Aion, you agree that your contributions will be licensed under the [GPLv3 License](LICENSE).
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Mainstream adoption of blockchains has been limited because of scalability, priv

Core to our hypothesis is the idea that many blockchains will be created to solve unique business challenges within unique industries. As such, the Aion network is designed to support custom blockchain architectures while providing a trustless mechanism for cross-chain interoperability.

The [Aion White Papers](https://aion.network/whitepapers.html) provides more details regarding our design and project roadmap.
The [Aion White Papers](https://aion.network/developers/#whitepapers) provides more details regarding our design and project roadmap.

This repository contains the main kernel implementation and releases for the Aion network.

Expand All @@ -16,9 +16,7 @@ This repository contains the main kernel implementation and releases for the Aio

Please refer to the details in the [Build Your Aion Network](https://github.com/aionnetwork/aion/wiki/Build-your-Aion-network) wiki to determine how to start setting up and building your Aion Network.

Please refer to the [Installation](https://github.com/aionnetwork/aion/wiki/Installation) wiki for the guide on installing the kernel prior to configuration and launching the kernel.

Please refer to [Aion Network Configuration](https://github.com/aionnetwork/aion/wiki/Aion-Network-Configuration) wiki to set up your desired network configuration for the kernel as well as how to launch the kernel.
Please refer to the [Installation](https://github.com/aionnetwork/aion/wiki/Installation) wiki for a guide on installing and configuring the kernel.

The [Owner's Manual](https://github.com/aionnetwork/aion/wiki/Aion-Owner's-Manual) wiki will include further instructions and details on working with the kernel.

Expand All @@ -36,5 +34,7 @@ Please refer to the [wiki pages](https://github.com/aionnetwork/aion/wiki) for f

Aion is released under the [GPL-V3 license](https://github.com/aionnetwork/aion/blob/dev/LICENSE)

### WE ARE HIRING!

If you are interested in being part of the Aion project, check out our available positions and apply [here](http://aion.humi.ca/job-board/it/697)!
<!--For additional Aion **command line options** run:```./aion.sh -h```-->
51 changes: 40 additions & 11 deletions modAionImpl/src/org/aion/zero/impl/AionBlockchainImpl.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*******************************************************************************
/*
* Copyright (c) 2017-2018 Aion foundation.
*
* This file is part of the aion network project.
Expand All @@ -19,8 +19,7 @@
*
* Contributors:
* Aion foundation.
******************************************************************************/

*/
package org.aion.zero.impl;

import static java.lang.Math.max;
Expand Down Expand Up @@ -139,8 +138,6 @@ public class AionBlockchainImpl implements IAionBlockchain {
*/
private volatile AionBlock pubBestBlock;

private volatile BigInteger pubBestTD = ZERO;

private volatile BigInteger totalDifficulty = ZERO;
private ChainStatistics chainStats;

Expand Down Expand Up @@ -572,7 +569,6 @@ ImportResult tryToConnectInternal(final AionBlock block, long currTimeSeconds) {
// update best block reference
if (ret == IMPORTED_BEST) {
pubBestBlock = bestBlock;
pubBestTD = summary.getTotalDifficulty();
}

// fire block events
Expand Down Expand Up @@ -602,11 +598,38 @@ ImportResult tryToConnectInternal(final AionBlock block, long currTimeSeconds) {
return ret;
}

/**
* Creates a new block, if you require more context refer to the blockContext creation method,
* which allows us to add metadata not usually associated with the block itself.
*
* @param parent block
* @param txs to be added into the block
* @param waitUntilBlockTime if we should wait until the specified blockTime before create a new block
* @see #createNewBlock(AionBlock, List, boolean)
*
* @return new block
*/
public synchronized AionBlock createNewBlock(AionBlock parent, List<AionTransaction> txs, boolean waitUntilBlockTime) {
return createNewBlockInternal(
parent, txs, waitUntilBlockTime, System.currentTimeMillis() / THOUSAND_MS).block;
}

/**
* Creates a new block, adding in context/metadata about the block
*
* @param parent block
* @param txs to be added into the block
* @param waitUntilBlockTime if we should wait until the specified blockTime before create a new block
* @see #createNewBlock(AionBlock, List, boolean)
*
* @return new block
*/
public synchronized BlockContext createNewBlockContext(
AionBlock parent, List<AionTransaction> txs, boolean waitUntilBlockTime) {
return createNewBlockInternal(parent, txs, waitUntilBlockTime, System.currentTimeMillis() / THOUSAND_MS);
}

AionBlock createNewBlockInternal(AionBlock parent, List<AionTransaction> txs, boolean waitUntilBlockTime,
BlockContext createNewBlockInternal(AionBlock parent, List<AionTransaction> txs, boolean waitUntilBlockTime,
long currTimeSeconds) {
long time = currTimeSeconds;

Expand Down Expand Up @@ -658,8 +681,10 @@ AionBlock createNewBlockInternal(AionBlock parent, List<AionTransaction> txs, bo
* Calculate the gas used for the included transactions
*/
long totalEnergyUsed = 0;
BigInteger totalTransactionFee = BigInteger.ZERO;
for (AionTxExecSummary summary : preBlock.summaries) {
totalEnergyUsed = totalEnergyUsed + summary.getNrgUsed().longValueExact();
totalTransactionFee = totalTransactionFee.add(summary.getFee());
}

byte[] stateRoot = getRepository().getRoot();
Expand All @@ -676,7 +701,11 @@ AionBlock createNewBlockInternal(AionBlock parent, List<AionTransaction> txs, bo
block.seal(preBlock.txs, calcTxTrie(preBlock.txs), stateRoot, logBloom.getData(),
calcReceiptsTrie(preBlock.receipts), totalEnergyUsed);

return block;
// derive base block reward
BigInteger baseBlockReward = this.chainConfiguration
.getRewardsCalculator()
.calculateReward(block.getHeader());
return new BlockContext(block, baseBlockReward, totalTransactionFee);
}

@Override
Expand All @@ -688,7 +717,7 @@ public synchronized AionBlockSummary add(AionBlock block) {
List<AionTxReceipt> receipts = summary.getReceipts();

updateTotalDifficulty(block);
summary.setTotalDifficulty(getInternalTD());
summary.setTotalDifficulty(block.getCumulativeDifficulty());

storeBlock(block, receipts);

Expand Down Expand Up @@ -1106,7 +1135,7 @@ public synchronized void close() {

@Override
public BigInteger getTotalDifficulty() {
return pubBestTD;
return getBestBlock().getCumulativeDifficulty();
}

// this method is for the testing purpose
Expand All @@ -1120,14 +1149,14 @@ private BigInteger getInternalTD() {

private void updateTotalDifficulty(AionBlock block) {
totalDifficulty = totalDifficulty.add(block.getDifficultyBI());
block.setCumulativeDifficulty(totalDifficulty);
if (LOG.isDebugEnabled()) {
LOG.debug("TD: updated to {}", totalDifficulty);
}
}

@Override
public void setTotalDifficulty(BigInteger totalDifficulty) {
this.pubBestTD = totalDifficulty;
this.totalDifficulty = totalDifficulty;
}

Expand Down
23 changes: 13 additions & 10 deletions modAionImpl/src/org/aion/zero/impl/AionHub.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
/* ******************************************************************************
/*
* Copyright (c) 2017-2018 Aion foundation.
*
* This file is part of the aion network project.
*
* The aion network project is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* The aion network project is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or any later version.
*
* The aion network project is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* The aion network project is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the aion network project source files.
* along with the aion network project source files.
* If not, see <https://www.gnu.org/licenses/>.
*
* Contributors:
* Aion foundation.
******************************************************************************/
*/
package org.aion.zero.impl;

import org.aion.base.db.IRepository;
Expand Down Expand Up @@ -259,6 +259,7 @@ private void loadBlockchain() {
this.repository.getBlockStore().load();

AionBlock bestBlock = this.repository.getBlockStore().getBestBlock();
bestBlock.setCumulativeDifficulty(repository.getBlockStore().getTotalDifficultyForHash(bestBlock.getHash()));

boolean recovered = true;
boolean bestBlockShifted = true;
Expand Down Expand Up @@ -302,6 +303,8 @@ private void loadBlockchain() {

if (recovered) {
bestBlock = this.repository.getBlockStore().getBestBlock();
bestBlock.setCumulativeDifficulty(repository.getBlockStore()
.getTotalDifficultyForHash(bestBlock.getHash()));

// checking is the best block has changed since attempting recovery
if (bestBlock == null) {
Expand Down Expand Up @@ -338,7 +341,7 @@ private void loadBlockchain() {
buildGenesis(genesis);

blockchain.setBestBlock(genesis);
blockchain.setTotalDifficulty(genesis.getCumulativeDifficulty());
blockchain.setTotalDifficulty(genesis.getDifficultyBI());

if (this.eventMgr != null) {
List<IEvent> evts = new ArrayList<>();
Expand Down
27 changes: 27 additions & 0 deletions modAionImpl/src/org/aion/zero/impl/BlockContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.aion.zero.impl;

import org.aion.zero.impl.types.AionBlock;

import java.math.BigInteger;

/**
* Wraps contextual / metadata about the block that are not
* part of the block itself (not associated with PoW/PoS)
*/
public class BlockContext {
public final AionBlock block;
public final BigInteger baseBlockReward;
public final BigInteger transactionFee;

public BlockContext(AionBlock block, BigInteger baseBlockReward, BigInteger transactionFee) {
this.block = block;
this.baseBlockReward = baseBlockReward;
this.transactionFee = transactionFee;
}

public BlockContext(BlockContext context) {
this.block = new AionBlock(context.block);
this.baseBlockReward = context.baseBlockReward;
this.transactionFee = context.transactionFee;
}
}
Loading

0 comments on commit 46fccd6

Please sign in to comment.