mirror of
https://github.com/luxfi/bft.git
synced 2026-10-30 17:01:54 +00:00
QuorumCertificates were carried around the network already parsed, which forced parsing to happen before a message reached the epoch.
Since a QC has an ability to verify its own signature, it implicitly means that a QC implementation needs knowledge of the public keys for the epoch the QC was created for.
Instead of wiring the public keys of the epoch to the QC, the QuorumCertificate.Verify() now receives the set of nodes so the verifier has access to validator membership (and their public keys) when checking a quorum certificate.
The nodes argument is threaded through verifyContextQC, the Finalization/Notarization/EmptyNotarization Verify() methods, the verifiableMessage interface, and VerifyQC, with
e.nodes supplied at every call site in epoch.go.
To support this, common.Node is reworked:
- rename the Node.Node field to Node.Id to disambiguate it from the
surrounding type
- add a PK []byte field to carry each node's public key
Signed-off-by: Yacov Manevich <[email protected]>
65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
// Copyright (C) 2019-2025, Ava Labs, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package common
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/hex"
|
|
"fmt"
|
|
)
|
|
|
|
type NodeID []byte
|
|
|
|
func (node NodeID) String() string {
|
|
var nodePrint [8]byte
|
|
copy(nodePrint[:], node)
|
|
return hex.EncodeToString(nodePrint[:])
|
|
}
|
|
|
|
func (node NodeID) Equals(otherNode NodeID) bool {
|
|
return bytes.Equal(node, otherNode)
|
|
}
|
|
|
|
type NodeIDs []NodeID
|
|
|
|
func (nodes NodeIDs) String() string {
|
|
var nodeStrings []string
|
|
for _, node := range nodes {
|
|
nodeStrings = append(nodeStrings, node.String())
|
|
}
|
|
return fmt.Sprintf("%v", nodeStrings)
|
|
}
|
|
|
|
func (nodes NodeIDs) Remove(targetNode NodeID) []NodeID {
|
|
for i, n := range nodes {
|
|
if n.Equals(targetNode) {
|
|
result := make([]NodeID, 0, len(nodes)-1)
|
|
result = append(result, nodes[:i]...)
|
|
result = append(result, nodes[i+1:]...)
|
|
return result
|
|
}
|
|
}
|
|
return nodes
|
|
}
|
|
|
|
func (nodes NodeIDs) IndexOf(id NodeID) int {
|
|
for i, n := range nodes {
|
|
if n.Equals(id) {
|
|
return i
|
|
}
|
|
}
|
|
return -1
|
|
}
|
|
|
|
func (nodes NodeIDs) EqualWeightedNodes() Nodes {
|
|
weights := make(Nodes, len(nodes))
|
|
for i, node := range nodes {
|
|
weights[i] = Node{
|
|
Id: node,
|
|
Weight: 1,
|
|
}
|
|
}
|
|
return weights
|
|
}
|