Adding coinbase transaction checkpoints... slight cleanup

This commit is contained in:
Michael Toutonghi
2018-04-15 00:10:21 -07:00
parent dba84931d4
commit d121e75b0b
4 changed files with 24 additions and 7 deletions

View File

@@ -57,8 +57,11 @@ uint32_t ASSETCHAINS_MAGIC = 2387029918;
uint64_t ASSETCHAINS_SUPPLY = 10;
uint64_t ASSETCHAINS_COMMISSION;
#define _ASSETCHAINS_TIMELOCKABOVE 0xffffffffffffffff
uint64_t ASSETCHAINS_TIMELOCKABOVE = _ASSETCHAINS_TIMELOCKABOVE;
#define _ASSETCHAINS_TIMELOCKOFF 0xffffffffffffffffLL
uint64_t ASSETCHAINS_TIMELOCKABOVE = _ASSETCHAINS_TIMELOCKOFF;
uint64_t ASSETCHAINS_TIMELOCKFROM = 0;
uint64_t ASSETCHAINS_TIMELOCKTO = 0;
uint32_t ASSETCHAINS_ERAS = 1;
uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_HALVING[ASSETCHAINS_MAX_ERAS],ASSETCHAINS_DECAY[ASSETCHAINS_MAX_ERAS];

View File

@@ -1106,7 +1106,7 @@ uint64_t blockPRG(uint32_t nHeight)
// to setup the chain and the specified block height. this can be used to create, validate, or spend a time locked coin base transaction
int64_t komodo_block_timelockscript(uint8_t *script, uint8_t p2sh160[20], uint8_t taddrrmd160[20], uint32_t nHeight, uint64_t fromTime, uint64_t toTime)
{
uint32_t locktime, n = 0;
uint32_t locktime, i, n = 0;
if ( toTime < fromTime )
return(0);
@@ -1114,7 +1114,9 @@ int64_t komodo_block_timelockscript(uint8_t *script, uint8_t p2sh160[20], uint8_
locktime = toTime;
else
{
locktime = fromTime + blockPRG(nHeight) / (0xffffffffffffffff / ((toTime - fromTime) + 1));
locktime = blockPRG(nHeight) / (0xffffffffffffffff / ((toTime - fromTime) + 1));
// boundary and power of 2 can make it exceed toTime by 1
locktime = i = (locktime + fromTime) <= toTime ? i : i - 1;
}
n = komodo_timelockspend(script, n, taddrrmd160, locktime);
calc_rmd160_sha256(p2sh160, script, n);
@@ -1756,7 +1758,9 @@ void komodo_args(char *argv0)
}
ASSETCHAINS_ERAS -= 1;
ASSETCHAINS_TIMELOCKABOVE = GetArg("-ac_lockabove", ASSETCHAINS_TIMELOCKABOVE);
ASSETCHAINS_TIMELOCKABOVE = GetArg("-ac_timelockabove", _ASSETCHAINS_TIMELOCKOFF);
ASSETCHAINS_TIMELOCKFROM = GetArg("-ac_timelockfrom", 0);
ASSETCHAINS_TIMELOCKTO = GetArg("-ac_timelockto", 0);
Split(GetArg("-ac_end",""), ASSETCHAINS_ENDSUBSIDY, 0);
Split(GetArg("-ac_reward",""), ASSETCHAINS_REWARD, 0);
@@ -1819,9 +1823,11 @@ void komodo_args(char *argv0)
// hash in lock above for time locked coinbase transactions above a certain reward value only if the lock above
// param was specified, otherwise, for compatibility, do nothing
if ( ASSETCHAINS_TIMELOCKABOVE != _ASSETCHAINS_TIMELOCKABOVE )
if ( ASSETCHAINS_TIMELOCKABOVE != _ASSETCHAINS_TIMELOCKOFF )
{
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_TIMELOCKABOVE),(void *)&ASSETCHAINS_TIMELOCKABOVE);
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_TIMELOCKFROM),(void *)&ASSETCHAINS_TIMELOCKFROM);
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_TIMELOCKTO),(void *)&ASSETCHAINS_TIMELOCKTO);
}
extralen += iguana_rwnum(1,&extraptr[extralen],sizeof(ASSETCHAINS_COMMISSION),(void *)&ASSETCHAINS_COMMISSION);

View File

@@ -963,6 +963,12 @@ bool ContextualCheckTransaction(const CTransaction& tx, CValidationState &state,
REJECT_INVALID, "bad-txns-invalid-joinsplit-signature");
}
}
if (tx.IsCoinBase() && tx.vout[0].value >= ASSETCHAINS_TIMELOCKABOVE)
{
// if time locks are on, ensure that this coin base is time locked exactly as it should be
}
return true;
}
@@ -3496,9 +3502,10 @@ bool CheckBlock(int32_t height,CBlockIndex *pindex,const CBlock& block, CValidat
REJECT_INVALID, "bad-blk-length");
// First transaction must be coinbase, the rest must not be
if (block.vtx.empty() || !block.vtx[0].IsCoinBase())
if (!block.vtx[0].IsCoinBase())
return state.DoS(100, error("CheckBlock(): first tx is not coinbase"),
REJECT_INVALID, "bad-cb-missing");
for (unsigned int i = 1; i < block.vtx.size(); i++)
if (block.vtx[i].IsCoinBase())
return state.DoS(100, error("CheckBlock(): more than one coinbase"),

View File

@@ -269,6 +269,7 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
COINBASE_MATURITY = _COINBASE_MATURITY;
quint32 numBlocksToMaturity = COINBASE_MATURITY + 1;
strHTML += "<br>" + tr("Generated coins must mature %1 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, its state will change to \"not accepted\" and it won't be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.").arg(QString::number(numBlocksToMaturity)) + "<br>";
// we need to display any possible CLTV lock time
}
//