| 192 | } |
| 193 | |
| 194 | void Executive::initialize(Transaction const& _transaction) |
| 195 | { |
| 196 | m_t = _transaction; |
| 197 | |
| 198 | // Avoid transactions that would take us beyond the block gas limit. |
| 199 | u256 startGasUsed = m_envInfo.gasUsed(); |
| 200 | if (startGasUsed + (bigint)m_t.gas() > m_envInfo.gasLimit()) |
| 201 | { |
| 202 | clog(ExecutiveWarnChannel) << "Cannot fit tx in block" << m_envInfo.number() << ": Require <" << (m_envInfo.gasLimit() - startGasUsed) << " Got" << m_t.gas(); |
| 203 | m_excepted = TransactionException::BlockGasLimitReached; |
| 204 | BOOST_THROW_EXCEPTION(BlockGasLimitReached() << RequirementError((bigint)(m_envInfo.gasLimit() - startGasUsed), (bigint)m_t.gas())); |
| 205 | } |
| 206 | |
| 207 | // Check gas cost is enough. |
| 208 | m_baseGasRequired = m_t.baseGasRequired(m_sealEngine.evmSchedule(m_envInfo)); |
| 209 | if (m_baseGasRequired > m_t.gas()) |
| 210 | { |
| 211 | clog(ExecutiveWarnChannel) << "Not enough gas to pay for the transaction: Require >" << m_baseGasRequired << " Got" << m_t.gas(); |
| 212 | m_excepted = TransactionException::OutOfGasBase; |
| 213 | BOOST_THROW_EXCEPTION(OutOfGasBase() << RequirementError((bigint)m_baseGasRequired, (bigint)m_t.gas())); |
| 214 | } |
| 215 | |
| 216 | // Avoid invalid transactions. |
| 217 | u256 nonceReq; |
| 218 | try |
| 219 | { |
| 220 | nonceReq = m_s.getNonce(m_t.sender()); |
| 221 | } |
| 222 | catch (...) |
| 223 | { |
| 224 | clog(ExecutiveWarnChannel) << "Invalid Signature"; |
| 225 | m_excepted = TransactionException::InvalidSignature; |
| 226 | throw; |
| 227 | } |
| 228 | if (m_t.nonce() != nonceReq) |
| 229 | { |
| 230 | clog(ExecutiveWarnChannel) << "Invalid Nonce: Require" << nonceReq << " Got" << m_t.nonce(); |
| 231 | m_excepted = TransactionException::InvalidNonce; |
| 232 | BOOST_THROW_EXCEPTION(InvalidNonce() << RequirementError((bigint)nonceReq, (bigint)m_t.nonce())); |
| 233 | } |
| 234 | |
| 235 | // Avoid unaffordable transactions. |
| 236 | bigint gasCost = (bigint)m_t.gas() * m_t.gasPrice(); |
| 237 | bigint totalCost = m_t.value() + gasCost; |
| 238 | if (m_s.balance(m_t.sender()) < totalCost) |
| 239 | { |
| 240 | clog(ExecutiveWarnChannel) << "Not enough cash: Require >" << totalCost << "=" << m_t.gas() << "*" << m_t.gasPrice() << "+" << m_t.value() << " Got" << m_s.balance(m_t.sender()) << "for sender: " << m_t.sender(); |
| 241 | m_excepted = TransactionException::NotEnoughCash; |
| 242 | BOOST_THROW_EXCEPTION(NotEnoughCash() << RequirementError(totalCost, (bigint)m_s.balance(m_t.sender())) << errinfo_comment(m_t.sender().abridged())); |
| 243 | } |
| 244 | m_gasCost = (u256)gasCost; // Convert back to 256-bit, safe now. |
| 245 | } |
| 246 | |
| 247 | bool Executive::execute() |
| 248 | { |
no test coverage detected