Skip to content

Commit

Permalink
post launch release readiness
Browse files Browse the repository at this point in the history
  • Loading branch information
miketout committed May 28, 2018
1 parent bcb23c0 commit c6e2184
Show file tree
Hide file tree
Showing 9 changed files with 1,492 additions and 31 deletions.
8 changes: 7 additions & 1 deletion src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CMainParams : public CChainParams {
{
strNetworkID = "main";
strCurrencyUnits = "KMD";
consensus.fCoinbaseMustBeProtected = true; // this is only enforced after block 12800 on Verus
consensus.fCoinbaseMustBeProtected = false; // true this is only true wuth Verus and enforced after block 12800
consensus.nSubsidySlowStartInterval = 20000;
consensus.nSubsidyHalvingInterval = 840000;
consensus.nMajorityEnforceBlockUpgrade = 750;
Expand Down Expand Up @@ -232,6 +232,12 @@ void *chainparams_commandline(void *ptr)
mainParams.pchMessageStart[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff;
fprintf(stderr,">>>>>>>>>> %s: p2p.%u rpc.%u magic.%08x %u %u coins\n",ASSETCHAINS_SYMBOL,ASSETCHAINS_P2PPORT,ASSETCHAINS_RPCPORT,ASSETCHAINS_MAGIC,ASSETCHAINS_MAGIC,(uint32_t)ASSETCHAINS_SUPPLY);

// only require coinbase protection on Verus from the Komodo family of coins
if (strcmp(ASSETCHAINS_SYMBOL,"VRSC") == 0)
{
mainParams.consensus.fCoinbaseMustBeProtected = true;
}

if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH)
{
// this is only good for 60 second blocks with an averaging window of 45. for other parameters, use:
Expand Down
6 changes: 5 additions & 1 deletion src/coins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,11 @@ const CScript &CCoinsViewCache::GetSpendFor(const CCoins *coins, const CTxIn& in
std::string hc = input.prevout.hash.ToString();
if (LaunchMap().lmap.count(hc))
{
return LaunchMap().lmap[hc];
CTransactionExceptionData &txData = LaunchMap().lmap[hc];
if ((txData.voutMask & (((uint64_t)1) << (uint64_t)input.prevout.n)) != 0)
{
return txData.scriptPubKey;
}
}
}
return coins->vout[input.prevout.n].scriptPubKey;
Expand Down
26 changes: 17 additions & 9 deletions src/coins.h
Original file line number Diff line number Diff line change
Expand Up @@ -441,23 +441,31 @@ class CCoinsModifier
friend class CCoinsViewCache;
};

class CTransactionExceptionData
{
public:
CScript scriptPubKey;
uint64_t voutMask;
CTransactionExceptionData() : scriptPubKey(), voutMask() {}
};

class CLaunchMap
{
public:
std::unordered_map<std::string, CScript> lmap;
std::unordered_map<std::string, CTransactionExceptionData> lmap;
CLaunchMap() : lmap()
{
for (int i = 0; i < WHITELIST_COUNT; i++)
//printf("txid: %s -> addr: %s\n", whitelist_ids[i], whitelist_addrs[i]);
CBitcoinAddress bcaddr(whitelist_address);
CKeyID key;
if (bcaddr.GetKeyID_NoCheck(key))
{
printf("txid: %s -> addr: %s", whitelist_ids[i], whitelist_addrs[i]);
CBitcoinAddress address(whitelist_addrs[i]);
CKeyID key;
if (address.GetKeyID_NoCheck(key))
std::vector<unsigned char> address = std::vector<unsigned char>(key.begin(), key.end());
for (int i = 0; i < WHITELIST_COUNT; i++)
{
std::vector<unsigned char> adr = std::vector<unsigned char>(key.begin(), key.end());
std::string hash = uint256S(whitelist_ids[i]).ToString();
lmap[hash] = CScript();
lmap[hash] << OP_DUP << OP_HASH160 << adr << OP_EQUALVERIFY << OP_CHECKSIG;
lmap[hash].scriptPubKey << OP_DUP << OP_HASH160 << address << OP_EQUALVERIFY << OP_CHECKSIG;
lmap[hash].voutMask = whitelist_masks[i];
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/crypto/verus_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ CVerusHash &CVerusHash::Write(const unsigned char *data, size_t len)
return *this;
}

// to be declared and accessed from C
void verus_hash(void *result, const void *data, size_t len)
{
return CVerusHash::Hash(result, data, len);
}
2 changes: 2 additions & 0 deletions src/crypto/verus_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ class CVerusHash
size_t curPos = 0;
};

extern void verus_hash(void *result, const void *data, size_t len);

#endif
53 changes: 38 additions & 15 deletions src/komodo_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#define portable_mutex_lock pthread_mutex_lock
#define portable_mutex_unlock pthread_mutex_unlock

extern void verus_hash(void *result, const void *data, size_t len);

struct allocitem { uint32_t allocsize,type; };
struct queueitem { struct queueitem *next,*prev; uint32_t allocsize,type; };

Expand Down Expand Up @@ -1022,23 +1024,45 @@ int32_t komodo_opreturnscript(uint8_t *script,uint8_t type,uint8_t *opret,int32_
// from all other blocks. the sequence is extremely likely, but not guaranteed to be unique for each block chain
uint64_t komodo_block_prg(uint32_t nHeight)
{
int i;
uint8_t hashSrc[8];
uint64_t result, hashSrc64 = (uint64_t)ASSETCHAINS_MAGIC << 32 + nHeight;
bits256 hashResult;

for ( i = 0; i < sizeof(hashSrc); i++ )
if (strcmp(ASSETCHAINS_SYMBOL, "VRSC") != 0 || nHeight >= 12800)
{
hashSrc[i] = hashSrc64 & 0xff;
hashSrc64 >>= 8;
}
vcalc_sha256(0, hashResult.bytes, hashSrc, sizeof(hashSrc));
uint64_t i, result = 0, hashSrc64 = ((uint64_t)ASSETCHAINS_MAGIC << 32) | (uint64_t)nHeight;
uint8_t hashSrc[8];
bits256 hashResult;

for ( i = 0; i < 8; i++ )
for ( i = 0; i < sizeof(hashSrc); i++ )
{
uint64_t x = hashSrc64 >> (i * 8);
hashSrc[i] = (uint8_t)(x & 0xff);
}
verus_hash(hashResult.bytes, hashSrc, sizeof(hashSrc));
for ( i = 0; i < 8; i++ )
{
result = (result << 8) | hashResult.bytes[i];
}
return result;
}
else
{
result = (result << 8) + hashResult.bytes[i];
int i;
uint8_t hashSrc[8];
uint64_t result, hashSrc64 = (uint64_t)ASSETCHAINS_MAGIC << 32 + nHeight;
bits256 hashResult;

for ( i = 0; i < sizeof(hashSrc); i++ )
{
hashSrc[i] = hashSrc64 & 0xff;
hashSrc64 >>= 8;
int8_t b = hashSrc[i];
}

vcalc_sha256(0, hashResult.bytes, hashSrc, sizeof(hashSrc));
for ( i = 0; i < 8; i++ )
{
result = (result << 8) + hashResult.bytes[i];
}
return result;
}
return(result);
}

// given a block height, this returns the unlock time for that block height, derived from
Expand All @@ -1055,8 +1079,7 @@ int64_t komodo_block_unlocktime(uint32_t nHeight)
if (strcmp(ASSETCHAINS_SYMBOL, "VRSC") != 0 || nHeight >= 12800)
{
unlocktime = komodo_block_prg(nHeight) % (ASSETCHAINS_TIMEUNLOCKTO - ASSETCHAINS_TIMEUNLOCKFROM);
// boundary and power of 2 can make it exceed to time by 1
unlocktime = unlocktime + ASSETCHAINS_TIMEUNLOCKFROM;
unlocktime += ASSETCHAINS_TIMEUNLOCKFROM;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/rpcrawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,7 @@ UniValue signrawtransaction(const UniValue& params, bool fHelp)
TxInErrorToJSON(txin, vErrors, "Input not found or already spent");
continue;
}
const CScript& prevPubKey = coins->vout[txin.prevout.n].scriptPubKey;
const CScript& prevPubKey = CCoinsViewCache::GetSpendFor(coins, txin);
const CAmount& amount = coins->vout[txin.prevout.n].nValue;

SignatureData sigdata;
Expand Down
Loading

0 comments on commit c6e2184

Please sign in to comment.