Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

pull Checkpoints out of #2289 #2457

Closed
wants to merge 5 commits into from

Conversation

rob-solana
Copy link
Contributor

@rob-solana rob-solana commented Jan 16, 2019

Problem

current Bank checkpoint code supports only a single stack of checkpoints, cannot support 2 simultaneous forks

Summary of Changes

implement Checkpoints, a directed acyclic graph, uses u64 (probably block index) as key for a checkpoint

@garious
Copy link
Contributor

garious commented Jan 16, 2019

Looks like a sloppy specialization of a DAG. Have you looked at:

https://docs.rs/petgraph/0.4.13/petgraph/

@rob-solana
Copy link
Contributor Author

rob-solana commented Jan 16, 2019

Looks like a sloppy specialization of a DAG. Have you looked at:

https://docs.rs/petgraph/0.4.13/petgraph/

I've just had a look, and I don't know if using it would be less code. Maybe I'd be able to copy and paste some generic DAG code for trunk() and collect(), but would that be better?

@codecov
Copy link

codecov bot commented Jan 16, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@72c7139). Click here to learn what that means.
The diff coverage is 99.2%.

@@           Coverage Diff            @@
##             master   #2457   +/-   ##
========================================
  Coverage          ?   67.5%           
========================================
  Files             ?     111           
  Lines             ?   20089           
  Branches          ?       0           
========================================
  Hits              ?   13575           
  Misses            ?    6514           
  Partials          ?       0

}
/// given a maximum depth, find the highest parent shared by all
/// forks
pub fn trunk(&self, num: usize) -> Option<u64> {
Copy link
Member

@aeyakovenko aeyakovenko Jan 16, 2019

Choose a reason for hiding this comment

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

why not a method that does

   /// returns the trunks, and an inverse dag
    pub fn invert(&self) -> (HashSet<u64>, HashMap<u64, HashSet<u64>>) {
        let mut trunks = HashSet::new();
        let mut idag = HashMap::new();
        for (k,(_,v)) in &self.checkpoints {
            trunks.remove(k);
            trunks.insert(*v);
            idag.entry(*v).or_insert(HashSet::new()).insert(*k);
        }
        (trunks, idag)
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

and then? probably what you've written is more along the lines of what you want for bank_state?

@garious
Copy link
Contributor

garious commented Jan 16, 2019

It's not clear what you're trying to do here (not integrated into anything, no issue referenced, and there's no PR description). You're adding what appears to be a fairly generic library awkwardly using the same name as the existing Checkpoint trait and specialized for u64 IDs.

@rob-solana
Copy link
Contributor Author

It's not clear what you're trying to do here (not integrated into anything, no issue referenced, and there's no PR description). You're adding what appears to be a fairly generic library awkwardly using the same name as the existing Checkpoint trait and specialized for u64 IDs.

new trait name
this piece of #2289 is easily separable and is teaching me something about that code

checkpoints.store(4, 0, 2);

let _trunks: Vec<_> = checkpoints.invert().0.into_iter().collect();
// TODO: returns [0, 2] ??
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aeyakovenko is this the expected behavior?

checkpoints.store(40, 0, 20);

let _trunks: Vec<_> = checkpoints.invert().0.into_iter().collect();
// TODO: returns [0, 2, 10, 20, 1] ??
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aeyakovenko is this the expected behavior? I don't understand how 1 is now part of trunks

@rob-solana
Copy link
Contributor Author

updated description, tests

@rob-solana rob-solana closed this Jan 21, 2019
@rob-solana rob-solana deleted the checkpoints branch January 21, 2019 21:47
jeffwashington added a commit to jeffwashington/solana that referenced this pull request Aug 6, 2024
* update test for shrink removing zero lamports

* clean up comment
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants