Skip to content

Commit ca721ad

Browse files
authored
ledger: refactor evaluator into an internal package (algorand#2983)
## Summary This PR reorganize the files inside the ledger package by move the evaluator related files into its own `internal` package. The files in the internal package cannot access the root ledger files, and therefore using the shared `ledgercore` as a place to share interfaces. ``` ledger/ ├── apply/ ├── internal/ ├── ledgercore/ └── testing/ ``` ## Test Plan use existing test, and update existing tests.
1 parent 1a58f33 commit ca721ad

File tree

5 files changed

+10
-258
lines changed

5 files changed

+10
-258
lines changed

compactcert/builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type Builder struct {
4545
sigs []sigslot // Indexed by pos in participants
4646
sigsHasValidL bool // The L values in sigs are consistent with weights
4747
signedWeight uint64 // Total weight of signatures so far
48-
participants []Participant
48+
participants []basics.Participant
4949
parttree *merklearray.Tree
5050

5151
// Cached cert, if Build() was called and no subsequent
@@ -57,7 +57,7 @@ type Builder struct {
5757
// to be signed, as well as other security parameters, are specified in
5858
// param. The participants that will sign the message are in part and
5959
// parttree.
60-
func MkBuilder(param Params, part []Participant, parttree *merklearray.Tree) (*Builder, error) {
60+
func MkBuilder(param Params, part []basics.Participant, parttree *merklearray.Tree) (*Builder, error) {
6161
npart := len(part)
6262

6363
b := &Builder{

compactcert/builder_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (m TestMessage) ToBeHashed() (protocol.HashID, []byte) {
3636
}
3737

3838
type PartCommit struct {
39-
participants []Participant
39+
participants []basics.Participant
4040
}
4141

4242
func (pc PartCommit) Length() uint64 {
@@ -78,10 +78,10 @@ func TestBuildVerify(t *testing.T) {
7878
// Share the key; we allow the same vote key to appear in multiple accounts..
7979
key := crypto.GenerateOneTimeSignatureSecrets(0, 1)
8080

81-
var parts []Participant
81+
var parts []basics.Participant
8282
var sigs []crypto.OneTimeSignature
8383
for i := 0; i < npartHi; i++ {
84-
part := Participant{
84+
part := basics.Participant{
8585
PK: key.OneTimeSignatureVerifier,
8686
Weight: uint64(totalWeight / 2 / npartHi),
8787
KeyDilution: 10000,
@@ -91,7 +91,7 @@ func TestBuildVerify(t *testing.T) {
9191
}
9292

9393
for i := 0; i < npartLo; i++ {
94-
part := Participant{
94+
part := basics.Participant{
9595
PK: key.OneTimeSignatureVerifier,
9696
Weight: uint64(totalWeight / 2 / npartLo),
9797
KeyDilution: 10000,
@@ -165,12 +165,12 @@ func BenchmarkBuildVerify(b *testing.B) {
165165
SecKQ: 128,
166166
}
167167

168-
var parts []Participant
168+
var parts []basics.Participant
169169
var partkeys []*crypto.OneTimeSignatureSecrets
170170
var sigs []crypto.OneTimeSignature
171171
for i := 0; i < npart; i++ {
172172
key := crypto.GenerateOneTimeSignatureSecrets(0, 1)
173-
part := Participant{
173+
part := basics.Participant{
174174
PK: key.OneTimeSignatureVerifier,
175175
Weight: uint64(totalWeight / npart),
176176
KeyDilution: 10000,

compactcert/msgp_gen.go

Lines changed: 0 additions & 160 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compactcert/msgp_gen_test.go

Lines changed: 0 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compactcert/structs.go

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,34 +30,6 @@ type Params struct {
3030
SecKQ uint64 // Security parameter (k+q) from analysis document
3131
}
3232

33-
// A Participant corresponds to an account whose AccountData.Status
34-
// is Online, and for which the expected sigRound satisfies
35-
// AccountData.VoteFirstValid <= sigRound <= AccountData.VoteLastValid.
36-
//
37-
// In the Algorand ledger, it is possible for multiple accounts to have
38-
// the same PK. Thus, the PK is not necessarily unique among Participants.
39-
// However, each account will produce a unique Participant struct, to avoid
40-
// potential DoS attacks where one account claims to have the same VoteID PK
41-
// as another account.
42-
type Participant struct {
43-
_struct struct{} `codec:",omitempty,omitemptyarray"`
44-
45-
// PK is AccountData.VoteID.
46-
PK crypto.OneTimeSignatureVerifier `codec:"p"`
47-
48-
// Weight is AccountData.MicroAlgos.
49-
Weight uint64 `codec:"w"`
50-
51-
// KeyDilution is AccountData.KeyDilution() with the protocol for sigRound
52-
// as expected by the Builder.
53-
KeyDilution uint64 `codec:"d"`
54-
}
55-
56-
// ToBeHashed implements the crypto.Hashable interface.
57-
func (p Participant) ToBeHashed() (protocol.HashID, []byte) {
58-
return protocol.CompactCertPart, protocol.Encode(&p)
59-
}
60-
6133
// CompactOneTimeSignature is crypto.OneTimeSignature with omitempty
6234
type CompactOneTimeSignature struct {
6335
_struct struct{} `codec:",omitempty,omitemptyarray"`
@@ -87,8 +59,8 @@ func (ssc sigslotCommit) ToBeHashed() (protocol.HashID, []byte) {
8759
type Reveal struct {
8860
_struct struct{} `codec:",omitempty,omitemptyarray"`
8961

90-
SigSlot sigslotCommit `codec:"s"`
91-
Part Participant `codec:"p"`
62+
SigSlot sigslotCommit `codec:"s"`
63+
Part basics.Participant `codec:"p"`
9264
}
9365

9466
// MaxReveals is a bound on allocation and on numReveals to limit log computation

0 commit comments

Comments
 (0)