|
6 | 6 | #include "herder/TxSetFrame.h" |
7 | 7 | #include "ledger/ImmutableLedgerView.h" |
8 | 8 | #include "ledger/test/LedgerTestUtils.h" |
| 9 | +#include "rust/RustBridge.h" |
9 | 10 | #include "simulation/LoadGenerator.h" |
10 | 11 | #include "simulation/Simulation.h" |
11 | 12 | #include "test/TxTests.h" |
|
16 | 17 | #include "work/WorkScheduler.h" |
17 | 18 | #include "xdrpp/marshal.h" |
18 | 19 |
|
| 20 | +#include <algorithm> |
| 21 | +#include <sstream> |
| 22 | + |
19 | 23 | namespace stellar |
20 | 24 | { |
21 | 25 |
|
22 | 26 | namespace testutil |
23 | 27 | { |
24 | 28 |
|
| 29 | +bool isTestApplicationProtocolVersionSupported(Config const& cfg); |
| 30 | + |
| 31 | +namespace |
| 32 | +{ |
| 33 | +bool |
| 34 | +isProtocolBackedByLinkedSorobanHost(uint32_t protocolVersion, |
| 35 | + std::vector<uint32_t> const& hostProtocols) |
| 36 | +{ |
| 37 | + if (protocolVersionIsBefore(protocolVersion, SOROBAN_PROTOCOL_VERSION)) |
| 38 | + { |
| 39 | + return true; |
| 40 | + } |
| 41 | + |
| 42 | + auto selectedHost = std::find_if( |
| 43 | + hostProtocols.begin(), hostProtocols.end(), |
| 44 | + [&](uint32_t hostProtocol) { return protocolVersion <= hostProtocol; }); |
| 45 | + if (selectedHost == hostProtocols.end()) |
| 46 | + { |
| 47 | + return false; |
| 48 | + } |
| 49 | + |
| 50 | + // Protocol 20 is serviced by the p21 host. All later Soroban protocols |
| 51 | + // should have their own linked host in non-fastdev builds. |
| 52 | + return protocolVersion == static_cast<uint32_t>(SOROBAN_PROTOCOL_VERSION) |
| 53 | + ? *selectedHost == static_cast<uint32_t>(ProtocolVersion::V_21) |
| 54 | + : *selectedHost == protocolVersion; |
| 55 | +} |
| 56 | + |
| 57 | +std::string |
| 58 | +joinProtocolVersions(std::vector<uint32_t> const& protocolVersions) |
| 59 | +{ |
| 60 | + std::ostringstream out; |
| 61 | + for (size_t i = 0; i < protocolVersions.size(); ++i) |
| 62 | + { |
| 63 | + if (i != 0) |
| 64 | + { |
| 65 | + out << ", "; |
| 66 | + } |
| 67 | + out << protocolVersions[i]; |
| 68 | + } |
| 69 | + return out.str(); |
| 70 | +} |
| 71 | +} |
| 72 | + |
| 73 | +void |
| 74 | +validateTestApplicationProtocolVersion(Config const& cfg) |
| 75 | +{ |
| 76 | + if (isTestApplicationProtocolVersionSupported(cfg)) |
| 77 | + { |
| 78 | + return; |
| 79 | + } |
| 80 | + |
| 81 | + auto const protocolVersion = cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION; |
| 82 | + std::vector<uint32_t> hostProtocols; |
| 83 | + auto rustVersions = rust_bridge::get_soroban_version_info( |
| 84 | + Config::CURRENT_LEDGER_PROTOCOL_VERSION); |
| 85 | + for (auto const& host : rustVersions) |
| 86 | + { |
| 87 | + hostProtocols.emplace_back(host.env_max_proto); |
| 88 | + } |
| 89 | + |
| 90 | + std::ostringstream msg; |
| 91 | + msg << "Test application requested genesis ledger protocol " |
| 92 | + << protocolVersion |
| 93 | + << ", but this binary does not have the matching Soroban host linked. " |
| 94 | + << "Linked Soroban host protocols: [" |
| 95 | + << joinProtocolVersions(hostProtocols) |
| 96 | + << "]. This usually means the build is using fastdev/unified Rust " |
| 97 | + << "mode, where historical Soroban protocols are collapsed to a newer " |
| 98 | + << "host and can fail later with opaque Soroban invocation errors. " |
| 99 | + << "Use a linked protocol for this test, or rebuild without fastdev " |
| 100 | + << "when testing historical Soroban protocol behavior."; |
| 101 | + throw std::runtime_error(msg.str()); |
| 102 | +} |
| 103 | + |
| 104 | +bool |
| 105 | +isTestApplicationProtocolVersionSupported(Config const& cfg) |
| 106 | +{ |
| 107 | + if (!cfg.USE_CONFIG_FOR_GENESIS) |
| 108 | + { |
| 109 | + return true; |
| 110 | + } |
| 111 | + |
| 112 | + auto const protocolVersion = cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION; |
| 113 | + if (protocolVersionIsBefore(protocolVersion, SOROBAN_PROTOCOL_VERSION)) |
| 114 | + { |
| 115 | + return true; |
| 116 | + } |
| 117 | + |
| 118 | + std::vector<uint32_t> hostProtocols; |
| 119 | + auto rustVersions = rust_bridge::get_soroban_version_info( |
| 120 | + Config::CURRENT_LEDGER_PROTOCOL_VERSION); |
| 121 | + for (auto const& host : rustVersions) |
| 122 | + { |
| 123 | + hostProtocols.emplace_back(host.env_max_proto); |
| 124 | + } |
| 125 | + |
| 126 | + if (isProtocolBackedByLinkedSorobanHost(protocolVersion, hostProtocols)) |
| 127 | + { |
| 128 | + return true; |
| 129 | + } |
| 130 | + |
| 131 | + return false; |
| 132 | +} |
| 133 | + |
25 | 134 | void |
26 | 135 | crankSome(VirtualClock& clock) |
27 | 136 | { |
|
0 commit comments