Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt Core to the CAP-67 XDR. #4666

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Builds/VisualStudio/stellar-core.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ exit /b 0
<ClCompile Include="..\..\lib\util\siphash.cpp" />
<ClCompile Include="..\..\src\bucket\BucketApplicator.cpp" />
<ClCompile Include="..\..\src\bucket\BucketBase.cpp" />
<ClCompile Include="..\..\src\bucket\BucketIndexImpl.cpp" />
<ClCompile Include="..\..\src\bucket\BucketIndexUtils.cpp" />
<ClCompile Include="..\..\src\bucket\BucketInputIterator.cpp" />
<ClCompile Include="..\..\src\bucket\BucketListBase.cpp" />
<ClCompile Include="..\..\src\bucket\BucketListSnapshotBase.cpp" />
Expand All @@ -467,10 +467,14 @@ exit /b 0
<ClCompile Include="..\..\src\bucket\BucketSnapshot.cpp" />
<ClCompile Include="..\..\src\bucket\BucketSnapshotManager.cpp" />
<ClCompile Include="..\..\src\bucket\BucketUtils.cpp" />
<ClCompile Include="..\..\src\bucket\DiskIndex.cpp" />
<ClCompile Include="..\..\src\bucket\FutureBucket.cpp" />
<ClCompile Include="..\..\src\bucket\HotArchiveBucket.cpp" />
<ClCompile Include="..\..\src\bucket\HotArchiveBucketIndex.cpp" />
<ClCompile Include="..\..\src\bucket\HotArchiveBucketList.cpp" />
<ClCompile Include="..\..\src\bucket\InMemoryIndex.cpp" />
<ClCompile Include="..\..\src\bucket\LiveBucket.cpp" />
<ClCompile Include="..\..\src\bucket\LiveBucketIndex.cpp" />
<ClCompile Include="..\..\src\bucket\LiveBucketList.cpp" />
<ClCompile Include="..\..\src\bucket\MergeKey.cpp" />
<ClCompile Include="..\..\src\bucket\SearchableBucketList.cpp" />
Expand Down Expand Up @@ -565,6 +569,7 @@ exit /b 0
<ClCompile Include="..\..\src\history\HistoryArchiveManager.cpp" />
<ClCompile Include="..\..\src\history\HistoryArchiveReportWork.cpp" />
<ClCompile Include="..\..\src\history\HistoryManagerImpl.cpp" />
<ClCompile Include="..\..\src\history\HistoryUtils.cpp" />
<ClCompile Include="..\..\src\history\StateSnapshot.cpp" />
<ClCompile Include="..\..\src\history\test\HistoryTests.cpp" />
<ClCompile Include="..\..\src\history\test\HistoryTestsUtils.cpp" />
Expand Down Expand Up @@ -912,8 +917,7 @@ exit /b 0
<ClInclude Include="..\..\lib\util\stdrandom.h" />
<ClInclude Include="..\..\src\bucket\BucketApplicator.h" />
<ClInclude Include="..\..\src\bucket\BucketBase.h" />
<ClInclude Include="..\..\src\bucket\BucketIndex.h" />
<ClInclude Include="..\..\src\bucket\BucketIndexImpl.h" />
<ClInclude Include="..\..\src\bucket\BucketIndexUtils.h" />
<ClInclude Include="..\..\src\bucket\BucketInputIterator.h" />
<ClInclude Include="..\..\src\bucket\BucketListBase.h" />
<ClInclude Include="..\..\src\bucket\BucketListSnapshotBase.h" />
Expand All @@ -923,11 +927,15 @@ exit /b 0
<ClInclude Include="..\..\src\bucket\BucketSnapshot.h" />
<ClInclude Include="..\..\src\bucket\BucketSnapshotManager.h" />
<ClInclude Include="..\..\src\bucket\BucketUtils.h" />
<ClInclude Include="..\..\src\bucket\DiskIndex.h" />
<ClInclude Include="..\..\src\bucket\FutureBucket.h" />
<ClInclude Include="..\..\src\bucket\HotArchiveBucket.h" />
<ClInclude Include="..\..\src\bucket\HotArchiveBucketIndex.h" />
<ClInclude Include="..\..\src\bucket\HotArchiveBucketList.h" />
<ClInclude Include="..\..\src\bucket\InMemoryIndex.h" />
<ClInclude Include="..\..\src\bucket\LedgerCmp.h" />
<ClInclude Include="..\..\src\bucket\LiveBucket.h" />
<ClInclude Include="..\..\src\bucket\LiveBucketIndex.h" />
<ClInclude Include="..\..\src\bucket\LiveBucketList.h" />
<ClInclude Include="..\..\src\bucket\MergeKey.h" />
<ClInclude Include="..\..\src\bucket\SearchableBucketList.h" />
Expand Down Expand Up @@ -1013,6 +1021,7 @@ exit /b 0
<ClInclude Include="..\..\src\history\HistoryArchiveReportWork.h" />
<ClInclude Include="..\..\src\history\HistoryManager.h" />
<ClInclude Include="..\..\src\history\HistoryManagerImpl.h" />
<ClInclude Include="..\..\src\history\HistoryUtils.h" />
<ClInclude Include="..\..\src\history\StateSnapshot.h" />
<ClInclude Include="..\..\src\history\test\HistoryTestsUtils.h" />
<ClInclude Include="..\..\src\invariant\AccountSubEntriesCountIsValid.h" />
Expand Down
45 changes: 36 additions & 9 deletions Builds/VisualStudio/stellar-core.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,6 @@
<ClCompile Include="..\..\src\bucket\BucketApplicator.cpp">
<Filter>bucket</Filter>
</ClCompile>
<ClCompile Include="..\..\src\bucket\BucketIndexImpl.cpp">
<Filter>bucket</Filter>
</ClCompile>
<ClCompile Include="..\..\src\bucket\BucketInputIterator.cpp">
<Filter>bucket</Filter>
</ClCompile>
Expand Down Expand Up @@ -1365,6 +1362,24 @@
<ClCompile Include="..\..\src\catchup\LedgerApplyManagerImpl.cpp">
<Filter>catchup</Filter>
</ClCompile>
<ClCompile Include="..\..\src\bucket\HotArchiveBucketIndex.cpp">
<Filter>bucket</Filter>
</ClCompile>
<ClCompile Include="..\..\src\bucket\LiveBucketIndex.cpp">
<Filter>bucket</Filter>
</ClCompile>
<ClCompile Include="..\..\src\bucket\DiskIndex.cpp">
<Filter>bucket</Filter>
</ClCompile>
<ClCompile Include="..\..\src\bucket\BucketIndexUtils.cpp">
<Filter>bucket</Filter>
</ClCompile>
<ClCompile Include="..\..\src\bucket\InMemoryIndex.cpp">
<Filter>bucket</Filter>
</ClCompile>
<ClCompile Include="..\..\src\history\HistoryUtils.cpp">
<Filter>history</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\lib\util\cpptoml.h">
Expand Down Expand Up @@ -1778,12 +1793,6 @@
<ClInclude Include="..\..\src\bucket\BucketApplicator.h">
<Filter>bucket</Filter>
</ClInclude>
<ClInclude Include="..\..\src\bucket\BucketIndex.h">
<Filter>bucket</Filter>
</ClInclude>
<ClInclude Include="..\..\src\bucket\BucketIndexImpl.h">
<Filter>bucket</Filter>
</ClInclude>
<ClInclude Include="..\..\src\bucket\BucketInputIterator.h">
<Filter>bucket</Filter>
</ClInclude>
Expand Down Expand Up @@ -2410,6 +2419,24 @@
<ClInclude Include="..\..\src\catchup\LedgerApplyManagerImpl.h">
<Filter>catchup</Filter>
</ClInclude>
<ClInclude Include="..\..\src\bucket\HotArchiveBucketIndex.h">
<Filter>bucket</Filter>
</ClInclude>
<ClInclude Include="..\..\src\bucket\LiveBucketIndex.h">
<Filter>bucket</Filter>
</ClInclude>
<ClInclude Include="..\..\src\bucket\DiskIndex.h">
<Filter>bucket</Filter>
</ClInclude>
<ClInclude Include="..\..\src\bucket\BucketIndexUtils.h">
<Filter>bucket</Filter>
</ClInclude>
<ClInclude Include="..\..\src\bucket\InMemoryIndex.h">
<Filter>bucket</Filter>
</ClInclude>
<ClInclude Include="..\..\src\history\HistoryUtils.h">
<Filter>history</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\AUTHORS" />
Expand Down
2 changes: 1 addition & 1 deletion src/bucket/DiskIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ DiskIndex<BucketT>::DiskIndex(BucketManager& bm,
mData.assetToPoolID = std::make_unique<AssetPoolIDMap>();
}

