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

Collect F+1 instead of (N+F)/2+1 signatures in multisigcollector #175

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions pkg/availability/multisigcollector/internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,7 @@ func DefaultModuleConfig() *ModuleConfig {
type ModuleParams struct {
InstanceUID []byte // unique identifier for this instance of BCB, used to prevent cross-instance replay attacks
AllNodes []t.NodeID // the list of participating nodes
}

// N is the total number of replicas.
func (params *ModuleParams) N() int {
return len(params.AllNodes)
}

// F is the maximum number of replicas that can be tolerated.
func (params *ModuleParams) F() int {
return (params.N() - 1) / 3
F int // the maximum number of failures tolerated. Must be less than (len(AllNodes)-1) / 2
}

// State represents the common state used by all parts of the multisig collector implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ func IncludeCreatingCertificates(
return nil
})

// When a quorum (more than (N+F)/2) of signatures are collected, create and output a certificate.
// When F+1 signatures are collected, create and output a certificate.
dsl.UponCondition(m, func() error {
// Iterate over active outgoing requests.
//Most of the time, there is expected to be at most one active outgoing request.
for reqID, requestState := range state.RequestState {
if len(requestState.sigs) > (params.N()+params.F())/2 {
if len(requestState.sigs) > params.F+1 {
certNodes, certSigs := maputil.GetKeysAndValues(requestState.sigs)

requestingModule := t.ModuleID(requestState.ReqOrigin.Module)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func verifyCertificateStructure(params *common.ModuleParams, cert *apb.Cert) (*m
mscCert := mscCertWrapper.Msc

// Check that the certificate contains a sufficient number of signatures.
if len(mscCert.Signers) <= (params.N()+params.F())/2 {
if len(mscCert.Signers) <= params.F+1 {
return nil, fmt.Errorf("insuficient number of signatures")
}

Expand Down
12 changes: 9 additions & 3 deletions pkg/availability/multisigcollector/multisigcollector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package multisigcollector

import (
"fmt"

"github.com/filecoin-project/mir/pkg/availability/multisigcollector/internal/common"
"github.com/filecoin-project/mir/pkg/availability/multisigcollector/internal/parts/batchreconstruction"
"github.com/filecoin-project/mir/pkg/availability/multisigcollector/internal/parts/certcreation"
Expand All @@ -18,9 +20,13 @@ type ModuleParams = common.ModuleParams
// NewModule creates a new instance of the multisig collector module.
// Multisig collector is the simplest implementation of the availability layer.
// Whenever an availability certificate is requested, it pulls a batch from the mempool module,
// sends it to all replicas and collects a quorum (i.e., more than (N+F)/2) of signatures confirming that
// sends it to all replicas and collects params.F+1 signatures confirming that
// other nodes have persistently stored the batch.
func NewModule(mc *ModuleConfig, params *ModuleParams, nodeID t.NodeID) modules.PassiveModule {
func NewModule(mc *ModuleConfig, params *ModuleParams, nodeID t.NodeID) (modules.PassiveModule, error) {
if 2*params.F+1 < len(params.AllNodes) {
return nil, fmt.Errorf("cannot tolerate %v / %v failures", params.F, len(params.AllNodes))
}

m := dsl.NewModule(mc.Self)

commonState := &common.State{
Expand All @@ -32,5 +38,5 @@ func NewModule(mc *ModuleConfig, params *ModuleParams, nodeID t.NodeID) modules.
certverification.IncludeVerificationOfCertificates(m, mc, params, nodeID, commonState)
batchreconstruction.IncludeBatchReconstruction(m, mc, params, nodeID, commonState)

return m
return m, nil
}