Skip to content

Commit

Permalink
Merge branch 'master-pre-merge'
Browse files Browse the repository at this point in the history
  • Loading branch information
AionJayT committed May 24, 2018
2 parents 708dfee + abb60a3 commit d77b1c1
Show file tree
Hide file tree
Showing 39 changed files with 7,914 additions and 3,668 deletions.
4 changes: 4 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 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.
Expand Down
2 changes: 1 addition & 1 deletion 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/developers/) 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 Down
37 changes: 35 additions & 2 deletions modAionImpl/src/org/aion/zero/impl/AionBlockchainImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,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 +685,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 +705,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 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 d77b1c1

Please sign in to comment.