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

Method commit

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

Source from the content-addressed store, hash-verified

1844}
1845
1846void TransactionExecutor::commit(
1847 const TwoPCParams& params, std::function<void(bcos::Error::Ptr)> callback)
1848{
1849 EXECUTOR_NAME_LOG(TRACE) << BLOCK_NUMBER(params.number) << "Commit request";
1850
1851 if (!m_isRunning)
1852 {
1853 EXECUTOR_NAME_LOG(WARNING) << "TransactionExecutor is not running";
1854 callback(
1855 BCOS_ERROR_UNIQUE_PTR(ExecuteError::STOPPED, "TransactionExecutor is not running"));
1856 return;
1857 }
1858
1859 auto first = m_stateStorages.begin();
1860 if (first == m_stateStorages.end())
1861 {
1862 auto errorMessage = "Commit failed: empty stateStorages";
1863 EXECUTOR_NAME_LOG(ERROR) << errorMessage;
1864 callback(BCOS_ERROR_PTR(INVALID_BLOCKNUMBER, errorMessage));
1865
1866 return;
1867 }
1868
1869 if (first->number != params.number)
1870 {
1871 auto errorMessage =
1872 "Commit failed: Request blockNumber: " +
1873 boost::lexical_cast<std::string>(params.number) +
1874 " not equal to last blockNumber: " + boost::lexical_cast<std::string>(first->number);
1875
1876 EXECUTOR_NAME_LOG(ERROR) << errorMessage;
1877 callback(BCOS_ERROR_PTR(INVALID_BLOCKNUMBER, errorMessage));
1878
1879 return;
1880 }
1881
1882 bcos::protocol::TwoPCParams storageParams{params.number, params.primaryKey, params.timestamp};
1883 m_backendStorage->asyncCommit(storageParams, [this, callback = std::move(callback),
1884 blockNumber = params.number](
1885 Error::Ptr&& error, uint64_t) {
1886 if (!m_isRunning)
1887 {
1888 callback(
1889 BCOS_ERROR_UNIQUE_PTR(ExecuteError::STOPPED, "TransactionExecutor is not running"));
1890 return;
1891 }
1892
1893 if (error)
1894 {
1895 auto errorMessage = "Commit failed: " + error->errorMessage();
1896
1897 EXECUTOR_NAME_LOG(ERROR) << BLOCK_NUMBER(blockNumber) << errorMessage;
1898 callback(BCOS_ERROR_WITH_PREV_PTR(ExecuteError::COMMIT_ERROR, errorMessage, *error));
1899 return;
1900 }
1901
1902 EXECUTOR_NAME_LOG(DEBUG) << BLOCK_NUMBER(blockNumber) << "Commit success";
1903

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 8

errorMessageMethod · 0.80
authCheckStatusMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
asyncCommitMethod · 0.45
updateLedgerConfigMethod · 0.45
compatibilityVersionMethod · 0.45
ledgerConfigMethod · 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