@@ -18,6 +18,7 @@ package participation
1818
1919import (
2020 "context"
21+ "encoding/hex"
2122 "os"
2223 "path/filepath"
2324 "runtime"
@@ -44,8 +45,10 @@ func TestOverlappingParticipationKeys(t *testing.T) {
4445 consensus := make (config.ConsensusProtocols )
4546 shortPartKeysProtocol := config .Consensus [protocol .ConsensusCurrentVersion ]
4647 shortPartKeysProtocol .ApprovedUpgrades = map [protocol.ConsensusVersion ]uint64 {}
48+ // keys round = current - 2 * (2 * 1) (see selector.go)
49+ // new keys must exist at least 4 rounds prior use
4750 shortPartKeysProtocol .SeedLookback = 2
48- shortPartKeysProtocol .SeedRefreshInterval = 8
51+ shortPartKeysProtocol .SeedRefreshInterval = 1
4952 if runtime .GOARCH == "amd64" {
5053 // amd64 platforms are generally quite capable, so accelerate the round times to make the test run faster.
5154 shortPartKeysProtocol .AgreementFilterTimeoutPeriod0 = 1 * time .Second
@@ -55,6 +58,8 @@ func TestOverlappingParticipationKeys(t *testing.T) {
5558
5659 var fixture fixtures.RestClientFixture
5760 fixture .SetConsensus (consensus )
61+ // ShortParticipationKeys template has LastPartKeyRound=8
62+ // to allow the 3rd key to be registered and appear after 4+4 round for its first use
5863 fixture .SetupNoStart (t , filepath .Join ("nettemplates" , "ShortParticipationKeys.json" ))
5964 defer fixture .Shutdown ()
6065
@@ -72,7 +77,7 @@ func TestOverlappingParticipationKeys(t *testing.T) {
7277 genesisHash := crypto .HashObj (genesis )
7378 rootKeys := make (map [int ]* account.Root )
7479 regTransactions := make (map [int ]transactions.SignedTxn )
75- lastRound := uint64 (64 )
80+ lastRound := uint64 (39 ) // check 3 rounds of keys rotations
7681
7782 // prepare the participation keys ahead of time.
7883 for round := uint64 (1 ); round < lastRound ; round ++ {
@@ -81,9 +86,9 @@ func TestOverlappingParticipationKeys(t *testing.T) {
8186 }
8287 acctIdx := (round - 1 ) % 10
8388 txStartRound := round
84- txEndRound := txStartRound + 36 + 10
85- regStartRound := round + 32
86- regEndRound := regStartRound + 11
89+ txEndRound := txStartRound + 10 + 4
90+ regStartRound := round
91+ regEndRound := regStartRound + 11 + 4
8792 err = prepareParticipationKey (a , & fixture , acctIdx , txStartRound , txEndRound , regStartRound , regEndRound , genesisHash , rootKeys , regTransactions )
8893 a .NoError (err )
8994 }
@@ -97,13 +102,13 @@ func TestOverlappingParticipationKeys(t *testing.T) {
97102 currentRound ++
98103 if (currentRound - 1 )% 10 < uint64 (accountsNum ) {
99104 acctIdx := (currentRound - 1 ) % 10
100- startRound := currentRound + 2
101- endRound := startRound + 36 + 10 - 2
102- regStartRound := currentRound + 32
103- regEndRound := regStartRound + 11
104- err = addParticipationKey (a , & fixture , acctIdx , startRound , endRound , regTransactions )
105+ startRound := currentRound + 2 // +2 and -2 below to balance, start/end must match in part key file name
106+ endRound := startRound + 10 + 4 - 2
107+ regStartRound := currentRound
108+ regEndRound := regStartRound + 11 + 4
109+ pk , err : = addParticipationKey (a , & fixture , acctIdx , startRound , endRound , regTransactions )
105110 a .NoError (err )
106- t .Logf ("[.] Round %d, Added reg key for node %d range [%d..%d]\n " , currentRound , acctIdx , regStartRound , regEndRound )
111+ t .Logf ("[.] Round %d, Added reg key for node %d range [%d..%d] %s \n " , currentRound , acctIdx , regStartRound , regEndRound , hex . EncodeToString ( pk [: 8 ]) )
107112 } else {
108113 t .Logf ("[.] Round %d\n " , currentRound )
109114 }
@@ -115,25 +120,22 @@ func TestOverlappingParticipationKeys(t *testing.T) {
115120
116121}
117122
118- func addParticipationKey (a * require.Assertions , fixture * fixtures.RestClientFixture , acctNum uint64 , startRound , endRound uint64 , regTransactions map [int ]transactions.SignedTxn ) error {
123+ func addParticipationKey (a * require.Assertions , fixture * fixtures.RestClientFixture , acctNum uint64 , startRound , endRound uint64 , regTransactions map [int ]transactions.SignedTxn ) (crypto. OneTimeSignatureVerifier , error ) {
119124 dataDir := fixture .NodeDataDirs ()[acctNum ]
120125 nc := fixture .GetNodeControllerForDataDir (dataDir )
121126 genesisDir , err := nc .GetGenesisDir ()
122127
123128 partKeyName := filepath .Join (dataDir , config .PartKeyFilename ("Wallet" , startRound , endRound ))
124129 partKeyNameTarget := filepath .Join (genesisDir , config .PartKeyFilename ("Wallet" , startRound , endRound ))
125130
126- // make the rename in the background to ensure it won't take too long. We have ~32 rounds to complete this.
131+ // make the rename in the background to ensure it won't take too long. We have ~4 rounds to complete this.
127132 go os .Rename (partKeyName , partKeyNameTarget )
128133
129134 signedTxn := regTransactions [int (startRound - 2 )]
130135 a .NotEmpty (signedTxn .Sig )
131136 _ , err = fixture .GetAlgodClientForController (nc ).SendRawTransaction (signedTxn )
132- if err != nil {
133- a .NoError (err )
134- return err
135- }
136- return err
137+ a .NoError (err )
138+ return signedTxn .Txn .KeyregTxnFields .VotePK , err
137139}
138140
139141func prepareParticipationKey (a * require.Assertions , fixture * fixtures.RestClientFixture , acctNum uint64 , txStartRound , txEndRound , regStartRound , regEndRound uint64 , genesisHash crypto.Digest , rootKeys map [int ]* account.Root , regTransactions map [int ]transactions.SignedTxn ) error {
@@ -190,15 +192,15 @@ func prepareParticipationKey(a *require.Assertions, fixture *fixtures.RestClient
190192 return err
191193 }
192194
193- persistedPerticipation , err := account .FillDBWithParticipationKeys (partkeyHandle , rootAccount .Address (), basics .Round (regStartRound ), basics .Round (regEndRound ), fixture .LibGoalFixture .Genesis ().PartKeyDilution )
195+ persistedParticipation , err := account .FillDBWithParticipationKeys (partkeyHandle , rootAccount .Address (), basics .Round (regStartRound ), basics .Round (regEndRound ), fixture .LibGoalFixture .Genesis ().PartKeyDilution )
194196 if err != nil {
195197 a .NoError (err )
196198 return err
197199 }
198200 partkeyHandle .Vacuum (context .Background ())
199- persistedPerticipation .Close ()
201+ persistedParticipation .Close ()
200202
201- unsignedTxn := persistedPerticipation .GenerateRegistrationTransaction (basics.MicroAlgos {Raw : 1000 }, basics .Round (txStartRound ), basics .Round (txEndRound ), [32 ]byte {})
203+ unsignedTxn := persistedParticipation .GenerateRegistrationTransaction (basics.MicroAlgos {Raw : 1000 }, basics .Round (txStartRound ), basics .Round (txEndRound ), [32 ]byte {})
202204 copy (unsignedTxn .GenesisHash [:], genesisHash [:])
203205 if err != nil {
204206 a .NoError (err )
0 commit comments