Skip to content

Commit

Permalink
Merge branch 'release-3.6.1' into mimaka
Browse files Browse the repository at this point in the history
  • Loading branch information
wenlinlee authored Jul 4, 2024
2 parents 5b29d13 + f4b2cdc commit 1b39ee0
Show file tree
Hide file tree
Showing 37 changed files with 615 additions and 337 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,19 @@ jobs:
- name: Remove cache if correspond dir change
run: ./tools/.ci/clear_build_cache.sh

- name: update vcpkg
run: |
cd vcpkg && git pull origin master && ./bootstrap-vcpkg.sh
cd -
- name: Build for Arm
run: |
export PATH="/usr/lib/ccache:/usr/local/opt/ccache/libexec:$PATH"
. /opt/rh/devtoolset-10/enable
. /opt/rh/rh-perl530/enable
export LIBCLANG_PATH=/opt/rh/llvm-toolset-7.0/root/lib64/
. /opt/rh/llvm-toolset-7.0/enable
alias cmake='cmake3'
cd build && cmake3 -DCMAKE_BUILD_TYPE=Release -DTESTS=OFF -DCOVERAGE=OFF -DWITH_LIGHTNODE=ON -DWITH_CPPSDK=ON -DWITH_TIKV=ON -DWITH_TARS_SERVICES=ON .. || cat *.log
make -j4 && make tar
cd build && cmake -DCMAKE_BUILD_TYPE=Release -DTESTS=OFF -DCOVERAGE=OFF -DWITH_LIGHTNODE=ON -DWITH_CPPSDK=ON -DWITH_TIKV=ON -DWITH_TARS_SERVICES=ON .. || cat *.log
make -j8 && make tar
- name: tar fisco-bcos for Arm
run: mkdir -p bin && mv build/fisco-bcos-air/fisco-bcos bin && mv build/lightnode/fisco-bcos-lightnode/fisco-bcos-lightnode bin && cd bin && strip fisco-bcos && strip fisco-bcos-lightnode && tar -cvzf fisco-bcos.tar.gz fisco-bcos && tar -cvzf lightnode.tar.gz fisco-bcos-lightnode
- name: Upload fisco-bcos binaries to release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/workflow-self-hosted-arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:

- name: update vcpkg
run: |
cd ${{ env.VCPKG_ROOT }} && git fetch --all
cd vcpkg && git pull origin master
cd -
- name: Build for linux
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ endif()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)

set(VERSION "3.6.0")
set(VERSION "3.6.1")
set(VERSION_SUFFIX "")
include(Options)
configure_project()
Expand Down
96 changes: 86 additions & 10 deletions bcos-executor/src/executive/TransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,51 @@ std::optional<storage::Entry> TransactionExecutive::getCodeByContractTableName(
}
}

bool TransactionExecutive::setCode(std::string_view contractTableName,
std::variant<std::string_view, std::string, bcos::bytes> code)
{
auto contractTable = storage().openTable(contractTableName);
// set code hash in contract table
if (contractTable)
{
crypto::HashType codeHash;
Entry codeEntry;
std::visit(
[&codeHash, &codeEntry, this](auto&& code) {
codeHash = m_hashImpl->hash(code);
codeEntry.importFields({std::move(code)});
},
code);
Entry codeHashEntry;
codeHashEntry.importFields({codeHash.asBytes()});

// not exist in code binary table, set it
if (!storage().getRow(bcos::ledger::SYS_CODE_BINARY, codeHash.toRawString()))
{
// set code in code binary table
storage().setRow(
bcos::ledger::SYS_CODE_BINARY, codeHash.toRawString(), std::move(codeEntry));
}

// dry code hash in account table
storage().setRow(contractTableName, ACCOUNT_CODE_HASH, std::move(codeHashEntry));
return true;
}
return false;
}

void TransactionExecutive::setAbiByCodeHash(std::string_view codeHash, std::string_view abi)
{
if (!storage().getRow(bcos::ledger::SYS_CONTRACT_ABI, codeHash))
{
Entry abiEntry;
abiEntry.importFields({std::move(abi)});

storage().setRow(bcos::ledger::SYS_CONTRACT_ABI, codeHash, std::move(abiEntry));
}
}


