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

move ledger into separate crate #606

Merged
merged 2 commits into from
Mar 11, 2024
Merged

move ledger into separate crate #606

merged 2 commits into from
Mar 11, 2024

Conversation

zeegomo
Copy link
Contributor

@zeegomo zeegomo commented Mar 10, 2024

No description provided.

@@ -0,0 +1,13 @@
[package]
name = "cryptarchia-ledger"
Copy link
Contributor

Choose a reason for hiding this comment

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

curious, why a separate crate and not a ledger module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was already a ledger module before 🤔
The idea is to make it clear we would like to have a distinction between the two, in the sense that consensus should have limited influence on ledger choices (e.g. transactions should probably have the same format regardless of the consensus alg, they should work with both carnot and cryptarchia). As a result, those items might better be defined in their own separate crate (for now I've not created a common crate/module since we don't have those components yet).

Of course, some things will have to change (like the header format and leadership proof), and for this reason we have specific ledger modules/crates.

Copy link
Contributor

@davidrusu davidrusu left a comment

Choose a reason for hiding this comment

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

So to summarize:

  • consensus/cryptarchia-engine deals with forks and branch selection
  • ledger/cryptarchis-ledger deals contents of blocks (header and body)

with the dependency going ledger -> consensus.

Sounds reasonable.

I guess we are still missing the bit that ties together the two crates

Comment on lines -144 to +152
let current_epoch = self.slot.epoch(config);
let new_epoch = slot.epoch(config);
let current_epoch = config.epoch(self.slot);
let new_epoch = config.epoch(slot);
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

pub struct Cryptarchia {
local_chain: Branch,
branches: Branches,
ledger: Ledger,
Copy link
Contributor

Choose a reason for hiding this comment

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

Prior to this PR, we had this Cryptarchia struct tying together ledger and branches.

It was making sure that whenever branches was updated, the ledger was also updated (and vice-versa).

This functionality seems to have been dropped in this PR? Or I'm just now seeing where it moved.

It seems we need something like this Cryptarchia struct in ledger to keep branches and ledger in sync.

@zeegomo
Copy link
Contributor Author

zeegomo commented Mar 11, 2024

with the dependency going ledger -> consensus.
Sounds reasonable.

The idea is that this is only true for the format of some components that might be part of the ledger (e.g. a leader proof that needs to access ledger properties like stake).

This functionality seems to have been dropped in this PR? Or I'm just now seeing where it moved.
It seems we need something like this Cryptarchia struct in ledger to keep branches and ledger in sync

True, this would be moved to a nomos service. The goal is that we shoudn't need to change the ledger much if we change consensus

@davidrusu
Copy link
Contributor

True, this would be moved to a nomos service. The goal is that we shoudn't need to change the ledger much if we change consensus

As I understand it, the rest of the nomos service should only be exposed to consensus indirectly through the ledger api right? so in that sense, the ledger should probably be the one that is driving consensus and ensuring it's state is in sync with the consensus state?

So what if you modified the Ledger struct to hold an instance of Cryptrachia and when there is a ledger state upate, it goes and updates cryptarchia as well.

@zeegomo
Copy link
Contributor Author

zeegomo commented Mar 11, 2024

As I see it there are two separate things:

  • The state(s) of the system, also called a ledger. It tracks who owns what and any other things we want to track. The only assumption is that a ledger is evolved incrementally through steps (corresponding to a block in our case), and that each step builds on top of some other existing state in the ledger. Each state can be identified univocally. At this stage, no state is special and they are all equally valid (i.e. there's no concept of a main branch or tip). I feel like this makes it easier to manage forks, as each fork is validated locally without any special consideration on whether it's the 'main' chain or not.
  • Fork selection, what I called consensus in this separation. The scope of this module is essentially just decide which state to adopt but in doing so it does not actually need to understand what's happening (e.g. block contents or state associated with the tip). Consensus can be achieved on random strings without any meaning, the fact that we associate a state with that random string (the id of a block) is orthogonal to this problem.

The goal of this separation is that we can develop the two somewhat independently. If an execution zone would like to use another consensus (like Carnot), it should not have to dramatically change the ledger, just change the way it selects which state to consider. I don't see a need for the ledger to track the state of consensus.

@davidrusu
Copy link
Contributor

Ok, got it, yeah I agree now, having the consensus instance inside Ledger doesn't make much sense.

@zeegomo zeegomo merged commit e51865f into master Mar 11, 2024
7 checks passed
@zeegomo zeegomo deleted the separate-ledger branch March 11, 2024 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants