Skip to content

Commit

Permalink
Merge branch 'release-3.10.2' into release-3.10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kyonRay authored Sep 9, 2024
2 parents 477e6b6 + 028f383 commit 9883f1b
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 21 deletions.
6 changes: 6 additions & 0 deletions bcos-executor/src/executive/BlockContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ BlockContext::BlockContext(std::shared_ptr<storage::StateStorageInterface> stora
}

task::syncWait(readFromStorage(m_features, *m_storage, m_blockNumber));
task::syncWait(readFromStorage(m_configs, *m_storage, m_blockNumber));
setVMSchedule();
}

Expand Down Expand Up @@ -189,3 +190,8 @@ const bcos::ledger::Features& bcos::executor::BlockContext::features() const
{
return m_features;
}

const bcos::ledger::SystemConfigs& BlockContext::configs() const
{
return m_configs;
}
2 changes: 2 additions & 0 deletions bcos-executor/src/executive/BlockContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class BlockContext : public std::enable_shared_from_this<BlockContext>
auto keyPageIgnoreTables() const { return m_keyPageIgnoreTables; }

const ledger::Features& features() const;
const ledger::SystemConfigs& configs() const;
storage::EntryCachePtr getCodeCache() const { return m_codeCache; }
storage::EntryCachePtr getCodeHashCache() const { return m_codeHashCache; }
auto backendStorage() const { return m_backendStorage; }
Expand Down Expand Up @@ -169,6 +170,7 @@ class BlockContext : public std::enable_shared_from_this<BlockContext>
storage::EntryCachePtr m_codeHashCache = std::make_shared<storage::EntryCache>();
bcos::storage::StorageInterface::Ptr m_backendStorage;
ledger::Features m_features;
ledger::SystemConfigs m_configs;
};

} // namespace bcos::executor
11 changes: 9 additions & 2 deletions bcos-executor/src/executive/TransactionExecutive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,17 @@ CallParameters::UniquePtr TransactionExecutive::execute(CallParameters::UniquePt
ledger::Features::Flag::feature_balance))
<< LOG_KV("value", callParameters->value);
}
// policy1 disable transfer balance
bool disableTransfer =
m_blockContext.features().get(ledger::Features::Flag::feature_balance_policy1);

if (m_blockContext.features().get(ledger::Features::Flag::feature_balance_policy1))
if (auto const& balanceTransfer =
m_blockContext.configs().get(ledger::SystemConfig::balance_transfer))
{
disableTransfer = (balanceTransfer.value() == "0");
}
if (disableTransfer)
{
// policy1 disable transfer balance
callParameters->value = 0;
}

Expand Down
4 changes: 4 additions & 0 deletions bcos-executor/src/precompiled/SystemConfigPrecompiled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ SystemConfigPrecompiled::SystemConfigPrecompiled(crypto::Hash::Ptr hashImpl) : P
defaultCmp(SYSTEM_KEY_RPBFT_EPOCH_SEALER_NUM, _value, RPBFT_EPOCH_SEALER_NUM_MIN,
version, BlockVersion::V3_5_VERSION);
}));
m_sysValueCmp.insert(
std::make_pair(ENABLE_BALANCE_TRANSFER, [defaultCmp](int64_t _value, uint32_t version) {
defaultCmp(ENABLE_BALANCE_TRANSFER, _value, 0, version, BlockVersion::V3_10_2_VERSION);
}));
// for compatibility
// Note: the compatibility_version is not compatibility
m_sysValueCmp.insert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,26 @@ BOOST_AUTO_TEST_CASE(sysConfig_test)
simpleSetFunc(number++, 110, std::string{ledger::SYSTEM_KEY_TX_GAS_PRICE},
std::string("error"), bcos::protocol::TransactionStatus::PrecompiledError);
}

