Repository navigation
Conversation
… part) A deterministic executor for the Layer 2 payment state described in the article "Why Proof of Work Was Built for Security, Not Speed": accounts holding several currencies, operations ordered in batches, one byte form per batch, and a payment with conversion applied as one operation (every leg or none). New library o_layer2 (src/o_layer2/payment_state.h/.cpp), linked into test_bitcoin only: no node binary, no consensus file and no existing source is changed. Integers only (no floating point, no 128-bit type), ordered containers only, SHA256 from src/crypto. Operations: DEPOSIT, WITHDRAW, PAY, PAY_CONVERT (swap with a named account that agreed to convert, at the batch's rate table, payee receives floor(paid x rate)), SET_CONVERTER. A batch that is malformed, out of turn or built on another state is refused whole; an operation that fails changes nothing. Tests (src/test/o_layer2_tests.cpp, suite o_layer2_tests, 7 cases): the byte form, nonces, the all-or-nothing conversion, conservation per currency over a mixed run, replay of the same bytes by separate instances, fixed roots. Test value only: no signature check, no sequencer, no network, no storage, no Layer 1 link, no proofs, no fee, no reward, no spam limit. The amount unit (#22), who converts, the source of the rates and the rounding rule are not decided here (see the header).
Owner
Author
|
CI result for this PR: run 44569229914 on
Still not done, as in the description: no network or second machine, no signature check, no storage, no Layer 1 link, no throughput figure. — Venus (automated coding worker) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this is
The first part of the Layer 2 prototype: the shared multi-currency payment state as a deterministic executor. Spec base: article 19, section "Layer 2: shared multi-currency payment execution" (one account-based state, transactions ordered in batches, independent nodes replay the same bytes and calculate the same resulting state, a payment with conversion is one operation: either every leg succeeds, or none does).
Prototype, test value only. Nothing here is linked into a node binary; no consensus file and no existing source file is changed.
src/o_layer2/payment_state.h/.cpp(new libraryo_layer2, linked intotest_bitcoinonly)src/test/o_layer2_tests.cpp(suiteo_layer2_tests, 7 cases)What it does
DEPOSIT,WITHDRAW,PAY,PAY_CONVERT,SET_CONVERTER.ApplyBatch(bytes)refuses a batch that is malformed, out of turn, or built on another state root, and then changes nothing.MulDivFlooris a 64x64/64 long division, checked against__int128in the test where the compiler has it).Tested, and how
No Boost / CMake on the machine this was written on, so the committed test file was compiled together with the module and
src/crypto/sha256.cppagainst a small Boost.Test macro stub:c++(clang, libc++)-fsanitize=address,undefinedpayment_state.cpp(converter not debited, rate not enforced, consent not required, rounding up, nonce not tested, previous root not tested, trailing bytes accepted, a field left out of the root, ...): the test fails on all 17.NOT tested / NOT done
cteststep is red for known reasons (Audit 2026-09: Revive CI and register the O unit/functional tests (CMake lists + test_runner) #24, Decision needed: mainnet genesis block is not mined (placeholder nonce) — ~30 unit-test fixtures fail #27), so the result to read is the suiteo_layer2_testsitself.Not decided here (the project owner's calls)
SET_CONVERTER) and holds the other currency: no unit of any currency is created or destroyed. Whether the protocol itself should be that party (mint / burn at the reference rate) is an economic choice and is not built.floor(paid x rate); the remainder (less than one smallest unit) stays with the converter. One rule had to be picked for the result to be reproducible; it is one function (ConvertFloor).About the base branch
Opened against
ci/revive-linux-ci(PR #26) and notmain, because only a branch that carries the newci.ymlgets a CI run. Nothing is merged; the 3 new files and the 2 CMake edits apply tomainunchanged if that is preferred.— Written and opened by Venus (automated coding worker) for Christophe's review. Not reviewed by a second model yet.