Skip to content

Commit

Permalink
Merge branch 'release-3.10.2' into sync_from_3.10.2
Browse files Browse the repository at this point in the history
  • Loading branch information
kyonRay committed Sep 18, 2024
2 parents ce7c03e + 7ba690f commit cc64a1c
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 60 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;
}
6 changes: 4 additions & 2 deletions bcos-executor/src/executive/BlockContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class BlockContext : public std::enable_shared_from_this<BlockContext>

uint64_t txGasLimit() const { return m_ledgerCache->fetchTxGasLimit(); }

auto getTxCriticals(
const protocol::Transaction::ConstPtr& _tx) -> std::shared_ptr<std::vector<std::string>>;
auto getTxCriticals(const protocol::Transaction::ConstPtr& _tx)
-> std::shared_ptr<std::vector<std::string>>;

crypto::Hash::Ptr hashHandler() const { return m_hashImpl; }
bool isWasm() const { return m_isWasm; }
Expand Down 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 @@ -240,10 +240,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 @@ -99,6 +99,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
1 change: 1 addition & 0 deletions bcos-executor/src/vm/gas_meter/Metric.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
#pragma once
#include <array>
#include <cstdint>
#include <string>

// #define WASM_FLOAT_ENABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,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
21 changes: 20 additions & 1 deletion bcos-framework/bcos-framework/ledger/SystemConfigs.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
*/

