Skip to content

Commit

Permalink
Removed separate dkgEvidenceLog implementation struct
Browse files Browse the repository at this point in the history
It does not make sense to separate the interface from the implementation
as we keep them in the same package and will use the concrete
implementation for the code and tests.
  • Loading branch information
pdyraga committed Oct 21, 2024
1 parent 64205f4 commit 20254f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
33 changes: 13 additions & 20 deletions gjkr/evidence_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,43 +27,36 @@ import (
// sent by the accused party. To do this, they read the round 3 message from the
// log, and decrypt it using the symmetric key used between the accuser and
// accused party. The key is publicly revealed by the accuser.
type evidenceLog interface {
// getEphemeralPublicKeyMessage returns the `ephemeralPublicKeyMessage`
// broadcast in the first protocol round by the given sender.
getEphemeralPublicKeyMessage(sender memberIndex) *ephemeralPublicKeyMessage

// putEphemeralMessage is a function that takes a single
// EphemeralPubKeyMessage, and stores that as evidence for future
// accusation trials for a given (sender, receiver) pair. If a message
// already exists for the given sender, we return an error to the user.
putEphemeralPublicKeyMessage(pubKeyMessage *ephemeralPublicKeyMessage) error
}

// dkgEvidenceLog is the default implementation of an evidenceLog.
type dkgEvidenceLog struct {
type evidenceLog struct {
// senderIndex -> *ephemeralPublicKeyMessage
pubKeyMessageLog *messageStorage
}

func newDkgEvidenceLog() *dkgEvidenceLog {
return &dkgEvidenceLog{
func newEvidenceLog() *evidenceLog {
return &evidenceLog{
pubKeyMessageLog: newMessageStorage(),
}
}

func (d *dkgEvidenceLog) putEphemeralPublicKeyMessage(
// putEphemeralMessage is a function that takes a single
// EphemeralPubKeyMessage, and stores that as evidence for future
// accusation trials for a given (sender, receiver) pair. If a message
// already exists for the given sender, we return an error to the user.
func (e *evidenceLog) putEphemeralPublicKeyMessage(
pubKeyMessage *ephemeralPublicKeyMessage,
) error {
return d.pubKeyMessageLog.putMessage(
return e.pubKeyMessageLog.putMessage(
pubKeyMessage.senderIndex,
pubKeyMessage,
)
}

func (d *dkgEvidenceLog) getEphemeralPublicKeyMessage(
// getEphemeralPublicKeyMessage returns the `ephemeralPublicKeyMessage`
// broadcast in the first protocol round by the given sender.
func (e *evidenceLog) getEphemeralPublicKeyMessage(
sender memberIndex,
) *ephemeralPublicKeyMessage {
storedMessage := d.pubKeyMessageLog.getMessage(sender)
storedMessage := e.pubKeyMessageLog.getMessage(sender)
switch message := storedMessage.(type) {
case *ephemeralPublicKeyMessage:
return message
Expand Down
14 changes: 7 additions & 7 deletions gjkr/evidence_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import (
)

func TestPutEphemeralPublicKeyMessageTwice(t *testing.T) {
dkgEvidenceLog := newDkgEvidenceLog()
err := dkgEvidenceLog.putEphemeralPublicKeyMessage(
evidenceLog := newEvidenceLog()
err := evidenceLog.putEphemeralPublicKeyMessage(
&ephemeralPublicKeyMessage{
senderIndex: memberIndex(1),
})
if err != nil {
t.Fatalf("unexpected error: [%v]", err)
}

err = dkgEvidenceLog.putEphemeralPublicKeyMessage(
err = evidenceLog.putEphemeralPublicKeyMessage(
&ephemeralPublicKeyMessage{
senderIndex: memberIndex(1),
})
Expand All @@ -34,23 +34,23 @@ func TestPutEphemeralPublicKeyMessageTwice(t *testing.T) {
}

func TestPutGetEphemeralPublicKeyMessage(t *testing.T) {
dkgEvidenceLog := newDkgEvidenceLog()
evidenceLog := newEvidenceLog()

message := &ephemeralPublicKeyMessage{
senderIndex: memberIndex(1),
}

m := dkgEvidenceLog.getEphemeralPublicKeyMessage(memberIndex(1))
m := evidenceLog.getEphemeralPublicKeyMessage(memberIndex(1))
if m != nil {
t.Fatalf("expected message not to be found but has [%v]", m)
}

err := dkgEvidenceLog.putEphemeralPublicKeyMessage(message)
err := evidenceLog.putEphemeralPublicKeyMessage(message)
if err != nil {
t.Fatalf("unexpected error: [%v]", err)
}

m = dkgEvidenceLog.getEphemeralPublicKeyMessage(memberIndex(1))
m = evidenceLog.getEphemeralPublicKeyMessage(memberIndex(1))
if !reflect.DeepEqual(message, m) {
t.Fatalf(
"unexpected message\nexpected: %v\nactual: %v",
Expand Down

0 comments on commit 20254f7

Please sign in to comment.