// balance_transfer
{
simpleSetFunc(number++, 111, std::string{ledger::SYSTEM_KEY_COMPATIBILITY_VERSION},
std::string("3.10.2"));

simpleSetFunc(
number++, 111, std::string{ledger::ENABLE_BALANCE_TRANSFER}, std::string("1"));
auto value = getValueByKey(number++, std::string{ledger::ENABLE_BALANCE_TRANSFER});
BOOST_CHECK_EQUAL(value, "1");

simpleSetFunc(
number++, 111, std::string{ledger::ENABLE_BALANCE_TRANSFER}, std::string("0"));

value = getValueByKey(number++, std::string{ledger::ENABLE_BALANCE_TRANSFER});
BOOST_CHECK_EQUAL(value, "0");

simpleSetFunc(number++, 111, std::string{ledger::ENABLE_BALANCE_TRANSFER},
std::string("error"), bcos::protocol::TransactionStatus::PrecompiledError);
}
}

BOOST_AUTO_TEST_CASE(consensus_test)
Expand Down
22 changes: 22 additions & 0 deletions bcos-framework/bcos-framework/ledger/LedgerTypeDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ constexpr static std::string_view SYSTEM_KEY_RPBFT_SWITCH = magic_enum::enum_nam
constexpr static std::string_view SYSTEM_KEY_BALANCE_PRECOMPILED_SWITCH = magic_enum::enum_name(SystemConfig::feature_balance_precompiled);
// notify rotate key for rpbft
constexpr static std::string_view INTERNAL_SYSTEM_KEY_NOTIFY_ROTATE = "feature_rpbft_notify_rotate";
constexpr static std::string_view ENABLE_BALANCE_TRANSFER = magic_enum::enum_name(SystemConfig::balance_transfer);
// clang-format on
constexpr static std::string_view PBFT_CONSENSUS_TYPE = "pbft";
constexpr static std::string_view RPBFT_CONSENSUS_TYPE = "rpbft";
Expand Down Expand Up @@ -123,4 +124,25 @@ struct CurrentState
int64_t totalTransactionCount;
int64_t totalFailedTransactionCount;
};

inline task::Task<void> readFromStorage(SystemConfigs& configs, auto&& storage, long blockNumber)
{
decltype(auto) keys = bcos::ledger::SystemConfigs::supportConfigs();
auto entries = co_await storage2::readSome(std::forward<decltype(storage)>(storage),
keys | RANGES::views::transform([](std::string_view key) {
return transaction_executor::StateKeyView(ledger::SYS_CONFIG, key);
}));
for (auto&& [key, entry] : RANGES::views::zip(keys, entries))
{
if (entry)
{
auto [value, enableNumber] = entry->template getObject<ledger::SystemConfigEntry>();
if (blockNumber >= enableNumber)
{
configs.set(key, value);
}
}
}
}

} // namespace bcos::ledger
15 changes: 13 additions & 2 deletions bcos-framework/bcos-framework/ledger/SystemConfigs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
*/

#pragma once
#include "../ledger/LedgerTypeDef.h"
#include "../protocol/Protocol.h"
#include "../storage/Entry.h"
#include "../storage/LegacyStorageMethods.h"
#include "../storage2/Storage.h"
#include "../transaction-executor/StateKey.h"
#include "bcos-framework/ledger/LedgerTypeDef.h"
#include "bcos-task/Task.h"
#include "bcos-tool/Exceptions.h"
#include "bcos-utilities/Ranges.h"
Expand Down Expand Up @@ -53,6 +53,7 @@ enum class SystemConfig
feature_rpbft_epoch_sealer_num,
feature_balance_precompiled,
web3_chain_id,
balance_transfer,
};
class SystemConfigs
{
Expand All @@ -69,7 +70,17 @@ class SystemConfigs
return *value;
}

