Skip to content

Commit

Permalink
Make lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
ranchalp committed Jul 28, 2023
1 parent d15f141 commit 063d1fc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func IncludeFullCertificate(m dsl.Module,
mc.Crypto,
sliceutil.Transform(maputil.GetValues(certificate),
func(i int, sp *accpbtypes.SignedPredecision) *cryptopbtypes.SignedData {
return &cryptopbtypes.SignedData{[][]byte{sp.Predecision, []byte(mc.Self)}}
return &cryptopbtypes.SignedData{Data: [][]byte{sp.Predecision, []byte(mc.Self)}}
}),
sliceutil.Transform(maputil.GetValues(certificate),
func(i int, sp *accpbtypes.SignedPredecision) []byte {
Expand All @@ -68,8 +68,8 @@ func IncludeFullCertificate(m dsl.Module,
})

cryptopbdsl.UponSigsVerified(m, func(nodeIds []t.NodeID, errs []error, allOk bool, vsr *verifySigs) error {
for i, nodeId := range nodeIds {
predecisions.ApplySigVerified(m, mc, params, state, nodeId, errs[i], vsr.certificate[nodeId], false, logger)
for i, nodeID := range nodeIds {
predecisions.ApplySigVerified(m, mc, params, state, nodeID, errs[i], vsr.certificate[nodeID], false, logger)
}
poms.SendPoMs(m, mc, params, state, logger)
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func IncludeLightCertificate(m dsl.Module,

accpbdsl.UponLightCertificateReceived(m, func(from t.NodeID, data []byte) error {

if !params.LightCertificates {
return nil
}

if state.DecidedCertificate == nil {
logger.Log(logging.LevelDebug, "Received light certificate before decided certificate, buffering it")
lightCertificates[from] = data
Expand Down
4 changes: 2 additions & 2 deletions pkg/accountability/simpleacc/internal/poms/poms.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func IncludePoMs(
nodeIds = append(nodeIds, pom.NodeId, pom.NodeId)

data = append(data,
&cryptopbtypes.SignedData{[][]byte{pom.ConflictingMsg_1.Predecision, []byte(mc.Self)}},
&cryptopbtypes.SignedData{[][]byte{pom.ConflictingMsg_2.Predecision, []byte(mc.Self)}})
&cryptopbtypes.SignedData{Data: [][]byte{pom.ConflictingMsg_1.Predecision, []byte(mc.Self)}},
&cryptopbtypes.SignedData{Data: [][]byte{pom.ConflictingMsg_2.Predecision, []byte(mc.Self)}})

signatures = append(signatures, pom.ConflictingMsg_1.Signature, pom.ConflictingMsg_2.Signature)
}
Expand Down
29 changes: 13 additions & 16 deletions pkg/accountability/simpleacc/internal/predecisions/predecisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func IncludePredecisions(
state.Predecided = true

// Sign predecision attaching mc.Self to prevent replay attacks
cryptopbdsl.SignRequest(m, mc.Crypto, &cryptopbtypes.SignedData{[][]byte{data, []byte(mc.Self)}}, &signRequest{data})
cryptopbdsl.SignRequest(m, mc.Crypto, &cryptopbtypes.SignedData{Data: [][]byte{data, []byte(mc.Self)}}, &signRequest{data: data})

return nil
})
Expand All @@ -69,7 +69,7 @@ func IncludePredecisions(

// Verify signature of received signed predecision
cryptopbdsl.VerifySig(m, mc.Crypto,
&cryptopbtypes.SignedData{[][]byte{predecision, []byte(mc.Self)}},
&cryptopbtypes.SignedData{Data: [][]byte{predecision, []byte(mc.Self)}},
signature,
from,
&accpbtypes.SignedPredecision{
Expand All @@ -80,7 +80,8 @@ func IncludePredecisions(
})

cryptopbdsl.UponSigVerified(m, func(nodeId t.NodeID, err error, sp *accpbtypes.SignedPredecision) error {
return ApplySigVerified(m, mc, params, state, nodeId, err, sp, true, logger)
ApplySigVerified(m, mc, params, state, nodeId, err, sp, true, logger)
return nil
})

}
Expand All @@ -94,27 +95,26 @@ func ApplySigVerified(
mc *common.ModuleConfig,
params *common.ModuleParams,
state *incommon.State,
nodeId t.NodeID,
nodeID t.NodeID,
err error,
sp *accpbtypes.SignedPredecision,
flushPoMs bool,
logger logging.Logger,
) error {
) {
if err != nil {
logger.Log(logging.LevelDebug, "Signature verification failed")
return nil
}

// Check if PoM found
if state.SignedPredecisions[nodeId] != nil {
if !reflect.DeepEqual(state.SignedPredecisions[nodeId].Predecision, sp.Predecision) {
if state.SignedPredecisions[nodeID] != nil {
if !reflect.DeepEqual(state.SignedPredecisions[nodeID].Predecision, sp.Predecision) {
logger.Log(logging.LevelWarn, "Received conflicting signed predecisions from same node")
// if a PoM for this node has not already been sent
if _, ok := state.SentPoMs[nodeId]; !ok {
if _, ok := state.SentPoMs[nodeID]; !ok {
state.UnsentPoMs = append(state.UnsentPoMs,
&accpbtypes.PoM{
NodeId: nodeId,
ConflictingMsg_1: state.SignedPredecisions[nodeId],
NodeId: nodeID,
ConflictingMsg_1: state.SignedPredecisions[nodeID],
ConflictingMsg_2: sp,
})

Expand All @@ -124,16 +124,15 @@ func ApplySigVerified(
}

logger.Log(logging.LevelDebug, "Discarding signed predecision as already received one from same node")
return nil
}
}

// Store signed predecision
state.SignedPredecisions[nodeId] = sp
state.SignedPredecisions[nodeID] = sp
if state.PredecisionCount[string(sp.Predecision)] == nil {
state.PredecisionCount[string(sp.Predecision)] = make([]t.NodeID, 0)
}
state.PredecisionCount[string(sp.Predecision)] = append(state.PredecisionCount[string(sp.Predecision)], nodeId)
state.PredecisionCount[string(sp.Predecision)] = append(state.PredecisionCount[string(sp.Predecision)], nodeID)

// Once verified, if strong quorum, broadcast accpbdsl.FullCertificate
if state.DecidedCertificate == nil &&
Expand Down Expand Up @@ -165,8 +164,6 @@ func ApplySigVerified(
maputil.GetKeys(params.Membership.Nodes))
}
}

return nil
}

type signRequest struct {
Expand Down

0 comments on commit 063d1fc

Please sign in to comment.