mirror of https://github.com/status-im/EIPs.git
Adjustment Interval (#1075)
Cleaned up presentation code and added adjustment interval getter to base interface
This commit is contained in:
parent
c1efb4c2fa
commit
c082b33f01
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
```
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -236,7 +237,7 @@ 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
|
||||
|
@ -244,7 +245,7 @@ function getMiningDifficulty() public constant returns (uint)
|
|||
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
|
||||
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue