summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Akiki <stephen.akiki@algorand.com>2022-07-11 13:03:11 -0400
committerStephen Akiki <stephen.akiki@algorand.com>2022-07-11 13:04:40 -0400
commit513e148b61e15aca939783c114592d8593746faf (patch)
treec214ce11a724875689c5cbc19483955ad80dd2e3
parent2fa8ef665dba64236913b512d77b9e74e9c828ac (diff)
-rw-r--r--data/account/participationRegistry.go8
-rw-r--r--data/accountManager.go33
-rw-r--r--util/db/initialize.go12
3 files changed, 24 insertions, 29 deletions
diff --git a/data/account/participationRegistry.go b/data/account/participationRegistry.go
index 142874a66..a6544a91d 100644
--- a/data/account/participationRegistry.go
+++ b/data/account/participationRegistry.go
@@ -24,8 +24,6 @@ import (
"fmt"
"time"
- "github.com/mattn/go-sqlite3"
-
"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/crypto/merklesignature"
@@ -286,12 +284,6 @@ func makeParticipationRegistry(accessor db.Pair, log logging.Logger) (*participa
err := db.Initialize(accessor.Wdb, migrations)
if err != nil {
accessor.Close()
-
- var sqlError *sqlite3.Error
- if errors.As(err, &sqlError) {
- return nil, fmt.Errorf("unable to initialize participation registry database: %w. Sql error - Code: %d, Extended Code: %d", err, sqlError.Code, sqlError.ExtendedCode)
- }
-
return nil, fmt.Errorf("unable to initialize participation registry database: %w", err)
}
diff --git a/data/accountManager.go b/data/accountManager.go
index 5cced846e..9763c4481 100644
--- a/data/accountManager.go
+++ b/data/accountManager.go
@@ -29,21 +29,12 @@ import (
"github.com/algorand/go-algorand/logging/telemetryspec"
)
-type accountPartKey struct {
- // Persisted participation record
- part account.PersistedParticipation
- // If true, then this participation record was actually deleted
- // but is recorded to ensure that duplicate participation keys
- // are not added
- ephemeral bool
-}
-
// AccountManager loads and manages accounts for the node
type AccountManager struct {
mu deadlock.Mutex
// syncronized by mu
- partKeys map[account.ParticipationKeyIdentity]accountPartKey
+ partKeys map[account.ParticipationKeyIdentity]account.PersistedParticipation
// Map to keep track of accounts for which we've sent
// AccountRegistered telemetry events
@@ -58,7 +49,7 @@ type AccountManager struct {
func MakeAccountManager(log logging.Logger, registry account.ParticipationRegistry) *AccountManager {
manager := &AccountManager{}
manager.log = log
- manager.partKeys = make(map[account.ParticipationKeyIdentity]accountPartKey)
+ manager.partKeys = make(map[account.ParticipationKeyIdentity]account.PersistedParticipation)
manager.registeredAccounts = make(map[string]bool)
manager.registry = registry
@@ -116,6 +107,11 @@ func (manager *AccountManager) AddParticipation(participation account.PersistedP
if err != nil && err != account.ErrAlreadyInserted {
manager.log.Warnf("Failed to insert participation key.")
}
+
+ if err == account.ErrAlreadyInserted {
+ return false
+ }
+
manager.log.Infof("Inserted key (%s) for account (%s) first valid (%d) last valid (%d)\n",
pid, participation.Parent, participation.FirstValid, participation.LastValid)
@@ -140,7 +136,9 @@ func (manager *AccountManager) AddParticipation(participation account.PersistedP
return false
}
- manager.partKeys[partkeyID] = accountPartKey{participation, ephemeral}
+ if !ephemeral {
+ manager.partKeys[partkeyID] = participation
+ }
addressString := address.String()
manager.log.EventWithDetails(telemetryspec.Accounts, telemetryspec.PartKeyRegisteredEvent, telemetryspec.PartKeyRegisteredEventDetails{
@@ -167,17 +165,12 @@ func (manager *AccountManager) DeleteOldKeys(latestHdr bookkeeping.BlockHeader,
manager.mu.Lock()
pendingItems := make(map[string]<-chan error, len(manager.partKeys))
- accountPartKeys := make([]accountPartKey, 0, len(manager.partKeys))
+ partKeys := make([]account.PersistedParticipation, 0, len(manager.partKeys))
for _, part := range manager.partKeys {
- accountPartKeys = append(accountPartKeys, part)
+ partKeys = append(partKeys, part)
}
manager.mu.Unlock()
- for _, accountPartKey := range accountPartKeys {
- if accountPartKey.ephemeral {
- continue
- }
-
- part := accountPartKey.part
+ for _, part := range partKeys {
// We need a key for round r+1 for agreement.
nextRound := latestHdr.Round + 1
diff --git a/util/db/initialize.go b/util/db/initialize.go
index 71141707c..36bf83770 100644
--- a/util/db/initialize.go
+++ b/util/db/initialize.go
@@ -21,6 +21,8 @@ import (
"database/sql"
"errors"
"fmt"
+
+ "github.com/mattn/go-sqlite3"
)
// Migration is used to upgrade a database from one version to the next.
@@ -32,9 +34,17 @@ type Migration func(ctx context.Context, tx *sql.Tx, newDatabase bool) error
// The Migration slice is ordered and must contain all prior migrations
// in order to determine which need to be called.
func Initialize(accessor Accessor, migrations []Migration) error {
- return accessor.Atomic(func(ctx context.Context, tx *sql.Tx) error {
+ err := accessor.Atomic(func(ctx context.Context, tx *sql.Tx) error {
return InitializeWithContext(ctx, tx, migrations)
})
+
+ var sqlError *sqlite3.Error
+ if errors.As(err, &sqlError) {
+ return fmt.Errorf("%w. Sql error - Code: %d, Extended Code: %d", err, sqlError.Code, sqlError.ExtendedCode)
+ }
+
+ return err
+
}
// InitializeWithContext creates or upgrades a DB accessor.