Skip to content

Commit

Permalink
initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
pocopoco committed May 7, 2013
1 parent 667a9ab commit 154d937
Show file tree
Hide file tree
Showing 30 changed files with 3,020 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ class CBitcoinAddress : public CBase58Data
public:
enum
{
PUBKEY_ADDRESS = 8,
SCRIPT_ADDRESS = 20,
PUBKEY_ADDRESS = 77, // yacoin: address begin with 'Y'
SCRIPT_ADDRESS = 139, // yacoin: address begin with 'y'
PUBKEY_ADDRESS_TEST = 111,
SCRIPT_ADDRESS_TEST = 196,
};
Expand Down
2 changes: 1 addition & 1 deletion src/checkpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ namespace Checkpoints
}

// ppcoin: sync-checkpoint master key
const std::string CSyncCheckpoint::strMasterPubKey = "04a51b735f816de4ec3f891d5b38bbc91e1f7245c7c08d17990760b86b4d8fc3910a850ffecf73bfa8886f01739a0c4c4322201282d07b6e48ce931cc92af94850";
const std::string CSyncCheckpoint::strMasterPubKey = "04bd3f419127f084f13e6d4ee35d915eb76e78f16b4c259c7ea5dbec5c4b4c0da5089060c1df266c1d167603ecedb2d5d49b26aefa165ad912dc3c664f429c6846";

std::string CSyncCheckpoint::strMasterPrivKey = "";

Expand Down
5 changes: 4 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ std::string HelpMessage()
" -socks=<n> " + _("Select the version of socks proxy to use (4-5, default: 5)") + "\n" +
" -tor=<ip:port> " + _("Use proxy to reach tor hidden services (default: same as -proxy)") + "\n"
" -dns " + _("Allow DNS lookups for -addnode, -seednode and -connect") + "\n" +
" -port=<port> " + _("Listen for connections on <port> (default: 7777 or testnet: 17777)") + "\n" +
" -port=<port> " + _("Listen for connections on <port> (default: 7888 or testnet: 17888)") + "\n" +
" -maxconnections=<n> " + _("Maintain at most <n> connections to peers (default: 125)") + "\n" +
" -addnode=<ip> " + _("Add a node to connect to and attempt to keep the connection open") + "\n" +
" -connect=<ip> " + _("Connect only to the specified node(s)") + "\n" +
Expand Down Expand Up @@ -645,6 +645,9 @@ bool AppInit2()
BOOST_FOREACH(string strDest, mapMultiArgs["-seednode"])
AddOneShot(strDest);

// TODO: replace this by DNSseed
//AddOneShot(string(""));

// ********************************************************* Step 7: load blockchain

if (!bitdb.Open(GetDataDir()))
Expand Down
2 changes: 1 addition & 1 deletion src/irc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void ThreadIRCSeed2(void* parg)
// int channel_number = GetRandInt(5);

// Channel number is always 0 for initial release
int channel_number = 0;
int channel_number = 77;
Send(hSocket, strprintf("JOIN #yacoin%02d\r", channel_number).c_str());
Send(hSocket, strprintf("WHO #yacoin%02d\r", channel_number).c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ unsigned int nModifierInterval = MODIFIER_INTERVAL;
// Hard checkpoints of stake modifiers to ensure they are deterministic
static std::map<int, unsigned int> mapStakeModifierCheckpoints =
boost::assign::map_list_of
( 0, 0x0fd11f4e7 ) // TODO: check this is true!
( 0, 0xfd11f4e7 )
;

// Get the last stake modifier and its generation time from a given block
Expand Down
54 changes: 44 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ static CBigNum bnInitialHashTarget(~uint256(0) >> 20);
unsigned int nStakeMinAge = 60 * 60 * 24 * 30; // minimum age for coin age
unsigned int nStakeMaxAge = 60 * 60 * 24 * 90; // stake age of full weight
unsigned int nStakeTargetSpacing = 1 * 60; // DIFF: 1-minute block spacing
int64 nChainStartTime = 1367872000;
int nCoinbaseMaturity = 500;
CBlockIndex* pindexGenesisBlock = NULL;
int nBestHeight = -1;
Expand Down Expand Up @@ -946,6 +947,37 @@ uint256 WantedByOrphan(const CBlock* pblockOrphan)
return pblockOrphan->hashPrevBlock;
}

// yacoin: increasing Nfactor gradually
const unsigned char minNfactor = 4;
const unsigned char maxNfactor = 30;