auto fileSize = fs::size(filename);
auto fileSize = fs::size(filename.string());
auto estimatedIndexEntries = fileSize / pageSize;
mData.keysToOffset.reserve(estimatedIndexEntries);

Expand Down
2 changes: 1 addition & 1 deletion src/bucket/LiveBucketIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ LiveBucketIndex::LiveBucketIndex(BucketManager& bm,
ZoneScoped;
releaseAssert(!filename.empty());

auto pageSize = getPageSize(bm.getConfig(), fs::size(filename));
auto pageSize = getPageSize(bm.getConfig(), fs::size(filename.string()));
if (pageSize == 0)
{

Expand Down
14 changes: 13 additions & 1 deletion src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ checkXDRFileIdentity()
{
continue;
}
// Temporarily (until we have cut the next minor release) disable the
// check for the XDR changes necessary for the minor release. These
// are mostly binary compatible with the Rust XDR, and the incompatible
// part (ScAddress change) is actually supposed to be not decodable on
// the Rust side.
if (cpp.first.filename() == "Stellar-types.x" ||
cpp.first.filename() == "Stellar-contract.x" ||
cpp.first.filename() == "Stellar-ledger-entries.x" ||
cpp.first.filename() == "Stellar-ledger.x")
{
continue;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of skipping, would it be better to statically assert the hashes of these files, on both sides?

bool found = false;
for (auto const& rust : rustHashes)
{
Expand Down Expand Up @@ -351,7 +363,7 @@ main(int argc, char* const* argv)
rust_bridge::check_sensible_soroban_config_for_protocol(
Config::CURRENT_LEDGER_PROTOCOL_VERSION);

// Disable XDR hash checking in vnext builds
// Temporarily disable XDR hash checking in vnext builds
#ifndef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
checkXDRFileIdentity();
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/protocol-curr/xdr
2 changes: 1 addition & 1 deletion src/protocol-next/xdr
9 changes: 7 additions & 2 deletions src/transactions/TransactionUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1986,10 +1986,15 @@ isTransactionXDRValidForProtocol(uint32_t currProtocol, Config const& cfg,
uint32_t maxProtocol = cfg.CURRENT_LEDGER_PROTOCOL_VERSION;
// If we could parse the XDR when ledger is using the maximum supported
// protocol version, then XDR has to be valid.
// This check is temporarily disabled because we're using different XDR in
// Rust and Core, and thus even at max protocol the check is necessary.
// if (maxProtocol == currProtocol)
//{
// return true;
//}
// This check also is pointless before protocol 21 as Soroban environment
// doesn't support XDR versions before 21.
if (maxProtocol == currProtocol ||
protocolVersionIsBefore(currProtocol, ProtocolVersion::V_21))
if (protocolVersionIsBefore(currProtocol, ProtocolVersion::V_21))
{
return true;
}
Expand Down
64 changes: 64 additions & 0 deletions src/transactions/test/TxEnvelopeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,70 @@ TEST_CASE("XDR protocol compatibility validation", "[tx][envelope]")
}
}

// This is a temporary case until we have released the next minor version.
// This can be safely removed after that (the test will also fail as soon as we
// caught up with the next XDR on the Rust side).
TEST_CASE("new ScAddress variants are not decodable by Rust", "[tx][envelope]")
{

VirtualClock clock;
auto cfg = getTestConfig();
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
Config::CURRENT_LEDGER_PROTOCOL_VERSION;
auto app = createTestApplication(clock, cfg);
auto root = TestAccount::createRoot(*app);
Operation op;
op.body.type(INVOKE_HOST_FUNCTION);
op.body.invokeHostFunctionOp().hostFunction.type(
HOST_FUNCTION_TYPE_INVOKE_CONTRACT);

LedgerSnapshot ls(*app);
SECTION("Invalid ScAddress in function args")
{
auto& val = op.body.invokeHostFunctionOp()
.hostFunction.invokeContract()
.args.emplace_back();
val.type(SCV_ADDRESS);
val.address().type(SC_ADDRESS_TYPE_MUXED_ACCOUNT);
val.address().muxedAccount().id = 123;
auto tx =
sorobanTransactionFrameFromOps(app->getNetworkID(), root, {op}, {},
SorobanResources(), 1000, 1'000'000);

auto res = tx->checkValid(app->getAppConnector(), ls, 0, 0, 0);
REQUIRE(res->getResult().result.code() == txMALFORMED);
}
SECTION("Invalid ScAddress in auth")
{
auto& authEntry = op.body.invokeHostFunctionOp().auth.emplace_back();
authEntry.rootInvocation.function.type(
SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN);
auto& address =
authEntry.rootInvocation.function.contractFn().contractAddress;
address.type(SC_ADDRESS_TYPE_CLAIMABLE_BALANCE);
address.claimableBalanceId().v0()[0] = 1;
auto tx =
sorobanTransactionFrameFromOps(app->getNetworkID(), root, {op}, {},
SorobanResources(), 1000, 1'000'000);
auto res = tx->checkValid(app->getAppConnector(), ls, 0, 0, 0);
REQUIRE(res->getResult().result.code() == txMALFORMED);
}
SECTION("Invalid ScAddress in footprint")
{
SorobanResources resources;
auto& key = resources.footprint.readOnly.emplace_back();
key.type(CONTRACT_DATA);
auto& address = key.contractData().contract;

address.type(SC_ADDRESS_TYPE_LIQUIDITY_POOL);
address.liquidityPoolId()[1] = 10;
auto tx = sorobanTransactionFrameFromOps(
app->getNetworkID(), root, {op}, {}, resources, 1000, 1'000'000);
auto res = tx->checkValid(app->getAppConnector(), ls, 0, 0, 0);
REQUIRE(res->getResult().result.code() == txMALFORMED);
}
}

TEST_CASE_VERSIONS("Soroban extension for non-Soroban tx",
"[tx][envelope][soroban]")
{
Expand Down
Loading