aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-18 19:37:11 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-18 19:37:11 +0100
commit6b58644e087b5288d11cf69abee6434341ff09ae (patch)
treec8d169a863de0bc35b2f29577f2bd9977791c9e7
parentf0a7ea609523e663d02ad832bfa669c7cbbb3f38 (diff)
fixed unintuitive variable names in ActiveSthSource
-rw-r--r--handler_test.go4
-rw-r--r--sth.go38
-rw-r--r--sth_test.go50
3 files changed, 46 insertions, 46 deletions
diff --git a/handler_test.go b/handler_test.go
index daa1a6c..0d9a856 100644
--- a/handler_test.go
+++ b/handler_test.go
@@ -38,13 +38,13 @@ func newTestHandler(t *testing.T, signer crypto.Signer, sth *StItem) *testHandle
logParameters: lp,
}
if sth != nil {
- source.currSth = NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, []SignatureV1{
+ source.currCosth = NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, []SignatureV1{
SignatureV1{
Namespace: *mustNewNamespaceEd25519V1(t, testdata.Ed25519Vk),
Signature: testSignature,
},
})
- source.nextSth = NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil)
+ source.nextCosth = NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil)
source.cosignatureFrom = make(map[string]bool)
}
return &testHandler{
diff --git a/sth.go b/sth.go
index cff0736..58b5c35 100644
--- a/sth.go
+++ b/sth.go
@@ -33,9 +33,9 @@ type SthSource interface {
type ActiveSthSource struct {
client trillian.TrillianLogClient
logParameters *LogParameters
- currSth *StItem // current cosigned_tree_head_v1 (already finalized)
- nextSth *StItem // next cosigned_tree_head_v1 (under preparation)
- cosignatureFrom map[string]bool // track who we got cosignatures from
+ currCosth *StItem // current cosigned_tree_head_v1 (already finalized)
+ nextCosth *StItem // next cosigned_tree_head_v1 (under preparation)
+ cosignatureFrom map[string]bool // track who we got cosignatures from in nextCosth
mutex sync.RWMutex
}
@@ -52,8 +52,8 @@ func NewActiveSthSource(cli trillian.TrillianLogClient, lp *LogParameters) (*Act
return nil, fmt.Errorf("Latest: %v", err)
}
// TODO: load persisted cosigned STH?
- s.currSth = NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil)
- s.nextSth = NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil)
+ s.currCosth = NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil)
+ s.nextCosth = NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil)
s.cosignatureFrom = make(map[string]bool)
return &s, nil
}
@@ -89,28 +89,28 @@ func (s *ActiveSthSource) Latest(ctx context.Context) (*StItem, error) {
func (s *ActiveSthSource) Stable(_ context.Context) (*StItem, error) {
s.mutex.RLock()
defer s.mutex.RUnlock()
- if s.nextSth == nil {
+ if s.nextCosth == nil {
return nil, fmt.Errorf("no stable sth available")
}
return &StItem{
Format: StFormatSignedTreeHeadV1,
- SignedTreeHeadV1: &s.nextSth.CosignedTreeHeadV1.SignedTreeHeadV1,
+ SignedTreeHeadV1: &s.nextCosth.CosignedTreeHeadV1.SignedTreeHeadV1,
}, nil
}
func (s *ActiveSthSource) Cosigned(_ context.Context) (*StItem, error) {
s.mutex.RLock()
defer s.mutex.RUnlock()
- if s.currSth == nil || len(s.currSth.CosignedTreeHeadV1.SignatureV1) == 0 {
+ if s.currCosth == nil || len(s.currCosth.CosignedTreeHeadV1.SignatureV1) == 0 {
return nil, fmt.Errorf("no cosigned sth available")
}
- return s.currSth, nil
+ return s.currCosth, nil
}
func (s *ActiveSthSource) AddCosignature(_ context.Context, costh *StItem) error {
s.mutex.Lock()
defer s.mutex.Unlock()
- if !reflect.DeepEqual(s.nextSth.CosignedTreeHeadV1.SignedTreeHeadV1, costh.CosignedTreeHeadV1.SignedTreeHeadV1) {
+ if !reflect.DeepEqual(s.nextCosth.CosignedTreeHeadV1.SignedTreeHeadV1, costh.CosignedTreeHeadV1.SignedTreeHeadV1) {
return fmt.Errorf("cosignature covers a different tree head")
}
witness := costh.CosignedTreeHeadV1.SignatureV1[0].Namespace.String()
@@ -118,7 +118,7 @@ func (s *ActiveSthSource) AddCosignature(_ context.Context, costh *StItem) error
return nil // duplicate
}
s.cosignatureFrom[witness] = true
- s.nextSth.CosignedTreeHeadV1.SignatureV1 = append(s.nextSth.CosignedTreeHeadV1.SignatureV1, costh.CosignedTreeHeadV1.SignatureV1[0])
+ s.nextCosth.CosignedTreeHeadV1.SignatureV1 = append(s.nextCosth.CosignedTreeHeadV1.SignatureV1, costh.CosignedTreeHeadV1.SignatureV1[0])
return nil
}
@@ -126,22 +126,22 @@ func (s *ActiveSthSource) AddCosignature(_ context.Context, costh *StItem) error
// source's read-write lock if there are concurrent reads and/or writes.
func (s *ActiveSthSource) rotate(fixedSth *StItem) {
// rotate stable -> cosigned
- if reflect.DeepEqual(&s.currSth.CosignedTreeHeadV1.SignedTreeHeadV1, &s.nextSth.CosignedTreeHeadV1.SignedTreeHeadV1) {
- for _, sigv1 := range s.currSth.CosignedTreeHeadV1.SignatureV1 {
+ if reflect.DeepEqual(&s.currCosth.CosignedTreeHeadV1.SignedTreeHeadV1, &s.nextCosth.CosignedTreeHeadV1.SignedTreeHeadV1) {
+ for _, sigv1 := range s.currCosth.CosignedTreeHeadV1.SignatureV1 {
witness := sigv1.Namespace.String()
if _, ok := s.cosignatureFrom[witness]; !ok {
s.cosignatureFrom[witness] = true
- s.nextSth.CosignedTreeHeadV1.SignatureV1 = append(s.nextSth.CosignedTreeHeadV1.SignatureV1, sigv1)
+ s.nextCosth.CosignedTreeHeadV1.SignatureV1 = append(s.nextCosth.CosignedTreeHeadV1.SignatureV1, sigv1)
}
}
}
- s.currSth.CosignedTreeHeadV1.SignedTreeHeadV1 = s.nextSth.CosignedTreeHeadV1.SignedTreeHeadV1
- s.currSth.CosignedTreeHeadV1.SignatureV1 = make([]SignatureV1, len(s.nextSth.CosignedTreeHeadV1.SignatureV1))
- copy(s.currSth.CosignedTreeHeadV1.SignatureV1, s.nextSth.CosignedTreeHeadV1.SignatureV1)
+ s.currCosth.CosignedTreeHeadV1.SignedTreeHeadV1 = s.nextCosth.CosignedTreeHeadV1.SignedTreeHeadV1
+ s.currCosth.CosignedTreeHeadV1.SignatureV1 = make([]SignatureV1, len(s.nextCosth.CosignedTreeHeadV1.SignatureV1))
+ copy(s.currCosth.CosignedTreeHeadV1.SignatureV1, s.nextCosth.CosignedTreeHeadV1.SignatureV1)
// rotate new stable -> stable
- if !reflect.DeepEqual(&s.nextSth.CosignedTreeHeadV1.SignedTreeHeadV1, fixedSth.SignedTreeHeadV1) {
- s.nextSth = NewCosignedTreeHeadV1(fixedSth.SignedTreeHeadV1, nil)
+ if !reflect.DeepEqual(&s.nextCosth.CosignedTreeHeadV1.SignedTreeHeadV1, fixedSth.SignedTreeHeadV1) {
+ s.nextCosth = NewCosignedTreeHeadV1(fixedSth.SignedTreeHeadV1, nil)
s.cosignatureFrom = make(map[string]bool)
}
}
diff --git a/sth_test.go b/sth_test.go
index b77e96c..e3350dd 100644
--- a/sth_test.go
+++ b/sth_test.go
@@ -50,10 +50,10 @@ func TestNewActiveSthSource(t *testing.T) {
return
}
- if got, want := source.currSth, table.wantCosi; !reflect.DeepEqual(got, want) {
+ if got, want := source.currCosth, table.wantCosi; !reflect.DeepEqual(got, want) {
t.Errorf("got cosigned sth %v but wanted %v in test %q", got, want, table.description)
}
- if got, want := source.nextSth, table.wantStable; !reflect.DeepEqual(got, want) {
+ if got, want := source.nextCosth, table.wantStable; !reflect.DeepEqual(got, want) {
t.Errorf("got stable sth %v but wanted %v in test %q", got, want, table.description)
}
cosignatureFrom := make(map[string]bool)
@@ -133,7 +133,7 @@ func TestStable(t *testing.T) {
{
description: "valid",
source: &ActiveSthSource{
- nextSth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil)},
+ nextCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil)},
wantRsp: sth,
},
} {
@@ -172,14 +172,14 @@ func TestCosigned(t *testing.T) {
{
description: "no cosigned sth: nil signatures",
source: &ActiveSthSource{
- currSth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil),
+ currCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil),
},
wantErr: true,
},
{
description: "valid",
source: &ActiveSthSource{
- currSth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, sigs),
+ currCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, sigs),
},
wantRsp: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, sigs),
},
@@ -211,7 +211,7 @@ func TestAddCosignature(t *testing.T) {
{
description: "invalid: cosignature must target the stable sth",
source: &ActiveSthSource{
- nextSth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil),
+ nextCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil),
cosignatureFrom: make(map[string]bool),
},
req: NewCosignedTreeHeadV1(NewSignedTreeHeadV1(NewTreeHeadV1(makeTrillianLogRoot(t, testTimestamp+1000000, testTreeSize, testNodeHash)), testLogId, testSignature).SignedTreeHeadV1, []SignatureV1{
@@ -225,7 +225,7 @@ func TestAddCosignature(t *testing.T) {
{
description: "valid: adding duplicate into a pool of cosignatures",
source: &ActiveSthSource{
- nextSth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, []SignatureV1{
+ nextCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, []SignatureV1{
SignatureV1{
Namespace: *wit1,
Signature: testSignature,
@@ -246,7 +246,7 @@ func TestAddCosignature(t *testing.T) {
{
description: "valid: adding into an empty pool of cosignatures",
source: &ActiveSthSource{
- nextSth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil),
+ nextCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, nil),
cosignatureFrom: make(map[string]bool),
},
req: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, []SignatureV1{
@@ -260,7 +260,7 @@ func TestAddCosignature(t *testing.T) {
{
description: "valid: adding into a pool of cosignatures",
source: &ActiveSthSource{
- nextSth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, []SignatureV1{
+ nextCosth: NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, []SignatureV1{
SignatureV1{
Namespace: *wit1,
Signature: testSignature,
@@ -295,7 +295,7 @@ func TestAddCosignature(t *testing.T) {
Signature: testSignature,
})
}
- if got, want := table.source.nextSth, NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, sigs); !reflect.DeepEqual(got, want) {
+ if got, want := table.source.nextCosth, NewCosignedTreeHeadV1(sth.SignedTreeHeadV1, sigs); !reflect.DeepEqual(got, want) {
t.Errorf("got %v but wanted %v in test %q", got, want, table.description)
}
// Check that the map tracking witness signatures is updated
@@ -329,8 +329,8 @@ func TestRotate(t *testing.T) {
{
description: "not repeated cosigned and not repeated stable",
source: &ActiveSthSource{
- currSth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, nil),
- nextSth: NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []SignatureV1{
+ currCosth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, nil),
+ nextCosth: NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []SignatureV1{
SignatureV1{
Namespace: *wit1,
Signature: testSignature,
@@ -353,8 +353,8 @@ func TestRotate(t *testing.T) {
{
description: "not repeated cosigned and repeated stable",
source: &ActiveSthSource{
- currSth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, nil),
- nextSth: NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []SignatureV1{
+ currCosth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, nil),
+ nextCosth: NewCosignedTreeHeadV1(sth2.SignedTreeHeadV1, []SignatureV1{
SignatureV1{
Namespace: *wit1,
Signature: testSignature,
@@ -382,7 +382,7 @@ func TestRotate(t *testing.T) {
{
description: "repeated cosigned and not repeated stable",
source: &ActiveSthSource{
- currSth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{
+ currCosth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{
SignatureV1{
Namespace: *wit1,
Signature: testSignature,
@@ -392,7 +392,7 @@ func TestRotate(t *testing.T) {
Signature: testSignature,
},
}),
- nextSth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{
+ nextCosth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{
SignatureV1{
Namespace: *wit2,
Signature: testSignature,
@@ -428,7 +428,7 @@ func TestRotate(t *testing.T) {
{
description: "repeated cosigned and repeated stable",
source: &ActiveSthSource{
- currSth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{
+ currCosth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{
SignatureV1{
Namespace: *wit1,
Signature: testSignature,
@@ -438,7 +438,7 @@ func TestRotate(t *testing.T) {
Signature: testSignature,
},
}),
- nextSth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{
+ nextCosth: NewCosignedTreeHeadV1(sth1.SignedTreeHeadV1, []SignatureV1{
SignatureV1{
Namespace: *wit2,
Signature: testSignature,
@@ -486,11 +486,11 @@ func TestRotate(t *testing.T) {
},
} {
table.source.rotate(table.fixedSth)
- if got, want := table.source.currSth, table.wantCurrSth; !reflect.DeepEqual(got, want) {
- t.Errorf("got currSth %X but wanted %X in test %q", got, want, table.description)
+ if got, want := table.source.currCosth, table.wantCurrSth; !reflect.DeepEqual(got, want) {
+ t.Errorf("got currCosth %X but wanted %X in test %q", got, want, table.description)
}
- if got, want := table.source.nextSth, table.wantNextSth; !reflect.DeepEqual(got, want) {
- t.Errorf("got nextSth %X but wanted %X in test %q", got, want, table.description)
+ if got, want := table.source.nextCosth, table.wantNextSth; !reflect.DeepEqual(got, want) {
+ t.Errorf("got nextCosth %X but wanted %X in test %q", got, want, table.description)
}
if got, want := len(table.source.cosignatureFrom), len(table.wantWit); got != want {
t.Errorf("witness map got %d cosignatures but wanted %d in test %q", got, want, table.description)
@@ -502,9 +502,9 @@ func TestRotate(t *testing.T) {
}
}
// check that adding cosignatures to stable will not effect cosigned sth
- wantLen := len(table.source.currSth.CosignedTreeHeadV1.SignatureV1)
- table.source.nextSth.CosignedTreeHeadV1.SignatureV1 = append(table.source.nextSth.CosignedTreeHeadV1.SignatureV1, SignatureV1{Namespace: *wit1, Signature: testSignature})
- if gotLen := len(table.source.currSth.CosignedTreeHeadV1.SignatureV1); gotLen != wantLen {
+ wantLen := len(table.source.currCosth.CosignedTreeHeadV1.SignatureV1)
+ table.source.nextCosth.CosignedTreeHeadV1.SignatureV1 = append(table.source.nextCosth.CosignedTreeHeadV1.SignatureV1, SignatureV1{Namespace: *wit1, Signature: testSignature})
+ if gotLen := len(table.source.currCosth.CosignedTreeHeadV1.SignatureV1); gotLen != wantLen {
t.Errorf("adding cosignatures to the stable sth modifies the fixated cosigned sth in test %q", table.description)
}
}