CallParameters::UniquePtr TransactionExecutive::transferBalance(
CallParameters::UniquePtr callParameters, int64_t requireGas,
std::string_view currentContextAddress)
Expand Down Expand Up @@ -588,6 +633,9 @@ std::tuple<std::unique_ptr<HostContext>, CallParameters::UniquePtr> TransactionE
revert();
return {nullptr, std::move(callParameters)};
}

this->setContractTableChanged();

if (callParameters->internalCreate)
{
callParameters->abi = std::move(extraData->abi);
Expand Down Expand Up @@ -787,19 +835,47 @@ CallParameters::UniquePtr TransactionExecutive::internalCreate(
auto codeTable = getContractTableName(newAddress, false);
m_storageWrapper->createTable(codeTable, std::string(STORAGE_VALUE));

/// set code field
Entry entry = {};
entry.importFields({codeString});
m_storageWrapper->setRow(codeTable, ACCOUNT_CODE, std::move(entry));
if (!callParameters->abi.empty())
if (m_blockContext.features().get(
ledger::Features::Flag::bugfix_internal_create_redundant_storage))
{
setCode(codeTable, std::move(codeString));
if (!callParameters->abi.empty())
{
auto codeHash = m_hashImpl->hash(codeString);
setAbiByCodeHash(codeHash.toRawString(), std::move(callParameters->abi));
}
}
else
{
Entry abiEntry = {};
abiEntry.importFields({std::move(callParameters->abi)});
m_storageWrapper->setRow(codeTable, ACCOUNT_ABI, std::move(abiEntry));
/// set code field
Entry entry = {};
entry.importFields({std::move(codeString)});
m_storageWrapper->setRow(codeTable, ACCOUNT_CODE, std::move(entry));
if (!callParameters->abi.empty() &&
blockContext().blockVersion() != (uint32_t)protocol::BlockVersion::V3_0_VERSION)
{
Entry abiEntry = {};
abiEntry.importFields({std::move(callParameters->abi)});
m_storageWrapper->setRow(codeTable, ACCOUNT_ABI, std::move(abiEntry));
}
}

/// set link data
tool::BfsFileFactory::buildLink(linkTable.value(), newAddress, "");
if (blockContext().blockVersion() == (uint32_t)protocol::BlockVersion::V3_0_VERSION)
{
/// set link data
Entry addressEntry = {};
addressEntry.importFields({newAddress});
m_storageWrapper->setRow(tableName, FS_LINK_ADDRESS, std::move(addressEntry));
Entry typeEntry = {};
typeEntry.importFields({FS_TYPE_LINK});
m_storageWrapper->setRow(tableName, FS_KEY_TYPE, std::move(typeEntry));
}
else
{
/// set link data
tool::BfsFileFactory::buildLink(
linkTable.value(), newAddress, "", blockContext().blockVersion());
}
}
callParameters->type = CallParameters::FINISHED;
callParameters->status = (int32_t)TransactionStatus::None;
Expand Down
3 changes: 3 additions & 0 deletions bcos-executor/src/executive/TransactionExecutive.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ class TransactionExecutive : public std::enable_shared_from_this<TransactionExec
std::optional<storage::Entry> getCodeEntryFromContractTable(
const std::string_view contractTableName);
std::optional<storage::Entry> getCodeByHash(const std::string_view& codeHash);
bool setCode(std::string_view contractTableName,
std::variant<std::string_view, std::string, bcos::bytes> code);
void setAbiByCodeHash(std::string_view codeHash, std::string_view abi);
std::optional<storage::Entry> getCodeByContractTableName(
const std::string_view& contractTableName, bool needTryFromContractTable = true);

Expand Down
10 changes: 8 additions & 2 deletions bcos-executor/src/executor/TransactionExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ TransactionExecutor::TransactionExecutor(bcos::ledger::LedgerInterface::Ptr ledg
{
initEvmEnvironment();
}

if (m_blockVersion == (uint32_t)protocol::BlockVersion::V3_0_VERSION)
{
// This 3.0.x's bug, but we still need to compatible with it
initTestPrecompiledTable(m_backendStorage);
}

assert(m_precompiled != nullptr && m_precompiled->size() > 0);
start();
}
Expand Down Expand Up @@ -1134,8 +1141,7 @@ void TransactionExecutor::getHash(bcos::protocol::BlockNumber number,
// remove suicides beforehand
m_blockContext->killSuicides();
auto start = utcTime();
auto hash = last.storage->hash(m_hashImpl,
m_blockContext->features().get(ledger::Features::Flag::bugfix_statestorage_hash));
auto hash = last.storage->hash(m_hashImpl, m_blockContext->features());
auto end = utcTime();
EXECUTOR_NAME_LOG(INFO) << BLOCK_NUMBER(number) << "GetTableHashes success"
<< LOG_KV("hash", hash.hex()) << LOG_KV("time(ms)", (end - start));
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());
}
}
24 changes: 2 additions & 22 deletions bcos-executor/src/vm/HostContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,36 +390,15 @@ evmc_result HostContext::callBuiltInPrecompiled(

bool HostContext::setCode(bytes code)
{
m_executive->setContractTableChanged();

// set code will cause exception when exec revert
// new logic
if (blockVersion() >= uint32_t(bcos::protocol::BlockVersion::V3_1_VERSION))
{
auto contractTable = m_executive->storage().openTable(m_tableName);
// set code hash in contract table
auto codeHash = hashImpl()->hash(code);
if (contractTable)
{
Entry codeHashEntry;
codeHashEntry.importFields({codeHash.asBytes()});

auto codeEntry = m_executive->storage().getRow(
bcos::ledger::SYS_CODE_BINARY, codeHashEntry.getField(0));

if (!codeEntry)
{
codeEntry = std::make_optional<Entry>();
codeEntry->importFields({std::move(code)});

// set code in code binary table
m_executive->storage().setRow(bcos::ledger::SYS_CODE_BINARY,
codeHashEntry.getField(0), std::move(codeEntry.value()));
}

// dry code hash in account table
m_executive->storage().setRow(m_tableName, ACCOUNT_CODE_HASH, std::move(codeHashEntry));

m_executive->setCode(m_tableName, std::move(code));
if (features().get(ledger::Features::Flag::feature_balance))
{
// update account's special code
Expand Down Expand Up @@ -477,6 +456,7 @@ void HostContext::setCodeAndAbi(bytes code, string abi)
m_executive->storage().setRow(
bcos::ledger::SYS_CONTRACT_ABI, codeHash, std::move(abiEntry.value()));
}
m_executive->setAbiByCodeHash(codeHash, std::move(abi));

return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class AccountPrecompiledFixture : public PrecompiledFixture
{
bytes input;
boost::algorithm::unhex(helloBin, std::back_inserter(input));
auto tx = fakeTransaction(cryptoSuite, keyPair, "", input, std::to_string(101), 100001, "1", "1");
auto tx =
fakeTransaction(cryptoSuite, keyPair, "", input, std::to_string(101), 100001, "1", "1");
if (_address != Address())
{
tx->forceSender(_address.asBytes());
Expand Down Expand Up @@ -127,7 +128,7 @@ class AccountPrecompiledFixture : public PrecompiledFixture
auto result3 = executePromise3.get_future().get();


BOOST_CHECK_EQUAL(result3->type(), ExecutionMessage::FINISHED);
BOOST_CHECK_EQUAL(result3->type(), ExecutionMessage::PRE_FINISH);
BOOST_CHECK_EQUAL(result3->newEVMContractAddress(), newAddress);
BOOST_CHECK_LT(result3->gasAvailable(), gas);

Expand All @@ -148,7 +149,8 @@ class AccountPrecompiledFixture : public PrecompiledFixture
{
nextBlock(_number, m_blockVersion);
bytes in = codec->encodeWithSig("get()");
auto tx = fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(101), 100001, "1", "1");
auto tx =
fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(101), 100001, "1", "1");
if (_address != Address())
{
tx->forceSender(_address.asBytes());
Expand Down Expand Up @@ -192,7 +194,8 @@ class AccountPrecompiledFixture : public PrecompiledFixture
{
nextBlock(_number, m_blockVersion);
bytes in = codec->encodeWithSig("set(string)", _value);
auto tx = fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(101), 100001, "1", "1");
auto tx =
fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(101), 100001, "1", "1");
if (_address != Address())
{
tx->forceSender(_address.asBytes());
Expand Down Expand Up @@ -238,7 +241,8 @@ class AccountPrecompiledFixture : public PrecompiledFixture
{
nextBlock(_number, m_blockVersion);
bytes in = codec->encodeWithSig("setAccountStatus(address,uint8)", account, status);
auto tx = fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(101), 100001, "1", "1");
auto tx =
fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(101), 100001, "1", "1");
auto newSender = Address(_sender);
tx->forceSender(newSender.asBytes());
auto hash = tx->hash();
Expand Down Expand Up @@ -281,7 +285,7 @@ class AccountPrecompiledFixture : public PrecompiledFixture
BOOST_CHECK(result3->status() == 0);
BOOST_CHECK(result3->to() == ACCOUNT_MGR_ADDRESS);
BOOST_CHECK(result3->from() == AUTH_COMMITTEE_ADDRESS);
BOOST_CHECK(result3->type() == ExecutionMessage::FINISHED);
BOOST_CHECK(result3->type() == ExecutionMessage::PRE_FINISH);

result3->setSeq(1000);

Expand Down Expand Up @@ -311,7 +315,7 @@ class AccountPrecompiledFixture : public PrecompiledFixture

BOOST_CHECK(result5->status() == 0);
BOOST_CHECK(result5->to() == ACCOUNT_MGR_ADDRESS);
BOOST_CHECK(result5->type() == ExecutionMessage::FINISHED);
BOOST_CHECK(result5->type() == ExecutionMessage::PRE_FINISH);

result5->setSeq(1000);

Expand Down Expand Up @@ -455,7 +459,8 @@ class AccountPrecompiledFixture : public PrecompiledFixture
{
nextBlock(_number, m_blockVersion);
bytes in = codec->encodeWithSig("getAccountStatus(address)", account);
auto tx = fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(101), 100001, "1", "1");
auto tx =
fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(101), 100001, "1", "1");
auto newSender = Address("0000000000000000000000000000000000010001");
tx->forceSender(newSender.asBytes());
auto hash = tx->hash();
Expand Down Expand Up @@ -531,7 +536,8 @@ class AccountPrecompiledFixture : public PrecompiledFixture
{
nextBlock(_number, m_blockVersion);
bytes in = codec->encodeWithSig("getAccountStatus()");
auto tx = fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(101), 100001, "1", "1");
auto tx =
fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(101), 100001, "1", "1");
auto hash = tx->hash();
txpool->hash2Transaction[hash] = tx;
sender = boost::algorithm::hex_lower(std::string(tx->sender()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class PermissionPrecompiledFixture : public PrecompiledFixture
}
else
{
BOOST_CHECK_EQUAL(result3->type(), ExecutionMessage::FINISHED);
BOOST_CHECK_EQUAL(result3->type(), ExecutionMessage::PRE_FINISH);
BOOST_CHECK_EQUAL(result3->newEVMContractAddress(), newAddress);
BOOST_CHECK_LT(result3->gasAvailable(), gas);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ConfigPrecompiledFixture : public PrecompiledFixture
// --------------------------------

std::promise<bcos::protocol::ExecutionMessage::UniquePtr> executePromise;
executor->dmcExecuteTransaction(
executor->executeTransaction(
std::move(params), [&](bcos::Error::UniquePtr&& error,
bcos::protocol::ExecutionMessage::UniquePtr&& result) {
BOOST_CHECK(!error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class CryptoPrecompiledFixture : public PrecompiledFixture
// --------------------------------

std::promise<bcos::protocol::ExecutionMessage::UniquePtr> executePromise;
executor->dmcExecuteTransaction(
executor->executeTransaction(
std::move(params), [&](bcos::Error::UniquePtr&& error,
bcos::protocol::ExecutionMessage::UniquePtr&& result) {
BOOST_CHECK(!error);
Expand Down
Loading

0 comments on commit 1b39ee0

Please sign in to comment.