Skip to content

Commit

Permalink
Merge branch 'master' into neil/add-gasprice-rpc-max
Browse files Browse the repository at this point in the history
  • Loading branch information
qtum-neil authored Sep 6, 2017
2 parents 1816fc0 + 5fca152 commit c7ec471
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 30 deletions.
6 changes: 3 additions & 3 deletions src/policy/policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 0;
/** Default for -blockmaxweight, which controls the range of block weights the mining code will create **/
static const unsigned int DEFAULT_BLOCK_MAX_WEIGHT = 7600000;
/** Default for -blockmintxfee, which sets the minimum feerate for a transaction in blocks created by mining code **/
static const unsigned int DEFAULT_BLOCK_MIN_TX_FEE = 1000;
static const unsigned int DEFAULT_BLOCK_MIN_TX_FEE = 400000;
/** The maximum weight for transactions we're willing to relay/mine */
static const unsigned int MAX_STANDARD_TX_WEIGHT = 400000;
/** Maximum number of signature check operations in an IsStandard() P2SH script */
Expand All @@ -31,7 +31,7 @@ extern unsigned int dgpMaxTxSigOps;
/** Default for -maxmempool, maximum megabytes of mempool memory usage */
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE = 300;
/** Default for -incrementalrelayfee, which sets the minimum feerate increase for mempool limiting or BIP 125 replacement **/
static const unsigned int DEFAULT_INCREMENTAL_RELAY_FEE = 1000;
static const unsigned int DEFAULT_INCREMENTAL_RELAY_FEE = 10000;
/** Default for -bytespersigop */
static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20;
/** The maximum number of witness stack items in a standard P2WSH script */
Expand All @@ -45,7 +45,7 @@ static const unsigned int MAX_STANDARD_P2WSH_SCRIPT_SIZE = 3600;
* standard and should be done with care and ideally rarely. It makes sense to
* only increase the dust limit after prior releases were already not creating
* outputs below the new threshold */
static const unsigned int DUST_RELAY_TX_FEE = 1000;
static const unsigned int DUST_RELAY_TX_FEE = 400000;
/**
* Standard script verification flags that standard transactions will comply
* with. However scripts violating these flags may still be present in valid
Expand Down
2 changes: 1 addition & 1 deletion src/qtum/qtumDGP.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static const uint32_t DEFAULT_BLOCK_SIZE_DGP = 2000000;

static const uint64_t MIN_MIN_GAS_PRICE_DGP = 1;
static const uint64_t MAX_MIN_GAS_PRICE_DGP = 10000;
static const uint64_t DEFAULT_MIN_GAS_PRICE_DGP = 1;
static const uint64_t DEFAULT_MIN_GAS_PRICE_DGP = 40;

static const uint64_t MIN_BLOCK_GAS_LIMIT_DGP = 1000000;
static const uint64_t MAX_BLOCK_GAS_LIMIT_DGP = 1000000000;
Expand Down
12 changes: 6 additions & 6 deletions src/rpc/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ UniValue getaccountinfo(const JSONRPCRequest& request)
LOCK(cs_main);

std::string strAddr = request.params[0].get_str();
if(strAddr.size() != 40 || !std::regex_match(strAddr, hexData))
if(strAddr.size() != 40 || !CheckHex(strAddr))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Incorrect address");

dev::Address addrAccount(strAddr);
Expand Down Expand Up @@ -822,7 +822,7 @@ UniValue getstorage(const JSONRPCRequest& request)
LOCK(cs_main);

std::string strAddr = request.params[0].get_str();
if(strAddr.size() != 40 || !std::regex_match(strAddr, hexData))
if(strAddr.size() != 40 || !CheckHex(strAddr))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Incorrect address");

TemporaryState ts(globalState);
Expand Down Expand Up @@ -1027,10 +1027,10 @@ UniValue callcontract(const JSONRPCRequest& request)
std::string strAddr = request.params[0].get_str();
std::string data = request.params[1].get_str();

if(data.size() % 2 != 0 || !std::regex_match(data, hexData))
if(data.size() % 2 != 0 || !CheckHex(data))
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid data (data not hex)");

if(strAddr.size() != 40 || !std::regex_match(strAddr, hexData))
if(strAddr.size() != 40 || !CheckHex(strAddr))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Incorrect address");

dev::Address addrAccount(strAddr);
Expand Down Expand Up @@ -1116,7 +1116,7 @@ bool getContarctAddressesFromParams(const UniValue& params, std::vector<dev::h16

for (std::vector<UniValue>::iterator it = values.begin(); it != values.end(); ++it) {
auto addrStr(it->get_str());
if (addrStr.length() != 40 || !std::regex_match(addrStr, hexData))
if (addrStr.length() != 40 || !CheckHex(addrStr))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
addresses.push_back(dev::h160(addrStr));
}
Expand All @@ -1142,7 +1142,7 @@ bool getTopicsFromParams(const UniValue& params, std::vector<std::pair<unsigned,
auto topicStr(values[i].get_str());
if (topicStr == "null")
continue;
if (topicStr.length() != 64 || !std::regex_match(topicStr, hexData))
if (topicStr.length() != 64 || !CheckHex(topicStr))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid topic");
topics.push_back({i, dev::h256(topicStr)});
}
Expand Down
2 changes: 1 addition & 1 deletion src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ bool CBlockTreeDB::ReadHeightIndex(const unsigned int &high, const unsigned int
while (pcursor->Valid()) {
boost::this_thread::interruption_point();
std::pair<char, CHeightTxIndexKey> key;
if (pcursor->GetKey(key) && key.first == DB_HEIGHTINDEX && key.second.height < high) {
if (pcursor->GetKey(key) && key.first == DB_HEIGHTINDEX && key.second.height <= high) {
if (!addresses.empty() && !addresses.count(key.second.address))
{
pcursor->Next();
Expand Down
15 changes: 15 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,3 +867,18 @@ std::string CopyrightHolders(const std::string& strPrefix)
}
return strCopyrightHolders;
}

bool CheckHex(const std::string& str) {
if(str.size() > 10000){
std::string tempStr = str;
while(!tempStr.empty()){
std::string part(tempStr.begin(), tempStr.size() >= 10000 ? (tempStr.begin() + 10000) : tempStr.end());
if(part.size() % 2 != 0 || !std::regex_match(part, hexData)){
return false;
}
tempStr.erase(tempStr.begin(), tempStr.begin() + part.size());
}
return true;
}
return std::regex_match(str, hexData);
}
2 changes: 2 additions & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,6 @@ template <typename Callable> void TraceThread(const char* name, Callable func)

std::string CopyrightHolders(const std::string& strPrefix);

bool CheckHex(const std::string& str);

#endif // BITCOIN_UTIL_H
24 changes: 17 additions & 7 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ CAmount maxTxFee = DEFAULT_TRANSACTION_MAXFEE;
CTxMemPool mempool(::minRelayTxFee);

static void CheckBlockIndex(const Consensus::Params& consensusParams);
static bool UpdateHashProof(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, CBlockIndex* pindex);

/** Constant stuff for coinbase transactions we create: */
CScript COINBASE_FLAGS;
Expand Down Expand Up @@ -2421,6 +2422,11 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
uint64_t countCumulativeGasUsed = 0;
/////////////////////////////////////////////////

