Skip to content

Commit

Permalink
<fix>(precompiled): fix bfs link write empty abi string bug in 3.0.0. (
Browse files Browse the repository at this point in the history
  • Loading branch information
kyonRay authored Feb 29, 2024
1 parent 79a46aa commit 4ae5709
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 48 deletions.
3 changes: 2 additions & 1 deletion bcos-executor/src/executive/TransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 8 additions & 5 deletions bcos-executor/src/precompiled/BFSPrecompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)));
}

Expand Down Expand Up @@ -670,8 +672,8 @@ void BFSPrecompiled::linkAdaptCNS(const std::shared_ptr<executor::TransactionExe
auto newLinkTable =
_executive->storage().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));
}

Expand Down Expand Up @@ -1267,6 +1269,7 @@ void BFSPrecompiled::buildSysSubs(const std::shared_ptr<executor::TransactionExe
continue;
}
auto linkTable = _executive->storage().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());
}
}
42 changes: 4 additions & 38 deletions bcos-tool/bcos-tool/BfsFileFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(Error::UniquePtr&&)> _callback)
{
_storage->asyncOpenTable(fileName,
[_callback = std::move(_callback), fileType](auto&& _error, std::optional<Table>&& _table) {
if (_error)
{
_callback(std::forward<decltype(_error)>(_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<Table> BfsFileFactory::createDir(
const bcos::storage::StorageInterface::Ptr& _storage, std::string _table)
{
Expand Down Expand Up @@ -108,8 +73,8 @@ void BfsFileFactory::buildDirEntry(
_mutableEntry.setObject<std::vector<std::string>>({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)});
Expand All @@ -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());
Expand Down
5 changes: 1 addition & 4 deletions bcos-tool/bcos-tool/BfsFileFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(Error::UniquePtr&&)> _callback);

static bool buildDir(storage::Table& _table);
// sync create dir
Expand All @@ -102,7 +99,7 @@ class BfsFileFactory
static void buildDirEntry(storage::Entry& _mutableEntry,
std::variant<FileType, std::string, std::string_view> 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);
};
Expand Down

0 comments on commit 4ae5709

Please sign in to comment.