Skip to content

Commit

Permalink
Fix start.sh, add hashImpl param for precompileds (FISCO-BCOS#3905)
Browse files Browse the repository at this point in the history
  • Loading branch information
morebtcg authored Sep 11, 2023
1 parent 662e4ce commit d93e35b
Show file tree
Hide file tree
Showing 24 changed files with 172 additions and 134 deletions.
31 changes: 16 additions & 15 deletions bcos-executor/src/executor/TransactionExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void TransactionExecutor::initEvmEnvironment()
make_shared<PrecompiledContract>(PrecompiledRegistrar::pricer("blake2_compression"),
PrecompiledRegistrar::executor("blake2_compression"))});

auto sysConfig = std::make_shared<precompiled::SystemConfigPrecompiled>();
auto sysConfig = std::make_shared<precompiled::SystemConfigPrecompiled>(m_hashImpl);
auto consensusPrecompiled = std::make_shared<precompiled::ConsensusPrecompiled>(m_hashImpl);
auto tableManagerPrecompiled =
std::make_shared<precompiled::TableManagerPrecompiled>(m_hashImpl);
Expand Down Expand Up @@ -288,10 +288,10 @@ void TransactionExecutor::initEvmEnvironment()
});
m_precompiled->insert(CAST_ADDRESS,
std::make_shared<CastPrecompiled>(GlobalHashImpl::g_hashImpl), BlockVersion::V3_2_VERSION);
m_precompiled->insert(ACCOUNT_MGR_ADDRESS, std::make_shared<AccountManagerPrecompiled>(),
m_precompiled->insert(ACCOUNT_MGR_ADDRESS,
std::make_shared<AccountManagerPrecompiled>(m_hashImpl), BlockVersion::V3_1_VERSION);
m_precompiled->insert(ACCOUNT_ADDRESS, std::make_shared<AccountPrecompiled>(m_hashImpl),
BlockVersion::V3_1_VERSION);
m_precompiled->insert(
ACCOUNT_ADDRESS, std::make_shared<AccountPrecompiled>(), BlockVersion::V3_1_VERSION);

set<string> builtIn = {CRYPTO_ADDRESS, GROUP_SIG_ADDRESS, RING_SIG_ADDRESS, CAST_ADDRESS};
m_staticPrecompiled = std::make_shared<set<string>>(builtIn);
Expand All @@ -302,16 +302,16 @@ void TransactionExecutor::initEvmEnvironment()
}
else
{
CpuHeavyPrecompiled::registerPrecompiled(m_precompiled);
SmallBankPrecompiled::registerPrecompiled(m_precompiled);
CpuHeavyPrecompiled::registerPrecompiled(m_precompiled, m_hashImpl);
SmallBankPrecompiled::registerPrecompiled(m_precompiled, m_hashImpl);
}
}

void TransactionExecutor::initWasmEnvironment()
{
m_precompiled = std::make_shared<PrecompiledMap>();

auto sysConfig = std::make_shared<precompiled::SystemConfigPrecompiled>();
auto sysConfig = std::make_shared<precompiled::SystemConfigPrecompiled>(m_hashImpl);
auto consensusPrecompiled = std::make_shared<precompiled::ConsensusPrecompiled>(m_hashImpl);
auto tableManagerPrecompiled =
std::make_shared<precompiled::TableManagerPrecompiled>(m_hashImpl);
Expand Down Expand Up @@ -344,10 +344,10 @@ void TransactionExecutor::initWasmEnvironment()

m_precompiled->insert(CAST_NAME, std::make_shared<CastPrecompiled>(GlobalHashImpl::g_hashImpl),
BlockVersion::V3_2_VERSION);
m_precompiled->insert(ACCOUNT_MANAGER_NAME, std::make_shared<AccountManagerPrecompiled>(),
m_precompiled->insert(ACCOUNT_MANAGER_NAME,
std::make_shared<AccountManagerPrecompiled>(m_hashImpl), BlockVersion::V3_1_VERSION);
m_precompiled->insert(ACCOUNT_ADDRESS, std::make_shared<AccountPrecompiled>(m_hashImpl),
BlockVersion::V3_1_VERSION);
m_precompiled->insert(
ACCOUNT_ADDRESS, std::make_shared<AccountPrecompiled>(), BlockVersion::V3_1_VERSION);

set<string> builtIn = {CRYPTO_ADDRESS, GROUP_SIG_ADDRESS, RING_SIG_ADDRESS, CAST_ADDRESS};
m_staticPrecompiled = std::make_shared<set<string>>(builtIn);
Expand All @@ -359,8 +359,8 @@ void TransactionExecutor::initWasmEnvironment()
}
else
{
CpuHeavyPrecompiled::registerPrecompiled(m_precompiled);
SmallBankPrecompiled::registerPrecompiled(m_precompiled);
CpuHeavyPrecompiled::registerPrecompiled(m_precompiled, m_hashImpl);
SmallBankPrecompiled::registerPrecompiled(m_precompiled, m_hashImpl);
}
}