unsigned char GetNfactor(int64 nTimestamp) {
int l = 0;

if (nTimestamp <= nChainStartTime)
return 4;

int64 s = nTimestamp - nChainStartTime;
while ((s >> 1) > 3) {
l += 1;
s >>= 1;
}

s &= 3;

int n = (l * 170 + s * 25 - 2320) / 100;

if (n < 0) n = 0;

if (n > 255)
printf("GetNfactor(%d) - something wrong(n == %d)\n", nTimestamp, n);

unsigned char N = (unsigned char)n;
//printf("GetNfactor: %d -> %d %d : %d / %d\n", nTimestamp - nChainStartTime, l, s, n, min(max(N, minNfactor), maxNfactor));

return min(max(N, minNfactor), maxNfactor);
}

int64 GetProofOfWorkReward(unsigned int nBits)
{
CBigNum bnSubsidyLimit = MAX_MINT_PROOF_OF_WORK;
Expand Down Expand Up @@ -2493,9 +2525,9 @@ bool LoadBlockIndex(bool fAllowNew)
// vMerkleTree: 4a5e1e

// Genesis block
const char* pszTimestamp = "https://bitcointalk.org/index.php?topic=134179.msg1502196#msg1502196";
const char* pszTimestamp = "https://bitcointalk.org/index.php?topic=196196";
CTransaction txNew;
txNew.nTime = 1360105017;
txNew.nTime = nChainStartTime;
txNew.vin.resize(1);
txNew.vout.resize(1);
txNew.vin[0].scriptSig = CScript() << 486604799 << CBigNum(9999) << vector<unsigned char>((const unsigned char*)pszTimestamp, (const unsigned char*)pszTimestamp + strlen(pszTimestamp));
Expand All @@ -2505,16 +2537,18 @@ bool LoadBlockIndex(bool fAllowNew)
block.hashPrevBlock = 0;
block.hashMerkleRoot = block.BuildMerkleTree();
block.nVersion = 1;
block.nTime = 1367057243;
block.nTime = nChainStartTime + 19;
block.nBits = bnProofOfWorkLimit.GetCompact();
block.nNonce = 1575379;
block.nNonce = 136291;

//// debug print
printf("block.GetHash() == %s\n", block.GetHash().ToString().c_str());
assert(block.hashMerkleRoot == uint256("0x4cb33b3b6a861dcbc685d3e614a9cafb945738d6833f182855679f2fad02057b"));
printf("block.hashMerkleRoot == %s\n", block.hashMerkleRoot.ToString().c_str());
assert(block.hashMerkleRoot == uint256("0x01222b30def82d9b2ddae9f11e5860e0ce7506bac0ac58cb0703b3d0c578b990"));
block.print();

assert(block.GetHash() == hashGenesisBlock);
//assert(block.CheckBlock()); // TODO: uncomment
assert(block.CheckBlock());

// Start new block file
unsigned int nFile;
Expand Down Expand Up @@ -2811,7 +2845,7 @@ bool static AlreadyHave(CTxDB& txdb, const CInv& inv)
// The message start string is designed to be unlikely to occur in normal data.
// The characters are rarely used upper ASCII, not valid as UTF-8, and produce
// a large 4-byte int at any alignment.
unsigned char pchMessageStart[4] = { 0xe4, 0xe8, 0xe9, 0xe5 };
unsigned char pchMessageStart[4] = { 0xe8, 0xe7, 0xe9, 0xe3 };

bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
{
Expand Down Expand Up @@ -4272,7 +4306,7 @@ void BitcoinMiner(CWallet *pwallet, bool fProofOfStake)
return;
while (vNodes.empty() || IsInitialBlockDownload())
{
printf("vNodes.size() == %d, IsInitialBlockDownload() == %d\n", vNodes.size(), IsInitialBlockDownload());
//printf("vNodes.size() == %d, IsInitialBlockDownload() == %d\n", vNodes.size(), IsInitialBlockDownload());
Sleep(1000);
if (fShutdown)
return;
Expand Down Expand Up @@ -4351,11 +4385,11 @@ void BitcoinMiner(CWallet *pwallet, bool fProofOfStake)

nNonceFound = scanhash_scrypt(
(block_header *)&pblock->nVersion,
scratchbuf,
max_nonce,
nHashesDone,
UBEGIN(result),
&res_header
&res_header,
GetNfactor(pblock->nTime)
);

// Check if something found
Expand Down
12 changes: 7 additions & 5 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ static const int fHaveUPnP = true;
static const int fHaveUPnP = false;
#endif

static const uint256 hashGenesisBlockOfficial("0x47e13f1b37a39ef9f85322a48ef84367b3b337fc28028b28ef80150356b647b8");
static const uint256 hashGenesisBlockTestNet("0x00000a060336cbb72fe969666d337b87198b1add2abaa59cca226820b32933a4");
static const uint256 hashGenesisBlockOfficial("0x00000f8de7134bdf87c15d5682de1b3d813d5fce28adf07612f123c30951de54");
static const uint256 hashGenesisBlockTestNet("0xfe20c2c2fc02b36d2473e1f51dba1fb455d41ff42966e2a4edabb98fdd7107e6");

static const int64 nMaxClockDrift = 2 * 60 * 60; // two hours

Expand Down Expand Up @@ -124,6 +124,8 @@ const CBlockIndex* GetLastBlockIndex(const CBlockIndex* pindex, bool fProofOfSta
void BitcoinMiner(CWallet *pwallet, bool fProofOfStake);
void ResendWalletTransactions();

// yacoin: calculate Nfactor using timestamp
unsigned char GetNfactor(int64 nTimestamp);



Expand Down Expand Up @@ -905,11 +907,11 @@ class CBlock
uint256 GetHash() const
{
uint256 thash;
void * scratchbuff = scrypt_buffer_alloc();
//void * scratchbuff = scrypt_buffer_alloc();

scrypt_hash(CVOIDBEGIN(nVersion), sizeof(block_header), UINTBEGIN(thash), scratchbuff);
scrypt_hash(CVOIDBEGIN(nVersion), sizeof(block_header), UINTBEGIN(thash), GetNfactor(nTime));

scrypt_buffer_free(scratchbuff);
//scrypt_buffer_free(scratchbuff);

return thash;
}
Expand Down
13 changes: 12 additions & 1 deletion src/makefile.unix
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ DEBUGFLAGS=-g
xCXXFLAGS=-O2 -msse2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter \
$(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)

# scrypt-jane specific parameters
DEFS+=-DSCRYPT_KECCAK512 -DSCRYPT_CHACHA

xCXXFLAGS_SCRYPT_JANE=-O3 -msse2 -pthread -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter \
$(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)


# LDFLAGS can be specified on the make command line, so we use xLDFLAGS that only
# adds some defaults in front. Unfortunately, LDFLAGS=... $(LDFLAGS) does not work.
xLDFLAGS=$(LDHARDENING) $(LDFLAGS)
Expand Down Expand Up @@ -132,7 +139,8 @@ OBJS= \
obj/pbkdf2.o \
obj/scrypt_mine.o \
obj/scrypt-x86.o \
obj/scrypt-x86_64.o
obj/scrypt-x86_64.o \
obj/scrypt-jane.o


all: yacoind
Expand All @@ -155,6 +163,9 @@ obj/scrypt-x86.o: scrypt-x86.S
obj/scrypt-x86_64.o: scrypt-x86_64.S
$(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<

obj/scrypt-jane.o: scrypt-jane/scrypt-jane.c
gcc -c $(xCXXFLAGS_SCRYPT_JANE) -MMD -o $@ $<

obj/%.o: %.cpp
$(CXX) -c $(xCXXFLAGS) -MMD -MF $(@:%.o=%.d) -o $@ $<
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
Expand Down
2 changes: 1 addition & 1 deletion src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ void MapPort()
// The first name is used as information source for addrman.
// The second name should resolve to a list of seed addresses.
static const char *strDNSSeed[][2] = {
//{"novacoin.su", "seed.novacoin.su"},
//{"yacoin.org", "seed.novacoin.su"},
};

void ThreadDNSAddressSeed(void* parg)
Expand Down
2 changes: 1 addition & 1 deletion src/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
extern bool fTestNet;
static inline unsigned short GetDefaultPort(const bool testnet = fTestNet)
{
return testnet ? 17777 : 7777;
return testnet ? 17888 : 7888;
}


Expand Down
132 changes: 132 additions & 0 deletions src/scrypt-jane/code/scrypt-jane-chacha.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
#define SCRYPT_MIX_BASE "ChaCha20/8"

typedef uint32_t scrypt_mix_word_t;

#define SCRYPT_WORDTO8_LE U32TO8_LE
#define SCRYPT_WORD_ENDIAN_SWAP U32_SWAP

#define SCRYPT_BLOCK_BYTES 64
#define SCRYPT_BLOCK_WORDS (SCRYPT_BLOCK_BYTES / sizeof(scrypt_mix_word_t))

/* must have these here in case block bytes is ever != 64 */
#include "scrypt-jane-romix-basic.h"

#include "scrypt-jane-mix_chacha-avx.h"
#include "scrypt-jane-mix_chacha-ssse3.h"
#include "scrypt-jane-mix_chacha-sse2.h"
#include "scrypt-jane-mix_chacha.h"

#if defined(SCRYPT_CHACHA_AVX)
#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_avx
#define SCRYPT_ROMIX_FN scrypt_ROMix_avx
#define SCRYPT_MIX_FN chacha_core_avx
#define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_nop
#define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_nop
#include "scrypt-jane-romix-template.h"
#endif

#if defined(SCRYPT_CHACHA_SSSE3)
#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_ssse3
#define SCRYPT_ROMIX_FN scrypt_ROMix_ssse3
#define SCRYPT_MIX_FN chacha_core_ssse3
#define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_nop
#define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_nop
#include "scrypt-jane-romix-template.h"
#endif

#if defined(SCRYPT_CHACHA_SSE2)
#define SCRYPT_CHUNKMIX_FN scrypt_ChunkMix_sse2
#define SCRYPT_ROMIX_FN scrypt_ROMix_sse2
#define SCRYPT_MIX_FN chacha_core_sse2
#define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_nop
#define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_nop
#include "scrypt-jane-romix-template.h"
#endif

/* cpu agnostic */
#define SCRYPT_ROMIX_FN scrypt_ROMix_basic
#define SCRYPT_MIX_FN chacha_core_basic
#define SCRYPT_ROMIX_TANGLE_FN scrypt_romix_convert_endian
#define SCRYPT_ROMIX_UNTANGLE_FN scrypt_romix_convert_endian
#include "scrypt-jane-romix-template.h"

#if !defined(SCRYPT_CHOOSE_COMPILETIME)
static scrypt_ROMixfn
scrypt_getROMix() {
size_t cpuflags = detect_cpu();

#if defined(SCRYPT_CHACHA_AVX)
if (cpuflags & cpu_avx)
return scrypt_ROMix_avx;
else
#endif

#if defined(SCRYPT_CHACHA_SSSE3)
if (cpuflags & cpu_ssse3)
return scrypt_ROMix_ssse3;
else
#endif

#if defined(SCRYPT_CHACHA_SSE2)
if (cpuflags & cpu_sse2)
return scrypt_ROMix_sse2;
else
#endif

return scrypt_ROMix_basic;
}
#endif


#if defined(SCRYPT_TEST_SPEED)
static size_t
available_implementations() {
size_t flags = 0;

#if defined(SCRYPT_CHACHA_AVX)
flags |= cpu_avx;
#endif

#if defined(SCRYPT_CHACHA_SSSE3)
flags |= cpu_ssse3;
#endif

#if defined(SCRYPT_CHACHA_SSE2)
flags |= cpu_sse2;
#endif

return flags;
}
#endif

static int
scrypt_test_mix() {
static const uint8_t expected[16] = {
0x48,0x2b,0x2d,0xb8,0xa1,0x33,0x22,0x73,0xcd,0x16,0xc4,0xb4,0xb0,0x7f,0xb1,0x8a,
};

int ret = 1;
size_t cpuflags = detect_cpu();

#if defined(SCRYPT_CHACHA_AVX)
if (cpuflags & cpu_avx)
ret &= scrypt_test_mix_instance(scrypt_ChunkMix_avx, scrypt_romix_nop, scrypt_romix_nop, expected);
#endif

#if defined(SCRYPT_CHACHA_SSSE3)
if (cpuflags & cpu_ssse3)
ret &= scrypt_test_mix_instance(scrypt_ChunkMix_ssse3, scrypt_romix_nop, scrypt_romix_nop, expected);
#endif

#if defined(SCRYPT_CHACHA_SSE2)
if (cpuflags & cpu_sse2)
ret &= scrypt_test_mix_instance(scrypt_ChunkMix_sse2, scrypt_romix_nop, scrypt_romix_nop, expected);
#endif

#if defined(SCRYPT_CHACHA_BASIC)
ret &= scrypt_test_mix_instance(scrypt_ChunkMix_basic, scrypt_romix_convert_endian, scrypt_romix_convert_endian, expected);
#endif

return ret;
}

Loading

0 comments on commit 154d937

Please sign in to comment.