std::optional<std::string> get(SystemConfig config) const { return m_sysConfigs.at(config); }
std::optional<std::string> get(SystemConfig config) const
{
if (const auto it = m_sysConfigs.find(config); it != m_sysConfigs.end())
{
return it->second;
}
else
{
return std::nullopt;
}
}
std::optional<std::string> get(std::string_view config) const
{
return get(fromString(config));
Expand Down
5 changes: 3 additions & 2 deletions bcos-framework/bcos-framework/protocol/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ enum ProtocolVersion : uint32_t

enum class BlockVersion : uint32_t
{
V3_10_2_VERSION = 0x030a0200,
V3_10_0_VERSION = 0x030a0000,
V3_9_0_VERSION = 0x03090000,
V3_8_0_VERSION = 0x03080000,
Expand All @@ -137,7 +138,7 @@ enum class BlockVersion : uint32_t
V3_0_VERSION = 0x03000000,
RC4_VERSION = 4,
MIN_VERSION = RC4_VERSION,
MAX_VERSION = V3_10_0_VERSION,
MAX_VERSION = V3_10_2_VERSION,
};

enum class TransactionVersion : uint32_t
Expand All @@ -152,7 +153,7 @@ const std::string RC4_VERSION_STR = "3.0.0-rc4";
const std::string RC_VERSION_PREFIX = "3.0.0-rc";
const std::string V3_9_VERSION_STR = "3.9.0";

const BlockVersion DEFAULT_VERSION = bcos::protocol::BlockVersion::V3_10_0_VERSION;
const BlockVersion DEFAULT_VERSION = bcos::protocol::BlockVersion::V3_10_2_VERSION;
const std::string DEFAULT_VERSION_STR = V3_9_VERSION_STR;
const uint8_t MAX_MAJOR_VERSION = std::numeric_limits<uint8_t>::max();
const uint8_t MIN_MAJOR_VERSION = 3;
Expand Down
5 changes: 4 additions & 1 deletion bcos-pbft/bcos-pbft/pbft/config/PBFTConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ class PBFTConfig : public ConsensusConfig, public std::enable_shared_from_this<P
{
return false;
}
return m_committedProposal->index() < _index;
// Note: If the consensus and blockSync are executing the same block at the same time,
// the blockSync is executed first, and the consensus is still executing, the cache
// should be cleared.
return m_committedProposal->index() <= _index;
}

virtual void setTimeoutState(bool _timeoutState) { m_timeoutState.store(_timeoutState); }
Expand Down
28 changes: 14 additions & 14 deletions tools/.ci/ci_check_air.sh
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ if [[ ${?} == "0" ]]; then
echo "java_sdk_integrationTest error"
exit 1
fi
bash ${current_path}/.ci/java_sdk_demo_ci_test.sh ${console_branch} "false" "${current_path}/nodes/127.0.0.1"
if [[ ${?} == "0" ]]; then
LOG_INFO "java_sdk_demo_ci_test success"
else
echo "java_sdk_demo_ci_test error"
exit 1
fi
#bash ${current_path}/.ci/java_sdk_demo_ci_test.sh ${console_branch} "false" "${current_path}/nodes/127.0.0.1"
#if [[ ${?} == "0" ]]; then
# LOG_INFO "java_sdk_demo_ci_test success"
# else
# echo "java_sdk_demo_ci_test error"
# exit 1
#fi
LOG_INFO "======== check non-sm success ========"

LOG_INFO "======== clear node after non-sm test ========"
Expand All @@ -217,13 +217,13 @@ if [[ ${?} == "0" ]]; then
echo "java_sdk_integrationTest error"
exit 1
fi
bash ${current_path}/.ci/java_sdk_demo_ci_test.sh ${console_branch} "true" "${current_path}/nodes/127.0.0.1"
if [[ ${?} == "0" ]]; then
LOG_INFO "java_sdk_demo_ci_test success"
else
echo "java_sdk_demo_ci_test error"
exit 1
fi
#bash ${current_path}/.ci/java_sdk_demo_ci_test.sh ${console_branch} "true" "${current_path}/nodes/127.0.0.1"
#if [[ ${?} == "0" ]]; then
# LOG_INFO "java_sdk_demo_ci_test success"
# else
# echo "java_sdk_demo_ci_test error"
# exit 1
#fi

LOG_INFO "======== check sm case success ========"
clear_node
Expand Down

0 comments on commit 9883f1b

Please sign in to comment.