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