-
Notifications
You must be signed in to change notification settings - Fork 13
Save decisions in certstore #322
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,25 +4,16 @@ import ( | |
| "context" | ||
| "time" | ||
|
|
||
| "github.com/filecoin-project/go-f3/certs" | ||
| "github.com/filecoin-project/go-f3/gpbft" | ||
| "github.com/filecoin-project/go-f3/sim" | ||
| "golang.org/x/xerrors" | ||
| ) | ||
|
|
||
| type Client interface { | ||
| gpbft.SignerWithMarshaler | ||
| gpbft.Verifier | ||
| gpbft.Tracer | ||
|
|
||
| BroadcastMessage(context.Context, *gpbft.MessageBuilder) error | ||
| IncomingMessages() <-chan gpbft.ValidatedMessage | ||
| Logger() Logger | ||
| } | ||
|
|
||
| // gpbftRunner is responsible for running gpbft.Participant, taking in all concurrent events and | ||
| // passing them to gpbft in a single thread. | ||
| type gpbftRunner struct { | ||
| client Client | ||
| client *client | ||
| participant *gpbft.Participant | ||
| manifest Manifest | ||
|
|
||
|
|
@@ -35,7 +26,7 @@ type gpbftRunner struct { | |
| // gpbftHost is a newtype of gpbftRunner exposing APIs required by the gpbft.Participant | ||
| type gpbftHost gpbftRunner | ||
|
|
||
| func newRunner(id gpbft.ActorID, m Manifest, client Client) (*gpbftRunner, error) { | ||
| func newRunner(id gpbft.ActorID, m Manifest, client *client) (*gpbftRunner, error) { | ||
| runner := &gpbftRunner{ | ||
| client: client, | ||
| manifest: m, | ||
|
|
@@ -118,14 +109,30 @@ func (h *gpbftRunner) ValidateMessage(msg *gpbft.GMessage) (gpbft.ValidatedMessa | |
| // ReceiveDecision (or known to be final via some other channel). | ||
| func (h *gpbftHost) GetProposalForInstance(instance uint64) (*gpbft.SupplementalData, gpbft.ECChain, error) { | ||
| // TODO: this is just a complete fake | ||
|
|
||
| pt, _, err := h.GetCommitteeForInstance(0) | ||
| if err != nil { | ||
| return nil, nil, xerrors.Errorf("getting power table: %w", err) | ||
| } | ||
| ptCid, err := certs.MakePowerTableCID(pt.Entries) | ||
| if err != nil { | ||
| return nil, nil, xerrors.Errorf("computing power table CID: %w", err) | ||
| } | ||
|
|
||
| ts := sim.NewTipSetGenerator(1) | ||
| chain, err := gpbft.NewChain(gpbft.TipSet{Epoch: 0, Key: ts.Sample()}, gpbft.TipSet{Epoch: 1, Key: ts.Sample()}) | ||
| chain, err := gpbft.NewChain( | ||
| gpbft.TipSet{Epoch: 0, Key: ts.Sample(), PowerTable: ptCid}, | ||
| gpbft.TipSet{Epoch: 1, Key: ts.Sample(), PowerTable: ptCid}, | ||
| ) | ||
| if err != nil { | ||
| return nil, nil, err | ||
| return nil, nil, xerrors.Errorf("geenrating chain: %w", err) | ||
| } | ||
| sd := &gpbft.SupplementalData{ | ||
| PowerTable: ptCid, | ||
| } | ||
|
|
||
| // TODO: use lookback to return the correct next power table commitment and commitments hash. | ||
| return new(gpbft.SupplementalData), chain, nil | ||
| return sd, chain, nil | ||
| } | ||
|
|
||
| func (h *gpbftHost) GetCommitteeForInstance(instance uint64) (*gpbft.PowerTable, []byte, error) { | ||
|
|
@@ -178,10 +185,43 @@ func (h *gpbftHost) SetAlarm(at time.Time) { | |
| // E.g. this might be: finalised tipset timestamp + epoch duration + stabilisation delay. | ||
| func (h *gpbftHost) ReceiveDecision(decision *gpbft.Justification) time.Time { | ||
| h.log.Infof("got decision: %+v", decision) | ||
| //TODO propagate and save this for use in GetCanonicalChain | ||
| err := h.saveDecision(decision) | ||
| if err != nil { | ||
| h.log.Errorf("error while saving decision: %+v", err) | ||
| } | ||
|
|
||
| return time.Now().Add(2 * time.Second) | ||
| } | ||
|
|
||
| func (h *gpbftHost) saveDecision(decision *gpbft.Justification) error { | ||
| instance := decision.Vote.Instance | ||
| current, _, err := h.GetCommitteeForInstance(instance) | ||
| if err != nil { | ||
| return xerrors.Errorf("getting commitee for current instance %d: %w", instance, err) | ||
| } | ||
|
|
||
| next, _, err := h.GetCommitteeForInstance(instance + 1) | ||
| if err != nil { | ||
| return xerrors.Errorf("getting commitee for next instance %d: %w", instance+1, err) | ||
| } | ||
| powerDiff := certs.MakePowerTableDiff(current.Entries, next.Entries) | ||
|
|
||
| cert, err := certs.NewFinalityCertificate(powerDiff, decision) | ||
| if err != nil { | ||
| return xerrors.Errorf("forming certificate out of decision: %w", err) | ||
| } | ||
| _, _, _, err = certs.ValidateFinalityCertificates(h, h.NetworkName(), current.Entries, decision.Vote.Instance, cert.ECChain.Base()) | ||
| if err != nil { | ||
| return xerrors.Errorf("certificate is invalid: %w", err) | ||
| } | ||
|
|
||
| err = h.client.certstore.Put(h.runningCtx, cert) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, we should spend the extra time and validate this certificate. We can either do that inside the certstore, or here. |
||
| if err != nil { | ||
| return xerrors.Errorf("saving ceritifcate in a store: %w", err) | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // MarshalPayloadForSigning marshals the given payload into the bytes that should be signed. | ||
| // This should usually call `Payload.MarshalForSigning(NetworkName)` except when testing as | ||
| // that method is slow (computes a merkle tree that's necessary for testing). | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: you don't need to pass the base. If you pass nil, it'll just ignore it.