From bc469c6ea7b428654bb5ad29c848cf508d425cd5 Mon Sep 17 00:00:00 2001 From: XingQiang Bai Date: Mon, 19 Feb 2024 09:27:53 +0800 Subject: [PATCH 01/12] fix keypage hash is inconsistent with stateStorage (#4230) --- CMakeLists.txt | 2 +- .../src/executor/TransactionExecutor.cpp | 3 +- .../bcos-framework/ledger/Features.h | 5 +- .../bcos-framework/protocol/Protocol.h | 3 +- .../unittests/interfaces/FeaturesTest.cpp | 1 + bcos-table/src/KeyPageStorage.cpp | 14 +- bcos-table/src/KeyPageStorage.h | 8 +- bcos-table/src/LegacyStorageWrapper.h | 2 +- bcos-table/src/StateStorage.h | 9 +- bcos-table/src/StateStorageInterface.h | 3 +- bcos-table/test/unittests/libtable/Table.cpp | 4 +- .../unittests/libtable/TestKeyPageStorage.cpp | 179 +++++++++++------- .../unittests/libtable/TestStateStorage.cpp | 73 +++---- tests/perf/benchmark.cpp | 5 +- tools/.ci/console_ci_test.sh | 30 ++- tools/.ci/java_sdk_ci_test.sh | 35 ++-- 16 files changed, 229 insertions(+), 147 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2f4827634b..b319b5e2b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/bcos-executor/src/executor/TransactionExecutor.cpp b/bcos-executor/src/executor/TransactionExecutor.cpp index a74df513c6..119c8aa650 100644 --- a/bcos-executor/src/executor/TransactionExecutor.cpp +++ b/bcos-executor/src/executor/TransactionExecutor.cpp @@ -1134,8 +1134,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)); diff --git a/bcos-framework/bcos-framework/ledger/Features.h b/bcos-framework/bcos-framework/ledger/Features.h index 6ddda2c824..3bf1c2ed35 100644 --- a/bcos-framework/bcos-framework/ledger/Features.h +++ b/bcos-framework/bcos-framework/ledger/Features.h @@ -35,6 +35,7 @@ class Features bugfix_call_noaddr_return, bugfix_precompiled_codehash, bugfix_dmc_revert, + bugfix_keypage_system_entry_hash, feature_dmc2serial, feature_sharding, feature_rpbft, @@ -138,7 +139,9 @@ class Features {Flag::bugfix_statestorage_hash, Flag::bugfix_evm_create2_delegatecall_staticcall_codecopy, Flag::bugfix_event_log_order, Flag::bugfix_call_noaddr_return, - Flag::bugfix_precompiled_codehash, Flag::bugfix_dmc_revert}}}); + Flag::bugfix_precompiled_codehash, Flag::bugfix_dmc_revert}}, + {protocol::BlockVersion::V3_6_1_VERSION, + {Flag::bugfix_keypage_system_entry_hash}}}); for (const auto& upgradeFeatures : upgradeRoadmap) { diff --git a/bcos-framework/bcos-framework/protocol/Protocol.h b/bcos-framework/bcos-framework/protocol/Protocol.h index e896e5aa6a..06642ae5b9 100644 --- a/bcos-framework/bcos-framework/protocol/Protocol.h +++ b/bcos-framework/bcos-framework/protocol/Protocol.h @@ -115,6 +115,7 @@ enum ProtocolVersion : uint32_t enum class BlockVersion : uint32_t { + V3_6_1_VERSION = 0x03060100, V3_6_VERSION = 0x03060000, V3_5_VERSION = 0x03050000, V3_4_VERSION = 0x03040000, @@ -130,7 +131,7 @@ enum class BlockVersion : uint32_t V3_0_VERSION = 0x03000000, RC4_VERSION = 4, MIN_VERSION = RC4_VERSION, - MAX_VERSION = V3_6_VERSION, + MAX_VERSION = V3_6_1_VERSION, }; enum class TransactionVersion : uint32_t diff --git a/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp b/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp index 03f5e28a2d..a279a0f018 100644 --- a/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp +++ b/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp @@ -135,6 +135,7 @@ BOOST_AUTO_TEST_CASE(feature) "bugfix_call_noaddr_return", "bugfix_precompiled_codehash", "bugfix_dmc_revert", + "bugfix_keypage_system_entry_hash", "feature_dmc2serial", "feature_sharding", "feature_rpbft", diff --git a/bcos-table/src/KeyPageStorage.cpp b/bcos-table/src/KeyPageStorage.cpp index 941a191802..ca9b5bef3b 100644 --- a/bcos-table/src/KeyPageStorage.cpp +++ b/bcos-table/src/KeyPageStorage.cpp @@ -361,8 +361,8 @@ void KeyPageStorage::parallelTraverse(bool onlyDirty, KeyPage_LOG(INFO) << LOG_DESC("parallelTraverse") << LOG_KV("size", m_size); } -auto KeyPageStorage::hash(const bcos::crypto::Hash::Ptr& hashImpl, bool /*useHashV310*/) const - -> crypto::HashType +auto KeyPageStorage::hash(const bcos::crypto::Hash::Ptr& hashImpl, + const ledger::Features& features) const -> crypto::HashType { bcos::crypto::HashType pagesHash(0); bcos::crypto::HashType entriesHash(0); @@ -397,9 +397,12 @@ auto KeyPageStorage::hash(const bcos::crypto::Hash::Ptr& hashImpl, bool /*useHas } else { // sys table - auto hash = hashImpl->hash(data->table); - hash ^= hashImpl->hash(data->key); - hash ^= entry.hash(data->table, data->key, *hashImpl, m_blockVersion); + auto hash = entry.hash(data->table, data->key, *hashImpl, m_blockVersion); + if (!features.get(ledger::Features::Flag::bugfix_keypage_system_entry_hash)) + { // v3.6.1 open this bugfix default + hash ^= hashImpl->hash(data->table); + hash ^= hashImpl->hash(data->key); + } localEntriesHash ^= hash; ++entrycount; } @@ -413,6 +416,7 @@ auto KeyPageStorage::hash(const bcos::crypto::Hash::Ptr& hashImpl, bool /*useHas totalHash ^= pagesHash; totalHash ^= entriesHash; KeyPage_LOG(INFO) << LOG_DESC("hash") << LOG_KV("size", allData.size()) + << LOG_KV("blockVersion", m_blockVersion) << LOG_KV("readLength", m_readLength) << LOG_KV("writeLength", m_writeLength) << LOG_KV("pageCount", pageCount) << LOG_KV("entrycount", entrycount) << LOG_KV("entriesHash", entriesHash.hex()) diff --git a/bcos-table/src/KeyPageStorage.h b/bcos-table/src/KeyPageStorage.h index a2da4ccd28..832737dda0 100644 --- a/bcos-table/src/KeyPageStorage.h +++ b/bcos-table/src/KeyPageStorage.h @@ -144,7 +144,7 @@ class KeyPageStorage : public virtual storage::StateStorageInterface callback) const override; crypto::HashType hash( - const bcos::crypto::Hash::Ptr& hashImpl, bool /*useHashV310*/) const override; + const bcos::crypto::Hash::Ptr& hashImpl, const ledger::Features& features) const override; void rollback(const Recoder& recoder) override; @@ -889,9 +889,9 @@ class KeyPageStorage : public virtual storage::StateStorageInterface if (!entries.empty() && pageKey != entries.rbegin()->first) { KeyPage_LOG(DEBUG) << LOG_DESC("import page with invalid pageKey") - << LOG_KV("pageKey", toHex(pageKey)) - << LOG_KV("validPageKey", toHex(entries.rbegin()->first)) - << LOG_KV("count", entries.size()); + << LOG_KV("pageKey", toHex(pageKey)) + << LOG_KV("validPageKey", toHex(entries.rbegin()->first)) + << LOG_KV("count", entries.size()); m_invalidPageKeys.insert(std::string(pageKey)); } if (entries.empty()) diff --git a/bcos-table/src/LegacyStorageWrapper.h b/bcos-table/src/LegacyStorageWrapper.h index bdd5e7de25..7e4e056ca6 100644 --- a/bcos-table/src/LegacyStorageWrapper.h +++ b/bcos-table/src/LegacyStorageWrapper.h @@ -150,7 +150,7 @@ class LegacyStateStorageWrapper : public virtual storage::StateStorageInterface, } crypto::HashType hash( - const bcos::crypto::Hash::Ptr& hashImpl, bool /*useHashV310*/) const override + const bcos::crypto::Hash::Ptr& hashImpl, const ledger::Features& features) const override { BOOST_THROW_EXCEPTION(std::runtime_error("Unimplemented!")); } diff --git a/bcos-table/src/StateStorage.h b/bcos-table/src/StateStorage.h index a5de77d03a..6266554fdd 100644 --- a/bcos-table/src/StateStorage.h +++ b/bcos-table/src/StateStorage.h @@ -391,11 +391,13 @@ class BaseStorage : public virtual storage::StateStorageInterface, STORAGE_LOG(INFO) << "Successful merged records" << LOG_KV("count", count); } - crypto::HashType hash(const bcos::crypto::Hash::Ptr& hashImpl, bool useHashV310) const override + crypto::HashType hash( + const bcos::crypto::Hash::Ptr& hashImpl, const ledger::Features& features) const override { bcos::crypto::HashType totalHash; - auto blockVersion = useHashV310 ? (uint32_t)bcos::protocol::BlockVersion::V3_1_VERSION : - (uint32_t)bcos::protocol::BlockVersion::V3_0_VERSION; + auto blockVersion = features.get(ledger::Features::Flag::bugfix_statestorage_hash) ? + (uint32_t)bcos::protocol::BlockVersion::V3_1_VERSION : + (uint32_t)bcos::protocol::BlockVersion::V3_0_VERSION; std::vector hashes(m_buckets.size()); tbb::parallel_for(tbb::blocked_range(0U, m_buckets.size()), [&, this]( @@ -434,7 +436,6 @@ class BaseStorage : public virtual storage::StateStorageInterface, totalHash ^= it; } - return totalHash; } diff --git a/bcos-table/src/StateStorageInterface.h b/bcos-table/src/StateStorageInterface.h index 2a0a8b8f5b..a23f16a6e6 100644 --- a/bcos-table/src/StateStorageInterface.h +++ b/bcos-table/src/StateStorageInterface.h @@ -20,6 +20,7 @@ */ #pragma once +#include "bcos-framework/ledger/Features.h" #include "bcos-framework/storage/StorageInterface.h" #include "bcos-framework/storage/Table.h" #include "tbb/enumerable_thread_specific.h" @@ -107,7 +108,7 @@ class StateStorageInterface : public virtual storage::TraverseStorageInterface } virtual crypto::HashType hash( - const bcos::crypto::Hash::Ptr& hashImpl, bool useHashV310) const = 0; + const bcos::crypto::Hash::Ptr& hashImpl, const ledger::Features& features) const = 0; virtual void setPrev(std::shared_ptr prev) { std::unique_lock lock(m_prevMutex); diff --git a/bcos-table/test/unittests/libtable/Table.cpp b/bcos-table/test/unittests/libtable/Table.cpp index ec3b707dad..cc7d6084a9 100644 --- a/bcos-table/test/unittests/libtable/Table.cpp +++ b/bcos-table/test/unittests/libtable/Table.cpp @@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE(removeFromCache) deleteEntry->setStatus(Entry::DELETED); BOOST_CHECK_NO_THROW(table->setRow("name", *deleteEntry)); - auto hashs = tableFactory->hash(hashImpl, false); + auto hashs = tableFactory->hash(hashImpl, ledger::Features()); auto tableFactory2 = std::make_shared(nullptr); BOOST_CHECK(tableFactory2->createTable(tableName, valueField)); @@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(removeFromCache) auto deleteEntry2 = std::make_optional(table2->newEntry()); deleteEntry2->setStatus(Entry::DELETED); BOOST_CHECK_NO_THROW(table2->setRow("name", *deleteEntry2)); - auto hashs2 = tableFactory2->hash(hashImpl, false); + auto hashs2 = tableFactory2->hash(hashImpl, ledger::Features()); BOOST_CHECK_EQUAL_COLLECTIONS(hashs.begin(), hashs.end(), hashs2.begin(), hashs2.end()); } diff --git a/bcos-table/test/unittests/libtable/TestKeyPageStorage.cpp b/bcos-table/test/unittests/libtable/TestKeyPageStorage.cpp index a4730c314a..f8a67be711 100644 --- a/bcos-table/test/unittests/libtable/TestKeyPageStorage.cpp +++ b/bcos-table/test/unittests/libtable/TestKeyPageStorage.cpp @@ -19,6 +19,7 @@ #include "Hash.h" #include "bcos-crypto/hash/Keccak256.h" +#include "bcos-framework/ledger/Features.h" #include "bcos-framework/storage/StorageInterface.h" #include "bcos-table/src/KeyPageStorage.h" #include "bcos-table/src/StateStorage.h" @@ -114,6 +115,7 @@ struct KeyPageStorageFixture std::string keyField = "key"; std::string valueField = "value"; Condition c; + ledger::Features features; }; BOOST_FIXTURE_TEST_SUITE(KeyPageStorageTest, KeyPageStorageFixture) @@ -163,7 +165,7 @@ BOOST_AUTO_TEST_CASE(rollback) deleteEntry.setStatus(Entry::DELETED); BOOST_REQUIRE_NO_THROW(table->setRow("name", deleteEntry)); - auto hash = tableFactory->hash(hashImpl, false); + auto hash = tableFactory->hash(hashImpl, features); auto countRet = tableFactory->count(testTableName); BOOST_REQUIRE_EQUAL(countRet.first, 0); @@ -182,7 +184,7 @@ BOOST_AUTO_TEST_CASE(rollback) countRet = tableFactory->count(testTableName); BOOST_REQUIRE_EQUAL(countRet.first, 1); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); @@ -191,7 +193,7 @@ BOOST_AUTO_TEST_CASE(rollback) BOOST_REQUIRE(entry.has_value()); BOOST_REQUIRE(entry->dirty() == true); BOOST_REQUIRE(entry->getField(0) == "Lili"); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); @@ -204,21 +206,21 @@ BOOST_AUTO_TEST_CASE(rollback) table->setRow("id", *entry); countRet = tableFactory->count(testTableName); BOOST_REQUIRE_EQUAL(countRet.first, 2); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("id"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); @@ -231,21 +233,21 @@ BOOST_AUTO_TEST_CASE(rollback) table->setRow("balance", *entry); countRet = tableFactory->count(testTableName); BOOST_REQUIRE_EQUAL(countRet.first, 3); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("2b7be3797d97dcf7000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("balance"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("2b7be3797d97dcf7000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("2b7be3797d97dcf7000000000000000000000000000000000000000000000000").hex()); @@ -257,7 +259,7 @@ BOOST_AUTO_TEST_CASE(rollback) table->setRow("name", *deleteEntry2); countRet = tableFactory->count(testTableName); BOOST_REQUIRE_EQUAL(countRet.first, 2); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); // delete entry will cause hash mismatch #if defined(__APPLE__) @@ -266,7 +268,7 @@ BOOST_AUTO_TEST_CASE(rollback) #endif entry = table->getRow("name"); BOOST_REQUIRE(!entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("4160d337ddd671e0000000000000000000000000000000000000000000000001").hex()); @@ -275,14 +277,14 @@ BOOST_AUTO_TEST_CASE(rollback) tableFactory->rollback(*savePoint2); countRet = tableFactory->count(testTableName); BOOST_REQUIRE_EQUAL(countRet.first, 3); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("2b7be3797d97dcf7000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("name"); BOOST_REQUIRE_NE(entry->status(), Entry::DELETED); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("2b7be3797d97dcf7000000000000000000000000000000000000000000000000").hex()); @@ -290,21 +292,21 @@ BOOST_AUTO_TEST_CASE(rollback) tableFactory->rollback(*savePoint1); countRet = tableFactory->count(testTableName); BOOST_REQUIRE_EQUAL(countRet.first, 2); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("balance"); BOOST_REQUIRE(!entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); @@ -315,21 +317,21 @@ BOOST_AUTO_TEST_CASE(rollback) BOOST_REQUIRE_EQUAL(countRet.first, 1); entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("balance"); BOOST_REQUIRE(!entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("id"); BOOST_REQUIRE(!entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); @@ -341,7 +343,7 @@ BOOST_AUTO_TEST_CASE(rollback) BOOST_REQUIRE_NO_THROW(table->setRow("id", *entry)); countRet = tableFactory->count(testTableName); BOOST_REQUIRE_EQUAL(countRet.first, 2); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("2c14904fc33bbbae000000000000000000000000000000000000000000000000").hex()); @@ -351,7 +353,7 @@ BOOST_AUTO_TEST_CASE(rollback) BOOST_REQUIRE_NO_THROW(table->setRow("id", *entry)); countRet = tableFactory->count(testTableName); BOOST_REQUIRE_EQUAL(countRet.first, 1); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); // delete entry will cause hash mismatch #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), @@ -361,7 +363,7 @@ BOOST_AUTO_TEST_CASE(rollback) BOOST_AUTO_TEST_CASE(rollback2) { - auto hash0 = tableFactory->hash(hashImpl, false); + auto hash0 = tableFactory->hash(hashImpl, features); // auto savePoint0 = tableFactory->savepoint(); auto savePoint0 = std::make_shared(); tableFactory->setRecoder(savePoint0); @@ -372,7 +374,7 @@ BOOST_AUTO_TEST_CASE(rollback2) auto deleteEntry = table->newDeletedEntry(); table->setRow("name", deleteEntry); - auto hash = tableFactory->hash(hashImpl, false); + auto hash = tableFactory->hash(hashImpl, features); // delete not exist entry will cause hash mismatch #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), @@ -382,14 +384,14 @@ BOOST_AUTO_TEST_CASE(rollback2) // entry->setField("key", "name"); entry->setField(0, "Lili"); table->setRow("name", *entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); @@ -405,21 +407,21 @@ BOOST_AUTO_TEST_CASE(rollback2) // entry->setField("key", "id"); entry->setField(0, "12345"); table->setRow("id", *entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("id"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); @@ -430,21 +432,21 @@ BOOST_AUTO_TEST_CASE(rollback2) entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("balance"); BOOST_REQUIRE(!entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("id"); BOOST_REQUIRE(!entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); @@ -452,12 +454,12 @@ BOOST_AUTO_TEST_CASE(rollback2) // BOOST_REQUIRE(table->dirty() == true); tableFactory->rollback(*savePoint0); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); BOOST_REQUIRE(hash.hex() == crypto::HashType("").hex()); entry = table->getRow("name"); BOOST_REQUIRE(!entry); - auto hash00 = tableFactory->hash(hashImpl, false); + auto hash00 = tableFactory->hash(hashImpl, features); BOOST_REQUIRE(hash00 == crypto::HashType(0)); BOOST_REQUIRE_EQUAL_COLLECTIONS(hash0.begin(), hash0.end(), hash00.begin(), hash00.end()); @@ -468,7 +470,7 @@ BOOST_AUTO_TEST_CASE(rollback2) BOOST_AUTO_TEST_CASE(rollback3) { - auto hash0 = tableFactory->hash(hashImpl, false); + auto hash0 = tableFactory->hash(hashImpl, features); // auto savePoint0 = tableFactory->savepoint(); auto savePoint0 = std::make_shared(); tableFactory->setRecoder(savePoint0); @@ -479,7 +481,7 @@ BOOST_AUTO_TEST_CASE(rollback3) auto entry = table->newEntry(); entry.set("value"); table->setRow("name", entry); - tableFactory->hash(hashImpl, false); + tableFactory->hash(hashImpl, features); // first rollback tableFactory->rollback(*savePoint0); @@ -543,7 +545,7 @@ BOOST_AUTO_TEST_CASE(hash) auto entries = table->getRows(keys); BOOST_REQUIRE(entries.size() == 2); - auto dbHash1 = tableFactory->hash(hashImpl, false); + auto dbHash1 = tableFactory->hash(hashImpl, features); auto savePoint = std::make_shared(); tableFactory->setRecoder(savePoint); @@ -561,7 +563,7 @@ BOOST_AUTO_TEST_CASE(hash) BOOST_REQUIRE(!entry); // BOOST_REQUIRE(table->dirty() == true); - auto dbHash2 = tableFactory->hash(hashImpl, false); + auto dbHash2 = tableFactory->hash(hashImpl, features); BOOST_REQUIRE_EQUAL(dbHash1.hex(), dbHash2.hex()); // getPrimaryKeys and getRows @@ -673,8 +675,8 @@ BOOST_AUTO_TEST_CASE(hash_V3_1_0) getRow.get_future().get(); } - auto dbHash1 = tableFactory1->hash(hashImpl, false); - auto dbHash2 = tableFactory2->hash(hashImpl, false); + auto dbHash1 = tableFactory1->hash(hashImpl, features); + auto dbHash2 = tableFactory2->hash(hashImpl, features); BOOST_REQUIRE_NE(dbHash1.hex(), dbHash2.hex()); } @@ -725,8 +727,8 @@ BOOST_AUTO_TEST_CASE(hash_different_table_same_data) }; setData1(tableFactory1); setData2(tableFactory2); - auto dbHash1 = tableFactory1->hash(hashImpl2, false); - auto dbHash2 = tableFactory2->hash(hashImpl2, false); + auto dbHash1 = tableFactory1->hash(hashImpl2, features); + auto dbHash2 = tableFactory2->hash(hashImpl2, features); BOOST_REQUIRE_EQUAL(dbHash1.hex(), dbHash2.hex()); auto tableFactory3 = make_shared( @@ -736,8 +738,8 @@ BOOST_AUTO_TEST_CASE(hash_different_table_same_data) setData1(tableFactory3); setData2(tableFactory4); - auto dbHash3 = tableFactory3->hash(hashImpl2, false); - auto dbHash4 = tableFactory4->hash(hashImpl2, false); + auto dbHash3 = tableFactory3->hash(hashImpl2, features); + auto dbHash4 = tableFactory4->hash(hashImpl2, features); BOOST_REQUIRE_NE(dbHash3.hex(), dbHash4.hex()); } @@ -1509,7 +1511,7 @@ BOOST_AUTO_TEST_CASE(randomRWHash) } } - hashes.push_back(storage->hash(hashImpl, false)); + hashes.push_back(storage->hash(hashImpl, features)); storage->setReadOnly(false); storage->setReadOnly(true); prev = storage; @@ -1714,7 +1716,7 @@ BOOST_AUTO_TEST_CASE(pageMergeRandom) // } } } - auto hash = tableStorage->hash(hashImpl, false); + auto hash = tableStorage->hash(hashImpl, features); // BOOST_TEST( // hash.hex() == // crypto::HashType("4d4a5c95180905cb000000000000000000000000000000000000000000000000").hex()); @@ -1740,7 +1742,7 @@ BOOST_AUTO_TEST_CASE(pageMergeRandom) } } - hash = tableStorage->hash(hashImpl, false); + hash = tableStorage->hash(hashImpl, features); // BOOST_TEST( // hash.hex() == // crypto::HashType("4d4a5c95180905cb000000000000000000000000000000000000000000000000").hex()); @@ -1770,7 +1772,7 @@ BOOST_AUTO_TEST_CASE(pageMergeRandom) } } - hash = tableStorage->hash(hashImpl, false); + hash = tableStorage->hash(hashImpl, features); // BOOST_TEST( // hash.hex() == // crypto::HashType("4d4a5c95180905cb000000000000000000000000000000000000000000000000").hex()); @@ -2288,11 +2290,11 @@ BOOST_AUTO_TEST_CASE(BigTableAdd) entry1->setField(0, value); BOOST_REQUIRE_NO_THROW(table1->setRow(key, *entry1)); } - auto hash0 = tableStorage0->hash(hashImpl, false); + auto hash0 = tableStorage0->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>KeyPageStorage0") << LOG_KV("i", i) << LOG_KV("hash", hash0.hex()); BOOST_REQUIRE(hash0.hex() != crypto::HashType(0).hex()); - auto hash1 = tableStorage1->hash(hashImpl, false); + auto hash1 = tableStorage1->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>KeyPageStorage1") << LOG_KV("i", i) << LOG_KV("hash", hash1.hex()); BOOST_REQUIRE(hash1.hex() != crypto::HashType(0).hex()); @@ -2303,10 +2305,10 @@ BOOST_AUTO_TEST_CASE(BigTableAdd) tableStorage1->setReadOnly(true); stateStorage0->merge(true, *tableStorage0); stateStorage1->merge(true, *tableStorage1); - hash0 = stateStorage0->hash(hashImpl, false); + hash0 = stateStorage0->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>stateStorage0") << LOG_KV("i", i) << LOG_KV("hash", hash0.hex()); - hash1 = stateStorage1->hash(hashImpl, false); + hash1 = stateStorage1->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>stateStorage1") << LOG_KV("i", i) << LOG_KV("hash", hash1.hex()); // BOOST_TEST(hash0.hex() == hash1.hex()); @@ -2362,11 +2364,11 @@ BOOST_AUTO_TEST_CASE(BigTableAddSerialize) entry1->setField(0, value); BOOST_REQUIRE_NO_THROW(table1->setRow(key, *entry1)); } - auto hash0 = tableStorage0->hash(hashImpl, false); + auto hash0 = tableStorage0->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>KeyPageStorage0") << LOG_KV("i", i) << LOG_KV("hash", hash0.hex()); BOOST_REQUIRE(hash0.hex() != crypto::HashType(0).hex()); - auto hash1 = tableStorage1->hash(hashImpl, false); + auto hash1 = tableStorage1->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>KeyPageStorage1") << LOG_KV("i", i) << LOG_KV("hash", hash1.hex()); BOOST_REQUIRE(hash0.hex() != crypto::HashType(0).hex()); @@ -2376,10 +2378,10 @@ BOOST_AUTO_TEST_CASE(BigTableAddSerialize) tableStorage1->setReadOnly(true); stateStorage0->merge(true, *tableStorage0); stateStorage1->merge(true, *tableStorage1); - hash0 = stateStorage0->hash(hashImpl, false); + hash0 = stateStorage0->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>stateStorage0") << LOG_KV("i", i) << LOG_KV("hash", hash0.hex()); - hash1 = stateStorage1->hash(hashImpl, false); + hash1 = stateStorage1->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>stateStorage1") << LOG_KV("i", i) << LOG_KV("hash", hash1.hex()); BOOST_TEST(hash0.hex() == hash1.hex()); @@ -2461,15 +2463,15 @@ BOOST_AUTO_TEST_CASE(mockCommitProcess) BOOST_REQUIRE(entry2); entry2 = table2->getRow(getKey); } - auto hash0 = tableStorage0->hash(hashImpl, false); + auto hash0 = tableStorage0->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>KeyPageStorage0") << LOG_KV("i", i) << LOG_KV("hash", hash0.hex()); BOOST_REQUIRE(hash0.hex() != crypto::HashType(0).hex()); - auto hash1 = tableStorage1->hash(hashImpl, false); + auto hash1 = tableStorage1->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>KeyPageStorage1") << LOG_KV("i", i) << LOG_KV("hash", hash1.hex()); BOOST_REQUIRE(hash1.hex() != crypto::HashType(0).hex()); - auto hash2 = tableStorage2->hash(hashImpl, false); + auto hash2 = tableStorage2->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>KeyPageStorage2") << LOG_KV("i", i) << LOG_KV("hash", hash2.hex()); BOOST_TEST(hash0.hex() == hash1.hex()); @@ -2579,15 +2581,15 @@ BOOST_AUTO_TEST_CASE(mockCommitProcessParallel) BOOST_REQUIRE(entry2); entry2 = table2->getRow(getKey); } - auto hash0 = tableStorage0->hash(hashImpl, false); + auto hash0 = tableStorage0->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>KeyPageStorage0") << LOG_KV("i", i) << LOG_KV("hash", hash0.hex()); BOOST_REQUIRE(hash0.hex() != crypto::HashType(0).hex()); - auto hash1 = tableStorage1->hash(hashImpl, false); + auto hash1 = tableStorage1->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>KeyPageStorage1") << LOG_KV("i", i) << LOG_KV("hash", hash1.hex()); BOOST_REQUIRE(hash1.hex() != crypto::HashType(0).hex()); - auto hash2 = tableStorage2->hash(hashImpl, false); + auto hash2 = tableStorage2->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>KeyPageStorage2") << LOG_KV("i", i) << LOG_KV("hash", hash2.hex()); BOOST_TEST(hash0.hex() == hash1.hex()); @@ -2837,13 +2839,13 @@ BOOST_AUTO_TEST_CASE(insertAndDelete) BOOST_REQUIRE_NO_THROW(table0->setRow(key, *entry0)); } } - auto hash0 = tableStorage0->hash(hashImpl, false); + auto hash0 = tableStorage0->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>KeyPageStorage0") << LOG_KV("i", i) << LOG_KV("hash", hash0.hex()); BOOST_TEST(hash0.hex() != crypto::HashType(0).hex()); tableStorage0->setReadOnly(true); stateStorage0->merge(true, *tableStorage0); - hash0 = stateStorage0->hash(hashImpl, false); + hash0 = stateStorage0->hash(hashImpl, features); BCOS_LOG(DEBUG) << LOG_DESC(">>>>>>>>>>>>stateStorage0") << LOG_KV("i", i) << LOG_KV("hash", hash0.hex()); index += keyCount; @@ -3015,8 +3017,8 @@ BOOST_AUTO_TEST_CASE(TableMeta_read_write_mutex) auto meta = std::make_shared(); for (int i = 0; i < loop; ++i) { - meta->insertPageInfoNoLock(storage::KeyPageStorage::PageInfo( - std::to_string(i), i % 2 == 0 ? 0 : i, i, nullptr)); + meta->insertPageInfoNoLock( + storage::KeyPageStorage::PageInfo(std::to_string(i), i % 2 == 0 ? 0 : i, i, nullptr)); } std::shared_ptr threadPool = std::make_shared("test", 2); auto promise = std::make_shared>(); @@ -3047,5 +3049,52 @@ BOOST_AUTO_TEST_CASE(TableMeta_read_write_mutex) std::cout << "==================== test end" << std::endl; // boost::log::core::get()->set_logging_enabled(false); } + + +BOOST_AUTO_TEST_CASE(bugfix_keypage_system_entry_hash) +{ + auto valueFields = "value1"; + auto cacheSize = 256 * 1024 * 1024; + auto pageSize = 512; + auto stateStorage0 = make_shared(nullptr); + stateStorage0->setMaxCapacity(cacheSize); + StateStorageInterface::Ptr prev0 = stateStorage0; + + auto tableName = "table_0"; + BOOST_REQUIRE(prev0->createTable(tableName, valueFields)); + + + auto getHashLambda = [&](std::shared_ptr storage, + const ledger::Features& f) { + auto table0 = storage->openTable(tableName); + BOOST_REQUIRE(table0); + auto key = "1"; + auto value = "value"; + auto entry0 = std::make_optional(table0->newEntry()); + entry0->setField(0, value); + BOOST_REQUIRE_NO_THROW(table0->setRow(key, *entry0)); + auto entry = std::make_optional(table0->newEntry()); + entry->setField(0, value); + storage->asyncSetRow(ledger::SYS_TABLES, "1", *entry, [](Error::UniquePtr) {}); + return storage->hash(hashImpl, f); + }; + auto keypage = std::make_shared( + prev0, pageSize, (uint32_t)protocol::BlockVersion::V3_6_1_VERSION); + auto state = std::make_shared(prev0); + auto hash0 = getHashLambda(keypage, features); + auto hash1 = getHashLambda(state, features); + BOOST_TEST(hash0.hex() != hash1.hex()); + + features.set(ledger::Features::Flag::bugfix_statestorage_hash); + hash0 = getHashLambda(keypage, features); + hash1 = getHashLambda(state, features); + BOOST_TEST(hash0.hex() != hash1.hex()); + + features.set(ledger::Features::Flag::bugfix_keypage_system_entry_hash); + hash0 = getHashLambda(keypage, features); + hash1 = getHashLambda(state, features); + BOOST_TEST(hash0.hex() == hash1.hex()); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace bcos::test diff --git a/bcos-table/test/unittests/libtable/TestStateStorage.cpp b/bcos-table/test/unittests/libtable/TestStateStorage.cpp index 5534fd7223..8825d18fae 100644 --- a/bcos-table/test/unittests/libtable/TestStateStorage.cpp +++ b/bcos-table/test/unittests/libtable/TestStateStorage.cpp @@ -104,6 +104,7 @@ struct TableFactoryFixture std::string testTableName = "t_test"; std::string keyField = "key"; std::string valueField = "value"; + ledger::Features features; }; BOOST_FIXTURE_TEST_SUITE(StateStorageTest, TableFactoryFixture) @@ -138,7 +139,7 @@ BOOST_AUTO_TEST_CASE(rollback) deleteEntry.setStatus(Entry::DELETED); BOOST_REQUIRE_NO_THROW(table->setRow("name", deleteEntry)); - auto hash = tableFactory->hash(hashImpl, false); + auto hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), @@ -148,7 +149,7 @@ BOOST_AUTO_TEST_CASE(rollback) BOOST_REQUIRE_NO_THROW(entry->setField(0, "Lili")); BOOST_REQUIRE_NO_THROW(table->setRow("name", *entry)); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); @@ -157,7 +158,7 @@ BOOST_AUTO_TEST_CASE(rollback) BOOST_REQUIRE(entry.has_value()); BOOST_REQUIRE(entry->dirty() == true); BOOST_REQUIRE(entry->getField(0) == "Lili"); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); @@ -168,21 +169,21 @@ BOOST_AUTO_TEST_CASE(rollback) entry = table->newEntry(); entry->setField(0, "12345"); table->setRow("id", *entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("id"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); @@ -193,21 +194,21 @@ BOOST_AUTO_TEST_CASE(rollback) entry = table->newEntry(); entry->setField(0, "500"); table->setRow("balance", *entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("2b7be3797d97dcf7000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("balance"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("2b7be3797d97dcf7000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("2b7be3797d97dcf7000000000000000000000000000000000000000000000000").hex()); @@ -217,7 +218,7 @@ BOOST_AUTO_TEST_CASE(rollback) auto deleteEntry2 = std::make_optional(table->newDeletedEntry()); table->setRow("name", *deleteEntry2); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); // delete entry will cause hash mismatch #if defined(__APPLE__) @@ -226,41 +227,41 @@ BOOST_AUTO_TEST_CASE(rollback) #endif entry = table->getRow("name"); BOOST_REQUIRE(!entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("4160d337ddd671e0000000000000000000000000000000000000000000000001").hex()); #endif std::cout << "Try remove balance" << std::endl; tableFactory->rollback(*savePoint2); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("2b7be3797d97dcf7000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("name"); BOOST_REQUIRE_NE(entry->status(), Entry::DELETED); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("2b7be3797d97dcf7000000000000000000000000000000000000000000000000").hex()); #endif tableFactory->rollback(*savePoint1); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("balance"); BOOST_REQUIRE(!entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); @@ -269,21 +270,21 @@ BOOST_AUTO_TEST_CASE(rollback) tableFactory->rollback(*savePoint); entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("balance"); BOOST_REQUIRE(!entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("id"); BOOST_REQUIRE(!entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); @@ -293,7 +294,7 @@ BOOST_AUTO_TEST_CASE(rollback) entry = table->newEntry(); entry->setField(0, "new record"); BOOST_REQUIRE_NO_THROW(table->setRow("id", *entry)); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("2c14904fc33bbbae000000000000000000000000000000000000000000000000").hex()); @@ -301,7 +302,7 @@ BOOST_AUTO_TEST_CASE(rollback) entry = table->newDeletedEntry(); BOOST_REQUIRE_NO_THROW(table->setRow("id", *entry)); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); // delete entry will cause hash mismatch #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), @@ -311,7 +312,7 @@ BOOST_AUTO_TEST_CASE(rollback) BOOST_AUTO_TEST_CASE(rollback2) { - auto hash0 = tableFactory->hash(hashImpl, false); + auto hash0 = tableFactory->hash(hashImpl, features); // auto savePoint0 = tableFactory->savepoint(); auto savePoint0 = std::make_shared(); tableFactory->setRecoder(savePoint0); @@ -322,7 +323,7 @@ BOOST_AUTO_TEST_CASE(rollback2) auto deleteEntry = table->newDeletedEntry(); table->setRow("name", deleteEntry); - auto hash = tableFactory->hash(hashImpl, false); + auto hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("ab98649ca506b076000000000000000000000000000000000000000000000001").hex()); @@ -331,14 +332,14 @@ BOOST_AUTO_TEST_CASE(rollback2) // entry->setField("key", "name"); entry->setField(0, "Lili"); table->setRow("name", *entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); @@ -354,21 +355,21 @@ BOOST_AUTO_TEST_CASE(rollback2) // entry->setField("key", "id"); entry->setField(0, "12345"); table->setRow("id", *entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("id"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("d26dbc9a92ed28b1000000000000000000000000000000000000000000000000").hex()); @@ -379,21 +380,21 @@ BOOST_AUTO_TEST_CASE(rollback2) entry = table->getRow("name"); BOOST_REQUIRE(entry.has_value()); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("balance"); BOOST_REQUIRE(!entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); #endif entry = table->getRow("id"); BOOST_REQUIRE(!entry); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); #if defined(__APPLE__) BOOST_CHECK_EQUAL(hash.hex(), crypto::HashType("c18354d205471d61000000000000000000000000000000000000000000000000").hex()); @@ -401,12 +402,12 @@ BOOST_AUTO_TEST_CASE(rollback2) // BOOST_REQUIRE(table->dirty() == true); tableFactory->rollback(*savePoint0); - hash = tableFactory->hash(hashImpl, false); + hash = tableFactory->hash(hashImpl, features); BOOST_REQUIRE(hash.hex() == crypto::HashType("").hex()); entry = table->getRow("name"); BOOST_REQUIRE(!entry); - auto hash00 = tableFactory->hash(hashImpl, false); + auto hash00 = tableFactory->hash(hashImpl, features); BOOST_REQUIRE(hash00 == crypto::HashType(0)); BOOST_REQUIRE_EQUAL_COLLECTIONS(hash0.begin(), hash0.end(), hash00.begin(), hash00.end()); @@ -450,7 +451,7 @@ BOOST_AUTO_TEST_CASE(hash) auto entries = table->getRows(keys); BOOST_TEST(entries.size() == 2); - auto dbHash1 = tableFactory->hash(hashImpl, false); + auto dbHash1 = tableFactory->hash(hashImpl, features); auto savePoint = std::make_shared(); tableFactory->setRecoder(savePoint); @@ -468,7 +469,7 @@ BOOST_AUTO_TEST_CASE(hash) BOOST_TEST(!entry); // BOOST_TEST(table->dirty() == true); - auto dbHash2 = tableFactory->hash(hashImpl, false); + auto dbHash2 = tableFactory->hash(hashImpl, features); BOOST_CHECK_EQUAL(dbHash1.hex(), dbHash2.hex()); // getPrimaryKeys and getRows @@ -1133,7 +1134,7 @@ BOOST_AUTO_TEST_CASE(randomRWHash) } } - hashes.push_back(storage->hash(hashImpl, false)); + hashes.push_back(storage->hash(hashImpl, features)); storage->setReadOnly(false); prev = storage; } diff --git a/tests/perf/benchmark.cpp b/tests/perf/benchmark.cpp index c9d96465e9..ecab3be426 100644 --- a/tests/perf/benchmark.cpp +++ b/tests/perf/benchmark.cpp @@ -1,4 +1,5 @@ #include "bcos-crypto/hash/Keccak256.h" +#include "bcos-framework/ledger/Features.h" #include "bcos-framework/storage/StorageInterface.h" #include "bcos-storage/RocksDBStorage.h" #include "bcos-table/src/KeyPageStorage.h" @@ -172,10 +173,12 @@ int main(int argc, const char* argv[]) auto onlyWriteReadEnd = std::chrono::system_clock::now(); // commit and read auto hashImpl = std::make_shared(); + ledger::Features features; + features.set(ledger::Features::Flag::bugfix_keypage_system_entry_hash); for (int i = 0; i < storageChainLength && !onlyWrite; ++i) { auto s = storages[i]; - s->hash(hashImpl, true); + s->hash(hashImpl, features); TraverseStorageInterface::Ptr t = std::dynamic_pointer_cast(s); bcos::protocol::TwoPCParams p; diff --git a/tools/.ci/console_ci_test.sh b/tools/.ci/console_ci_test.sh index 2f58bd4c4d..1d8fe40b05 100644 --- a/tools/.ci/console_ci_test.sh +++ b/tools/.ci/console_ci_test.sh @@ -15,7 +15,7 @@ LOG_INFO() { download_console() { cd ${current_path} - + LOG_INFO "Pull console, branch: ${console_branch} ..." console_file=console if [ -d ${console_file} ] && [ -d "${console_file}/.git" ]; then @@ -24,16 +24,26 @@ download_console() git fetch --all rm -rf build log dist git reset --hard - git checkout ${console_branch} + # check if console_branch exists + if [ -n "$(git branch -a | grep origin/${console_branch})" ]; then + git checkout origin/${console_branch} + else + git checkout origin/master + fi if [ $? -ne 0 ]; then cd .. rm -rf ${console_file} - git clone -b ${console_branch} https://github.com/FISCO-BCOS/console.git + git clone https://github.com/FISCO-BCOS/console.git fi - git pull else rm -rf ${console_file} - git clone -b ${console_branch} https://github.com/FISCO-BCOS/console.git + git clone https://github.com/FISCO-BCOS/console.git + cd console + if [ -n "$(git branch -a | grep origin/${console_branch})" ]; then + git checkout origin/${console_branch} + else + git checkout origin/master + fi fi } @@ -51,10 +61,10 @@ config_console() cp ./src/integration-test/resources/config-example.toml ./src/integration-test/resources/config.toml ${sed_cmd} "s/peers=\[\"127.0.0.1:20200\", \"127.0.0.1:20201\"\]/peers=\[\"127.0.0.1:20201\"\]/g" ./src/integration-test/resources/config.toml cp -r ./src/main/resources/contract ./contracts - + local not_use_sm="true" if [ "${use_sm}" == "true" ]; then - not_use_sm="false" + not_use_sm="false" fi use_sm_str="useSMCrypto = \"${use_sm}\"" ${sed_cmd} "s/useSMCrypto = \"${not_use_sm}\"/${use_sm_str}/g" ./src/integration-test/resources/config.toml @@ -74,9 +84,9 @@ console_integrationTest() } if [ $# != 3 ]; then - echo "USAGE: ${0} console_branch is_sm node_path" - echo " e.g.: ${0} master true ./nodes" - exit 1; + echo "USAGE: ${0} console_branch is_sm node_path" + echo " e.g.: ${0} master true ./nodes" + exit 1; fi console_branch="${1}" diff --git a/tools/.ci/java_sdk_ci_test.sh b/tools/.ci/java_sdk_ci_test.sh index 73ebdc22ec..dd514dce4e 100644 --- a/tools/.ci/java_sdk_ci_test.sh +++ b/tools/.ci/java_sdk_ci_test.sh @@ -15,7 +15,7 @@ LOG_INFO() { download_java_sdk() { cd ${current_path} - + LOG_INFO "Pull java sdk, branch: ${java_sdk_branch} ..." local java_sdk_file=java-sdk if [ -d ${java_sdk_file} ] && [ -d "${java_sdk_file}/.git" ]; then @@ -24,16 +24,25 @@ download_java_sdk() git fetch --all rm -rf build log git reset --hard - git checkout ${java_sdk_branch} + if [ -n "$(git branch -a | grep origin/${java_sdk_branch})" ]; then + git checkout origin/${java_sdk_branch} + else + git checkout origin/master + fi if [ $? -ne 0 ]; then cd .. rm -rf ${java_sdk_file} git clone -b ${java_sdk_branch} https://github.com/FISCO-BCOS/java-sdk.git fi - git pull else rm -rf ${java_sdk_file} - git clone -b ${java_sdk_branch} https://github.com/FISCO-BCOS/java-sdk.git + git clone https://github.com/FISCO-BCOS/java-sdk.git + cd java-sdk + if [ -n "$(git branch -a | grep origin/${java_sdk_branch})" ]; then + git checkout origin/${java_sdk_branch} + else + git checkout origin/master + fi fi } @@ -54,14 +63,14 @@ config_java_sdk() rm -rf src/integration-test/resources/bin local not_use_sm="true" if [ "${use_sm}" == "true" ]; then - not_use_sm="false" - cp -r ./src/test/resources/gm/abi ./src/integration-test/resources/abi - cp -r ./src/test/resources/gm/bin ./src/integration-test/resources/bin + not_use_sm="false" + cp -r ./src/test/resources/gm/abi ./src/integration-test/resources/abi + cp -r ./src/test/resources/gm/bin ./src/integration-test/resources/bin else - cp -r ./src/test/resources/ecdsa/abi ./src/integration-test/resources/abi - cp -r ./src/test/resources/ecdsa/bin ./src/integration-test/resources/bin + cp -r ./src/test/resources/ecdsa/abi ./src/integration-test/resources/abi + cp -r ./src/test/resources/ecdsa/bin ./src/integration-test/resources/bin fi - + use_sm_str="useSMCrypto = \"${use_sm}\"" ${sed_cmd} "s/useSMCrypto = \"${not_use_sm}\"/${use_sm_str}/g" ./src/integration-test/resources/config.toml ${sed_cmd} "s/useSMCrypto = \"${not_use_sm}\"/${use_sm_str}/g" ./src/integration-test/resources/amop/config-subscriber-for-test.toml @@ -82,9 +91,9 @@ java_sdk_integration_test() } if [ $# != 3 ]; then - echo "USAGE: ${0} java_sdk_branch is_sm node_path" - echo " e.g.: ${0} master true ./nodes" - exit 1; + echo "USAGE: ${0} java_sdk_branch is_sm node_path" + echo " e.g.: ${0} master true ./nodes" + exit 1; fi java_sdk_branch="${1}" From 4b9c562445c6473a6aa9757d77da6f76fbb194b9 Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Mon, 19 Feb 2024 17:42:49 +0800 Subject: [PATCH 02/12] fix arm ci vcpkg version problem (#4233) --- .github/workflows/workflow-self-hosted-arm.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow-self-hosted-arm.yml b/.github/workflows/workflow-self-hosted-arm.yml index 7bf85beeb7..fd735d3727 100644 --- a/.github/workflows/workflow-self-hosted-arm.yml +++ b/.github/workflows/workflow-self-hosted-arm.yml @@ -61,7 +61,7 @@ jobs: - name: update vcpkg run: | - cd ${{ env.VCPKG_ROOT }} && git fetch --all + cd vcpkg && git pull origin master && ./bootstrap-vcpkg.sh cd - - name: Build for linux From 47a1963c18951a7586e2feaf91cb2469ed6c45bc Mon Sep 17 00:00:00 2001 From: jimmyshi <417711026@qq.com> Date: Tue, 20 Feb 2024 19:48:45 +0800 Subject: [PATCH 03/12] (smallbank): Compatible with 3.0.1 init table bug (#4236) --- bcos-executor/src/executor/TransactionExecutor.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bcos-executor/src/executor/TransactionExecutor.cpp b/bcos-executor/src/executor/TransactionExecutor.cpp index 119c8aa650..c059b380f5 100644 --- a/bcos-executor/src/executor/TransactionExecutor.cpp +++ b/bcos-executor/src/executor/TransactionExecutor.cpp @@ -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(); } From aa6ecbc799302570102fe4c06d525c90ace3830a Mon Sep 17 00:00:00 2001 From: MO NAN <651932351@qq.com> Date: Wed, 21 Feb 2024 17:37:25 +0800 Subject: [PATCH 04/12] Add get enable flag for flow control (#4241) --- bcos-gateway/bcos-gateway/GatewayConfig.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bcos-gateway/bcos-gateway/GatewayConfig.cpp b/bcos-gateway/bcos-gateway/GatewayConfig.cpp index be588707d8..8bf728444f 100644 --- a/bcos-gateway/bcos-gateway/GatewayConfig.cpp +++ b/bcos-gateway/bcos-gateway/GatewayConfig.cpp @@ -533,9 +533,11 @@ void GatewayConfig::initFlowControlConfig(const boost::property_tree::ptree& _pt m_rateLimiterConfig.timeWindowSec = timeWindowSec; m_rateLimiterConfig.statInterval = statInterval; m_rateLimiterConfig.enableConnectDebugInfo = enableConnectDebugInfo; + m_rateLimiterConfig.enable = _pt.get("flow_control.enable", false); GATEWAY_CONFIG_LOG(INFO) << LOG_BADGE("initFlowControlConfig") << LOG_DESC("load flow_control common config items") + << LOG_KV("enable", m_rateLimiterConfig.enable) << LOG_KV("flow_control.stat_reporter_interval", m_rateLimiterConfig.statInterval) << LOG_KV("flow_control.enable_connect_debug_info", From 3d561655139101fbe471972fb165bb30b4d8c4c3 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:09:37 +0800 Subject: [PATCH 05/12] (executor,feature): add bugfix_internal_create_storage flag to perf internal create code and abi storage. (#4243) --- .../src/executive/TransactionExecutive.cpp | 73 +++++++- .../src/executive/TransactionExecutive.h | 3 + bcos-executor/src/vm/HostContext.cpp | 22 +-- .../libprecompiled/AccountPrecompiledTest.cpp | 24 ++- .../libprecompiled/AuthPrecompiledTest.cpp | 2 +- .../libprecompiled/ConfigPrecompiledTest.cpp | 2 +- .../libprecompiled/CryptoPrecompiledTest.cpp | 2 +- .../libprecompiled/EVMStateContextTest.cpp | 2 +- .../FileSystemPrecompiledTest.cpp | 2 +- .../libprecompiled/PreCompiledFixture.h | 33 +++- .../libprecompiled/ShardPrecompiledTest.cpp | 35 ++-- .../TablePrecompiledV320Test.cpp | 156 ++++++++++++------ .../bcos-framework/ledger/Features.h | 34 ++-- .../bcos-framework/protocol/Protocol.h | 2 +- .../unittests/interfaces/FeaturesTest.cpp | 1 + bcos-table/src/KeyPageStorage.h | 8 +- bcos-table/src/LegacyStorageWrapper.h | 4 +- bcos-utilities/bcos-utilities/FixedBytes.h | 5 +- 18 files changed, 277 insertions(+), 133 deletions(-) diff --git a/bcos-executor/src/executive/TransactionExecutive.cpp b/bcos-executor/src/executive/TransactionExecutive.cpp index 349cd0e75a..4178cd877f 100644 --- a/bcos-executor/src/executive/TransactionExecutive.cpp +++ b/bcos-executor/src/executive/TransactionExecutive.cpp @@ -337,6 +337,51 @@ std::optional TransactionExecutive::getCodeByContractTableName( } } +bool TransactionExecutive::setCode(std::string_view contractTableName, + std::variant 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) @@ -787,15 +832,27 @@ 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_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()) + { + Entry abiEntry = {}; + abiEntry.importFields({std::move(callParameters->abi)}); + m_storageWrapper->setRow(codeTable, ACCOUNT_ABI, std::move(abiEntry)); + } } /// set link data diff --git a/bcos-executor/src/executive/TransactionExecutive.h b/bcos-executor/src/executive/TransactionExecutive.h index a19c5894ed..6a08e900a8 100644 --- a/bcos-executor/src/executive/TransactionExecutive.h +++ b/bcos-executor/src/executive/TransactionExecutive.h @@ -154,6 +154,9 @@ class TransactionExecutive : public std::enable_shared_from_this getCodeEntryFromContractTable( const std::string_view contractTableName); std::optional getCodeByHash(const std::string_view& codeHash); + bool setCode(std::string_view contractTableName, + std::variant code); + void setAbiByCodeHash(std::string_view codeHash, std::string_view abi); std::optional getCodeByContractTableName( const std::string_view& contractTableName, bool needTryFromContractTable = true); diff --git a/bcos-executor/src/vm/HostContext.cpp b/bcos-executor/src/vm/HostContext.cpp index 3629beb755..72f9d3d7ef 100644 --- a/bcos-executor/src/vm/HostContext.cpp +++ b/bcos-executor/src/vm/HostContext.cpp @@ -398,28 +398,9 @@ bool HostContext::setCode(bytes code) { 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(); - 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 @@ -477,6 +458,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; } diff --git a/bcos-executor/test/unittest/libprecompiled/AccountPrecompiledTest.cpp b/bcos-executor/test/unittest/libprecompiled/AccountPrecompiledTest.cpp index 4254c1f93d..0019eeaf00 100644 --- a/bcos-executor/test/unittest/libprecompiled/AccountPrecompiledTest.cpp +++ b/bcos-executor/test/unittest/libprecompiled/AccountPrecompiledTest.cpp @@ -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()); @@ -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); @@ -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()); @@ -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()); @@ -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(); @@ -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); @@ -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); @@ -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(); @@ -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())); diff --git a/bcos-executor/test/unittest/libprecompiled/AuthPrecompiledTest.cpp b/bcos-executor/test/unittest/libprecompiled/AuthPrecompiledTest.cpp index 0ba656ec44..dda8f2396e 100644 --- a/bcos-executor/test/unittest/libprecompiled/AuthPrecompiledTest.cpp +++ b/bcos-executor/test/unittest/libprecompiled/AuthPrecompiledTest.cpp @@ -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); } diff --git a/bcos-executor/test/unittest/libprecompiled/ConfigPrecompiledTest.cpp b/bcos-executor/test/unittest/libprecompiled/ConfigPrecompiledTest.cpp index 676e7eb2c1..980a1f00ac 100644 --- a/bcos-executor/test/unittest/libprecompiled/ConfigPrecompiledTest.cpp +++ b/bcos-executor/test/unittest/libprecompiled/ConfigPrecompiledTest.cpp @@ -96,7 +96,7 @@ class ConfigPrecompiledFixture : public PrecompiledFixture // -------------------------------- std::promise executePromise; - executor->dmcExecuteTransaction( + executor->executeTransaction( std::move(params), [&](bcos::Error::UniquePtr&& error, bcos::protocol::ExecutionMessage::UniquePtr&& result) { BOOST_CHECK(!error); diff --git a/bcos-executor/test/unittest/libprecompiled/CryptoPrecompiledTest.cpp b/bcos-executor/test/unittest/libprecompiled/CryptoPrecompiledTest.cpp index dc7cac3b1c..9f43acd245 100644 --- a/bcos-executor/test/unittest/libprecompiled/CryptoPrecompiledTest.cpp +++ b/bcos-executor/test/unittest/libprecompiled/CryptoPrecompiledTest.cpp @@ -96,7 +96,7 @@ class CryptoPrecompiledFixture : public PrecompiledFixture // -------------------------------- std::promise executePromise; - executor->dmcExecuteTransaction( + executor->executeTransaction( std::move(params), [&](bcos::Error::UniquePtr&& error, bcos::protocol::ExecutionMessage::UniquePtr&& result) { BOOST_CHECK(!error); diff --git a/bcos-executor/test/unittest/libprecompiled/EVMStateContextTest.cpp b/bcos-executor/test/unittest/libprecompiled/EVMStateContextTest.cpp index c1f8a07fac..5f7ba8422c 100644 --- a/bcos-executor/test/unittest/libprecompiled/EVMStateContextTest.cpp +++ b/bcos-executor/test/unittest/libprecompiled/EVMStateContextTest.cpp @@ -85,7 +85,7 @@ class EVMStateContextFixture : public PrecompiledFixture // -------------------------------- std::promise executePromise; - executor->dmcExecuteTransaction( + executor->executeTransaction( std::move(params), [&](bcos::Error::UniquePtr&& error, bcos::protocol::ExecutionMessage::UniquePtr&& result) { BOOST_CHECK(!error); diff --git a/bcos-executor/test/unittest/libprecompiled/FileSystemPrecompiledTest.cpp b/bcos-executor/test/unittest/libprecompiled/FileSystemPrecompiledTest.cpp index eb7cc23e27..259b460c6d 100644 --- a/bcos-executor/test/unittest/libprecompiled/FileSystemPrecompiledTest.cpp +++ b/bcos-executor/test/unittest/libprecompiled/FileSystemPrecompiledTest.cpp @@ -136,7 +136,7 @@ class FileSystemPrecompiledFixture : public PrecompiledFixture // -------------------------------- std::promise executePromise; - executor->dmcExecuteTransaction( + executor->executeTransaction( std::move(params), [&](bcos::Error::UniquePtr&& error, bcos::protocol::ExecutionMessage::UniquePtr&& result) { BOOST_CHECK(!error); diff --git a/bcos-executor/test/unittest/libprecompiled/PreCompiledFixture.h b/bcos-executor/test/unittest/libprecompiled/PreCompiledFixture.h index ec9ba6324b..16caef5a91 100644 --- a/bcos-executor/test/unittest/libprecompiled/PreCompiledFixture.h +++ b/bcos-executor/test/unittest/libprecompiled/PreCompiledFixture.h @@ -22,6 +22,7 @@ #include "executive/BlockContext.h" #include "executive/TransactionExecutive.h" #include "executor/TransactionExecutorFactory.h" +#include "libtask/bcos-task/Wait.h" #include "mock/MockKeyPageStorage.h" #include "mock/MockLedger.h" #include "mock/MockTransactionalStorage.h" @@ -289,6 +290,26 @@ class PrecompiledFixture : public TestPromptFixture auto blockHeader = std::make_shared( [m_blockHeader = bcostars::BlockHeader()]() mutable { return &m_blockHeader; }); blockHeader->setNumber(blockNumber); + Features features; + features.setUpgradeFeatures(BlockVersion::V3_0_VERSION, version); + std::vector keys; + std::vector values; + for (auto [_, name, value] : features.flags()) + { + if (value) + { + storage::Entry entry; + entry.setObject( + SystemConfigEntry{boost::lexical_cast((int)value), blockNumber}); + keys.push_back(std::string(name)); + values.push_back(std::string(entry.get())); + } + } + + if (!keys.empty()) + { + storage->setRows(SYS_CONFIG, keys, values); + } bcos::protocol::ParentInfo p{ .blockNumber = blockNumber - 1, .blockHash = h256(blockNumber - 1)}; @@ -395,7 +416,7 @@ class PrecompiledFixture : public TestPromptFixture }); auto result2 = executePromise2.get_future().get(); - BOOST_CHECK_EQUAL((int32_t)result2->type(), (int32_t)ExecutionMessage::FINISHED); + BOOST_CHECK_EQUAL((int32_t)result2->type(), (int32_t)ExecutionMessage::PRE_FINISH); BOOST_CHECK_EQUAL(result2->evmStatus(), 0); result2->setSeq(1000); @@ -460,7 +481,7 @@ class PrecompiledFixture : public TestPromptFixture }); auto result6 = executePromise6.get_future().get(); - BOOST_CHECK_EQUAL(result6->type(), ExecutionMessage::FINISHED); + BOOST_CHECK_EQUAL(result6->type(), ExecutionMessage::PRE_FINISH); BOOST_CHECK_EQUAL(result6->contextID(), 99); BOOST_CHECK_EQUAL(result6->seq(), 1002); BOOST_CHECK_EQUAL(result6->create(), false); @@ -590,7 +611,7 @@ class PrecompiledFixture : public TestPromptFixture auto result14 = executePromise14.get_future().get(); result14->setSeq(1006); - BOOST_CHECK_EQUAL((int32_t)result14->type(), (int32_t)ExecutionMessage::FINISHED); + BOOST_CHECK_EQUAL((int32_t)result14->type(), (int32_t)ExecutionMessage::PRE_FINISH); // committee callback to voteComputer std::promise executePromise15; @@ -601,7 +622,7 @@ class PrecompiledFixture : public TestPromptFixture executePromise15.set_value(std::move(result)); }); auto result15 = executePromise15.get_future().get(); - BOOST_CHECK_EQUAL((int32_t)result15->type(), (int32_t)ExecutionMessage::FINISHED); + BOOST_CHECK_EQUAL((int32_t)result15->type(), (int32_t)ExecutionMessage::PRE_FINISH); result15->setSeq(1004); @@ -616,7 +637,7 @@ class PrecompiledFixture : public TestPromptFixture auto result16 = executePromise16.get_future().get(); - BOOST_CHECK_EQUAL((int32_t)result16->type(), (int32_t)ExecutionMessage::FINISHED); + BOOST_CHECK_EQUAL((int32_t)result16->type(), (int32_t)ExecutionMessage::PRE_FINISH); BOOST_CHECK_EQUAL(result16->contextID(), 99); BOOST_CHECK_EQUAL(result16->seq(), 1004); BOOST_CHECK_EQUAL(result16->create(), false); @@ -636,7 +657,7 @@ class PrecompiledFixture : public TestPromptFixture }); auto result17 = executePromise17.get_future().get(); - BOOST_CHECK_EQUAL(result17->type(), ExecutionMessage::FINISHED); + BOOST_CHECK_EQUAL(result17->type(), ExecutionMessage::PRE_FINISH); BOOST_CHECK_EQUAL(result17->contextID(), 99); BOOST_CHECK_EQUAL(result17->seq(), 1000); BOOST_CHECK_EQUAL(result17->create(), false); diff --git a/bcos-executor/test/unittest/libprecompiled/ShardPrecompiledTest.cpp b/bcos-executor/test/unittest/libprecompiled/ShardPrecompiledTest.cpp index 26ee87e174..17ef01fd9c 100644 --- a/bcos-executor/test/unittest/libprecompiled/ShardPrecompiledTest.cpp +++ b/bcos-executor/test/unittest/libprecompiled/ShardPrecompiledTest.cpp @@ -107,7 +107,8 @@ class ShardPrecompiledFixture : public PrecompiledFixture "6bd9750029"; 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); @@ -136,7 +137,7 @@ class ShardPrecompiledFixture : public PrecompiledFixture // -------------------------------- std::promise executePromise; - executor->dmcExecuteTransaction( + executor->executeTransaction( std::move(params), [&](bcos::Error::UniquePtr&& error, bcos::protocol::ExecutionMessage::UniquePtr&& result) { BOOST_CHECK(!error); @@ -162,7 +163,8 @@ class ShardPrecompiledFixture : public PrecompiledFixture nextBlock(_number, m_blockVersion); bytes in = codec->encodeWithSig("createKVTable(string,string,string)", tableName, key, value); - auto tx = fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(100), 10000, "1", "1"); + auto tx = + fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(100), 10000, "1", "1"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -255,7 +257,8 @@ class ShardPrecompiledFixture : public PrecompiledFixture std::string const& shardName, int _errorCode = 0, bool errorInPrecompiled = false) { bytes in = codec->encodeWithSig("makeShard(string)", shardName); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -326,7 +329,8 @@ class ShardPrecompiledFixture : public PrecompiledFixture int _errorCode = 0, bool errorInPrecompiled = false) { bytes in = codec->encodeWithSig("mkdir(string)", path); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -402,7 +406,8 @@ class ShardPrecompiledFixture : public PrecompiledFixture in = codec->encodeWithSig("linkShard(string,string)", name, address); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -493,7 +498,8 @@ class ShardPrecompiledFixture : public PrecompiledFixture protocol::BlockNumber _number, std::string const& contract, int _errorCode = 0) { bytes in = codec->encodeWithSig("getContractShard(string)", contract); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -563,7 +569,8 @@ class ShardPrecompiledFixture : public PrecompiledFixture in = codec->encodeWithSig( "link(string,string,string,string)", name, version, address, abi); } - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -635,7 +642,8 @@ class ShardPrecompiledFixture : public PrecompiledFixture protocol::BlockNumber _number, std::string const& _path, int _errorCode = 0) { bytes in = codec->encodeWithSig("readlink(string)", _path); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -673,7 +681,8 @@ class ShardPrecompiledFixture : public PrecompiledFixture protocol::BlockNumber _number, uint32_t from, uint32_t to, int _errorCode = 0) { bytes in = codec->encodeWithSig("rebuildBfs(uint256,uint256)", from, to); - 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"); Address newSender = Address(isWasm ? std::string(precompiled::SYS_CONFIG_NAME) : std::string(precompiled::SYS_CONFIG_ADDRESS)); tx->forceSender(newSender.asBytes()); @@ -715,7 +724,8 @@ class ShardPrecompiledFixture : public PrecompiledFixture { bytes in = codec->encodeWithSig("setValueByKey(string,string)", std::string(ledger::SYSTEM_KEY_COMPATIBILITY_VERSION), version); - 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"); Address newSender = Address(std::string(precompiled::AUTH_COMMITTEE_ADDRESS)); tx->forceSender(newSender.asBytes()); sender = boost::algorithm::hex_lower(std::string(tx->sender())); @@ -779,7 +789,8 @@ class ShardPrecompiledFixture : public PrecompiledFixture { bytes in = codec->encodeWithSig("list(string,uint256,uint256)", path, u256(offset), u256(count)); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); diff --git a/bcos-executor/test/unittest/libprecompiled/TablePrecompiledV320Test.cpp b/bcos-executor/test/unittest/libprecompiled/TablePrecompiledV320Test.cpp index 191f46cb50..27af72b25f 100644 --- a/bcos-executor/test/unittest/libprecompiled/TablePrecompiledV320Test.cpp +++ b/bcos-executor/test/unittest/libprecompiled/TablePrecompiledV320Test.cpp @@ -51,11 +51,12 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture const std::vector& value, const std::string& callAddress, int _errorCode = 0, bool errorInTableManager = false) { - nextBlock(_number, protocol::BlockVersion::V3_2_VERSION); + nextBlock(_number, protocol::BlockVersion::V3_6_1_VERSION); TableInfoTupleV320 tableInfoTuple = std::make_tuple(keyOrder, key, value); bytes in = codec->encodeWithSig( "createTable(string,(uint8,string,string[]))", tableName, tableInfoTuple); - auto tx = fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(100), 10000, "1", "1"); + auto tx = + fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(100), 10000, "1", "1"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -147,9 +148,10 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture ExecutionMessage::UniquePtr appendColumns(protocol::BlockNumber _number, const std::string& tableName, const std::vector& values, int _errorCode = 0) { - nextBlock(_number, protocol::BlockVersion::V3_2_VERSION); + nextBlock(_number, protocol::BlockVersion::V3_6_1_VERSION); bytes in = codec->encodeWithSig("appendColumns(string,string[])", tableName, values); - auto tx = fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(100), 10000, "1", "1"); + auto tx = + fakeTransaction(cryptoSuite, keyPair, "", in, std::to_string(100), 10000, "1", "1"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -187,7 +189,8 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture protocol::BlockNumber _number, std::string const& _path, int _errorCode = 0) { bytes in = codec->encodeWithSig("openTable(string)", _path); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -203,7 +206,7 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture params2->setGasAvailable(gas); params2->setData(std::move(in)); params2->setType(NativeExecutionMessage::TXHASH); - nextBlock(_number, protocol::BlockVersion::V3_2_VERSION); + nextBlock(_number, protocol::BlockVersion::V3_6_1_VERSION); std::promise executePromise2; executor->dmcExecuteTransaction(std::move(params2), @@ -223,9 +226,10 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture ExecutionMessage::UniquePtr desc(protocol::BlockNumber _number, std::string const& tableName) { - nextBlock(_number, protocol::BlockVersion::V3_2_VERSION); + nextBlock(_number, protocol::BlockVersion::V3_6_1_VERSION); bytes in = codec->encodeWithSig("descWithKeyOrder(string)", tableName); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -258,10 +262,11 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture ExecutionMessage::UniquePtr insert(protocol::BlockNumber _number, const std::string& key, const std::vector& values, const std::string& callAddress) { - nextBlock(_number, protocol::BlockVersion::V3_2_VERSION); + nextBlock(_number, protocol::BlockVersion::V3_6_1_VERSION); EntryTuple entryTuple = {key, values}; bytes in = codec->encodeWithSig("insert((string,string[]))", entryTuple); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -313,9 +318,10 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture ExecutionMessage::UniquePtr selectByKey( protocol::BlockNumber _number, const std::string& key, const std::string& callAddress) { - nextBlock(_number, protocol::BlockVersion::V3_2_VERSION); + nextBlock(_number, protocol::BlockVersion::V3_6_1_VERSION); bytes in = codec->encodeWithSig("select(string)", key); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -368,10 +374,11 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture const std::vector& keyCond, const LimitTuple& limit, const std::string& callAddress) { - nextBlock(_number, protocol::BlockVersion::V3_2_VERSION); + nextBlock(_number, protocol::BlockVersion::V3_6_1_VERSION); bytes in = codec->encodeWithSig("select((uint8,string,string)[],(uint32,uint32))", keyCond, limit); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -423,9 +430,10 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture ExecutionMessage::UniquePtr count(protocol::BlockNumber _number, const std::vector& keyCond, const std::string& callAddress) { - nextBlock(_number, protocol::BlockVersion::V3_2_VERSION); + nextBlock(_number, protocol::BlockVersion::V3_6_1_VERSION); bytes in = codec->encodeWithSig("count((uint8,string,string)[])", keyCond); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -478,9 +486,10 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture const std::vector& _updateFields, const std::string& callAddress, bool _isErrorInTable = false) { - nextBlock(_number, protocol::BlockVersion::V3_2_VERSION); + nextBlock(_number, protocol::BlockVersion::V3_6_1_VERSION); bytes in = codec->encodeWithSig("update(string,(string,string)[])", key, _updateFields); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -542,11 +551,12 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture const std::vector& _updateFields, const std::string& callAddress) { - nextBlock(_number, protocol::BlockVersion::V3_2_VERSION); + nextBlock(_number, protocol::BlockVersion::V3_6_1_VERSION); bytes in = codec->encodeWithSig( "update((uint8,string,string)[],(uint32,uint32),(string,string)[])", conditions, _limit, _updateFields); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -605,9 +615,10 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture ExecutionMessage::UniquePtr removeByKey( protocol::BlockNumber _number, const std::string& key, const std::string& callAddress) { - nextBlock(_number, protocol::BlockVersion::V3_2_VERSION); + nextBlock(_number, protocol::BlockVersion::V3_6_1_VERSION); bytes in = codec->encodeWithSig("remove(string)", key); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -660,10 +671,11 @@ class TableFactoryPrecompiledV320Fixture : public PrecompiledFixture const std::vector& keyCond, const LimitTuple& limit, const std::string& callAddress) { - nextBlock(_number, protocol::BlockVersion::V3_2_VERSION); + nextBlock(_number, protocol::BlockVersion::V3_6_1_VERSION); bytes in = codec->encodeWithSig("remove((uint8,string,string)[],(uint32,uint32))", keyCond, limit); - 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"); sender = boost::algorithm::hex_lower(std::string(tx->sender())); auto hash = tx->hash(); txpool->hash2Transaction.emplace(hash, tx); @@ -835,22 +847,65 @@ struct ConditionNative class ConditionTest { public: - ConditionTest(const std::string& field, - std::function& conds, std::vector& entries)> selectFunc) - : m_field(field), m_selectFunc(selectFunc) {} + ConditionTest(const std::string& field, + std::function& conds, std::vector& entries)> + selectFunc) + : m_field(field), m_selectFunc(selectFunc) + {} ~ConditionTest() = default; - - void EQ(const std::string& value) { m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::EQ, m_field, value); m_condition1.EQ(value); } - void NE(const std::string& value) { m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::NE, m_field, value); m_condition1.NE(value); } - void GT(const std::string& value) { m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::GT, m_field, value); m_condition1.GT(value); } - void GE(const std::string& value) { m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::GE, m_field, value); m_condition1.GE(value); } - void LT(const std::string& value) { m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::LT, m_field, value); m_condition1.LT(value); } - void LE(const std::string& value) { m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::LE, m_field, value); m_condition1.LE(value); } - void startsWith(const std::string& value) { m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::STARTS_WITH, m_field, value); m_condition1.startsWith(value); } - void endsWith(const std::string& value) { m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::ENDS_WITH, m_field, value); m_condition1.endsWith(value); } - void contains(const std::string& value) { m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::CONTAINS, m_field, value); m_condition1.contains(value); } - - static std::vector getKeys(const std::vector& keys, const ConditionNative& cond) + + void EQ(const std::string& value) + { + m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::EQ, m_field, value); + m_condition1.EQ(value); + } + void NE(const std::string& value) + { + m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::NE, m_field, value); + m_condition1.NE(value); + } + void GT(const std::string& value) + { + m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::GT, m_field, value); + m_condition1.GT(value); + } + void GE(const std::string& value) + { + m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::GE, m_field, value); + m_condition1.GE(value); + } + void LT(const std::string& value) + { + m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::LT, m_field, value); + m_condition1.LT(value); + } + void LE(const std::string& value) + { + m_condition2.emplace_back((uint8_t)storage::Condition::Comparator::LE, m_field, value); + m_condition1.LE(value); + } + void startsWith(const std::string& value) + { + m_condition2.emplace_back( + (uint8_t)storage::Condition::Comparator::STARTS_WITH, m_field, value); + m_condition1.startsWith(value); + } + void endsWith(const std::string& value) + { + m_condition2.emplace_back( + (uint8_t)storage::Condition::Comparator::ENDS_WITH, m_field, value); + m_condition1.endsWith(value); + } + void contains(const std::string& value) + { + m_condition2.emplace_back( + (uint8_t)storage::Condition::Comparator::CONTAINS, m_field, value); + m_condition1.contains(value); + } + + static std::vector getKeys( + const std::vector& keys, const ConditionNative& cond) { std::vector ret; for (auto& key : keys) @@ -863,9 +918,10 @@ class ConditionTest return ret; } - static bool checkResultEQ(const std::vector& data1, const std::vector& data2) + static bool checkResultEQ( + const std::vector& data1, const std::vector& data2) { - if (data1.size() != data2.size()) + if (data1.size() != data2.size()) { return false; } @@ -895,7 +951,9 @@ class ConditionTest std::string m_field; ConditionNative m_condition1; std::vector m_condition2; - std::function& conds, std::vector& entries)> m_selectFunc; + std::function& conds, std::vector& entries)> + m_selectFunc; }; static void generateRandomVector( @@ -3935,13 +3993,13 @@ BOOST_AUTO_TEST_CASE(mixConditionTest) return stream.str(); }; - auto selectFunc = [this, &number, &callAddress]( - const std::vector& conds, std::vector& entries) { + auto selectFunc = [this, &number, &callAddress](const std::vector& conds, + std::vector& entries) { LimitTuple limit = {0, 500}; auto r1 = selectByCondition(number++, conds, limit, callAddress); codec->decode(r1->data(), entries); }; - + { creatTable(number++, "t_test_condv320_mix1", 0, "id", {"value"}, callAddress); } @@ -3955,7 +4013,7 @@ BOOST_AUTO_TEST_CASE(mixConditionTest) record.push_back(_fillZeros(j)); insert(number++, record.back(), {"0"}, callAddress); boost::log::core::get()->set_logging_enabled(true); - } + } // test GE { @@ -4396,7 +4454,7 @@ BOOST_AUTO_TEST_CASE(mixConditionTest) boost::log::core::get()->set_logging_enabled(false); insert(number++, recordStartsWith[j], {"0"}, callAddress); boost::log::core::get()->set_logging_enabled(true); - } + } // test startsWith { @@ -4435,7 +4493,7 @@ BOOST_AUTO_TEST_CASE(mixConditionTest) boost::log::core::get()->set_logging_enabled(false); insert(number++, recordContainsWith[j], {"0"}, callAddress); boost::log::core::get()->set_logging_enabled(true); - } + } // test contains { @@ -4467,7 +4525,7 @@ BOOST_AUTO_TEST_CASE(mixConditionTest) boost::log::core::get()->set_logging_enabled(false); insert(number++, recordEndsWith[j], {"0"}, callAddress); boost::log::core::get()->set_logging_enabled(true); - } + } // test ends_with { diff --git a/bcos-framework/bcos-framework/ledger/Features.h b/bcos-framework/bcos-framework/ledger/Features.h index 3bf1c2ed35..024c8815c4 100644 --- a/bcos-framework/bcos-framework/ledger/Features.h +++ b/bcos-framework/bcos-framework/ledger/Features.h @@ -36,6 +36,7 @@ class Features bugfix_precompiled_codehash, bugfix_dmc_revert, bugfix_keypage_system_entry_hash, + bugfix_internal_create_storage, // to perf internal create code and abi storage feature_dmc2serial, feature_sharding, feature_rpbft, @@ -126,22 +127,23 @@ class Features protocol::BlockVersion to; std::vector flags; }; - const static auto upgradeRoadmap = std::to_array( - {{protocol::BlockVersion::V3_2_3_VERSION, {Flag::bugfix_revert}}, - {protocol::BlockVersion::V3_2_4_VERSION, - {Flag::bugfix_statestorage_hash, - Flag::bugfix_evm_create2_delegatecall_staticcall_codecopy}}, - {protocol::BlockVersion::V3_2_7_VERSION, - {Flag::bugfix_event_log_order, Flag::bugfix_call_noaddr_return, - Flag::bugfix_precompiled_codehash, Flag::bugfix_dmc_revert}}, - {protocol::BlockVersion::V3_5_VERSION, {Flag::bugfix_revert}}, - {protocol::BlockVersion::V3_6_VERSION, - {Flag::bugfix_statestorage_hash, - Flag::bugfix_evm_create2_delegatecall_staticcall_codecopy, - Flag::bugfix_event_log_order, Flag::bugfix_call_noaddr_return, - Flag::bugfix_precompiled_codehash, Flag::bugfix_dmc_revert}}, - {protocol::BlockVersion::V3_6_1_VERSION, - {Flag::bugfix_keypage_system_entry_hash}}}); + const static auto upgradeRoadmap = std::to_array({ + {protocol::BlockVersion::V3_2_3_VERSION, {Flag::bugfix_revert}}, + {protocol::BlockVersion::V3_2_4_VERSION, + {Flag::bugfix_statestorage_hash, + Flag::bugfix_evm_create2_delegatecall_staticcall_codecopy}}, + {protocol::BlockVersion::V3_2_7_VERSION, + {Flag::bugfix_event_log_order, Flag::bugfix_call_noaddr_return, + Flag::bugfix_precompiled_codehash, Flag::bugfix_dmc_revert}}, + {protocol::BlockVersion::V3_5_VERSION, {Flag::bugfix_revert}}, + {protocol::BlockVersion::V3_6_VERSION, + {Flag::bugfix_statestorage_hash, + Flag::bugfix_evm_create2_delegatecall_staticcall_codecopy, + Flag::bugfix_event_log_order, Flag::bugfix_call_noaddr_return, + Flag::bugfix_precompiled_codehash, Flag::bugfix_dmc_revert}}, + {protocol::BlockVersion::V3_6_1_VERSION, + {Flag::bugfix_keypage_system_entry_hash, Flag::bugfix_internal_create_storage}}, + }); for (const auto& upgradeFeatures : upgradeRoadmap) { diff --git a/bcos-framework/bcos-framework/protocol/Protocol.h b/bcos-framework/bcos-framework/protocol/Protocol.h index 06642ae5b9..64b770f886 100644 --- a/bcos-framework/bcos-framework/protocol/Protocol.h +++ b/bcos-framework/bcos-framework/protocol/Protocol.h @@ -152,7 +152,7 @@ const std::string V3_6_VERSION_STR = "3.6.0"; const std::string RC_VERSION_PREFIX = "3.0.0-rc"; -const BlockVersion DEFAULT_VERSION = bcos::protocol::BlockVersion::V3_6_VERSION; +const BlockVersion DEFAULT_VERSION = bcos::protocol::BlockVersion::V3_6_1_VERSION; const std::string DEFAULT_VERSION_STR = V3_6_VERSION_STR; const uint8_t MAX_MAJOR_VERSION = std::numeric_limits::max(); const uint8_t MIN_MAJOR_VERSION = 3; diff --git a/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp b/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp index a279a0f018..d6e979944f 100644 --- a/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp +++ b/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp @@ -136,6 +136,7 @@ BOOST_AUTO_TEST_CASE(feature) "bugfix_precompiled_codehash", "bugfix_dmc_revert", "bugfix_keypage_system_entry_hash", + "bugfix_internal_create_storage", "feature_dmc2serial", "feature_sharding", "feature_rpbft", diff --git a/bcos-table/src/KeyPageStorage.h b/bcos-table/src/KeyPageStorage.h index 832737dda0..8fe0488833 100644 --- a/bcos-table/src/KeyPageStorage.h +++ b/bcos-table/src/KeyPageStorage.h @@ -1039,7 +1039,7 @@ class KeyPageStorage : public virtual storage::StateStorageInterface continue; } ++count; - ar& i.first; + ar & i.first; auto value = i.second.get(); ar&(uint32_t)value.size(); ar.save_binary(value.data(), value.size()); @@ -1051,15 +1051,15 @@ class KeyPageStorage : public virtual storage::StateStorageInterface { std::ignore = version; uint32_t count = 0; - ar& count; + ar & count; m_validCount = count; auto iter = entries.begin(); for (size_t i = 0; i < m_validCount; ++i) { std::string key; - ar& key; + ar & key; uint32_t len = 0; - ar& len; + ar & len; m_size += len; m_size += key.size(); auto value = std::make_shared>(len, 0); diff --git a/bcos-table/src/LegacyStorageWrapper.h b/bcos-table/src/LegacyStorageWrapper.h index 7e4e056ca6..d26643103c 100644 --- a/bcos-table/src/LegacyStorageWrapper.h +++ b/bcos-table/src/LegacyStorageWrapper.h @@ -60,7 +60,7 @@ class LegacyStorageWrapper : public virtual bcos::storage::StorageInterface decltype(callback) callback) -> task::Task { try { - auto stateKeys = keys | RANGES::views::transform([&table](auto&& key) -> auto{ + auto stateKeys = keys | RANGES::views::transform([&table](auto&& key) -> auto { return transaction_executor::StateKeyView{ table, std::forward(key)}; }) | RANGES::to(); @@ -112,7 +112,7 @@ class LegacyStorageWrapper : public virtual bcos::storage::StorageInterface keys | RANGES::views::transform([&](std::string_view key) { return transaction_executor::StateKey{tableName, key}; }), - values | RANGES::views::transform([](std::string_view value) -> auto{ + values | RANGES::views::transform([](std::string_view value) -> auto { storage::Entry entry; entry.setField(0, value); return entry; diff --git a/bcos-utilities/bcos-utilities/FixedBytes.h b/bcos-utilities/bcos-utilities/FixedBytes.h index 9602ef9872..25dcba9781 100644 --- a/bcos-utilities/bcos-utilities/FixedBytes.h +++ b/bcos-utilities/bcos-utilities/FixedBytes.h @@ -125,7 +125,8 @@ class FixedBytes } if (view.size() != N) - {} + { + } auto startIndex = 0; if (_alignType == DataAlignType::AlignRight) [[likely]] @@ -299,6 +300,8 @@ class FixedBytes /// @returns a copy of the object's data as a byte vector. bytes asBytes() const { return bytes(data(), data() + N); } + std::string toRawString() const { return std::string(data(), data() + N); } + /// Populate with random data. template void generateRandomFixedBytesByEngine(Engine& _eng) From 1d782a02969496627ed05fbad023cf07fe80a910 Mon Sep 17 00:00:00 2001 From: wenlinli <1574249665@qq.com> Date: Thu, 22 Feb 2024 16:13:32 +0800 Subject: [PATCH 06/12] fix release.yml arm compile problem (#4244) --- .github/workflows/release.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8eecee1449..cfce39c8f9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 From 2700a7b0c636b6d44d3936853b98bf20673072ba Mon Sep 17 00:00:00 2001 From: jimmyshi <417711026@qq.com> Date: Thu, 22 Feb 2024 23:11:00 +0800 Subject: [PATCH 07/12] (executive): move trigger change into create function for internal create (#4245) --- bcos-executor/src/executive/TransactionExecutive.cpp | 3 +++ bcos-executor/src/vm/HostContext.cpp | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/bcos-executor/src/executive/TransactionExecutive.cpp b/bcos-executor/src/executive/TransactionExecutive.cpp index 4178cd877f..64dc1fd841 100644 --- a/bcos-executor/src/executive/TransactionExecutive.cpp +++ b/bcos-executor/src/executive/TransactionExecutive.cpp @@ -633,6 +633,9 @@ std::tuple, CallParameters::UniquePtr> TransactionE revert(); return {nullptr, std::move(callParameters)}; } + + this->setContractTableChanged(); + if (callParameters->internalCreate) { callParameters->abi = std::move(extraData->abi); diff --git a/bcos-executor/src/vm/HostContext.cpp b/bcos-executor/src/vm/HostContext.cpp index 72f9d3d7ef..9ee9415a4a 100644 --- a/bcos-executor/src/vm/HostContext.cpp +++ b/bcos-executor/src/vm/HostContext.cpp @@ -390,8 +390,6 @@ 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)) From d4764c0f551b0588fad1d90d88103413dcfeb0d7 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Fri, 23 Feb 2024 11:08:38 +0800 Subject: [PATCH 08/12] (feature): rename bugfix_internal_create_redundant_storage. (#4247) --- bcos-executor/src/executive/TransactionExecutive.cpp | 3 ++- bcos-framework/bcos-framework/ledger/Features.h | 5 +++-- bcos-framework/test/unittests/interfaces/FeaturesTest.cpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bcos-executor/src/executive/TransactionExecutive.cpp b/bcos-executor/src/executive/TransactionExecutive.cpp index 64dc1fd841..3ec0366895 100644 --- a/bcos-executor/src/executive/TransactionExecutive.cpp +++ b/bcos-executor/src/executive/TransactionExecutive.cpp @@ -835,7 +835,8 @@ CallParameters::UniquePtr TransactionExecutive::internalCreate( auto codeTable = getContractTableName(newAddress, false); m_storageWrapper->createTable(codeTable, std::string(STORAGE_VALUE)); - if (m_blockContext.features().get(ledger::Features::Flag::bugfix_internal_create_storage)) + if (m_blockContext.features().get( + ledger::Features::Flag::bugfix_internal_create_redundant_storage)) { setCode(codeTable, std::move(codeString)); if (!callParameters->abi.empty()) diff --git a/bcos-framework/bcos-framework/ledger/Features.h b/bcos-framework/bcos-framework/ledger/Features.h index 024c8815c4..7e6c305e62 100644 --- a/bcos-framework/bcos-framework/ledger/Features.h +++ b/bcos-framework/bcos-framework/ledger/Features.h @@ -36,7 +36,7 @@ class Features bugfix_precompiled_codehash, bugfix_dmc_revert, bugfix_keypage_system_entry_hash, - bugfix_internal_create_storage, // to perf internal create code and abi storage + bugfix_internal_create_redundant_storage, // to perf internal create code and abi storage feature_dmc2serial, feature_sharding, feature_rpbft, @@ -142,7 +142,8 @@ class Features Flag::bugfix_event_log_order, Flag::bugfix_call_noaddr_return, Flag::bugfix_precompiled_codehash, Flag::bugfix_dmc_revert}}, {protocol::BlockVersion::V3_6_1_VERSION, - {Flag::bugfix_keypage_system_entry_hash, Flag::bugfix_internal_create_storage}}, + {Flag::bugfix_keypage_system_entry_hash, + Flag::bugfix_internal_create_redundant_storage}}, }); for (const auto& upgradeFeatures : upgradeRoadmap) diff --git a/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp b/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp index d6e979944f..7a17b2bcbb 100644 --- a/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp +++ b/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp @@ -136,7 +136,7 @@ BOOST_AUTO_TEST_CASE(feature) "bugfix_precompiled_codehash", "bugfix_dmc_revert", "bugfix_keypage_system_entry_hash", - "bugfix_internal_create_storage", + "bugfix_internal_create_redundant_storage", "feature_dmc2serial", "feature_sharding", "feature_rpbft", From 79a46aace8ab0b3ed58271dae9f730e9dc08efee Mon Sep 17 00:00:00 2001 From: MO NAN <651932351@qq.com> Date: Thu, 29 Feb 2024 09:32:57 +0800 Subject: [PATCH 09/12] add Stateroot hash bugfix for 3.5.0 (#4261) --- .github/workflows/workflow-self-hosted-arm.yml | 2 +- bcos-framework/bcos-framework/ledger/Features.h | 3 ++- .../test/unittests/interfaces/FeaturesTest.cpp | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/workflow-self-hosted-arm.yml b/.github/workflows/workflow-self-hosted-arm.yml index fd735d3727..0571727115 100644 --- a/.github/workflows/workflow-self-hosted-arm.yml +++ b/.github/workflows/workflow-self-hosted-arm.yml @@ -61,7 +61,7 @@ jobs: - name: update vcpkg run: | - cd vcpkg && git pull origin master && ./bootstrap-vcpkg.sh + cd vcpkg && git pull origin master cd - - name: Build for linux diff --git a/bcos-framework/bcos-framework/ledger/Features.h b/bcos-framework/bcos-framework/ledger/Features.h index 7e6c305e62..395b966108 100644 --- a/bcos-framework/bcos-framework/ledger/Features.h +++ b/bcos-framework/bcos-framework/ledger/Features.h @@ -135,7 +135,8 @@ class Features {protocol::BlockVersion::V3_2_7_VERSION, {Flag::bugfix_event_log_order, Flag::bugfix_call_noaddr_return, Flag::bugfix_precompiled_codehash, Flag::bugfix_dmc_revert}}, - {protocol::BlockVersion::V3_5_VERSION, {Flag::bugfix_revert}}, + {protocol::BlockVersion::V3_5_VERSION, + {Flag::bugfix_revert, Flag::bugfix_statestorage_hash}}, {protocol::BlockVersion::V3_6_VERSION, {Flag::bugfix_statestorage_hash, Flag::bugfix_evm_create2_delegatecall_staticcall_codecopy, diff --git a/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp b/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp index 7a17b2bcbb..08e653df45 100644 --- a/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp +++ b/bcos-framework/test/unittests/interfaces/FeaturesTest.cpp @@ -220,7 +220,7 @@ BOOST_AUTO_TEST_CASE(upgrade) Features features6; features6.setUpgradeFeatures( bcos::protocol::BlockVersion::V3_4_VERSION, bcos::protocol::BlockVersion::V3_5_VERSION); - auto expect3 = std::to_array({"bugfix_revert"}); + auto expect3 = std::to_array({"bugfix_revert", "bugfix_statestorage_hash"}); BOOST_CHECK_EQUAL(validFlags(features6).size(), expect3.size()); for (auto feature : expect3) { @@ -262,6 +262,17 @@ BOOST_AUTO_TEST_CASE(upgrade) { BOOST_CHECK(features9.get(feature)); } + + // 3.5.0 + Features features10; + features10.setUpgradeFeatures( + bcos::protocol::BlockVersion::V3_4_VERSION, bcos::protocol::BlockVersion::V3_5_VERSION); + auto expect8 = std::to_array({"bugfix_revert", "bugfix_statestorage_hash"}); + BOOST_CHECK_EQUAL(validFlags(features10).size(), expect8.size()); + for (auto feature : expect8) + { + BOOST_CHECK(features10.get(feature)); + } } BOOST_AUTO_TEST_CASE(genesis) @@ -280,7 +291,7 @@ BOOST_AUTO_TEST_CASE(genesis) // 3.5.0 Features features2; features2.setGenesisFeatures(bcos::protocol::BlockVersion::V3_5_VERSION); - auto expect2 = std::to_array({"bugfix_revert"}); + auto expect2 = std::to_array({"bugfix_revert", "bugfix_statestorage_hash"}); BOOST_CHECK_EQUAL(validFlags(features2).size(), expect2.size()); for (auto feature : expect2) { From 4ae5709ff74f43d0f0e7fb93a017155a037c0514 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Thu, 29 Feb 2024 13:46:05 +0800 Subject: [PATCH 10/12] (precompiled): fix bfs link write empty abi string bug in 3.0.0. (#4262) --- .../src/executive/TransactionExecutive.cpp | 3 +- .../src/precompiled/BFSPrecompiled.cpp | 13 +++--- bcos-tool/bcos-tool/BfsFileFactory.cpp | 42 ++----------------- bcos-tool/bcos-tool/BfsFileFactory.h | 5 +-- 4 files changed, 15 insertions(+), 48 deletions(-) diff --git a/bcos-executor/src/executive/TransactionExecutive.cpp b/bcos-executor/src/executive/TransactionExecutive.cpp index 3ec0366895..ce32b4c62e 100644 --- a/bcos-executor/src/executive/TransactionExecutive.cpp +++ b/bcos-executor/src/executive/TransactionExecutive.cpp @@ -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; diff --git a/bcos-executor/src/precompiled/BFSPrecompiled.cpp b/bcos-executor/src/precompiled/BFSPrecompiled.cpp index 900b51330f..403021b35c 100644 --- a/bcos-executor/src/precompiled/BFSPrecompiled.cpp +++ b/bcos-executor/src/precompiled/BFSPrecompiled.cpp @@ -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; } @@ -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))); } @@ -670,8 +672,8 @@ void BFSPrecompiled::linkAdaptCNS(const std::shared_ptrstorage().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)); } @@ -1267,6 +1269,7 @@ void BFSPrecompiled::buildSysSubs(const std::shared_ptrstorage().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()); } } \ No newline at end of file diff --git a/bcos-tool/bcos-tool/BfsFileFactory.cpp b/bcos-tool/bcos-tool/BfsFileFactory.cpp index 31cb35f2b9..b261ced54a 100644 --- a/bcos-tool/bcos-tool/BfsFileFactory.cpp +++ b/bcos-tool/bcos-tool/BfsFileFactory.cpp @@ -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 _callback) -{ - _storage->asyncOpenTable(fileName, - [_callback = std::move(_callback), fileType](auto&& _error, std::optional&& _table) { - if (_error) - { - _callback(std::forward(_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
BfsFileFactory::createDir( const bcos::storage::StorageInterface::Ptr& _storage, std::string _table) { @@ -108,8 +73,8 @@ void BfsFileFactory::buildDirEntry( _mutableEntry.setObject>({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)}); @@ -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()); diff --git a/bcos-tool/bcos-tool/BfsFileFactory.h b/bcos-tool/bcos-tool/BfsFileFactory.h index e686d87254..b7a3daeb25 100644 --- a/bcos-tool/bcos-tool/BfsFileFactory.h +++ b/bcos-tool/bcos-tool/BfsFileFactory.h @@ -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 _callback); static bool buildDir(storage::Table& _table); // sync create dir @@ -102,7 +99,7 @@ class BfsFileFactory static void buildDirEntry(storage::Entry& _mutableEntry, std::variant 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); }; From 91b07ddfd24289dd11d5f90ba9c35f1032a728b9 Mon Sep 17 00:00:00 2001 From: MO NAN <651932351@qq.com> Date: Thu, 29 Feb 2024 18:23:05 +0800 Subject: [PATCH 11/12] Add init genesis feature (#4264) --- bcos-ledger/src/libledger/Ledger.cpp | 8 +++- .../test/unittests/ledger/LedgerTest.cpp | 38 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/bcos-ledger/src/libledger/Ledger.cpp b/bcos-ledger/src/libledger/Ledger.cpp index 2236cb4987..fcc051ad57 100644 --- a/bcos-ledger/src/libledger/Ledger.cpp +++ b/bcos-ledger/src/libledger/Ledger.cpp @@ -1742,7 +1742,9 @@ bool Ledger::buildGenesisBlock( ", No support this version")); } - // Before return, make sure sharding flag is placed + // 已有的链,仅替换了二进制,还没有执行升级版本交易 + // The existing chain, which only replaces the binary, has not yet executed the upgraded + // version of the transaction task::syncWait([&]() -> task::Task { auto versionEntry = co_await storage2::readOne( *m_storage, transaction_executor::StateKeyView( @@ -1754,8 +1756,12 @@ bool Ledger::buildGenesisBlock( auto [versionStr, _] = versionEntry->getObject(); auto storageVersion = tool::toVersionNumber(versionStr); + // 设置sharding default,相关的bugfix也要设置上,否则会不一致 + // Set sharding default, and related bugfixes should also be set, otherwise it + // will be inconsistent Features shardingFeature; shardingFeature.setToShardingDefault((protocol::BlockVersion)storageVersion); + shardingFeature.setGenesisFeatures((protocol::BlockVersion)storageVersion); co_await shardingFeature.writeToStorage( *m_storage, boost::lexical_cast(blockNumberEntry->get())); } diff --git a/bcos-ledger/test/unittests/ledger/LedgerTest.cpp b/bcos-ledger/test/unittests/ledger/LedgerTest.cpp index 4b85af6da4..1c09226fa3 100644 --- a/bcos-ledger/test/unittests/ledger/LedgerTest.cpp +++ b/bcos-ledger/test/unittests/ledger/LedgerTest.cpp @@ -1436,5 +1436,43 @@ BOOST_AUTO_TEST_CASE(genesisBlockWithAllocs) }()); } +BOOST_AUTO_TEST_CASE(replaceBinary) +{ + task::syncWait([this]() -> task::Task { + auto hashImpl = std::make_shared(); + auto memoryStorage = std::make_shared(nullptr); + auto storage = std::make_shared(memoryStorage); + auto ledger = std::make_shared(m_blockFactory, storage, 1); + + LedgerConfig param; + param.setBlockNumber(0); + param.setHash(HashType("")); + param.setBlockTxCountLimit(0); + + GenesisConfig genesisConfig; + genesisConfig.m_txGasLimit = 3000000000; + genesisConfig.m_compatibilityVersion = + tool::toVersionNumber(bcos::protocol::V3_5_VERSION_STR); + auto code = "I am a solidity code!"s; + std::string hexCode; + boost::algorithm::hex_lower(code, std::back_inserter(hexCode)); + + co_await ledger::buildGenesisBlock(*ledger, genesisConfig, param); + + // Delete the bugfix_statestorage_hash + BOOST_CHECK(co_await storage2::existsOne(*storage, + transaction_executor::StateKeyView(ledger::SYS_CONFIG, "bugfix_statestorage_hash"))); + Entry entry; + entry.setStatus(Entry::DELETED); + co_await storage2::writeOne(*storage, + transaction_executor::StateKey(ledger::SYS_CONFIG, "bugfix_statestorage_hash"), entry); + + co_await ledger::buildGenesisBlock(*ledger, genesisConfig, param); + auto result = co_await storage2::readOne(*storage, + transaction_executor::StateKeyView(ledger::SYS_CONFIG, "bugfix_statestorage_hash")); + BOOST_REQUIRE(result); + }()); +} + BOOST_AUTO_TEST_SUITE_END() } // namespace bcos::test From f4b2cdcf246597a68daaafa67637670e366f7f55 Mon Sep 17 00:00:00 2001 From: Kyon <32325790+kyonRay@users.noreply.github.com> Date: Fri, 1 Mar 2024 17:29:01 +0800 Subject: [PATCH 12/12] (precompiled,executor): fix internal create write empty abi string bug in 3.0.0. (#4269) --- .../src/executive/TransactionExecutive.cpp | 22 +++++++++++++++---- bcos-tool/bcos-tool/BfsFileFactory.cpp | 2 +- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/bcos-executor/src/executive/TransactionExecutive.cpp b/bcos-executor/src/executive/TransactionExecutive.cpp index ce32b4c62e..c2426bb682 100644 --- a/bcos-executor/src/executive/TransactionExecutive.cpp +++ b/bcos-executor/src/executive/TransactionExecutive.cpp @@ -851,7 +851,8 @@ CallParameters::UniquePtr TransactionExecutive::internalCreate( Entry entry = {}; entry.importFields({std::move(codeString)}); m_storageWrapper->setRow(codeTable, ACCOUNT_CODE, std::move(entry)); - if (!callParameters->abi.empty()) + if (!callParameters->abi.empty() && + blockContext().blockVersion() != (uint32_t)protocol::BlockVersion::V3_0_VERSION) { Entry abiEntry = {}; abiEntry.importFields({std::move(callParameters->abi)}); @@ -859,9 +860,22 @@ CallParameters::UniquePtr TransactionExecutive::internalCreate( } } - /// set link data - tool::BfsFileFactory::buildLink( - linkTable.value(), newAddress, "", blockContext().blockVersion()); + 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; diff --git a/bcos-tool/bcos-tool/BfsFileFactory.cpp b/bcos-tool/bcos-tool/BfsFileFactory.cpp index b261ced54a..57c570954f 100644 --- a/bcos-tool/bcos-tool/BfsFileFactory.cpp +++ b/bcos-tool/bcos-tool/BfsFileFactory.cpp @@ -94,7 +94,7 @@ bool BfsFileFactory::buildLink(Table& _table, const std::string& _address, const _table.setRow(FS_LINK_ABI, std::move(abiEntry)); } - if (!name.empty()) + if (!name.empty() || blockVersion == (uint32_t)protocol::BlockVersion::V3_0_VERSION) { Entry nameEntry; nameEntry.importFields({name});