Skip to content

Commit

Permalink
Changed the contract staking adding code so it takes the full tx gas …
Browse files Browse the repository at this point in the history
…limit into account, added missing state reversion
  • Loading branch information
davidjaenson committed Sep 5, 2017
1 parent 8622df8 commit f6aa2e9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
18 changes: 14 additions & 4 deletions qa/rpc-tests/qtum-soft-block-gas-limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,12 @@ def verify_hard_block_gas_limit_test(self):
assert_equal(self.nodes[0].listcontracts()[contract_address], 8)



def send_raw_to_contract(self, node, contract_address, gas_limit, gas_price):
def send_raw_to_contract(self, node, contract_address, gas_limit, gas_price, num_outputs=1):
unspent = node.listunspent()[0]
tx = CTransaction()
tx.vin = [CTxIn(COutPoint(int(unspent['txid'], 16), unspent['vout']), nSequence=0)]
amount = int((float(str(unspent['amount'])) - 1000)*COIN)
tx.vout = [CTxOut(amount, scriptPubKey=CScript([b"\x04", CScriptNum(gas_limit), CScriptNum(gas_price), b"\x00", hex_str_to_bytes(contract_address), OP_CALL]))]
amount = int((float(str(unspent['amount'])) - 1000)*COIN // num_outputs)
tx.vout = [CTxOut(amount, scriptPubKey=CScript([b"\x04", CScriptNum(gas_limit), CScriptNum(gas_price), b"\x00", hex_str_to_bytes(contract_address), OP_CALL])) for i in range(num_outputs)]
tx_hex_signed = node.signrawtransaction(bytes_to_hex_str(tx.serialize()))['hex']
return node.sendrawtransaction(tx_hex_signed)

Expand Down Expand Up @@ -163,6 +162,17 @@ def run_test(self):
assert_equal(len(self.nodes[6].getrawmempool()), 0)
self.sync_all()

# Also make sure that the update counting the sum gas of all outputs works correctly for the soft tx gas limit
self.send_raw_to_contract(self.nodes[4], contract_address, 34000, 1, num_outputs=3)
self.nodes[4].generate(1)
assert_equal(len(self.nodes[4].getrawmempool()), 1)
self.sync_all()
assert_equal(len(self.nodes[3].getrawmempool()), 1)
self.nodes[3].generate(1)
self.sync_all()
assert_equal(len(self.nodes[3].getrawmempool()), 0)
assert_equal(len(self.nodes[4].getrawmempool()), 0)

self.verify_hard_block_gas_limit_test()

if __name__ == '__main__':
Expand Down
6 changes: 5 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,10 @@ bool BlockAssembler::AttemptToAddContractToBlock(CTxMemPool::txiter iter, uint64
return false;
}
std::vector<QtumTransaction> qtumTransactions = resultConverter.first;
dev::u256 txGas = 0;
for(QtumTransaction qtumTransaction : qtumTransactions){
if(qtumTransaction.gas() > txGasLimit) {
txGas += qtumTransaction.gas();
if(txGas > txGasLimit) {
// Limit the tx gas limit by the soft limit if such a limit has been specified.
return false;
}
Expand All @@ -580,6 +582,8 @@ bool BlockAssembler::AttemptToAddContractToBlock(CTxMemPool::txiter iter, uint64

ByteCodeExecResult testExecResult;
if(!exec.processingResults(testExecResult)){
globalState->setRoot(oldHashStateRoot);
globalState->setRootUTXO(oldHashUTXORoot);
return false;
}

Expand Down

0 comments on commit f6aa2e9

Please sign in to comment.