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

Cryptarchia: rework specification #116

Merged
merged 23 commits into from
Feb 25, 2025
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bf5ef98
cryptarchia/ghost: prep for move to weight based fork choice
davidrusu Oct 30, 2024
893ffb5
cryptarchia/ghost: remove common_prefix_len helper
davidrusu Oct 30, 2024
37eb040
cryptarchia/ghost: common_prefix_depth returns depth of both chains
davidrusu Oct 30, 2024
e9d4793
cryptarchia/ghost: fix chain density calculation
davidrusu Oct 30, 2024
30bc359
cryptarchia/ghost: maxvalid_bg uses block ids rather than chains
davidrusu Oct 30, 2024
363ca76
cryptarchia/ghost: unimported_orphans returns orphans w.r.t. to tip
davidrusu Nov 1, 2024
d1b5678
cryptarchia/ghost: remove redundant check
davidrusu Nov 1, 2024
cc50e2e
cryptarchia/ghost: rewrite unimported_orphan w/ common_prefix_depths
davidrusu Nov 1, 2024
639b744
cryptarchia/ghost: validate_header w.r.t. block parent
davidrusu Nov 1, 2024
170b825
cryptachia/ghost: rewrite on_block to remove dependency on Chain
davidrusu Nov 1, 2024
91e1482
cryptarchia/ghost: remove Chain abstraction
davidrusu Nov 1, 2024
0421e9f
cryptarchia/ghost: remove local / fork naming in common_prefix_depth
davidrusu Nov 1, 2024
5050f46
cryptarchia/ghost: rewrite common_prefix_depth in terms of iter_chain
davidrusu Nov 1, 2024
adaeba2
cryptarchia/ghost: impl GHOST fork choice rule
davidrusu Nov 1, 2024
e4d8887
cryptarchia/ghost: integrate GHOST with maxvalid fork choice
davidrusu Nov 1, 2024
c33365b
cryptarchia: remove unused imports
davidrusu Nov 1, 2024
987060d
cryptarchia: cleanup
davidrusu Nov 1, 2024
9eabadd
cryptarchia: cleanup
davidrusu Nov 1, 2024
55da6dd
cryptarchia: remove height from ledger state
davidrusu Nov 1, 2024
dca237f
cryptachia/ghost: update fork choice rule comments
davidrusu Nov 14, 2024
de32864
cryptarchia: switch back to longest chain
davidrusu Dec 1, 2024
155ac24
cryptarchia: update tests
davidrusu Dec 1, 2024
ee2c36b
cryptarchia: remove debug log
davidrusu Dec 1, 2024
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
Prev Previous commit
Next Next commit
cryptarchia/ghost: rewrite common_prefix_depth in terms of iter_chain
davidrusu committed Nov 1, 2024
commit 5050f4636ec3ab177745274b3fcba5e13e746238
47 changes: 18 additions & 29 deletions cryptarchia/cryptarchia.py
Original file line number Diff line number Diff line change
@@ -676,42 +676,31 @@ def chain_suffix(tip: Id, n: int, states: Dict[Id, LedgerState]) -> list[LedgerS


def common_prefix_depth(a: Id, b: Id, states: Dict[Id, LedgerState]) -> (int, int):
a_block = a
b_block = b
a_blocks = iter_chain(a, states)
b_blocks = iter_chain(b, states)

seen = {}
depth = 0
while True:
if a_block not in states and b_block not in states:
# conflicting genesis blocks
print("")
print("a\t", a[:2])
print("b\t", b[:2])
print(
"states\n\t",
"\n\t".join(
[f"{b[:2]} -> {s.block.parent[:2]}" for b, s in states.items()]
),
)
print("seen\t", {s[:2] for s in seen})
break

if a_block in seen:
# we had seen this block from the fork chain
return depth, seen[a_block]
try:
a_block = next(a_blocks).block.id()
if a_block in seen:
# we had seen this block from the fork chain
return depth, seen[a_block]

if a_block in states:
seen[a_block] = depth
a_block = states[a_block].block.parent

if b_block in seen:
# we had seen the fork in the local chain
# return the depth w.r.t to the local chain
return seen[b_block], depth

if b_block in states:
except StopIteration:
pass

try:
b_block = next(b_blocks).block.id()
if b_block in seen:
# we had seen the fork in the local chain
return seen[b_block], depth
seen[b_block] = depth
b_block = states[b_block].block.parent
except StopIteration:
pass

depth += 1

assert False