// State is filled in by UpdateHashProof
if (!UpdateHashProof(block, state, chainparams.GetConsensus(), pindex)) {
return error("%s: ConnectBlock(): %s", __func__, state.GetRejectReason().c_str());
}

// Move this check from CheckBlock to ConnectBlock as it depends on DGP values
if (block.vtx.empty() || block.vtx.size() > dgpMaxBlockSize || ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) > dgpMaxBlockSize) // qtum
return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, "size limits failed");
Expand Down Expand Up @@ -4217,22 +4223,23 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
return true;
}


static bool UpdateHashProof(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, CBlockIndex* pindex)
{
int nHeight = pindex->nHeight;
uint256 hash = block.GetHash();

//reject proof of work at height consensusParams.nLastPOWBlock
if (block.IsProofOfWork() && nHeight > consensusParams.nLastPOWBlock)
return state.DoS(100, error("AcceptBlock() : reject proof-of-work at height %d", nHeight));
return state.DoS(100, error("UpdateHashProof() : reject proof-of-work at height %d", nHeight));

// Check coinstake timestamp
if (block.IsProofOfStake() && !CheckCoinStakeTimestamp(block.GetBlockTime()))
return state.DoS(50, error("AcceptBlock() : coinstake timestamp violation nTimeBlock=%d", block.GetBlockTime()));
return state.DoS(50, error("UpdateHashProof() : coinstake timestamp violation nTimeBlock=%d", block.GetBlockTime()));

// Check proof-of-work or proof-of-stake
if (block.nBits != GetNextWorkRequired(pindex->pprev, &block, consensusParams,block.IsProofOfStake()))
return state.DoS(100, error("AcceptBlock() : incorrect %s", block.IsProofOfWork() ? "proof-of-work" : "proof-of-stake"));
return state.DoS(100, error("UpdateHashProof() : incorrect %s", block.IsProofOfWork() ? "proof-of-work" : "proof-of-stake"));

uint256 hashProof;
// Verify hash target and signature of coinstake tx
Expand All @@ -4241,7 +4248,7 @@ static bool UpdateHashProof(const CBlock& block, CValidationState& state, const
uint256 targetProofOfStake;
if (!CheckProofOfStake(pindex->pprev, state, *block.vtx[1], block.nBits, block.nTime, hashProof, targetProofOfStake))
{
return error("AcceptBlock() : check proof-of-stake failed for block %s", hash.ToString());
return error("UpdateHashProof() : check proof-of-stake failed for block %s", hash.ToString());
}
}

Expand All @@ -4256,6 +4263,7 @@ static bool UpdateHashProof(const CBlock& block, CValidationState& state, const
return true;
}


static bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex)
{
AssertLockHeld(cs_main);
Expand Down Expand Up @@ -4338,9 +4346,11 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation
if (!AcceptBlockHeader(block, state, chainparams, &pindex))
return false;

if (!UpdateHashProof(block, state, chainparams.GetConsensus(), pindex))
{
return error("%s: UpdateHashProof(): %s", __func__, state.GetRejectReason().c_str());
if(block.IsProofOfWork()) {
if (!UpdateHashProof(block, state, chainparams.GetConsensus(), pindex))
{
return error("%s: AcceptBlock(): %s", __func__, state.GetRejectReason().c_str());
}
}

// Get prev block index
Expand Down
12 changes: 6 additions & 6 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ static const bool DEFAULT_WHITELISTRELAY = true;
/** Default for DEFAULT_WHITELISTFORCERELAY. */
static const bool DEFAULT_WHITELISTFORCERELAY = true;
/** Default for -minrelaytxfee, minimum relay fee for transactions */
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 400000;
//! -maxtxfee default
static const CAmount DEFAULT_TRANSACTION_MAXFEE = 0.1 * COIN;
static const CAmount DEFAULT_TRANSACTION_MAXFEE = 1 * COIN;
//! Discourage users to set fees higher than this amount (in satoshis) per kB
static const CAmount HIGH_TX_FEE_PER_KB = 0.01 * COIN;
static const CAmount HIGH_TX_FEE_PER_KB = 1 * COIN;
//! -maxtxfee will warn if called with a higher fee than this amount (in satoshis)
static const CAmount HIGH_MAX_TX_FEE = 100 * HIGH_TX_FEE_PER_KB;
/** Default for -limitancestorcount, max number of in-mempool ancestors */
Expand Down Expand Up @@ -175,9 +175,9 @@ static const int MAX_UNCONNECTING_HEADERS = 10;

static const bool DEFAULT_PEERBLOOMFILTERS = true;

static const uint64_t DEFAULT_GAS_LIMIT_OP_CREATE=1000000;
static const uint64_t DEFAULT_GAS_LIMIT_OP_SEND=200000;
static const CAmount DEFAULT_GAS_PRICE=0.00000001*COIN;
static const uint64_t DEFAULT_GAS_LIMIT_OP_CREATE=2500000;
static const uint64_t DEFAULT_GAS_LIMIT_OP_SEND=250000;
static const CAmount DEFAULT_GAS_PRICE=0.00000040*COIN;
static const CAmount MAX_RPC_GAS_PRICE=0.00000100*COIN;

static const size_t MAX_CONTRACT_VOUTS = 1000; // qtum
Expand Down
10 changes: 5 additions & 5 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,14 @@ UniValue createcontract(const JSONRPCRequest& request){
"]\n"
"\nExamples:\n"
+ HelpExampleCli("createcontract", "\"60606040525b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690836c010000000000000000000000009081020402179055506103786001600050819055505b600c80605b6000396000f360606040526008565b600256\"")
+ HelpExampleCli("createcontract", "\"60606040525b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690836c010000000000000000000000009081020402179055506103786001600050819055505b600c80605b6000396000f360606040526008565b600256\" 6000000 0.00000001 \"QM72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" true")
+ HelpExampleCli("createcontract", "\"60606040525b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff02191690836c010000000000000000000000009081020402179055506103786001600050819055505b600c80605b6000396000f360606040526008565b600256\" 6000000 "+FormatMoney(minGasPrice)+" \"QM72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\" true")
);

LOCK2(cs_main, pwalletMain->cs_wallet);

string bytecode=request.params[0].get_str();

if(bytecode.size() % 2 != 0 || !std::regex_match(bytecode, hexData))
if(bytecode.size() % 2 != 0 || !CheckHex(bytecode))
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid data (data not hex)");

uint64_t nGasLimit=DEFAULT_GAS_LIMIT_OP_CREATE;
Expand Down Expand Up @@ -666,21 +666,21 @@ UniValue sendtocontract(const JSONRPCRequest& request){
"]\n"
"\nExamples:\n"
+ HelpExampleCli("sendtocontract", "\"c6ca2697719d00446d4ea51f6fac8fd1e9310214\" \"54f6127f\"")
+ HelpExampleCli("sendtocontract", "\"c6ca2697719d00446d4ea51f6fac8fd1e9310214\" \"54f6127f\" 12.0015 6000000 0.00000001 \"QM72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\"")
+ HelpExampleCli("sendtocontract", "\"c6ca2697719d00446d4ea51f6fac8fd1e9310214\" \"54f6127f\" 12.0015 6000000 "+FormatMoney(minGasPrice)+" \"QM72Sfpbz1BPpXFHz9m3CdqATR44Jvaydd\"")
);

LOCK2(cs_main, pwalletMain->cs_wallet);

std::string contractaddress = request.params[0].get_str();
if(contractaddress.size() != 40 || !std::regex_match(contractaddress, hexData))
if(contractaddress.size() != 40 || !CheckHex(contractaddress))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Incorrect contract address");

dev::Address addrAccount(contractaddress);
if(!globalState->addressInUse(addrAccount))
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "contract address does not exist");

string datahex = request.params[1].get_str();
if(datahex.size() % 2 != 0 || !std::regex_match(datahex, hexData))
if(datahex.size() % 2 != 0 || !CheckHex(datahex))
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid data (data not hex)");

CAmount nAmount = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static const CAmount DEFAULT_TRANSACTION_FEE = 0;
//! -fallbackfee default
static const CAmount DEFAULT_FALLBACK_FEE = 20000;
//! -mintxfee default
static const CAmount DEFAULT_TRANSACTION_MINFEE = 1000;
static const CAmount DEFAULT_TRANSACTION_MINFEE = 400000;
//! minimum recommended increment for BIP 125 replacement txs
static const CAmount WALLET_INCREMENTAL_RELAY_FEE = 5000;
//! target minimum change amount
Expand Down

0 comments on commit c7ec471

Please sign in to comment.