From 4ae5709ff74f43d0f0e7fb93a017155a037c0514 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Thu, 29 Feb 2024 13:46:05 +0800 Subject: [PATCH] (precompiled): fix bfs link write empty abi string bug in 3.0.0. (#4262) --- .../src/executive/TransactionExecutive.cpp | 3 +- .../src/precompiled/BFSPrecompiled.cpp | 13 +++--- bcos-tool/bcos-tool/BfsFileFactory.cpp | 42 ++----------------- bcos-tool/bcos-tool/BfsFileFactory.h | 5 +-- 4 files changed, 15 insertions(+), 48 deletions(-) diff --git a/bcos-executor/src/executive/TransactionExecutive.cpp b/bcos-executor/src/executive/TransactionExecutive.cpp index 3ec0366895..ce32b4c62e 100644 --- a/bcos-executor/src/executive/TransactionExecutive.cpp +++ b/bcos-executor/src/executive/TransactionExecutive.cpp @@ -860,7 +860,8 @@ CallParameters::UniquePtr TransactionExecutive::internalCreate( } /// set link data - tool::BfsFileFactory::buildLink(linkTable.value(), newAddress, ""); + tool::BfsFileFactory::buildLink( + linkTable.value(), newAddress, "", blockContext().blockVersion()); } callParameters->type = CallParameters::FINISHED; callParameters->status = (int32_t)TransactionStatus::None; diff --git a/bcos-executor/src/precompiled/BFSPrecompiled.cpp b/bcos-executor/src/precompiled/BFSPrecompiled.cpp index 900b51330f..403021b35c 100644 --- a/bcos-executor/src/precompiled/BFSPrecompiled.cpp +++ b/bcos-executor/src/precompiled/BFSPrecompiled.cpp @@ -565,7 +565,8 @@ void BFSPrecompiled::linkImpl(const std::string& _absolutePath, const std::strin if (typeEntry && typeEntry->getField(0) == FS_TYPE_LINK) { // contract name and version exist, overwrite address and abi - tool::BfsFileFactory::buildLink(linkTable.value(), contractAddress, _contractAbi); + tool::BfsFileFactory::buildLink( + linkTable.value(), contractAddress, _contractAbi, blockContext.blockVersion()); _callParameters->setExecResult(codec.encode(s256((int)CODE_SUCCESS))); return; } @@ -592,7 +593,8 @@ void BFSPrecompiled::linkImpl(const std::string& _absolutePath, const std::strin auto newLinkTable = _executive->storage().createTable(linkTableName, std::string(STORAGE_VALUE)); // set link info to link table - tool::BfsFileFactory::buildLink(newLinkTable.value(), contractAddress, _contractAbi); + tool::BfsFileFactory::buildLink( + newLinkTable.value(), contractAddress, _contractAbi, blockContext.blockVersion()); _callParameters->setExecResult(codec.encode(s256((int)CODE_SUCCESS))); } @@ -670,8 +672,8 @@ void BFSPrecompiled::linkAdaptCNS(const std::shared_ptrstorage().createTable(linkTableName, std::string(STORAGE_VALUE)); // set link info to link table - tool::BfsFileFactory::buildLink( - newLinkTable.value(), contractAddress, contractAbi, contractVersion); + tool::BfsFileFactory::buildLink(newLinkTable.value(), contractAddress, contractAbi, + blockContext.blockVersion(), contractVersion); _callParameters->setExecResult(codec.encode((int32_t)CODE_SUCCESS)); } @@ -1267,6 +1269,7 @@ void BFSPrecompiled::buildSysSubs(const std::shared_ptrstorage().createTable(std::string(name), SYS_VALUE_FIELDS); - tool::BfsFileFactory::buildLink(linkTable.value(), std::string(address), ""); + tool::BfsFileFactory::buildLink( + linkTable.value(), std::string(address), "", _executive->blockContext().blockVersion()); } } \ No newline at end of file diff --git a/bcos-tool/bcos-tool/BfsFileFactory.cpp b/bcos-tool/bcos-tool/BfsFileFactory.cpp index 31cb35f2b9..b261ced54a 100644 --- a/bcos-tool/bcos-tool/BfsFileFactory.cpp +++ b/bcos-tool/bcos-tool/BfsFileFactory.cpp @@ -27,41 +27,6 @@ using namespace bcos::tool; using namespace bcos::storage; -void BfsFileFactory::buildAsync(bcos::storage::StorageInterface::Ptr const& _storage, - std::string_view fileName, FileType fileType, std::function _callback) -{ - _storage->asyncOpenTable(fileName, - [_callback = std::move(_callback), fileType](auto&& _error, std::optional&& _table) { - if (_error) - { - _callback(std::forward(_error)); - return; - } - if (!_table.has_value()) - { - _callback(BCOS_ERROR_UNIQUE_PTR(-1, "Table not exist")); - return; - } - bool buildRet = false; - switch (fileType) - { - case DIRECTOR: - buildRet = buildDir(_table.value()); - break; - case LINK: - buildRet = buildLink(_table.value(), "", ""); - break; - case AUTH: - buildRet = buildAuth(_table.value(), ""); - break; - case CONTRACT: - buildRet = buildContract(_table.value()); - break; - } - _callback(buildRet ? nullptr : BCOS_ERROR_UNIQUE_PTR(-1, "Build BFS file error.")); - }); -} - std::optional
BfsFileFactory::createDir( const bcos::storage::StorageInterface::Ptr& _storage, std::string _table) { @@ -108,8 +73,8 @@ void BfsFileFactory::buildDirEntry( _mutableEntry.setObject>({type.data(), "0", "0", "", "", ""}); } -bool BfsFileFactory::buildLink( - Table& _table, const std::string& _address, const std::string& _abi, const std::string& name) +bool BfsFileFactory::buildLink(Table& _table, const std::string& _address, const std::string& _abi, + uint32_t blockVersion, const std::string& name) { Entry tEntry; tEntry.importFields({std::string(FS_TYPE_LINK)}); @@ -119,7 +84,8 @@ bool BfsFileFactory::buildLink( linkEntry.importFields({_address}); _table.setRow(FS_LINK_ADDRESS, std::move(linkEntry)); - if (!_abi.empty()) + // in block version 3.0, save abi in link even if it is empty + if (!_abi.empty() || blockVersion == (uint32_t)protocol::BlockVersion::V3_0_VERSION) { BCOS_LOG(TRACE) << LOG_BADGE("BFS") << "buildLink with abi" << LOG_KV("abiSize", _abi.size()); diff --git a/bcos-tool/bcos-tool/BfsFileFactory.h b/bcos-tool/bcos-tool/BfsFileFactory.h index e686d87254..b7a3daeb25 100644 --- a/bcos-tool/bcos-tool/BfsFileFactory.h +++ b/bcos-tool/bcos-tool/BfsFileFactory.h @@ -91,9 +91,6 @@ class BfsFileFactory BfsFileFactory(BfsFileFactory&&) noexcept = delete; BfsFileFactory& operator=(const BfsFileFactory&) = delete; BfsFileFactory& operator=(BfsFileFactory&&) noexcept = delete; - static void buildAsync(bcos::storage::StorageInterface::Ptr const& _storage, - std::string_view fileName, FileType fileType, - std::function _callback); static bool buildDir(storage::Table& _table); // sync create dir @@ -102,7 +99,7 @@ class BfsFileFactory static void buildDirEntry(storage::Entry& _mutableEntry, std::variant fileType); static bool buildLink(storage::Table& _table, const std::string& _address, - const std::string& _abi, const std::string& name = ""); + const std::string& _abi, uint32_t blockVersion, const std::string& name = ""); static bool buildAuth(storage::Table& _table, const std::string& _admin); static bool buildContract(storage::Table& _table); };