Skip to content
Adding Bitcoin-like features to Naivecoin.
JavaScript HTML Shell Dockerfile
Branch: master
Clone or download
Pull request Compare This branch is 16 commits ahead, 15 commits behind conradoqg:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
doc
lib
test
.eslintrc.json
.gitignore
.travis.yml
Dockerfile
LICENSE
README.md
docker-compose.yml
dockerExec.sh
package.json
processes.json

README.md

(NotSo)Naivecoin

Adding Bitcoin-like features to Naivecoin.

  1. Difficulty adjustment
const EVERY_X_BLOCKS = 100;
// Estimated completion time for X blocks.
const EXPECTED_BLOCK_COMPLETION_TIME = 604800 // 1 week.

let index = blocks.length - 1;

// Initially assume new blocks difficulty is the same as the one at the end of the chain.
difficulty = blocks[index].difficulty;

// If the index of the block at the end of the chain indicates that a difficulty adjustment may need to take place (for the next block).
if ( index % EVERY_X_BLOCKS == 0 ) {
	
	// Propose to adjust difficulty based on ratio between expected completion time of last block set and actual completion time.
	let adjustment = difficulty * ( EXPECTED_BLOCK_COMPLETION_TIME / ( blocks[index].timestamp - blocks[index - EVERY_X_BLOCKS].timestamp ) );
	
	// Don't make any adjustments that are too extreme.
	if ( adjustment > ( difficulty * 4 ) ) {
		difficulty = difficulty * 4;
	} else if ( adjustment < ( difficulty * 0.25 ) ) {
		difficulty = difficulty * 0.25;
	} else {
		difficulty = adjustment;
	}
	
}

// Return difficulty unchanged, or adjusted.
return difficulty;
  1. Periodic reward depreciation
const REWARD_REDUCTION_BLOCKS = 500;
return module.exports.MINING_REWARD / Math.ceil( blocks.length / REWARD_REDUCTION_BLOCKS );

Powering

You can’t perform that action at this time.