From 164e9c046737551d6a420e2f7ec5368a2c500286 Mon Sep 17 00:00:00 2001 From: JimmyShi22 <417711026@qq.com> Date: Thu, 25 Jan 2024 22:58:46 +0800 Subject: [PATCH] support deploy with value --- .../src/executive/TransactionExecutive.cpp | 34 +++++++++++++------ .../extension/AccountPrecompiled.cpp | 2 +- bcos-executor/src/vm/HostContext.cpp | 8 +++++ bcos-executor/src/vm/HostContext.h | 1 + 4 files changed, 34 insertions(+), 11 deletions(-) diff --git a/bcos-executor/src/executive/TransactionExecutive.cpp b/bcos-executor/src/executive/TransactionExecutive.cpp index 0ba3d201a5..09a48f7a8c 100644 --- a/bcos-executor/src/executive/TransactionExecutive.cpp +++ b/bcos-executor/src/executive/TransactionExecutive.cpp @@ -562,16 +562,30 @@ std::tuple, CallParameters::UniquePtr> TransactionE // Create table try { - m_storageWrapper->createTable(tableName, std::string(STORAGE_VALUE)); - EXECUTIVE_LOG(DEBUG) << "create contract table " << LOG_KV("table", tableName) - << LOG_KV("sender", callParameters->senderAddress); - if (m_blockContext.isAuthCheck() || - (!m_blockContext.isWasm() && - m_blockContext.blockVersion() >= BlockVersion::V3_3_VERSION)) + if (callParameters->value == 0) + { + // only create table when value is 0 need to create table, if value > 0, table is + // created in accountPrecompiled addBalance() + m_storageWrapper->createTable(tableName, std::string(STORAGE_VALUE)); + + + EXECUTIVE_LOG(DEBUG) << "create contract table " << LOG_KV("table", tableName) + << LOG_KV("sender", callParameters->senderAddress); + if (m_blockContext.isAuthCheck() || + (!m_blockContext.isWasm() && + m_blockContext.blockVersion() >= BlockVersion::V3_3_VERSION)) + { + // Create auth table, always create auth table when version >= 3.3.0 + creatAuthTable(tableName, callParameters->origin, callParameters->senderAddress, + m_blockContext.blockVersion()); + } + } + else { - // Create auth table, always create auth table when version >= 3.3.0 - creatAuthTable(tableName, callParameters->origin, callParameters->senderAddress, - m_blockContext.blockVersion()); + EXECUTIVE_LOG(DEBUG) << "no need create contract table when deploy with value " + << LOG_KV("table", tableName) + << LOG_KV("sender", callParameters->senderAddress) + << LOG_KV("value", callParameters->value); } if (m_blockContext.features().get(ledger::Features::Flag::feature_sharding)) @@ -769,7 +783,7 @@ CallParameters::UniquePtr TransactionExecutive::go( evmcMessage.flags = flags; evmcMessage.depth = 0; // depth own by scheduler evmcMessage.gas = leftGas; - evmcMessage.value = toEvmC(h256(0)); + evmcMessage.value = toEvmC(hostContext.value()); evmcMessage.create2_salt = toEvmC(0x0_cppui256); if (blockContext.isWasm()) diff --git a/bcos-executor/src/precompiled/extension/AccountPrecompiled.cpp b/bcos-executor/src/precompiled/extension/AccountPrecompiled.cpp index e7d4f2bcda..4c58d1c9e6 100644 --- a/bcos-executor/src/precompiled/extension/AccountPrecompiled.cpp +++ b/bcos-executor/src/precompiled/extension/AccountPrecompiled.cpp @@ -300,7 +300,7 @@ void AccountPrecompiled::addAccountBalance(const std::string& accountTableName, if (response->status != (int32_t)TransactionStatus::None) { - PRECOMPILED_LOG(INFO) << LOG_BADGE("AccountManagerPrecompiled") + PRECOMPILED_LOG(INFO) << LOG_BADGE("AccountPrecompiled") << LOG_DESC("createAccount failed") << LOG_KV("accountTableName", accountTableName) << LOG_KV("status", response->status); diff --git a/bcos-executor/src/vm/HostContext.cpp b/bcos-executor/src/vm/HostContext.cpp index 5cd5daca45..b855f98681 100644 --- a/bcos-executor/src/vm/HostContext.cpp +++ b/bcos-executor/src/vm/HostContext.cpp @@ -382,6 +382,14 @@ bool HostContext::setCode(bytes code) // dry code hash in account table m_executive->storage().setRow(m_tableName, ACCOUNT_CODE_HASH, std::move(codeHashEntry)); + + if (features().get(ledger::Features::Flag::feature_balance)) + { + // update account's special code + Entry entryToDelete; + entryToDelete.setStatus(Entry::DELETED); + m_executive->storage().setRow(m_tableName, ACCOUNT_CODE, std::move(entryToDelete)); + } return true; } return false; diff --git a/bcos-executor/src/vm/HostContext.h b/bcos-executor/src/vm/HostContext.h index 8c97e9cdf9..af706ceb3a 100644 --- a/bcos-executor/src/vm/HostContext.h +++ b/bcos-executor/src/vm/HostContext.h @@ -132,6 +132,7 @@ class HostContext : public evmc_host_context bool isCreate() const { return m_callParameters->create; } bool staticCall() const { return m_callParameters->staticCall; } int64_t gas() const { return m_callParameters->gas; } + u256 value() const { return m_callParameters->value; } void suicide() { m_executive->setContractTableChanged();