Expand Down Expand Up @@ -502,8 +502,8 @@ void TransactionExecutor::nextBlockHeader(int64_t schedulerTermId,
{
// Only 3.1 goes here,for compat with the bug:
// 3.1 only init these two precompiled in genesis block
CpuHeavyPrecompiled::registerPrecompiled(m_precompiled);
SmallBankPrecompiled::registerPrecompiled(m_precompiled);
CpuHeavyPrecompiled::registerPrecompiled(m_precompiled, m_hashImpl);
SmallBankPrecompiled::registerPrecompiled(m_precompiled, m_hashImpl);
}

initTestPrecompiledTable(stateStorage);
Expand Down Expand Up @@ -2208,7 +2208,8 @@ void TransactionExecutor::asyncExecuteExecutiveFlow(ExecutiveFlowInterface::Ptr
callback)
{
ExecuteOutputs::Ptr allOutputs = std::make_shared<ExecuteOutputs>();
EXECUTOR_NAME_LOG(DEBUG) << "asyncExecuteExecutiveFlow start" << LOG_KV("blockNumber", m_blockContext->number());
EXECUTOR_NAME_LOG(DEBUG) << "asyncExecuteExecutiveFlow start"
<< LOG_KV("blockNumber", m_blockContext->number());
executiveFlow->asyncRun(
// onTxReturn
[this, allOutputs, callback](CallParameters::UniquePtr output) {
Expand Down
2 changes: 1 addition & 1 deletion bcos-executor/src/precompiled/BFSPrecompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ BFSPrecompiled::BFSPrecompiled(crypto::Hash::Ptr _hashImpl) : Precompiled(_hashI
name2Selector[FILE_SYSTEM_METHOD_INIT] = getFuncSelector(FILE_SYSTEM_METHOD_INIT, _hashImpl);
name2Selector[FILE_SYSTEM_METHOD_REBUILD] =
getFuncSelector(FILE_SYSTEM_METHOD_REBUILD, _hashImpl);
name2Selector[FILE_SYSTEM_METHOD_FIX] = getFuncSelector(FILE_SYSTEM_METHOD_FIX);
name2Selector[FILE_SYSTEM_METHOD_FIX] = getFuncSelector(FILE_SYSTEM_METHOD_FIX, _hashImpl);
BfsTypeSet = {FS_TYPE_DIR, FS_TYPE_CONTRACT, FS_TYPE_LINK};
}

Expand Down
17 changes: 7 additions & 10 deletions bcos-executor/src/precompiled/SystemConfigPrecompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ using namespace bcos::protocol;
const char* const SYSCONFIG_METHOD_SET_STR = "setValueByKey(string,string)";
const char* const SYSCONFIG_METHOD_GET_STR = "getValueByKey(string)";

SystemConfigPrecompiled::SystemConfigPrecompiled() : Precompiled(GlobalHashImpl::g_hashImpl)
SystemConfigPrecompiled::SystemConfigPrecompiled(crypto::Hash::Ptr hashImpl) : Precompiled(hashImpl)
{
name2Selector[SYSCONFIG_METHOD_SET_STR] =
getFuncSelector(SYSCONFIG_METHOD_SET_STR, GlobalHashImpl::g_hashImpl);
name2Selector[SYSCONFIG_METHOD_GET_STR] =
getFuncSelector(SYSCONFIG_METHOD_GET_STR, GlobalHashImpl::g_hashImpl);
name2Selector[SYSCONFIG_METHOD_SET_STR] = getFuncSelector(SYSCONFIG_METHOD_SET_STR, hashImpl);
name2Selector[SYSCONFIG_METHOD_GET_STR] = getFuncSelector(SYSCONFIG_METHOD_GET_STR, hashImpl);
auto defaultCmp = [](std::string_view _key, int64_t _value, int64_t _minValue, uint32_t version,
BlockVersion minVersion = BlockVersion::V3_0_VERSION) {
if (versionCompareTo(version, minVersion) < 0) [[unlikely]]
Expand Down Expand Up @@ -341,21 +339,20 @@ void SystemConfigPrecompiled::upgradeChain(
}

// Write default features when data version changes
if (toVersion >= static_cast<uint32_t>(BlockVersion::V3_2_VERSION))
if (toVersion >= static_cast<uint32_t>(BlockVersion::V3_2_3_VERSION))
{
Features bugfixFeatures;
bugfixFeatures.setToDefault(protocol::BlockVersion(toVersion));
task::syncWait(bugfixFeatures.writeToStorage(
*_executive->blockContext().storage(), _executive->blockContext().number()));
task::syncWait(bugfixFeatures.writeToStorage(*_executive->blockContext().storage(), 0));

// From 3.3 / 3.4 or to 3.3 / 3.4, enable the feature_sharding
if ((version >= BlockVersion::V3_3_VERSION && version <= BlockVersion::V3_4_VERSION) ||
(toVersion >= BlockVersion::V3_3_VERSION && toVersion <= BlockVersion::V3_4_VERSION))
{
Features shardingFeatures;
shardingFeatures.set(ledger::Features::Flag::feature_sharding);
task::syncWait(shardingFeatures.writeToStorage(
*_executive->blockContext().backendStorage(), _executive->blockContext().number()));
task::syncWait(
shardingFeatures.writeToStorage(*_executive->blockContext().backendStorage(), 0));
}
}
}
2 changes: 1 addition & 1 deletion bcos-executor/src/precompiled/SystemConfigPrecompiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SystemConfigPrecompiled : public bcos::precompiled::Precompiled
public:
using Ptr = std::shared_ptr<SystemConfigPrecompiled>;

SystemConfigPrecompiled();
SystemConfigPrecompiled(crypto::Hash::Ptr hashImpl);
SystemConfigPrecompiled(const SystemConfigPrecompiled&) = default;
SystemConfigPrecompiled& operator=(const SystemConfigPrecompiled&) = delete;
SystemConfigPrecompiled(SystemConfigPrecompiled&&) = default;
Expand Down
21 changes: 10 additions & 11 deletions bcos-executor/src/precompiled/TableManagerPrecompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,33 @@ constexpr const char* const TABLE_METHOD_CREATE_V320 =
TableManagerPrecompiled::TableManagerPrecompiled(crypto::Hash::Ptr _hashImpl)
: Precompiled(_hashImpl)
{
registerFunc(getFuncSelector(TABLE_METHOD_CREATE),
registerFunc(getFuncSelector(TABLE_METHOD_CREATE, _hashImpl),
[this](auto&& executive, auto&& pricer, auto&& params) {
createTable(executive, pricer, params);
});
registerFunc(getFuncSelector(TABLE_METHOD_APPEND),
registerFunc(getFuncSelector(TABLE_METHOD_APPEND, _hashImpl),
[this](auto&& executive, auto&& pricer, auto&& params) {
appendColumns(executive, pricer, params);
});
registerFunc(getFuncSelector(TABLE_METHOD_CREATE_KV),
registerFunc(getFuncSelector(TABLE_METHOD_CREATE_KV, _hashImpl),
[this](auto&& executive, auto&& pricer, auto&& params) {
createKVTable(executive, pricer, params);
});
registerFunc(
getFuncSelector(TABLE_METHOD_OPEN), [this](auto&& executive, auto&& pricer, auto&& params) {
registerFunc(getFuncSelector(TABLE_METHOD_OPEN, _hashImpl),
[this](auto&& executive, auto&& pricer, auto&& params) {
openTable(executive, pricer, params);
});
registerFunc(getFuncSelector(TABLE_METHOD_DESC, _hashImpl),
[this](
auto&& executive, auto&& pricer, auto&& params) { desc(executive, pricer, params); });
registerFunc(
getFuncSelector(TABLE_METHOD_DESC), [this](auto&& executive, auto&& pricer, auto&& params) {
desc(executive, pricer, params);
});
registerFunc(
getFuncSelector(TABLE_METHOD_DESC_V32),
getFuncSelector(TABLE_METHOD_DESC_V32, _hashImpl),
[this](auto&& executive, auto&& pricer, auto&& params) {
descWithKeyOrder(executive, pricer, params);
},
protocol::BlockVersion::V3_2_VERSION);
registerFunc(
getFuncSelector(TABLE_METHOD_CREATE_V320),
getFuncSelector(TABLE_METHOD_CREATE_V320, _hashImpl),
[this](auto&& executive, auto&& pricer, auto&& params) {
createTableV32(executive, pricer, params);
},
Expand Down
24 changes: 12 additions & 12 deletions bcos-executor/src/precompiled/TablePrecompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,58 +180,58 @@ static void processEntryByValueCond(

TablePrecompiled::TablePrecompiled(crypto::Hash::Ptr _hashImpl) : Precompiled(_hashImpl)
{
registerFunc(getFuncSelector(TABLE_METHOD_SELECT_KEY),
registerFunc(getFuncSelector(TABLE_METHOD_SELECT_KEY, _hashImpl),
[this](auto&& table, auto&& executive, auto&& data, auto&& pricer, auto&& params) {
selectByKey(table, executive, data, pricer, params);
});
registerFunc(getFuncSelector(TABLE_METHOD_SELECT_CON),
registerFunc(getFuncSelector(TABLE_METHOD_SELECT_CON, _hashImpl),
[this](auto&& table, auto&& executive, auto&& data, auto&& pricer, auto&& params) {
selectByCondition(table, executive, data, pricer, params);
});
registerFunc(getFuncSelector(TABLE_METHOD_COUNT),
registerFunc(getFuncSelector(TABLE_METHOD_COUNT, _hashImpl),
[this](auto&& table, auto&& executive, auto&& data, auto&& pricer, auto&& params) {
count(table, executive, data, pricer, params);
});
registerFunc(getFuncSelector(TABLE_METHOD_INSERT),
registerFunc(getFuncSelector(TABLE_METHOD_INSERT, _hashImpl),
[this](auto&& table, auto&& executive, auto&& data, auto&& pricer, auto&& params) {
insert(table, executive, data, pricer, params);
});
registerFunc(getFuncSelector(TABLE_METHOD_UPDATE_KEY),
registerFunc(getFuncSelector(TABLE_METHOD_UPDATE_KEY, _hashImpl),
[this](auto&& table, auto&& executive, auto&& data, auto&& pricer, auto&& params) {
updateByKey(table, executive, data, pricer, params);
});
registerFunc(getFuncSelector(TABLE_METHOD_UPDATE_CON),
registerFunc(getFuncSelector(TABLE_METHOD_UPDATE_CON, _hashImpl),
[this](auto&& table, auto&& executive, auto&& data, auto&& pricer, auto&& params) {
updateByCondition(table, executive, data, pricer, params);
});
registerFunc(getFuncSelector(TABLE_METHOD_REMOVE_KEY),
registerFunc(getFuncSelector(TABLE_METHOD_REMOVE_KEY, _hashImpl),
[this](auto&& table, auto&& executive, auto&& data, auto&& pricer, auto&& params) {
removeByKey(table, executive, data, pricer, params);
});
registerFunc(getFuncSelector(TABLE_METHOD_REMOVE_CON),
registerFunc(getFuncSelector(TABLE_METHOD_REMOVE_CON, _hashImpl),
[this](auto&& table, auto&& executive, auto&& data, auto&& pricer, auto&& params) {
removeByCondition(table, executive, data, pricer, params);
});
registerFunc(
getFuncSelector(TABLE_METHOD_SELECT_CON_V320),
getFuncSelector(TABLE_METHOD_SELECT_CON_V320, _hashImpl),
[this](auto&& table, auto&& executive, auto&& data, auto&& pricer, auto&& params) {
selectByConditionV32(table, executive, data, pricer, params);
},
BlockVersion::V3_2_VERSION);
registerFunc(
getFuncSelector(TABLE_METHOD_COUNT_V320),
getFuncSelector(TABLE_METHOD_COUNT_V320, _hashImpl),
[this](auto&& table, auto&& executive, auto&& data, auto&& pricer, auto&& params) {
countV32(table, executive, data, pricer, params);
},
BlockVersion::V3_2_VERSION);
registerFunc(
getFuncSelector(TABLE_METHOD_UPDATE_CON_V320),
getFuncSelector(TABLE_METHOD_UPDATE_CON_V320, _hashImpl),
[this](auto&& table, auto&& executive, auto&& data, auto&& pricer, auto&& params) {
updateByConditionV32(table, executive, data, pricer, params);
},
BlockVersion::V3_2_VERSION);
registerFunc(
getFuncSelector(TABLE_METHOD_REMOVE_CON_V320),
getFuncSelector(TABLE_METHOD_REMOVE_CON_V320, _hashImpl),
[this](auto&& table, auto&& executive, auto&& data, auto&& pricer, auto&& params) {
removeByConditionV32(table, executive, data, pricer, params);
},
Expand Down
3 changes: 1 addition & 2 deletions bcos-executor/src/precompiled/common/Utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ std::string checkCreateTableParam(const std::string_view& _tableName, std::strin
const std::variant<std::string, std::vector<std::string>>& _valueField,
std::optional<uint8_t> keyOrder = std::nullopt);

uint32_t getFuncSelector(std::string const& _functionName,
const crypto::Hash::Ptr& _hashImpl = executor::GlobalHashImpl::g_hashImpl);
uint32_t getFuncSelector(std::string const& _functionName, const crypto::Hash::Ptr& _hashImpl);
// for ut
void clearName2SelectCache();
uint32_t getParamFunc(bytesConstRef _param);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ using namespace bcos::protocol;
const char* const AM_METHOD_SET_ACCOUNT_STATUS = "setAccountStatus(address,uint8)";
const char* const AM_METHOD_GET_ACCOUNT_STATUS = "getAccountStatus(address)";

AccountManagerPrecompiled::AccountManagerPrecompiled() : Precompiled(GlobalHashImpl::g_hashImpl)
AccountManagerPrecompiled::AccountManagerPrecompiled(crypto::Hash::Ptr hashImpl)
: Precompiled(hashImpl)
{
name2Selector[AM_METHOD_SET_ACCOUNT_STATUS] =
getFuncSelector(AM_METHOD_SET_ACCOUNT_STATUS, GlobalHashImpl::g_hashImpl);
getFuncSelector(AM_METHOD_SET_ACCOUNT_STATUS, hashImpl);
name2Selector[AM_METHOD_GET_ACCOUNT_STATUS] =
getFuncSelector(AM_METHOD_GET_ACCOUNT_STATUS, GlobalHashImpl::g_hashImpl);
getFuncSelector(AM_METHOD_GET_ACCOUNT_STATUS, hashImpl);
}

std::shared_ptr<PrecompiledExecResult> AccountManagerPrecompiled::call(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AccountManagerPrecompiled : public bcos::precompiled::Precompiled
{
public:
using Ptr = std::shared_ptr<AccountManagerPrecompiled>;
AccountManagerPrecompiled();
AccountManagerPrecompiled(crypto::Hash::Ptr hashImpl);
~AccountManagerPrecompiled() override = default;

std::shared_ptr<PrecompiledExecResult> call(
Expand Down
10 changes: 5 additions & 5 deletions bcos-executor/src/precompiled/extension/AccountPrecompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ using namespace bcos::protocol;
const char* const AM_METHOD_SET_ACCOUNT_STATUS = "setAccountStatus(uint8)";
const char* const AM_METHOD_GET_ACCOUNT_STATUS = "getAccountStatus()";

AccountPrecompiled::AccountPrecompiled() : Precompiled(GlobalHashImpl::g_hashImpl)
AccountPrecompiled::AccountPrecompiled(crypto::Hash::Ptr hashImpl) : Precompiled(hashImpl)
{
name2Selector[AM_METHOD_SET_ACCOUNT_STATUS] =
getFuncSelector(AM_METHOD_SET_ACCOUNT_STATUS, GlobalHashImpl::g_hashImpl);
getFuncSelector(AM_METHOD_SET_ACCOUNT_STATUS, hashImpl);
name2Selector[AM_METHOD_GET_ACCOUNT_STATUS] =
getFuncSelector(AM_METHOD_GET_ACCOUNT_STATUS, GlobalHashImpl::g_hashImpl);
getFuncSelector(AM_METHOD_GET_ACCOUNT_STATUS, hashImpl);
}

std::shared_ptr<PrecompiledExecResult> AccountPrecompiled::call(
Expand Down Expand Up @@ -172,8 +172,8 @@ uint8_t AccountPrecompiled::getAccountStatus(const std::string& account,
statusStr = std::string(lastStatusEntry->get());
}

PRECOMPILED_LOG(TRACE) << LOG_BADGE("AccountPrecompiled")
<< BLOCK_NUMBER(blockContext.number()) << LOG_DESC("getAccountStatus")
PRECOMPILED_LOG(TRACE) << LOG_BADGE("AccountPrecompiled") << BLOCK_NUMBER(blockContext.number())
<< LOG_DESC("getAccountStatus")
<< LOG_KV("lastUpdateNumber", lastUpdateNumber)
<< LOG_KV("status", statusStr);
auto status = boost::lexical_cast<uint8_t>(statusStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AccountPrecompiled : public bcos::precompiled::Precompiled
{
public:
using Ptr = std::shared_ptr<AccountPrecompiled>;
AccountPrecompiled();
AccountPrecompiled(crypto::Hash::Ptr hashImpl);
~AccountPrecompiled() override = default;

std::shared_ptr<PrecompiledExecResult> call(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,13 +432,13 @@ void AuthManagerPrecompiled::setContractStatus(
auto func = getParamFunc(_callParameters->input());
const auto& blockContext = _executive->blockContext();
auto codec = CodecWrapper(blockContext.hashHandler(), blockContext.isWasm());
if (func == getFuncSelector(AUTH_METHOD_SET_CONTRACT))
if (func == getFuncSelector(AUTH_METHOD_SET_CONTRACT, m_hashImpl))
{
Address contractAddress;
codec.decode(data, contractAddress, isFreeze);
address = contractAddress.hex();
}
else if (func == getFuncSelector(AUTH_METHOD_SET_CONTRACT_32))
else if (func == getFuncSelector(AUTH_METHOD_SET_CONTRACT_32, m_hashImpl))
{
Address contractAddress;
codec.decode(data, contractAddress, status);
Expand Down
Loading

0 comments on commit d93e35b

Please sign in to comment.