Skip to content

Commit

Permalink
Rename Payload.Value -> Payload.Chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed May 28, 2024
1 parent 31e5408 commit 458718c
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 86 deletions.
20 changes: 10 additions & 10 deletions gpbft/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 31 additions & 31 deletions gpbft/gpbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,21 @@ type Payload struct {
// The common data.
Data InstanceData
// The value agreed-upon in a single instance.
Value ECChain
Chain ECChain
}

func (p *Payload) Eq(other *Payload) bool {
return p.Instance == other.Instance &&
p.Round == other.Round &&
p.Step == other.Step &&
p.Data.Eq(&other.Data) &&
p.Value.Eq(other.Value)
p.Chain.Eq(other.Chain)
}

func (p *Payload) MarshalForSigning(nn NetworkName) []byte {
values := make([][]byte, len(p.Value))
for i := range p.Value {
values[i] = p.Value[i].MarshalForSigning()
values := make([][]byte, len(p.Chain))
for i := range p.Chain {
values[i] = p.Chain[i].MarshalForSigning()
}
root := merkle.Tree(values)

Expand All @@ -137,7 +137,7 @@ func (p *Payload) MarshalForSigning(nn NetworkName) []byte {
}

func (m GMessage) String() string {
return fmt.Sprintf("%s{%d}(%d %s)", m.Vote.Step, m.Vote.Instance, m.Vote.Round, &m.Vote.Value)
return fmt.Sprintf("%s{%d}(%d %s)", m.Vote.Step, m.Vote.Instance, m.Vote.Round, &m.Vote.Chain)
}

// A single Granite consensus instance.
Expand Down Expand Up @@ -325,25 +325,25 @@ func (i *instance) receiveOne(msg *GMessage) error {
switch msg.Vote.Step {
case QUALITY_PHASE:
// Receive each prefix of the proposal independently.
i.quality.ReceiveEachPrefix(msg.Sender, msg.Vote.Value)
i.quality.ReceiveEachPrefix(msg.Sender, msg.Vote.Chain)
case CONVERGE_PHASE:
if err := round.converged.Receive(msg.Sender, msg.Vote.Value, msg.Ticket, msg.Justification); err != nil {
if err := round.converged.Receive(msg.Sender, msg.Vote.Chain, msg.Ticket, msg.Justification); err != nil {
return fmt.Errorf("failed processing CONVERGE message: %w", err)
}
case PREPARE_PHASE:
round.prepared.Receive(msg.Sender, msg.Vote.Value, msg.Signature)
round.prepared.Receive(msg.Sender, msg.Vote.Chain, msg.Signature)
case COMMIT_PHASE:
round.committed.Receive(msg.Sender, msg.Vote.Value, msg.Signature)
round.committed.Receive(msg.Sender, msg.Vote.Chain, msg.Signature)
// The only justifications that need to be stored for future propagation are for COMMITs
// to non-bottom values.
// This evidence can be brought forward to justify a CONVERGE message in the next round.
if !msg.Vote.Value.IsZero() {
round.committed.ReceiveJustification(msg.Vote.Value, msg.Justification)
if !msg.Vote.Chain.IsZero() {
round.committed.ReceiveJustification(msg.Vote.Chain, msg.Justification)
}
case DECIDE_PHASE:
i.decision.Receive(msg.Sender, msg.Vote.Value, msg.Signature)
i.decision.Receive(msg.Sender, msg.Vote.Chain, msg.Signature)
if i.phase != DECIDE_PHASE {
i.skipToDecide(msg.Vote.Value, msg.Justification)
i.skipToDecide(msg.Vote.Chain, msg.Justification)
}
if err := i.tryDecide(); err != nil {
return fmt.Errorf("failed to decide: %w", err)
Expand Down Expand Up @@ -441,12 +441,12 @@ func (i *instance) validateMessage(msg *GMessage) error {
}

// Check that message value is a valid chain.
if err := msg.Vote.Value.Validate(); err != nil {
if err := msg.Vote.Chain.Validate(); err != nil {
return xerrors.Errorf("invalid message vote value chain: %w", err)
}
// Check the value is acceptable.
if !(msg.Vote.Value.IsZero() || msg.Vote.Value.HasBase(i.input.Base())) {
return xerrors.Errorf("unexpected base %s", &msg.Vote.Value)
if !(msg.Vote.Chain.IsZero() || msg.Vote.Chain.HasBase(i.input.Base())) {
return xerrors.Errorf("unexpected base %s", &msg.Vote.Chain)
}

// Check phase-specific constraints.
Expand All @@ -455,14 +455,14 @@ func (i *instance) validateMessage(msg *GMessage) error {
if msg.Vote.Round != 0 {
return xerrors.Errorf("unexpected round %d for quality phase", msg.Vote.Round)
}
if msg.Vote.Value.IsZero() {
if msg.Vote.Chain.IsZero() {
return xerrors.Errorf("unexpected zero value for quality phase")
}
case CONVERGE_PHASE:
if msg.Vote.Round == 0 {
return xerrors.Errorf("unexpected round 0 for converge phase")
}
if msg.Vote.Value.IsZero() {
if msg.Vote.Chain.IsZero() {
return xerrors.Errorf("unexpected zero value for converge phase")
}
if !VerifyTicket(i.beacon, i.instanceID, msg.Vote.Round, senderPubKey, i.participant.host, msg.Ticket) {
Expand All @@ -472,7 +472,7 @@ func (i *instance) validateMessage(msg *GMessage) error {
if msg.Vote.Round != 0 {
return xerrors.Errorf("unexpected non-zero round %d for decide phase", msg.Vote.Round)
}
if msg.Vote.Value.IsZero() {
if msg.Vote.Chain.IsZero() {
return xerrors.Errorf("unexpected zero value for decide phase")
}
case PREPARE_PHASE, COMMIT_PHASE:
Expand All @@ -490,7 +490,7 @@ func (i *instance) validateMessage(msg *GMessage) error {
// Check justification
needsJustification := !(msg.Vote.Step == QUALITY_PHASE ||
(msg.Vote.Step == PREPARE_PHASE && msg.Vote.Round == 0) ||
(msg.Vote.Step == COMMIT_PHASE && msg.Vote.Value.IsZero()))
(msg.Vote.Step == COMMIT_PHASE && msg.Vote.Chain.IsZero()))
if needsJustification {
if msg.Justification == nil {
return fmt.Errorf("message for phase %v round %v has no justification", msg.Vote.Step, msg.Vote.Round)
Expand All @@ -500,7 +500,7 @@ func (i *instance) validateMessage(msg *GMessage) error {
return fmt.Errorf("message with instanceID %v has evidence from instanceID: %v", msg.Vote.Instance, msg.Justification.Vote.Instance)
}
// Check that justification vote value is a valid chain.
if err := msg.Justification.Vote.Value.Validate(); err != nil {
if err := msg.Justification.Vote.Chain.Validate(); err != nil {
return xerrors.Errorf("invalid justification vote value chain: %w", err)
}

Expand All @@ -516,21 +516,21 @@ func (i *instance) validateMessage(msg *GMessage) error {
// or a strong quorum of PREPARE for the same value, from the previous round.
CONVERGE_PHASE: {
COMMIT_PHASE: {msg.Vote.Round - 1, ECChain{}},
PREPARE_PHASE: {msg.Vote.Round - 1, msg.Vote.Value},
PREPARE_PHASE: {msg.Vote.Round - 1, msg.Vote.Chain},
},
// PREPARE is justified by the same rules as CONVERGE (in rounds > 0).
PREPARE_PHASE: {
COMMIT_PHASE: {msg.Vote.Round - 1, ECChain{}},
PREPARE_PHASE: {msg.Vote.Round - 1, msg.Vote.Value},
PREPARE_PHASE: {msg.Vote.Round - 1, msg.Vote.Chain},
},
// COMMIT is justified by strong quorum of PREPARE from the same round with the same value.
COMMIT_PHASE: {
PREPARE_PHASE: {msg.Vote.Round, msg.Vote.Value},
PREPARE_PHASE: {msg.Vote.Round, msg.Vote.Chain},
},
// DECIDE is justified by strong quorum of COMMIT with the same value.
// The DECIDE message doesn't specify a round.
DECIDE_PHASE: {
COMMIT_PHASE: {math.MaxUint64, msg.Vote.Value},
COMMIT_PHASE: {math.MaxUint64, msg.Vote.Chain},
},
}

Expand All @@ -539,8 +539,8 @@ func (i *instance) validateMessage(msg *GMessage) error {
if msg.Justification.Vote.Round != expected.Round && expected.Round != math.MaxUint64 {
return fmt.Errorf("message %v has justification from wrong round %d", msg, msg.Justification.Vote.Round)
}
if !msg.Justification.Vote.Value.Eq(expected.Value) {
return fmt.Errorf("message %v has justification for a different value: %v", msg, msg.Justification.Vote.Value)
if !msg.Justification.Vote.Chain.Eq(expected.Value) {
return fmt.Errorf("message %v has justification for a different value: %v", msg, msg.Justification.Vote.Chain)
}
} else {
return fmt.Errorf("message %v has justification with unexpected phase: %v", msg, msg.Justification.Vote.Step)
Expand Down Expand Up @@ -887,7 +887,7 @@ func (i *instance) isCandidate(c ECChain) bool {
func (i *instance) terminate(decision *Justification) {
i.log("✅ terminated %s during round %d", &i.value, i.round)
i.phase = TERMINATED_PHASE
i.value = decision.Vote.Value
i.value = decision.Vote.Chain
i.terminationValue = decision
}

Expand All @@ -900,7 +900,7 @@ func (i *instance) broadcast(round uint64, step Phase, value ECChain, ticket Tic
Instance: i.instanceID,
Round: round,
Step: step,
Value: value,
Chain: value,
}
sp := i.participant.host.MarshalPayloadForSigning(&p)

Expand Down Expand Up @@ -942,7 +942,7 @@ func (i *instance) buildJustification(quorum QuorumResult, round uint64, phase P
Instance: i.instanceID,
Round: round,
Step: phase,
Value: value,
Chain: value,
},
Signers: quorum.SignersBitfield(),
Signature: aggSignature,
Expand Down
Loading

0 comments on commit 458718c

Please sign in to comment.