MCPcopy Create free account
hub / github.com/FISCO-BCOS/FISCO-BCOS / prepare

Method prepare

bcos-executor/src/executor/TransactionExecutor.cpp:1782–1844  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1780}
1781
1782void TransactionExecutor::prepare(
1783 const TwoPCParams& params, std::function<void(bcos::Error::Ptr)> callback)
1784{
1785 EXECUTOR_NAME_LOG(DEBUG) << BLOCK_NUMBER(params.number) << "Prepare request";
1786
1787 if (!m_isRunning)
1788 {
1789 EXECUTOR_NAME_LOG(WARNING) << "TransactionExecutor is not running";
1790 callback(
1791 BCOS_ERROR_UNIQUE_PTR(ExecuteError::STOPPED, "TransactionExecutor is not running"));
1792 return;
1793 }
1794
1795 auto first = m_stateStorages.begin();
1796 if (first == m_stateStorages.end())
1797 {
1798 const auto* errorMessage = "Prepare failed: empty stateStorages";
1799 EXECUTOR_NAME_LOG(WARNING) << errorMessage;
1800 callback(BCOS_ERROR_PTR(-1, errorMessage));
1801
1802 return;
1803 }
1804
1805 if (first->number != params.number)
1806 {
1807 auto errorMessage =
1808 "Prepare failed: Request blockNumber: " +
1809 boost::lexical_cast<std::string>(params.number) +
1810 " not equal to last blockNumber: " + boost::lexical_cast<std::string>(first->number) +
1811 " trigger switch";
1812
1813 EXECUTOR_NAME_LOG(WARNING) << errorMessage;
1814 callback(BCOS_ERROR_PTR(ExecuteError::SCHEDULER_TERM_ID_ERROR, errorMessage));
1815
1816 return;
1817 }
1818
1819 bcos::protocol::TwoPCParams storageParams{params.number, params.primaryKey, params.timestamp};
1820
1821 m_backendStorage->asyncPrepare(storageParams, *(first->storage),
1822 [this, callback = std::move(callback), blockNumber = params.number](
1823 auto&& error, uint64_t, const std::string&) {
1824 if (!m_isRunning)
1825 {
1826 callback(BCOS_ERROR_UNIQUE_PTR(
1827 ExecuteError::STOPPED, "TransactionExecutor is not running"));
1828 return;
1829 }
1830
1831 if (error)
1832 {
1833 auto errorMessage = "Prepare failed: " + error->errorMessage();
1834
1835 EXECUTOR_NAME_LOG(ERROR) << BLOCK_NUMBER(blockNumber) << errorMessage;
1836 callback(
1837 BCOS_ERROR_WITH_PREV_PTR(ExecuteError::PREPARE_ERROR, errorMessage, *error));
1838 return;
1839 }

Callers 5

commitBlockMethod · 0.45
BOOST_AUTO_TEST_CASEFunction · 0.45
BOOST_AUTO_TEST_CASEFunction · 0.45
BOOST_AUTO_TEST_CASEFunction · 0.45
commitBlockMethod · 0.45

Calls 4

errorMessageMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
asyncPrepareMethod · 0.45

Tested by 5

commitBlockMethod · 0.36
BOOST_AUTO_TEST_CASEFunction · 0.36
BOOST_AUTO_TEST_CASEFunction · 0.36
BOOST_AUTO_TEST_CASEFunction · 0.36
commitBlockMethod · 0.36