Skip to content

Commit

Permalink
Adjustment Interval (#1075)
Browse files Browse the repository at this point in the history
Cleaned up presentation code and added adjustment interval getter to base interface
  • Loading branch information
10d9e authored and Arachnid committed May 11, 2018
1 parent c1efb4c commit c082b33
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions EIPS/eip-918.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ Token distribution via the ICO model and it's derivatives is susceptable to illi
The general behavioral specification includes a primary function that defines the token minting operation, an optional merged minting operation for issuing multiple tokens, getters for challenge number, mining difficulty, mining target and current reward, and finally a Mint event, to be emitted upon successful solution validation and token issuance. At a minimum, contracts must adhere to this interface (save the optional merge operation). It is recommended that contracts interface with the more behaviorally defined Abstract Contract described below, in order to leverage a more defined construct, allowing for easier external implementations via overridden phased functions. (see 'Abstract Contract' below)

``` js
interface EIP918Interface {
contract EIP918Interface {

function mint(uint256 nonce, bytes32 challenge_digest) public returns (bool success);

function getAdjustmentInterval() public view returns (uint);

function getChallengeNumber() public constant returns (bytes32);

Expand All @@ -38,10 +40,10 @@ interface EIP918Interface {

function getMiningReward() public constant returns (uint);

event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);

// Optional
function merge(uint256 nonce, bytes32 challenge_digest, address[] mineTokens) public returns (bool success);
function merge(uint256 nonce, bytes32 challenge_digest, address[] mineTokens) public returns (bool success){}

event Mint(address indexed from, uint reward_amount, uint epochCount, bytes32 newChallengeNumber);

}
```
Expand Down Expand Up @@ -86,7 +88,10 @@ populate statistics, mutate epoch variables and adjust the solution difficulty a
a Mint event is emitted before returning a boolean success flag.

``` js
contract AbstractERC918 is EIP918Interface {
contract AbstractERC918 is EIP918Interface {

// the amount of time between difficulty adjustments
uint public adjustmentInterval = 10 minutes;

// generate a new challenge number after a new reward is minted
bytes32 public challengeNumber;
Expand All @@ -97,21 +102,12 @@ a Mint event is emitted before returning a boolean success flag.
// cumulative counter of the total minted tokens
uint public tokensMinted;

// number of blocks per difficulty adjustment
// number of blocks per difficulty readjustment
uint public blocksPerReadjustment;

uint public epochCount;//number of 'blocks' mined

// track read only minting statistics
struct Statistics {
address lastRewardTo;
uint lastRewardAmount;
uint lastRewardEthBlockNumber;
uint lastRewardTimestamp;
}

Statistics public statistics;

//number of 'blocks' mined
uint public epochCount;

/*
* Externally facing mint function that is called by miners to validate challenge digests, calculate reward,
* populate statistics, mutate epoch variables and adjust the solution difficulty as required. Once complete,
Expand All @@ -129,15 +125,12 @@ a Mint event is emitted before returning a boolean success flag.
// increment the minted tokens amount
tokensMinted += rewardAmount;

uint epochCount = _epoch();
epochCount = _epoch();

//every so often, readjust difficulty. Dont readjust when deploying
if(epochCount % blocksPerReadjustment == 0){
_adjustDifficulty();
}

//populate read only diagnostics data
statistics = Statistics(msg.sender, rewardAmount, block.number, now);

// send Mint event indicating a successful implementation
emit Mint(msg.sender, rewardAmount, epochCount, challengeNumber);
Expand Down Expand Up @@ -222,12 +215,20 @@ Internal interface function \_adjustDifficulty, meant to be overridden in implem
function _adjustDifficulty() internal returns (uint);
```

#### getAdjustmentInterval

The amount of time, in seconds, between difficulty adjustment operations.

``` js
function getAdjustmentInterval() public view returns (uint);
```

#### getChallengeNumber

Recent ethereum block hash, used to prevent pre-mining future blocks.

``` js
function getChallengeNumber() public constant returns (bytes32)
function getChallengeNumber() public view returns (bytes32);
```

#### getMiningDifficulty
Expand All @@ -236,15 +237,15 @@ The number of digits that the digest of the PoW solution requires which typicall


``` js
function getMiningDifficulty() public constant returns (uint)
function getMiningDifficulty() public view returns (uint)
```

#### getMiningReward

Return the current reward amount. Depending on the algorithm, typically rewards are divided every reward era as tokens are mined to provide scarcity.

``` js
function getMiningReward() public constant returns (uint)
function getMiningReward() public view returns (uint)
```

### Example mining function
Expand Down Expand Up @@ -280,7 +281,6 @@ Backwards incompatibilities are not introduced.
### Implementation

Simple Example:

https://github.com/0xbitcoin/EIP918-Mineable-Token/blob/master/contracts/SimpleERC918.sol

Complex Examples:
Expand Down

0 comments on commit c082b33

Please sign in to comment.