#pragma once
#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/Exceptions.h"
#include "bcos-utilities/Ranges.h"
#include <boost/throw_exception.hpp>
Expand All @@ -45,6 +53,7 @@ enum class SystemConfig
feature_rpbft_epoch_sealer_num,
feature_balance_precompiled,
web3_chain_id,
balance_transfer,
};
class SystemConfigs
{
Expand All @@ -61,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
1 change: 1 addition & 0 deletions bcos-framework/bcos-framework/protocol/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ enum class BlockVersion : uint32_t
{
V3_12_0_VERSION = 0x030c0000, // 3.12.0
V3_11_0_VERSION = 0x030b0000,
V3_10_2_VERSION = 0x030a0200,
V3_10_0_VERSION = 0x030a0000,
V3_9_0_VERSION = 0x03090000,
V3_8_0_VERSION = 0x03080000,
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
50 changes: 17 additions & 33 deletions bcos-pbft/bcos-pbft/pbft/engine/PBFTEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
#include "PBFTEngine.h"
#include "../cache/PBFTCacheFactory.h"
#include "../cache/PBFTCacheProcessor.h"
#include "bcos-framework/ledger/Ledger.h"
#include "bcos-ledger/LedgerMethods.h"
#include "bcos-task/Wait.h"
#include "bcos-framework/protocol/CommonError.h"
#include "bcos-utilities/BoostLog.h"
#include "bcos-utilities/Common.h"
#include <bcos-framework/dispatcher/SchedulerTypeDef.h>
Expand All @@ -33,7 +31,6 @@
#include <bcos-utilities/ThreadPool.h>
#include <boost/bind/bind.hpp>
#include <utility>

using namespace bcos;
using namespace bcos::consensus;
using namespace bcos::ledger;
Expand All @@ -45,8 +42,7 @@ PBFTEngine::PBFTEngine(PBFTConfig::Ptr _config)
: ConsensusEngine("pbft", 0),
m_config(_config),
m_worker(std::make_shared<ThreadPool>("pbftWorker", 4)),
m_msgQueue(std::make_shared<PBFTMsgQueue>()),
m_ledgerConfig(std::make_shared<LedgerConfig>())
m_msgQueue(std::make_shared<PBFTMsgQueue>())
{
auto cacheFactory = std::make_shared<PBFTCacheFactory>();
m_cacheProcessor = std::make_shared<PBFTCacheProcessor>(cacheFactory, _config);
Expand Down Expand Up @@ -798,14 +794,14 @@ CheckResult PBFTEngine::checkPrePrepareMsg(std::shared_ptr<PBFTMessageInterface>
CheckResult PBFTEngine::checkSignature(PBFTBaseMessageInterface::Ptr _req)
{
// check the signature
auto* nodeInfo = m_config->getConsensusNodeByIndex(_req->generatedFrom());
auto nodeInfo = m_config->getConsensusNodeByIndex(_req->generatedFrom());
if (!nodeInfo)
{
PBFT_LOG(WARNING) << LOG_DESC("checkSignature failed for the node is not a consensus node")
<< printPBFTMsgInfo(_req);
return CheckResult::INVALID;
}
auto publicKey = nodeInfo->nodeID;
auto publicKey = nodeInfo->nodeID();
if (!_req->verifySignature(m_config->cryptoSuite(), publicKey))
{
PBFT_LOG(WARNING) << LOG_DESC("checkSignature failed for invalid signature")
Expand Down Expand Up @@ -833,11 +829,11 @@ bool PBFTEngine::checkProposalSignature(
}

return m_config->cryptoSuite()->signatureImpl()->verify(
nodeInfo->nodeID, _proposal->hash(), _proposal->signature());
nodeInfo->nodeID(), _proposal->hash(), _proposal->signature());
}

bool PBFTEngine::checkRotateTransactionValid(PBFTMessageInterface::Ptr const& _proposal,
ConsensusNode const& _leaderInfo, bool needCheckSign)
ConsensusNodeInterface::Ptr const& _leaderInfo, bool needCheckSign)
{
if (m_config->consensusType() == ConsensusType::PBFT_TYPE &&
m_config->rpbftConfigTools() == nullptr) [[likely]]
Expand Down Expand Up @@ -880,7 +876,7 @@ bool PBFTEngine::checkRotateTransactionValid(PBFTMessageInterface::Ptr const& _p
}

// FIXME: should not use source
auto leaderAddress = right160(m_config->cryptoSuite()->hash(_leaderInfo.nodeID));
auto leaderAddress = right160(m_config->cryptoSuite()->hash(_leaderInfo->nodeID()));
if (rotatingTx->source() == leaderAddress.hex())
{
return true;
Expand All @@ -890,7 +886,7 @@ bool PBFTEngine::checkRotateTransactionValid(PBFTMessageInterface::Ptr const& _p
<< LOG_KV("reqIndex", _proposal->index())
<< LOG_KV("reqHash", _proposal->hash().abridged())
<< LOG_KV("fromIdx", _proposal->generatedFrom())
<< LOG_KV("leader", _leaderInfo.nodeID->hex())
<< LOG_KV("leader", _leaderInfo->nodeID()->hex())
<< LOG_KV("leaderAddress", leaderAddress.hex())
<< LOG_KV("sender", rotatingTx->source());
return false;
Expand Down Expand Up @@ -983,12 +979,12 @@ bool PBFTEngine::handlePrePrepareMsg(PBFTMessageInterface::Ptr _prePrepareMsg,
}
// verify the proposal
auto self = weak_from_this();
auto* leaderNodeInfo = m_config->getConsensusNodeByIndex(_prePrepareMsg->generatedFrom());
auto leaderNodeInfo = m_config->getConsensusNodeByIndex(_prePrepareMsg->generatedFrom());
if (!leaderNodeInfo)
{
return false;
}
m_config->validator()->verifyProposal(leaderNodeInfo->nodeID,
m_config->validator()->verifyProposal(leaderNodeInfo->nodeID(),
_prePrepareMsg->consensusProposal(),
[self, _prePrepareMsg, _generatedFromNewView, leaderNodeInfo, _needCheckSignature](
auto&& _error, bool _verifyResult) {
Expand Down Expand Up @@ -1023,7 +1019,7 @@ bool PBFTEngine::handlePrePrepareMsg(PBFTMessageInterface::Ptr _prePrepareMsg,
return;
}
auto rotateResult = pbftEngine->checkRotateTransactionValid(
_prePrepareMsg, *leaderNodeInfo, _needCheckSignature);
_prePrepareMsg, leaderNodeInfo, _needCheckSignature);
// verify failed
if (!_verifyResult || !rotateResult)
{
Expand Down Expand Up @@ -1387,12 +1383,12 @@ bool PBFTEngine::isValidNewViewMsg(std::shared_ptr<NewViewMsgInterface> _newView
<< printPBFTMsgInfo(viewChangeReq);
return false;
}
auto* nodeInfo = m_config->getConsensusNodeByIndex(viewChangeReq->generatedFrom());
auto nodeInfo = m_config->getConsensusNodeByIndex(viewChangeReq->generatedFrom());
if (!nodeInfo)
{
continue;
}
weight += nodeInfo->voteWeight;
weight += nodeInfo->weight();
}
// TODO: need to ensure the accuracy of local weight parameters
if (weight < m_config->minRequiredQuorum())
Expand Down Expand Up @@ -1467,9 +1463,9 @@ void PBFTEngine::reHandlePrePrepareProposals(NewViewMsgInterface::Ptr _newViewRe
continue;
}
// miss the cache, request to from node
auto* from = m_config->getConsensusNodeByIndex(prePrepare->generatedFrom());
auto from = m_config->getConsensusNodeByIndex(prePrepare->generatedFrom());
m_logSync->requestPrecommitData(
from->nodeID, prePrepare, [self](PBFTMessageInterface::Ptr _prePrepare) {
from->nodeID(), prePrepare, [self](PBFTMessageInterface::Ptr _prePrepare) {
auto engine = self.lock();
if (!engine)
{
Expand Down Expand Up @@ -1777,8 +1773,8 @@ void PBFTEngine::clearExceptionProposalState(bcos::protocol::BlockNumber _number
void PBFTEngine::fetchAndUpdateLedgerConfig()
{
PBFT_LOG(INFO) << LOG_DESC("fetchAndUpdateLedgerConfig");
task::syncWait(ledger::getLedgerConfig(*m_ledger, *m_ledgerConfig));
auto& ledgerConfig = m_ledgerConfig;
m_ledgerFetcher->fetchAll();
auto ledgerConfig = m_ledgerFetcher->ledgerConfig();
PBFT_LOG(INFO) << LOG_DESC("fetchAndUpdateLedgerConfig success")
<< LOG_KV("blockNumber", ledgerConfig->blockNumber())
<< LOG_KV("hash", ledgerConfig->hash().abridged())
Expand All @@ -1798,15 +1794,3 @@ void PBFTEngine::switchToRPBFT(const LedgerConfig::Ptr& _ledgerConfig)
this->m_config->setRPBFTConfigTools(std::make_shared<RPBFTConfigTools>());
}
}
bool bcos::consensus::PBFTEngine::shouldRotateSealers(protocol::BlockNumber _number) const
{
if (m_config->rpbftConfigTools() == nullptr)
{
return false;
}
return m_config->rpbftConfigTools()->shouldRotateSealers(_number);
}
void bcos::consensus::PBFTEngine::setLedger(ledger::LedgerInterface::Ptr ledger)
{
m_ledger = std::move(ledger);
}
2 changes: 1 addition & 1 deletion cmake/ProjectGroupSig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ file(MAKE_DIRECTORY ${GROUPSIG_INCLUDE_DIR}) # Must exist.

find_package(cryptopp CONFIG REQUIRED)
set_property(TARGET GroupSig PROPERTY IMPORTED_LOCATION ${GROUPSIG_LIBRARY})
set_property(TARGET GroupSig PROPERTY INTERFACE_LINK_LIBRARIES PbcSig Pbc Gmp cryptopp-static)
set_property(TARGET GroupSig PROPERTY INTERFACE_LINK_LIBRARIES PbcSig Pbc Gmp cryptopp::cryptopp)
set_property(TARGET GroupSig PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${GROUPSIG_INCLUDE_DIR} ${DEPS_INCLUDE_DIR})
add_dependencies(GroupSig GroupSigLib)
unset(SOURCE_DIR)
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
Loading

0 comments on commit cc64a1c

Please sign in to comment.