Skip to content

Commit

Permalink
port few small changes off the main PR into this one, for faster revi…
Browse files Browse the repository at this point in the history
…ewing. (#2129)

This PR adds a ParticipationKeysRefreshInterval config option that would replace the hard-coded 60-second value used.
  • Loading branch information
tsachiherman authored May 5, 2021
1 parent 1341f39 commit 76aaa2d
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions agreement/fuzzer/fuzzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func MakeFuzzer(config FuzzerConfig) *Fuzzer {
crashAccessors: make([]db.Accessor, config.NodesCount),
accounts: make([]account.Participation, config.NodesCount),
balances: make(map[basics.Address]basics.AccountData),
accountAccessors: make([]db.Accessor, config.NodesCount*2),
accountAccessors: make([]db.Accessor, config.NodesCount),
ledgers: make([]*testLedger, config.NodesCount),
agreementParams: make([]agreement.Parameters, config.NodesCount),
tickGranularity: time.Millisecond * 300,
Expand Down Expand Up @@ -196,7 +196,7 @@ func (n *Fuzzer) initAccountsAndBalances(rootSeed []byte, onlineNodes []bool) er
if err != nil {
return err
}
n.accountAccessors[i*2+0] = rootAccess
n.accountAccessors[i] = rootAccess

seed = sha256.Sum256(seed[:])
root, err := account.ImportRoot(rootAccess, seed)
Expand Down
4 changes: 4 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ type Local struct {
// Time interval in nanoseconds for generating accountUpdates telemetry event
AccountUpdatesStatsInterval time.Duration `version[17]:"5000000000"`

// ParticipationKeysRefreshInterval is the duration between two consecutive checks to see if new participation
// keys have been placed on the genesis directory.
ParticipationKeysRefreshInterval time.Duration `version[17]:"60000000000"`

// DisableNetworking disables all the incoming and outgoing communication a node would perform. This is useful
// when we have a single-node private network, where there is no other nodes that need to be communicated with.
// features like catchpoint catchup would be rendered completly non-operational, and many of the node inner
Expand Down
1 change: 1 addition & 0 deletions config/local_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ var defaultLocal = Local{
OptimizeAccountsDatabaseOnStartup: false,
OutgoingMessageFilterBucketCount: 3,
OutgoingMessageFilterBucketSize: 128,
ParticipationKeysRefreshInterval: 60000000000,
PeerConnectionsUpdateInterval: 3600,
PeerPingPeriodSeconds: 0,
PriorityPeers: map[string]bool{},
Expand Down
14 changes: 9 additions & 5 deletions data/account/participation.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (part Participation) VotingSigner() crypto.OneTimeSigner {
}

// GenerateRegistrationTransaction returns a transaction object for registering a Participation with its parent.
func (part Participation) GenerateRegistrationTransaction(fee basics.MicroAlgos, txnFirstValid, txnLastValid basics.Round, leaseBytes [32]byte, params config.ConsensusParams) transactions.Transaction {
func (part Participation) GenerateRegistrationTransaction(fee basics.MicroAlgos, txnFirstValid, txnLastValid basics.Round, leaseBytes [32]byte) transactions.Transaction {
t := transactions.Transaction{
Type: protocol.KeyRegistrationTx,
Header: transactions.Header{
Expand Down Expand Up @@ -191,7 +191,6 @@ func FillDBWithParticipationKeys(store db.Accessor, address basics.Address, firs
},
Store: store,
}

// Persist the Participation into the database
err = part.Persist()
return part, err
Expand All @@ -203,19 +202,24 @@ func (part PersistedParticipation) Persist() error {
voting := part.Voting.Snapshot()
rawVoting := protocol.Encode(&voting)

return part.Store.Atomic(func(ctx context.Context, tx *sql.Tx) error {
err := part.Store.Atomic(func(ctx context.Context, tx *sql.Tx) error {
err := partInstallDatabase(tx)
if err != nil {
return fmt.Errorf("Participation.persist: failed to install database: %v", err)
return fmt.Errorf("failed to install database: %w", err)
}

_, err = tx.Exec("INSERT INTO ParticipationAccount (parent, vrf, voting, firstValid, lastValid, keyDilution) VALUES (?, ?, ?, ?, ?, ?)",
part.Parent[:], rawVRF, rawVoting, part.FirstValid, part.LastValid, part.KeyDilution)
if err != nil {
return fmt.Errorf("Participation.persist: failed to insert account: %v", err)
return fmt.Errorf("failed to insert account: %w", err)
}
return nil
})

if err != nil {
err = fmt.Errorf("PersistedParticipation.Persist: %w", err)
}
return err
}

// Migrate is called when loading participation keys.
Expand Down
1 change: 1 addition & 0 deletions installer/config.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"OptimizeAccountsDatabaseOnStartup": false,
"OutgoingMessageFilterBucketCount": 3,
"OutgoingMessageFilterBucketSize": 128,
"ParticipationKeysRefreshInterval": 60000000000,
"PeerConnectionsUpdateInterval": 3600,
"PeerPingPeriodSeconds": 0,
"PriorityPeers": {},
Expand Down
2 changes: 1 addition & 1 deletion libgoal/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (c *Client) MakeUnsignedGoOnlineTx(address string, part *account.Participat
parsedLastValid := basics.Round(lastValid)
parsedFee := basics.MicroAlgos{Raw: fee}

goOnlineTransaction := part.GenerateRegistrationTransaction(parsedFee, parsedFrstValid, parsedLastValid, leaseBytes, cparams)
goOnlineTransaction := part.GenerateRegistrationTransaction(parsedFee, parsedFrstValid, parsedLastValid, leaseBytes)
if cparams.SupportGenesisHash {
var genHash crypto.Digest
copy(genHash[:], params.GenesisHash)
Expand Down
2 changes: 2 additions & 0 deletions netdeploy/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -146,6 +147,7 @@ func (n Network) NodeDataDirs() []string {
for _, nodeDir := range n.nodeDirs {
directories = append(directories, n.getNodeFullPath(nodeDir))
}
sort.Strings(directories)
return directories
}

Expand Down
4 changes: 1 addition & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ import (
"github.com/algorand/go-deadlock"
)

const participationKeyCheckSecs = 60

// StatusReport represents the current basic status of the node
type StatusReport struct {
LastRound basics.Round
Expand Down Expand Up @@ -704,7 +702,7 @@ func (node *AlgorandFullNode) GetPendingTxnsFromPool() ([]transactions.SignedTxn
// Reload participation keys from disk periodically
func (node *AlgorandFullNode) checkForParticipationKeys() {
defer node.monitoringRoutinesWaitGroup.Done()
ticker := time.NewTicker(participationKeyCheckSecs * time.Second)
ticker := time.NewTicker(node.config.ParticipationKeysRefreshInterval)
for {
select {
case <-ticker.C:
Expand Down
1 change: 1 addition & 0 deletions test/testdata/configs/config-v17.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"OptimizeAccountsDatabaseOnStartup": false,
"OutgoingMessageFilterBucketCount": 3,
"OutgoingMessageFilterBucketSize": 128,
"ParticipationKeysRefreshInterval": 60000000000,
"PeerConnectionsUpdateInterval": 3600,
"PeerPingPeriodSeconds": 0,
"PriorityPeers": {},
Expand Down

0 comments on commit 76aaa2d

Please sign in to comment.