Repository navigation
Config Setting upgrades - #3674
Conversation
There was a problem hiding this comment.
I'm not sure if this has the same format as all the other entries (with '='). Also, this will return JSON, right? So the formatting might be a bit weird due to it being multiline. Not sure though where we're using the toString though...
There was a problem hiding this comment.
NB: I believe exception is fine here as we shouldn't get to upgrade execution for the invalid/unknown upgrades. But we need to make sure we don't crash during validation itself.
There was a problem hiding this comment.
So this is still an open question I have. If a valid configUpgrade is nominated, is it possible so change the underlying ContractData entry that holds the ConfigUpgradeSet before the upgrade is applied? If so, that scenario needs to be handled.
There was a problem hiding this comment.
Hmm, yeah, it might change, so we need to verify that hash in the key matches the content hash. That can happen at validation time though, as upgrades happen after all the transactions. At apply time the upgrade set should be guaranteed to be correct and hence it should be ok to throw an exception (as that would be a bug)
There was a problem hiding this comment.
The hash is already verified in ConfigUpgradeSetFrame::isValidXDR.
There was a problem hiding this comment.
So we should be good, right? Also we load the actual entry just once anyway, so there shouldn't be mismatch between the config upgrade set at validation and application time.
There was a problem hiding this comment.
We load the entry at validation and at apply (every time we call makeFromKey). It's possible that the ledger the upgrade should be included in changes the entry, making the upgrade invalid. In that case, an exception would be thrown here -
stellar-core/src/ledger/LedgerManagerImpl.cpp
Line 744 in 53ea43a
There was a problem hiding this comment.
Updated code to ignore invalid upgrades instead of throwing an exception.
a07289b to
b330107
Compare
There was a problem hiding this comment.
Hmm, yeah, it might change, so we need to verify that hash in the key matches the content hash. That can happen at validation time though, as upgrades happen after all the transactions. At apply time the upgrade set should be guaranteed to be correct and hence it should be ok to throw an exception (as that would be a bug)
There was a problem hiding this comment.
Just wanted to make sure, how the downstream code handles nullptr here? Would it just act as if we didn't have such upgrade armed?
There was a problem hiding this comment.
It depends. In the CommandHandler, we actually check after setting to make sure something was set. In applyTo, we throw an exception (this shouldn't happen, but if it does, it'll be caught). In isValidForApply, we return XDR_INVALID. In isValidForNomination, we return false.
78a46c4 to
7e47c86
Compare
| hexAbbrev(key.contentHash)); | ||
| return false; | ||
| } | ||
| if (std::adjacent_find( |
There was a problem hiding this comment.
is_sorted above already does not allow for duplicates
There was a problem hiding this comment.
That's not true - it 'Checks if the elements in range [first, last) are sorted in non-descending order'
There was a problem hiding this comment.
bleh yes! I always get is_sorted wrong
So I guess the suggestion becomes: as we use a custom predicate we should just use >= for adjacent_find which should do what we want (can't use this with is_sorted as >= is not Compare).
80b11d3 to
77bcdd3
Compare
|
Change looks good now! |
14f73ba to
ed002c2
Compare
This is to support how the new XDR is generated.
While this can be supported from the ledger standpoint, I think that semantically these shouldn't be removed and hence it's better to introduce some harness to make sure we don't accidentally remove it.
- Add methods to generate unique entries, so that we don't need to exclude `CONFIG_SETTING` entry from the fuzzer due to them having key collisions - Add methods to generate entries of given type and entries with exclusions to be more explicit about including/excluding the entry types where relevant
…of `CONFIG_SETTING` entries.
ed002c2 to
1b2f664
Compare
|
I cleaned up history and merged in the xdr change. One thing I'm trying to figure out though - I only updated the C++ and not env, but the xdr mismatch check isn't triggering for me locally. |
1b2f664 to
27bf0bd
Compare
@graydon do you think this is related to the fix you made? |
Looks like the github action correctly failed though. Weird. |
Ah I see this in my make output. I got a new laptop recently which is why I haven't run into this before. I'll try to get this to fail the build. |
29f2490 to
cd3d956
Compare
|
r+ cd3d956 |
|
(@MonsieurNicolas is on vacation but I believe all his concerns were addressed, I'm going to dismiss his change-request) |
on vacation, all changes addressed
**Prototype, not for merge as is.** Like #5495 it has no flag and no protocol gate. It moves tx-set dissemination from a request model to a push model: the round's leader sends the tx set it is about to propose to its peers as soon as the set is built, instead of waiting for each follower to ask for it. Stacked on #5495. The branch sits on `b524ef962`, the head #5495 had when it was merged; `overlay-v2-shared` (`cc51aba48`, #5496) has the same tree, so this PR shows only its own four commits: - `0f9255d47` Start QUIC connections with an 8 MiB congestion window - `8f7768be7` Push the leader's tx set to peers when it is built (prototype) - `d0fe62652` Document the remaining gaps of the tx-set push (docs and one `.gitattributes` line, no code) - `2f9baef24` Describe the tx-set push experiment and its perfnet results in the README (the branch `README.md` now covers this experiment, with #5495's values as "before"; README only) Everything below was built, tested and measured on `8f7768be7`. ## Result in one paragraph On perfnet (30 validators, 4 AWS regions, c6id.2xlarge, 3,000 SAC TPS) at the 1 s target that #5495 failed, all four windows are on target on every node: avg p75 1,091 / 1,096 / 1,109 / 1,115 ms against 1,386 ms, and 1.05 s per ledger against 1.33 s. A follower's Core gets the leader's tx set 16 ms after it asks for it, where it took 217 ms. One caveat: every node's ledgers hold 60 transactions more than the 2,880,000 that were offered. The counters point to about 60 transactions being included in two ledgers, which only the fixture's overlay-only mode allows; see "The inclusion check" below. The run was judged with the exact check and reported FAIL for that check alone. It is accepted as an artifact of that mode, and the check is being relaxed to allow such duplicates (stellar-experimental/performance-testing#4). One run, against one run of the base from the same day. ## Design - **Trigger.** A new Core-to-overlay IPC message `PUSH_TX_SET [hash][slot]`. `HerderImpl` sends it right after `CACHE_TX_SET` from inside the build when the node leads the current round, after the build for a first-round leader's capacity-limited prepared set (the one case where the prepared set is proposed unchanged), and again when a prepared set is taken at the trigger. Later-round leaders go through the same build hook. `CACHE_TX_SET` alone does not push: it also carries sets that are never proposed. - **Sender.** The overlay writes the cached, already compressed set to the tx-set stream of every connected peer that has not been sent it. One push in flight per peer; a peer that does not read is not sent further sets and requests them. - **Wire.** The pushed frame is the existing tx-set frame, sent without a request. No new wire message, no claimed hash, no slot. - **Receiver.** The overlay decompresses, strict-parses and hashes the frame as it does a response and caches it under the hash it computed. Core is not told. When an SCP statement names that hash, Core's `RequestTxSet` is answered from the cache at once. - **Push against request.** If the proposal reaches a follower before the push is complete, the follower requests the set as before. The leader does not answer the first request from a peer for a set that is still being written to it or was written less than 500 ms ago: the bytes are already on the same ordered stream. Every other request is answered. - **Fallback.** The request path is unchanged. A node that is not connected to the leader, connected later, or was busy with an earlier push has no cached set and requests it; Core's 1 s retry to another peer is still behind that. The push is not relayed: a node that is not connected to the leader asks the peer that relayed the proposal, which holds the pushed copy. - **One flight.** quinn paces one congestion window over 0.8 round trips and does not grow the window while the sender is application limited. Measured locally (two overlay nodes over a loopback with a netem delay, 150 ms round trip, 640 KB frame, one run per setting): with quinn's default window the frame arrives 229-253 ms after the send on a warm connection (75 ms of that is the one-way delay) and 965 ms on a cold one; with an initial window of 8 MiB it arrives after 94 ms. Without that, a push would lose the race against the proposal (sent about 70 ms later) on every cross-region link. Hence the first commit. The window applies to every stream of a connection; it is a prototype setting. - **Considered and not done:** a compact wire form (transaction hashes, rebuilt from the follower's mempool; a follower that lacks one transaction needs another round trip, and at 3,000 TPS the newest transactions are still flooding); an announcement before the body (a new way to stall a follower); relaying (in a full mesh every set would arrive 29 times without an inventory exchange). ## Why it should be safe - No change to tx-set validation, the voting rules, the ballot protocol or apply. The C++ diff adds IPC sends on the main thread and metrics. - A follower only uses a set whose hash is in a signed SCP statement: the overlay files a pushed set under the hash of its own content, Core asks only for hashes named by statements it is processing, accepts a set only while it is fetching that hash, and re-checks the content hash. A pushed set that does not match the proposal is never looked up; the proposed set is requested. This is tested at three levels (below). - What a leader can do with the push: push nothing or late (followers request, as before); push a set it does not propose (it sits in a bounded cache and is never used); push to some peers only (the others request); push garbage or a truncated frame (dropped at decode; a stalled frame blocks only that peer's own tx-set stream, as a stalled response does today); push many or large sets (bounded, next point). - Unrequested tx-set frames were accepted without limits before this change. They now have a per-peer token bucket applied before decompression (burst 8, 4 per second; answers to the node's own requests do not use it) and limits on cached sets from peers that Core has not asked for (per peer 4 pushed and 16 requested, 128 MiB in total, largest holder evicted first). - Known gaps, stated in `docs/rust-overlay/txset-fetching.md`: - A follower that drops a pushed set on arrival (its own limits) asks inside the 500 ms in which the leader skips the request, so it is only served by Core's 1 s retry. Honest leaders do not trigger those limits. - The overlay prefetches any hash named in an SCP envelope before Core checks the signature, so a peer can buy one frame over the rate per envelope; a reconnect resets a peer's allowance; many colluding peers can even out the shared byte budget; the 100-entry cache itself is first in, first out over all sets. - Hardening of the overlay's XDR parsing limits is not addressed here; it is the same on the base for every message type. ## Testing (all on `8f7768be7`) - New, C++ (`herder/test/TxSetPushTests.cpp`, 4 network simulations with real overlay processes): the leader's push is used (no follower waits for the retry); consensus through the request path when no push is sent; a network where half the leaders push; every leader pushes one set and proposes another (the pushed set is never used, every ledger externalizes the proposed set). One IPC section in `overlay/test/IPCTests.cpp`. - New, Rust: 16 unit tests for the push bookkeeping (`flood/txset_push.rs`), 7 two- and three-node tests (`libp2p_overlay/txset_push_tests.rs`: push reaches every peer once, a crossing request is skipped once, a late request is answered, a peer that missed the push is served, the record is cleared on a closed connection, the rate limit, a malformed frame), 7 App-level tests (`main.rs`: a pushed set reaches Core only on request, a set with another hash does not answer a request, the limits), 4 end-to-end tests with two overlay binaries (`tests/e2e_binary.rs`: push before the request, no push, pushed set with another hash, a dropped push recovered by a request). - Full suite: PASS. 602 test cases / 2,383,553 assertions in 121 batches, libsodium 77, xdrpp 7, check-rust and the soroban host tests (103 `test result: ok`, 0 failed). - Full suite `--all-versions`: PASS. 602 test cases / 8,155,400 assertions. - Tag run `[herder],[scp],[txset],[overlay-ipc],[overlay],[ipc],[upgrades],[simulation]` (150 tests, on the PR head `d0fe62652`): passes except three `[acceptance]` tests that are not in the full suite and fail without this change: "hierarchical topology scales 1 to 3" and "core nodes with outer nodes" (as reported in #5495), and "SCP Driver / validateValue txSet cached" (`HerderTests.cpp:2964`, `0 == 9`), which fails on #5495's source too whenever the test runs with `--base-instance` 50 or 400, i.e. in partition 2 or 9 of a partitioned run, and passes with 0 or 450. - `clang-format` 20.1.8 on the changed C++ files and `cargo fmt --check` on the overlay crate: clean. - **Not passing:** a `--disable-tests` build stops in `herder/HerderImpl.cpp` on the same test headers as on #5495. The three other non-test objects this change touches compile without `BUILD_TESTS`. - **Not run:** sanitizers; the tx-meta and LedgerCloseMeta determinism checks (the change does not touch apply). - **Test gaps:** no test with a peer that really stops reading its tx-set stream; none that drives a failed push write end to end; the C++ simulations run with empty mempools, so the prepared-set push and realistic set sizes are only exercised on perfnet; with three or more nodes, the path "request skipped, then Core's retry to another peer" is not tested; the network tests use fixed ports and 1 s windows. - Three independent review passes of the diff; the last one found no correctness, determinism or safety problem. Its minor findings are under "Open review findings". ## Perfnet 30 validators in 4 regions, 10 tier-1 orgs, c6id.2xlarge, SAC payments, 150 ms simulated apply per ledger (50 us per op at this setting), 900 s measured, all SCP timeouts 2 s. Target 1,000 ms, 3,000 TPS. Base: #5495's commit `daa965f4c` (before its rebases, which changed formatting, the README and a CI file), build #3674, the same fixture and instance type on the same day; its load was stopped after the first window, as block_time_check does on a miss. This PR: build #3675 of `8f7768be7`. **One run each.** | | #5495 `daa965f4c` | This PR `8f7768be7` | |---|---:|---:| | Windows | 1 of 1 missed (all 30 nodes) | **4 of 4 on target (all 30 nodes)** | | avg p75 per window | 1,386 ms | 1,091 / 1,096 / 1,109 / 1,115 ms | | avg p99 per window | 1,599 ms | 1,227 / 1,243 / 1,253 / 1,290 ms | | Ledgers per 5 min | 225-226 (1.33 s each) | 285-286 / 283-284 / 281-282 (1.05-1.07 s) | | Txs per ledger | 3,750 (the cap) | 3,155 (below the cap) | | Tx-set fetch `scp.fetch.txset`: mean (p75 / p99) | 0.217 s (0.33 / n/r) | **0.016 s (0.017 / 0.024)** | | Sets a follower had to await from the network | every set (0.198 s mean) | none in window 1 | | Trigger to first ballot: mean (p75 / p99) | 0.70 s | 0.42 s (0.47 / 0.57) | | Ballot to externalize: mean (p75 / p99) | 0.41 s (0.53 / 0.76) | 0.33 s (0.34 / 0.50) | | Leader build / follower validation / ledger close (mean) | 0.25 / 0.12 / 0.20 s | 0.15 / 0.11 / 0.16 s | | **Trigger to close (sum)** | **1.30 s** | **0.91 s** | | Leader timeouts, prepare timeouts, rounds above 1, empty tx sets | 0, 0, none, 0 | 0, 0, none, 0 | | Error counters, in sync, no fork, still closing | passed | passed | | Inclusion | skipped (early stop) | **failed: 2,880,060 on every node, 2,880,000 offered** | | Verdict as judged | FAIL (block time) | FAIL (inclusion only, with the exact check; passes the relaxed one) | Stage values are 5-minute means at the end of window 1, median over the 30 nodes. - Push counters over the whole load (network totals): 28,507 pushes sent, 28,456 received, 28,181 already in place when Core asked, 64 requests that crossed a push (not answered twice), 0 dropped, 0 evicted, 0 retries, 0 write errors. - From live logs of one node per region: a follower's Core has the set a median 126 ms after the leader logs "Built TX set" (76-169 ms by region pair). On #5495 that took about 480 ms on a 147 ms link. A follower externalizes 0.45-0.55 s after the leader's set is built (0.97 s on #5495 at the 2 s setting). - The two runs are in different regimes. #5495 could not close a ledger in under 1.33 s, so every set was at the cap and the mempool backed up. Here the cycle fits into about 0.91 s and ledgers hold what was offered. That also makes stages this change does not touch cheaper (the leader pulls 3,200 candidates instead of 7,700; sets are smaller). - Block time is about 1.05 s although the stages sum to 0.91 s; not looked into. - A slow drift over the 16 minutes: avg p75 1,091 to 1,115 ms, trigger to first ballot 0.42 to 0.45 s. Cause not identified. - **Not separable in one run:** the push and the 8 MiB window. The window also applies to SCP and transaction flooding. ### The inclusion check: 60 transactions too many block_time_check compares the transactions in every node's ledgers with the number offered. All 30 nodes hold exactly 60 more (same value everywhere, no fork). The generators submitted exactly 2,880,000 (96,000 each, none rejected) and every node pulled every foreign transaction exactly once, so about 60 transactions (0.002%) were included in two ledgers. #5495's completed run at 2 s had the exact count; its 1 s run stopped before this check. How that can happen here (the code path is the stack's documented behaviour; that it explains these 60 is inferred from the counters, the logs carry no transaction hashes): 1. The fixture runs in overlay-only mode. Apply is skipped, sequence numbers do not advance, and the one-transaction-per-source-account rule is off, so nothing in Core rejects a transaction that an earlier ledger already held. With real apply such a copy fails validation when a leader builds its set. 2. The overlay's mempool removes a ledger's transactions at externalization and deliberately keeps no memory of them: the test `externalization_removes_queued_admission_without_remembering_hashes` says "Truly later admissions are deliberately allowed; no finalized hash history remains. Ledger-state validity is still checked by Core." A copy that reaches a node for the first time after the removal is admitted as new and included when that node next leads. 3. A leader that is not backed up takes everything in its mempool, including transactions that are still flooding to the far nodes (an inventory batch plus one and a half round trips: up to about 0.5 s). 4. With the push, a follower externalizes 0.45-0.55 s after the leader's set is built, which is now as fast as the slowest flooding. On #5495 it was about a second, so the two never met. So the design relies on Core's ledger-state validation, which this fixture switches off, and the push's speed-up is what makes the two meet. This PR does not change that, and the overlay keeps its behaviour (remembering finalized hashes there would change production behaviour for a test-mode artifact). The duplicates are accepted for this fixture: block_time_check's inclusion check is relaxed to allow up to 1 in 10,000 transactions more than offered, with the caveat written next to it (stellar-experimental/performance-testing#4). Fewer than offered, more than that, and nodes that disagree still fail. No run has been made with the relaxed check; applied to this run's recorded counts it passes with 60 over. ## Open review findings (not fixed in `8f7768be7`) - The in-flight count of a push is only released when the write task ends. A panic in that task, or a stream open that never completes while the peer is disconnected, would leave the peer marked busy (it would then always request). - A push that is still being written when a connection to that peer closes is no longer recorded: a crossing request gets a second copy, and a request skipped before the close is not answered if the write then fails (Core's retry covers it). - Per-peer unclaimed entries can add up to 20 while the cache holds 100 sets of any kind. - A set is accounted to the peer that delivered it first, so a peer that delivers the leader's set first and then pushes four more evicts it. - The token bucket's parameters assume at most two sets per led slot at 500 ms or more per slot. ## Next steps Not started: a run of the base with only the congestion window, and of the push on quinn's default window, to separate the two effects; repeats (n = 1 here); a longer run to see whether the drift continues; then 800 ms.
Description
Resolves stellar/rs-soroban-env#664.
Add a mechanism to propose upgrades that are stored in ContractData ledger entries. This PR is built on top of #3522, and starts with the "ConfigSettingEntry upgrades" commit.
Related xdr change - stellar/stellar-xdr#75.
xdr has not been merged in yet so this PR will fail until that happens.
Checklist
clang-formatv8.0.0 (viamake formator the Visual Studio extension)